KWin
Loading...
Searching...
No Matches
plasmashell.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
3 SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7#include "plasmashell.h"
8#include "display.h"
9#include "surface.h"
10#include "utils/resource.h"
11
12#include <qwayland-server-plasma-shell.h>
13
14#include <QPointer>
15
16namespace KWin
17{
18static const quint32 s_version = 8;
19static QList<PlasmaShellSurfaceInterface *> s_shellSurfaces;
20
21class PlasmaShellInterfacePrivate : public QtWaylandServer::org_kde_plasma_shell
22{
23public:
25
26private:
27 void org_kde_plasma_shell_get_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface) override;
29};
30
32 : QtWaylandServer::org_kde_plasma_shell(*display, s_version)
33 , q(_q)
34{
35}
36
37class PlasmaShellSurfaceInterfacePrivate : public QtWaylandServer::org_kde_plasma_surface
38{
39public:
41
42 QPointer<SurfaceInterface> surface;
47 bool m_positionSet = false;
48 bool m_skipTaskbar = false;
49 bool m_skipSwitcher = false;
50 bool m_panelTakesFocus = false;
52
53private:
54 void org_kde_plasma_surface_destroy_resource(Resource *resource) override;
55 void org_kde_plasma_surface_destroy(Resource *resource) override;
56 void org_kde_plasma_surface_set_output(Resource *resource, struct ::wl_resource *output) override;
57 void org_kde_plasma_surface_set_position(Resource *resource, int32_t x, int32_t y) override;
58 void org_kde_plasma_surface_set_role(Resource *resource, uint32_t role) override;
59 void org_kde_plasma_surface_set_panel_behavior(Resource *resource, uint32_t flag) override;
60 void org_kde_plasma_surface_set_skip_taskbar(Resource *resource, uint32_t skip) override;
61 void org_kde_plasma_surface_panel_auto_hide_hide(Resource *resource) override;
62 void org_kde_plasma_surface_panel_auto_hide_show(Resource *resource) override;
63 void org_kde_plasma_surface_set_panel_takes_focus(Resource *resource, uint32_t takes_focus) override;
64 void org_kde_plasma_surface_set_skip_switcher(Resource *resource, uint32_t skip) override;
65 void org_kde_plasma_surface_open_under_cursor(Resource *resource) override;
66};
67
69 : QObject(parent)
70 , d(new PlasmaShellInterfacePrivate(this, display))
71{
72}
73
75
76void PlasmaShellInterfacePrivate::org_kde_plasma_shell_get_surface(QtWaylandServer::org_kde_plasma_shell::Resource *resource,
77 uint32_t id,
78 struct ::wl_resource *surface)
79{
81 if (!s) {
82 wl_resource_post_error(resource->handle, 0, "Invalid surface");
83 return;
84 }
85
87 wl_resource_post_error(resource->handle, 0, "org_kde_plasma_shell_surface already exists");
88 return;
89 }
90
91 wl_resource *shell_resource = wl_resource_create(resource->client(), &org_kde_plasma_surface_interface, resource->version(), id);
92
93 auto shellSurface = new PlasmaShellSurfaceInterface(s, shell_resource);
94 s_shellSurfaces.append(shellSurface);
95
96 QObject::connect(shellSurface, &QObject::destroyed, [shellSurface]() {
97 s_shellSurfaces.removeOne(shellSurface);
98 });
99
100 Q_EMIT q->surfaceCreated(shellSurface);
101}
102
103/*********************************
104 * ShellSurfaceInterface
105 *********************************/
107 : QtWaylandServer::org_kde_plasma_surface(resource)
108 , surface(surface)
109 , q(_q)
110{
111}
112
113PlasmaShellSurfaceInterface::PlasmaShellSurfaceInterface(SurfaceInterface *surface, wl_resource *resource)
114 : d(new PlasmaShellSurfaceInterfacePrivate(this, surface, resource))
115{
116}
117
119
121{
122 return d->surface;
123}
124
125void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_destroy(Resource *resource)
126{
127 wl_resource_destroy(resource->handle);
128}
129
130void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_destroy_resource(Resource *resource)
131{
132 delete q;
133}
134
135void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_set_output(Resource *resource, struct ::wl_resource *output)
136{
137 // TODO: implement
138}
139
140void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_set_position(Resource *resource, int32_t x, int32_t y)
141{
142 QPoint globalPos(x, y);
143 if (m_globalPos == globalPos && m_positionSet) {
144 return;
145 }
146 m_positionSet = true;
147 m_globalPos = globalPos;
148 Q_EMIT q->positionChanged();
149}
150
151void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_open_under_cursor(Resource *resource)
152{
153 if (surface && surface->buffer()) {
154 wl_resource_post_error(resource->handle, -1, "open_under_cursor: surface has a buffer");
155 }
157 Q_EMIT q->openUnderCursorRequested();
158}
159
160void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_set_role(Resource *resource, uint32_t role)
161{
163 switch (role) {
164 case role_desktop:
166 break;
167 case role_panel:
169 break;
170 case role_onscreendisplay:
172 break;
173 case role_notification:
175 break;
176 case role_tooltip:
178 break;
179 case role_criticalnotification:
181 break;
182 case role_appletpopup:
184 break;
185 case role_normal:
186 default:
188 break;
189 }
190 if (r == m_role) {
191 return;
192 }
193 m_role = r;
194 Q_EMIT q->roleChanged();
195}
196
197void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_set_panel_behavior(Resource *resource, uint32_t flag)
198{
200 switch (flag) {
201 case panel_behavior_auto_hide:
203 break;
204 case panel_behavior_windows_can_cover:
206 break;
207 case panel_behavior_windows_go_below:
209 break;
210 case panel_behavior_always_visible:
211 default:
212 break;
213 }
214 if (m_panelBehavior == newBehavior) {
215 return;
216 }
217 m_panelBehavior = newBehavior;
218 Q_EMIT q->panelBehaviorChanged();
219}
220
221void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_set_skip_taskbar(Resource *resource, uint32_t skip)
222{
223 m_skipTaskbar = (bool)skip;
224 Q_EMIT q->skipTaskbarChanged();
225}
226
227void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_set_skip_switcher(Resource *resource, uint32_t skip)
228{
229 m_skipSwitcher = (bool)skip;
230 Q_EMIT q->skipSwitcherChanged();
231}
232
233void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_panel_auto_hide_hide(Resource *resource)
234{
238 wl_resource_post_error(resource->handle, error_panel_not_auto_hide, "Not an auto hide panel");
239 return;
240 }
242}
243
244void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_panel_auto_hide_show(Resource *resource)
245{
247 wl_resource_post_error(resource->handle, error_panel_not_auto_hide, "Not an auto hide panel");
248 return;
249 }
251}
252
253void PlasmaShellSurfaceInterfacePrivate::org_kde_plasma_surface_set_panel_takes_focus(Resource *resource, uint32_t takesFocus)
254{
255 if (m_panelTakesFocus == takesFocus) {
256 return;
257 }
258 m_panelTakesFocus = takesFocus;
259 Q_EMIT q->panelTakesFocusChanged();
260}
261
263{
264 return d->m_globalPos;
265}
266
271
273{
274 return d->m_positionSet;
275}
276
278{
279 return d->m_openUnderCursorRequested;
280}
281
286
288{
289 return d->m_skipTaskbar;
290}
291
293{
294 return d->m_skipSwitcher;
295}
296
298{
299 d->send_auto_hidden_panel_hidden();
300}
301
303{
304 d->send_auto_hidden_panel_shown();
305}
306
308{
309 return d->m_panelTakesFocus;
310}
311
313{
314 if (auto surfacePrivate = resource_cast<PlasmaShellSurfaceInterfacePrivate *>(native)) {
315 return surfacePrivate->q;
316 }
317 return nullptr;
318}
319
321{
322 for (PlasmaShellSurfaceInterface *shellSurface : std::as_const(s_shellSurfaces)) {
323 if (shellSurface->surface() == surface) {
324 return shellSurface;
325 }
326 }
327 return nullptr;
328}
329
330}
331
332#include "moc_plasmashell.cpp"
Class holding the Wayland server display loop.
Definition display.h:34
Global for the org_kde_plasma_shell interface.
Definition plasmashell.h:37
void surfaceCreated(KWin::PlasmaShellSurfaceInterface *)
PlasmaShellInterface(Display *display, QObject *parent)
PlasmaShellInterfacePrivate(PlasmaShellInterface *q, Display *display)
Resource for the org_kde_plasma_shell_surface interface.
Definition plasmashell.h:60
PanelBehavior panelBehavior() const
SurfaceInterface * surface() const
static PlasmaShellSurfaceInterface * get(wl_resource *native)
@ Desktop
The surface represents a desktop, normally stacked below all other surfaces.
@ CriticalNotification
The surface represents a critical notification, like battery is running out.
@ Notification
The surface represents a notification.
@ Panel
The surface represents a panel (dock), normally stacked above normal surfaces.
@ OnScreenDisplay
The surface represents an on screen display, like a volume changed notification.
@ ToolTip
The surface represents a tooltip.
@ AppletPopup
The surface represents an applet popup window.
@ WindowsGoBelow
Window are allowed to go below the panel.
@ AutoHide
The panel auto hides at a screen edge and returns on mouse press against edge.
@ WindowsCanCover
Windows are allowed to go above the panel, it raises on mouse press against screen edge.
@ AlwaysVisible
The panel should be always visible.
PlasmaShellSurfaceInterface * q
PlasmaShellSurfaceInterfacePrivate(PlasmaShellSurfaceInterface *q, SurfaceInterface *surface, wl_resource *resource)
QPointer< SurfaceInterface > surface
PlasmaShellSurfaceInterface::Role m_role
PlasmaShellSurfaceInterface::PanelBehavior m_panelBehavior
Resource representing a wl_surface.
Definition surface.h:80
static SurfaceInterface * get(wl_resource *native)
Definition surface.cpp:819