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 
19 class Q_DECL_HIDDEN PlasmaShell::Private
20 {
21 public:
22  WaylandPointer<org_kde_plasma_shell, org_kde_plasma_shell_destroy> shell;
23  EventQueue *queue = nullptr;
24 };
25 
26 class Q_DECL_HIDDEN PlasmaShellSurface::Private
27 {
28 public:
29  Private(PlasmaShellSurface *q);
30  ~Private();
31  void setup(org_kde_plasma_surface *surface);
32 
33  WaylandPointer<org_kde_plasma_surface, org_kde_plasma_surface_destroy> surface;
34  QSize size;
35  QPointer<Surface> parentSurface;
37 
38  static PlasmaShellSurface *get(Surface *surface);
39 
40 private:
41  static void autoHidingPanelHiddenCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface);
42  static void autoHidingPanelShownCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface);
43 
44  PlasmaShellSurface *q;
45  static QVector<Private*> s_surfaces;
46  static const org_kde_plasma_surface_listener s_listener;
47 };
48 
49 QVector<PlasmaShellSurface::Private*> PlasmaShellSurface::Private::s_surfaces;
50 
51 PlasmaShell::PlasmaShell(QObject *parent)
52  : QObject(parent)
53  , d(new Private)
54 {
55 }
56 
57 PlasmaShell::~PlasmaShell()
58 {
59  release();
60 }
61 
63 {
64  if (!d->shell) {
65  return;
66  }
67  emit interfaceAboutToBeDestroyed();
68  d->shell.destroy();
69 }
70 
72 {
73  if (!d->shell) {
74  return;
75  }
76  emit interfaceAboutToBeReleased();
77  d->shell.release();
78 }
79 
80 void PlasmaShell::setup(org_kde_plasma_shell *shell)
81 {
82  Q_ASSERT(!d->shell);
83  Q_ASSERT(shell);
84  d->shell.setup(shell);
85 }
86 
88 {
89  d->queue = queue;
90 }
91 
93 {
94  return d->queue;
95 }
96 
98 {
99  Q_ASSERT(isValid());
100  auto kwS = Surface::get(surface);
101  if (kwS) {
102  if (auto s = PlasmaShellSurface::Private::get(kwS)) {
103  return s;
104  }
105  }
106  PlasmaShellSurface *s = new PlasmaShellSurface(parent);
109  auto w = org_kde_plasma_shell_get_surface(d->shell, surface);
110  if (d->queue) {
111  d->queue->addProxy(w);
112  }
113  s->setup(w);
114  s->d->parentSurface = QPointer<Surface>(kwS);
115  return s;
116 }
117 
119 {
120  return createSurface(*surface, parent);
121 }
122 
124 {
125  return d->shell.isValid();
126 }
127 
128 PlasmaShell::operator org_kde_plasma_shell*()
129 {
130  return d->shell;
131 }
132 
133 PlasmaShell::operator org_kde_plasma_shell*() const
134 {
135  return d->shell;
136 }
137 
138 PlasmaShellSurface::Private::Private(PlasmaShellSurface *q)
140  q(q)
141 {
142  s_surfaces << this;
143 }
144 
145 PlasmaShellSurface::Private::~Private()
146 {
147  s_surfaces.removeAll(this);
148 }
149 
150 PlasmaShellSurface *PlasmaShellSurface::Private::get(Surface *surface)
151 {
152  if (!surface) {
153  return nullptr;
154  }
155  for (auto it = s_surfaces.constBegin(); it != s_surfaces.constEnd(); ++it) {
156  if ((*it)->parentSurface == surface) {
157  return (*it)->q;
158  }
159  }
160  return nullptr;
161 }
162 
163 void PlasmaShellSurface::Private::setup(org_kde_plasma_surface *s)
164 {
165  Q_ASSERT(s);
166  Q_ASSERT(!surface);
167  surface.setup(s);
168  org_kde_plasma_surface_add_listener(surface, &s_listener, this);
169 }
170 
171 const org_kde_plasma_surface_listener PlasmaShellSurface::Private::s_listener = {
172  autoHidingPanelHiddenCallback,
173  autoHidingPanelShownCallback
174 };
175 
176 void PlasmaShellSurface::Private::autoHidingPanelHiddenCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface)
177 {
178  auto p = reinterpret_cast<PlasmaShellSurface::Private*>(data);
179  Q_ASSERT(p->surface == org_kde_plasma_surface);
180  emit p->q->autoHidePanelHidden();
181 }
182 
183 void PlasmaShellSurface::Private::autoHidingPanelShownCallback(void *data, org_kde_plasma_surface *org_kde_plasma_surface)
184 {
185  auto p = reinterpret_cast<PlasmaShellSurface::Private*>(data);
186  Q_ASSERT(p->surface == org_kde_plasma_surface);
187  emit p->q->autoHidePanelShown();
188 }
189 
190 PlasmaShellSurface::PlasmaShellSurface(QObject *parent)
191  : QObject(parent)
192  , d(new Private(this))
193 {
194 }
195 
196 PlasmaShellSurface::~PlasmaShellSurface()
197 {
198  release();
199 }
200 
202 {
203  d->surface.release();
204 }
205 
207 {
208  d->surface.destroy();
209 }
210 
211 void PlasmaShellSurface::setup(org_kde_plasma_surface *surface)
212 {
213  d->setup(surface);
214 }
215 
217 {
218  if (auto s = PlasmaShellSurface::Private::get(surface)) {
219  return s;
220  }
221 
222  return nullptr;
223 }
224 
226 {
227  return d->surface.isValid();
228 }
229 
230 PlasmaShellSurface::operator org_kde_plasma_surface*()
231 {
232  return d->surface;
233 }
234 
235 PlasmaShellSurface::operator org_kde_plasma_surface*() const
236 {
237  return d->surface;
238 }
239 
241 {
242  Q_ASSERT(isValid());
243  org_kde_plasma_surface_set_position(d->surface, point.x(), point.y());
244 }
245 
247 {
248  Q_ASSERT(isValid());
249  uint32_t wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL;
250  switch (role) {
251  case Role::Normal:
252  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL;
253  break;
254  case Role::Desktop:
255  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_DESKTOP;
256  break;
257  case Role::Panel:
258  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_PANEL;
259  break;
260  case Role::OnScreenDisplay:
261  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_ONSCREENDISPLAY;
262  break;
263  case Role::Notification:
264  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NOTIFICATION;
265  break;
266  case Role::ToolTip:
267  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_TOOLTIP;
268  break;
269  case Role::CriticalNotification:
270  if (wl_proxy_get_version(d->surface) < ORG_KDE_PLASMA_SURFACE_ROLE_CRITICALNOTIFICATION_SINCE_VERSION) {
271  // Fall back to generic notification type if not supported
272  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_NOTIFICATION;
273  } else {
274  wlRole = ORG_KDE_PLASMA_SURFACE_ROLE_CRITICALNOTIFICATION;
275  }
276  break;
277  default:
278  Q_UNREACHABLE();
279  break;
280  }
281  org_kde_plasma_surface_set_role(d->surface, wlRole);
282  d->role = role;
283 }
284 
286 {
287  return d->role;
288 }
289 
291 {
292  Q_ASSERT(isValid());
293  uint32_t wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE;
294  switch (behavior) {
295  case PanelBehavior::AlwaysVisible:
296  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE;
297  break;
298  case PanelBehavior::AutoHide:
299  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_AUTO_HIDE;
300  break;
301  case PanelBehavior::WindowsCanCover:
302  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_CAN_COVER;
303  break;
304  case PanelBehavior::WindowsGoBelow:
305  wlRole = ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_GO_BELOW;
306  break;
307  default:
308  Q_UNREACHABLE();
309  break;
310  }
311  org_kde_plasma_surface_set_panel_behavior(d->surface, wlRole);
312 }
313 
315 {
316  org_kde_plasma_surface_set_skip_taskbar(d->surface, skip);
317 }
318 
320 {
321  org_kde_plasma_surface_set_skip_switcher(d->surface, skip);
322 }
323 
325 {
326  org_kde_plasma_surface_panel_auto_hide_hide(d->surface);
327 }
328 
330 {
331  org_kde_plasma_surface_panel_auto_hide_show(d->surface);
332 }
333 
335 {
336  org_kde_plasma_surface_set_panel_takes_focus(d->surface, takesFocus);
337 }
338 
339 }
340 }
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:121
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:87
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:97
void destroy()
Destroys the data held by this PlasmaShell.
Definition: plasmashell.cpp:62
void release()
Releases the org_kde_plasma_surface interface.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
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:44
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:80
void release()
Releases the org_kde_plasma_shell interface.
Definition: plasmashell.cpp:71
static Surface * get(wl_surface *native)
Definition: surface.cpp:286
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.
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-2020 The KDE developers.
Generated on Sat Jul 4 2020 22:50:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.