6 #include "plasmashell_interface.h" 8 #include "resource_p.h" 10 #include "surface_interface.h" 14 #include <wayland-server.h> 15 #include <wayland-plasma-shell-server-protocol.h> 22 class PlasmaShellInterface::Private :
public Global::Private
25 Private(PlasmaShellInterface *q, Display *d);
30 static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface);
31 void bind(wl_client *client, uint32_t version, uint32_t
id)
override;
32 void createSurface(wl_client *client, uint32_t version, uint32_t
id, SurfaceInterface *surface, wl_resource *parentResource);
34 PlasmaShellInterface *q;
35 static const struct org_kde_plasma_shell_interface s_interface;
36 static const quint32 s_version;
39 const quint32 PlasmaShellInterface::Private::s_version = 6;
41 PlasmaShellInterface::Private::Private(PlasmaShellInterface *q, Display *d)
42 : Global::Private(d, &org_kde_plasma_shell_interface, s_version)
48 const struct org_kde_plasma_shell_interface PlasmaShellInterface::Private::s_interface = {
54 class PlasmaShellSurfaceInterface::Private :
public Resource::Private
57 Private(PlasmaShellSurfaceInterface *q, PlasmaShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource);
59 SurfaceInterface *surface;
62 bool m_positionSet =
false;
64 bool m_skipTaskbar =
false;
65 bool m_skipSwitcher =
false;
66 bool panelTakesFocus =
false;
70 static void setOutputCallback(wl_client *client, wl_resource *resource, wl_resource *output);
71 static void setPositionCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y);
72 static void setRoleCallback(wl_client *client, wl_resource *resource, uint32_t
role);
73 static void setPanelBehaviorCallback(wl_client *client, wl_resource *resource, uint32_t flag);
74 static void setSkipTaskbarCallback(wl_client *client, wl_resource *resource, uint32_t skip);
75 static void setSkipSwitcherCallback(wl_client *client, wl_resource *resource, uint32_t skip);
76 static void panelAutoHideHideCallback(wl_client *client, wl_resource *resource);
77 static void panelAutoHideShowCallback(wl_client *client, wl_resource *resource);
78 static void panelTakesFocusCallback(wl_client *client, wl_resource *resource, uint32_t takesFocus);
84 PlasmaShellSurfaceInterface *q_func() {
85 return reinterpret_cast<PlasmaShellSurfaceInterface *
>(q);
88 static const struct org_kde_plasma_surface_interface s_interface;
91 PlasmaShellInterface::PlasmaShellInterface(Display *display,
QObject *
parent)
92 : Global(new Private(this, display), parent)
96 PlasmaShellInterface::~PlasmaShellInterface() =
default;
98 void PlasmaShellInterface::Private::bind(wl_client *client, uint32_t version, uint32_t
id)
100 auto c = display->getConnection(client);
101 wl_resource *shell = c->createResource(&org_kde_plasma_shell_interface, qMin(version, s_version),
id);
103 wl_client_post_no_memory(client);
106 wl_resource_set_implementation(shell, &s_interface,
this,
nullptr);
109 void PlasmaShellInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface)
111 auto s =
reinterpret_cast<PlasmaShellInterface::Private*
>(wl_resource_get_user_data(resource));
112 s->createSurface(client, wl_resource_get_version(resource),
id, SurfaceInterface::get(surface), resource);
115 void PlasmaShellInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t
id, SurfaceInterface *surface, wl_resource *parentResource)
117 auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(),
118 [surface](PlasmaShellSurfaceInterface *s) {
119 return surface == s->surface();
122 if (it != surfaces.constEnd()) {
123 wl_resource_post_error(surface->resource(), WL_DISPLAY_ERROR_INVALID_OBJECT,
"PlasmaShellSurface already created");
126 PlasmaShellSurfaceInterface *shellSurface =
new PlasmaShellSurfaceInterface(q, surface, parentResource);
127 surfaces << shellSurface;
129 [
this, shellSurface] {
130 surfaces.removeAll(shellSurface);
133 shellSurface->d->create(display->getConnection(client), version, id);
134 Q_EMIT q->surfaceCreated(shellSurface);
140 PlasmaShellSurfaceInterface::Private::Private(PlasmaShellSurfaceInterface *q, PlasmaShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource)
141 : Resource::Private(q, shell, parentResource, &org_kde_plasma_surface_interface, &s_interface)
147 const struct org_kde_plasma_surface_interface PlasmaShellSurfaceInterface::Private::s_interface = {
148 resourceDestroyedCallback,
152 setPanelBehaviorCallback,
153 setSkipTaskbarCallback,
154 panelAutoHideHideCallback,
155 panelAutoHideShowCallback,
156 panelTakesFocusCallback,
157 setSkipSwitcherCallback
161 PlasmaShellSurfaceInterface::PlasmaShellSurfaceInterface(PlasmaShellInterface *shell, SurfaceInterface *
parent, wl_resource *parentResource)
162 : Resource(new Private(this, shell, parent, parentResource))
164 auto unsetSurface = [
this] {
166 d->surface =
nullptr;
168 connect(parent, &Resource::unbound,
this, unsetSurface);
172 PlasmaShellSurfaceInterface::~PlasmaShellSurfaceInterface() =
default;
184 PlasmaShellSurfaceInterface::Private *PlasmaShellSurfaceInterface::d_func()
const 186 return reinterpret_cast<PlasmaShellSurfaceInterface::Private*
>(d.
data());
189 void PlasmaShellSurfaceInterface::Private::setOutputCallback(wl_client *client, wl_resource *resource, wl_resource *output)
197 void PlasmaShellSurfaceInterface::Private::setPositionCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y)
199 auto s = cast<Private>(resource);
200 Q_ASSERT(client == *s->client);
201 s->setPosition(
QPoint(x, y));
204 void PlasmaShellSurfaceInterface::Private::setPosition(
const QPoint &globalPos)
206 if (m_globalPos == globalPos && m_positionSet) {
209 m_positionSet =
true;
210 m_globalPos = globalPos;
212 Q_EMIT q->positionChanged();
215 void PlasmaShellSurfaceInterface::Private::setRoleCallback(wl_client *client, wl_resource *resource, uint32_t
role)
217 auto s = cast<Private>(resource);
218 Q_ASSERT(client == *s->client);
222 void PlasmaShellSurfaceInterface::Private::setRole(uint32_t role)
226 case ORG_KDE_PLASMA_SURFACE_ROLE_DESKTOP:
229 case ORG_KDE_PLASMA_SURFACE_ROLE_PANEL:
232 case ORG_KDE_PLASMA_SURFACE_ROLE_ONSCREENDISPLAY:
235 case ORG_KDE_PLASMA_SURFACE_ROLE_NOTIFICATION:
238 case ORG_KDE_PLASMA_SURFACE_ROLE_TOOLTIP:
241 case ORG_KDE_PLASMA_SURFACE_ROLE_CRITICALNOTIFICATION:
244 case ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL:
257 void PlasmaShellSurfaceInterface::Private::setPanelBehaviorCallback(wl_client *client, wl_resource *resource, uint32_t flag)
259 auto s = cast<Private>(resource);
260 Q_ASSERT(client == *s->client);
261 s->setPanelBehavior(org_kde_plasma_surface_panel_behavior(flag));
264 void PlasmaShellSurfaceInterface::Private::setSkipTaskbarCallback(wl_client *client, wl_resource *resource, uint32_t skip)
266 auto s = cast<Private>(resource);
267 Q_ASSERT(client == *s->client);
268 s->m_skipTaskbar = (bool)skip;
269 Q_EMIT s->q_func()->skipTaskbarChanged();
272 void PlasmaShellSurfaceInterface::Private::setSkipSwitcherCallback(wl_client *client, wl_resource *resource, uint32_t skip)
274 auto s = cast<Private>(resource);
275 Q_ASSERT(client == *s->client);
276 s->m_skipSwitcher = (bool)skip;
277 Q_EMIT s->q_func()->skipSwitcherChanged();
280 void PlasmaShellSurfaceInterface::Private::panelAutoHideHideCallback(wl_client *client, wl_resource *resource)
282 auto s = cast<Private>(resource);
283 Q_ASSERT(client == *s->client);
284 if (s->m_role !=
Role::Panel || s->m_panelBehavior != PanelBehavior::AutoHide) {
285 wl_resource_post_error(s->resource, ORG_KDE_PLASMA_SURFACE_ERROR_PANEL_NOT_AUTO_HIDE,
"Not an auto hide panel");
288 Q_EMIT s->q_func()->panelAutoHideHideRequested();
291 void PlasmaShellSurfaceInterface::Private::panelAutoHideShowCallback(wl_client *client, wl_resource *resource)
293 auto s = cast<Private>(resource);
294 Q_ASSERT(client == *s->client);
295 if (s->m_role !=
Role::Panel || s->m_panelBehavior != PanelBehavior::AutoHide) {
296 wl_resource_post_error(s->resource, ORG_KDE_PLASMA_SURFACE_ERROR_PANEL_NOT_AUTO_HIDE,
"Not an auto hide panel");
299 Q_EMIT s->q_func()->panelAutoHideShowRequested();
302 void PlasmaShellSurfaceInterface::Private::panelTakesFocusCallback(wl_client *client, wl_resource *resource, uint32_t takesFocus)
304 auto s = cast<Private>(resource);
305 Q_ASSERT(client == *s->client);
306 if (s->panelTakesFocus == takesFocus) {
309 s->panelTakesFocus = takesFocus;
310 Q_EMIT s->q_func()->panelTakesFocusChanged();
313 void PlasmaShellSurfaceInterface::Private::setPanelBehavior(org_kde_plasma_surface_panel_behavior behavior)
317 case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_AUTO_HIDE:
318 newBehavior = PanelBehavior::AutoHide;
320 case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_CAN_COVER:
321 newBehavior = PanelBehavior::WindowsCanCover;
323 case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_GO_BELOW:
324 newBehavior = PanelBehavior::WindowsGoBelow;
326 case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE:
330 if (m_panelBehavior == newBehavior) {
333 m_panelBehavior = newBehavior;
335 Q_EMIT q->panelBehaviorChanged();
338 QPoint PlasmaShellSurfaceInterface::position()
const 341 return d->m_globalPos;
350 bool PlasmaShellSurfaceInterface::isPositionSet()
const 353 return d->m_positionSet;
359 return d->m_panelBehavior;
362 bool PlasmaShellSurfaceInterface::skipTaskbar()
const 365 return d->m_skipTaskbar;
368 bool PlasmaShellSurfaceInterface::skipSwitcher()
const 371 return d->m_skipSwitcher;
374 void PlasmaShellSurfaceInterface::hideAutoHidingPanel()
380 org_kde_plasma_surface_send_auto_hidden_panel_hidden(d->resource);
383 void PlasmaShellSurfaceInterface::showAutoHidingPanel()
389 org_kde_plasma_surface_send_auto_hidden_panel_shown(d->resource);
392 bool PlasmaShellSurfaceInterface::panelTakesFocus()
const 395 return d->panelTakesFocus;
400 return Private::get<PlasmaShellSurfaceInterface>(native);
The Surface represents a tooltip.
Global for the org_kde_plasma_shell interface.
The Surface represents a desktop, normally stacked below all other surfaces.
The Surface represents a critical notification, like battery is running out.
The Surface represents a notification.
void setPanelBehavior(PanelBehavior behavior)
Sets the PanelBehavior for a PlasmaShellSurface with Role Role::Panel.
void setRole(Role role)
Changes the requested Role to role.
The Surface represents an on screen display, like a volume changed notification.
Resource for the org_kde_plasma_shell_surface interface.
Resource representing a wl_surface.
The Surface represents a panel (dock), normally stacked above normal surfaces.
void setPosition(const QPoint &point)
Requests to position this PlasmaShellSurface at point in global coordinates.
PanelBehavior
Describes how a PlasmaShellSurfaceInterface with role Role::Panel should behave.
Role
Describes possible roles this PlasmaShellSurfaceInterface can have.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void destroyed(QObject *obj)
Role
Describes possible roles this PlasmaShellSurface can have.
PanelBehavior
Describes how a PlasmaShellSurface with role Role::Panel should behave.