KWayland

plasmashell.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "plasmashell.h"
7 #include "event_queue.h"
8 #include "output.h"
9 #include "surface.h"
10 #include "wayland_pointer_p.h"
11 // Wayland
12 #include <wayland-plasma-shell-client-protocol.h>
13 
14 namespace KWayland
15 {
16 namespace Client
17 {
18 class Q_DECL_HIDDEN PlasmaShell::Private
19 {
20 public:
21  WaylandPointer<org_kde_plasma_shell, org_kde_plasma_shell_destroy> shell;
22  EventQueue *queue = nullptr;
23 };
24 
25 class Q_DECL_HIDDEN PlasmaShellSurface::Private
26 {
27 public:
28  Private(PlasmaShellSurface *q);
29  ~Private();
30  void setup(org_kde_plasma_surface *surface);
31 
32  WaylandPointer<org_kde_plasma_surface, org_kde_plasma_surface_destroy> surface;
33  QSize size;
34  QPointer<Surface> parentSurface;
36 
37  static PlasmaShellSurface *get(Surface *surface);
38 
39 private:
40  static void autoHidingPanelHiddenCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface);
41  static void autoHidingPanelShownCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface);
42 
43  PlasmaShellSurface *q;
44  static QVector<Private *> s_surfaces;
45  static const org_kde_plasma_surface_listener s_listener;
46 };
47 
48 QVector<PlasmaShellSurface::Private *> PlasmaShellSurface::Private::s_surfaces;
49 
50 PlasmaShell::PlasmaShell(QObject *parent)
51  : QObject(parent)
52  , d(new Private)
53 {
54 }
55 
56 PlasmaShell::~PlasmaShell()
57 {
58  release();
59 }
60 
62 {
63  if (!d->shell) {
64  return;
65  }
66  Q_EMIT interfaceAboutToBeDestroyed();
67  d->shell.destroy();
68 }
69 
71 {
72  if (!d->shell) {
73  return;
74  }
75  Q_EMIT interfaceAboutToBeReleased();
76  d->shell.release();
77 }
78 
79 void PlasmaShell::setup(org_kde_plasma_shell *shell)
80 {
81  Q_ASSERT(!d->shell);
82  Q_ASSERT(shell);
83  d->shell.setup(shell);
84 }
85 
87 {
88  d->queue = queue;
89 }
90 
92 {
93  return d->queue;
94 }
95 
97 {
98  Q_ASSERT(isValid());
99  auto kwS = Surface::get(surface);
100  if (kwS) {
101  if (auto s = PlasmaShellSurface::Private::get(kwS)) {
102  return s;
103  }
104  }
105  PlasmaShellSurface *s = new PlasmaShellSurface(parent);
108  auto w = org_kde_plasma_shell_get_surface(d->shell, surface);
109  if (d->queue) {
110  d->queue->addProxy(w);
111  }
112  s->setup(w);
113  s->d->parentSurface = QPointer<Surface>(kwS);
114  return s;
115 }
116 
118 {
119  return createSurface(*surface, parent);
120 }
121 
123 {
124  return d->shell.isValid();
125 }
126 
127 PlasmaShell::operator org_kde_plasma_shell *()
128 {
129  return d->shell;
130 }
131 
132 PlasmaShell::operator org_kde_plasma_shell *() const
133 {
134  return d->shell;
135 }
136 
137 PlasmaShellSurface::Private::Private(PlasmaShellSurface *q)
139  , q(q)
140 {
141  s_surfaces << this;
142 }
143 
144 PlasmaShellSurface::Private::~Private()
145 {
146  s_surfaces.removeAll(this);
147 }
148 
149 PlasmaShellSurface *PlasmaShellSurface::Private::get(Surface *surface)
150 {
151  if (!surface) {
152  return nullptr;
153  }
154  for (auto it = s_surfaces.constBegin(); it != s_surfaces.constEnd(); ++it) {
155  if ((*it)->parentSurface == surface) {
156  return (*it)->q;
157  }
158  }
159  return nullptr;
160 }
161 
162 void PlasmaShellSurface::Private::setup(org_kde_plasma_surface *s)
163 {
164  Q_ASSERT(s);
165  Q_ASSERT(!surface);
166  surface.setup(s);
167  org_kde_plasma_surface_add_listener(surface, &s_listener, this);
168 }
169 
170 const org_kde_plasma_surface_listener PlasmaShellSurface::Private::s_listener = {autoHidingPanelHiddenCallback, autoHidingPanelShownCallback};
171 
172 void PlasmaShellSurface::Private::autoHidingPanelHiddenCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface)
173 {
174  auto p = reinterpret_cast<PlasmaShellSurface::Private *>(data);
175  Q_ASSERT(p->surface == org_kde_plasma_surface);
176  Q_EMIT p->q->autoHidePanelHidden();
177 }
178 
179 void PlasmaShellSurface::Private::autoHidingPanelShownCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface)
180 {
181  auto p = reinterpret_cast<PlasmaShellSurface::Private *>(data);
182  Q_ASSERT(p->surface == org_kde_plasma_surface);
183  Q_EMIT p->q->autoHidePanelShown();
184 }
185 
186 PlasmaShellSurface::PlasmaShellSurface(QObject *parent)
187  : QObject(parent)
188  , d(new Private(this))
189 {
190 }
191 
192 PlasmaShellSurface::~PlasmaShellSurface()
193 {
194  release();
195 }
196 
198 {
199  d->surface.release();
200 }
201 
203 {
204  d->surface.destroy();
205 }
206 
207 void PlasmaShellSurface::setup(org_kde_plasma_surface *surface)
208 {
209  d->setup(surface);
210 }
211 
213 {
214  if (auto s = PlasmaShellSurface::Private::get(surface)) {
215  return s;
216  }
217 
218  return nullptr;
219 }
220 
222 {
223  return d->surface.isValid();
224 }
225 
226 PlasmaShellSurface::operator org_kde_plasma_surface *()
227 {
228  return d->surface;
229 }
230 
231 PlasmaShellSurface::operator org_kde_plasma_surface *() const
232 {
233  return d->surface;
234 }
235 
237 {
238  Q_ASSERT(isValid());
239  org_kde_plasma_surface_set_position(d->surface, point.x(), point.y());
240 }
241 
243 {
244  Q_ASSERT(isValid());
245  uint32_t wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL;
246  switch (role) {
247  case Role::Normal:
248  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL;
249  break;
250  case Role::Desktop:
251  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_DESKTOP;
252  break;
253  case Role::Panel:
254  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_PANEL;
255  break;
256  case Role::OnScreenDisplay:
257  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_ONSCREENDISPLAY;
258  break;
259  case Role::Notification:
260  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NOTIFICATION;
261  break;
262  case Role::ToolTip:
263  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_TOOLTIP;
264  break;
265  case Role::CriticalNotification:
266  if (wl_proxy_get_version(d->surface) < ORG_KDE_PLASMA_SURFACE_ROLE_CRITICALNOTIFICATION_SINCE_VERSION) {
267  // Fall back to generic notification type if not supported
268  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NOTIFICATION;
269  } else {
270  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_CRITICALNOTIFICATION;
271  }
272  break;
273  default:
274  Q_UNREACHABLE();
275  break;
276  }
277  org_kde_plasma_surface_set_role(d->surface, wlRole);
278  d->role = role;
279 }
280 
282 {
283  return d->role;
284 }
285 
287 {
288  Q_ASSERT(isValid());
289  uint32_t wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE;
290  switch (behavior) {
291  case PanelBehavior::AlwaysVisible:
292  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE;
293  break;
294  case PanelBehavior::AutoHide:
295  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_AUTO_HIDE;
296  break;
297  case PanelBehavior::WindowsCanCover:
298  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_CAN_COVER;
299  break;
300  case PanelBehavior::WindowsGoBelow:
301  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_GO_BELOW;
302  break;
303  default:
304  Q_UNREACHABLE();
305  break;
306  }
307  org_kde_plasma_surface_set_panel_behavior(d->surface, wlRole);
308 }
309 
311 {
312  org_kde_plasma_surface_set_skip_taskbar(d->surface, skip);
313 }
314 
316 {
317  org_kde_plasma_surface_set_skip_switcher(d->surface, skip);
318 }
319 
321 {
322  org_kde_plasma_surface_panel_auto_hide_hide(d->surface);
323 }
324 
326 {
327  org_kde_plasma_surface_panel_auto_hide_show(d->surface);
328 }
329 
331 {
332  org_kde_plasma_surface_set_panel_takes_focus(d->surface, takesFocus);
333 }
334 
335 }
336 }
Wrapper for the org_kde_plasma_surface interface.
Definition: plasmashell.h:173
void setup(wl_surface *surface)
Setup this Surface to manage the surface.
Definition: surface.cpp:120
void requestShowAutoHidingPanel()
Requests to show a surface with Role Panel and PanelBahvior AutoHide.
void destroy()
Destroys the data held by this PlasmaShellSurface.
void interfaceAboutToBeDestroyed()
This signal is emitted right before the data is destroyed.
void setSkipTaskbar(bool skip)
Setting this bit to the window, will make it say it prefers to not be listed in the taskbar...
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating a Surface.
Definition: plasmashell.cpp:86
void release()
Releases the org_kde_kwin_outputmanagement interface.
PlasmaShellSurface * createSurface(wl_surface *surface, QObject *parent=nullptr)
Creates a PlasmaShellSurface for the given surface and sets it up.
Definition: plasmashell.cpp:96
void destroy()
Destroys the data held by this PlasmaShell.
Definition: plasmashell.cpp:61
void release()
Releases the org_kde_plasma_surface interface.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
int x() const const
int y() const const
void setPanelBehavior(PanelBehavior behavior)
Sets the PanelBehavior for a PlasmaShellSurface with Role Role::Panel.
void setRole(Role role)
Changes the requested Role to role.
Wrapper for the wl_surface interface.
Definition: surface.h:43
static PlasmaShellSurface * get(Surface *surf)
void setSkipSwitcher(bool skip)
Setting this bit on a window will indicate it does not prefer to be included in a window switcher...
void interfaceAboutToBeReleased()
This signal is emitted right before the interface is released.
void setPosition(const QPoint &point)
Requests to position this PlasmaShellSurface at point in global coordinates.
QObject(QObject *parent)
void setPanelTakesFocus(bool takesFocus)
Set whether a PlasmaShellSurface should get focus or not.
void setup(org_kde_plasma_shell *shell)
Setup this Shell to manage the shell.
Definition: plasmashell.cpp:79
void release()
Releases the org_kde_plasma_shell interface.
Definition: plasmashell.cpp:70
static Surface * get(wl_surface *native)
Definition: surface.cpp:278
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void setup(org_kde_plasma_surface *surface)
Setup this PlasmaShellSurface to manage the surface.
Q_EMITQ_EMIT
void requestHideAutoHidingPanel()
Requests to hide a surface with Role Panel and PanelBahvior AutoHide.
Role
Describes possible roles this PlasmaShellSurface can have.
Definition: plasmashell.h:229
PanelBehavior
Describes how a PlasmaShellSurface with role Role::Panel should behave.
Definition: plasmashell.h:257
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Sep 23 2021 22:51:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.