• Skip to content
  • Skip to link menu
Brand

API Documentation

  1. KDE API Reference
  2. The KDE Frameworks
  3. KWayland
  • KDE Home
  • Contact Us

Quick Links

Skip menu "KWayland"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules
  • Dependencies
  • Related Pages

Class Picker

About

Qt-style API to interact with the wayland-client and wayland-server API

Maintainer
Martin Flöser
Supported platforms
FreeBSD, Linux
Community
IRC: #kde-devel on Freenode
Mailing list: kde-frameworks-devel
Use with CMake
find_package(KF5Wayland)
target_link_libraries(yourapp KF5::WaylandClient KF5::WaylandServer)
Use with QMake
QT += KWaylandClient KWaylandServer 
Clone
git clone git://anongit.kde.org/kwayland.git
Browse source
KWayland on cgit.kde.org

KWayland

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

KDE's Doxygen guidelines are available online.

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal