KWayland

idleinhibit_interface_v1.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Martin Flöser <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "idleinhibit_interface_p.h"
7 #include "display.h"
8 #include "surface_interface_p.h"
9 
10 namespace KWayland
11 {
12 namespace Server
13 {
14 
15 class Q_DECL_HIDDEN IdleInhibitManagerUnstableV1Interface::Private : public IdleInhibitManagerInterface::Private
16 {
17 public:
18  Private(IdleInhibitManagerUnstableV1Interface *q, Display *d);
19 
20 private:
21  void bind(wl_client *client, uint32_t version, uint32_t id) override;
22 
23  static void unbind(wl_resource *resource);
24  static Private *cast(wl_resource *r) {
25  return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
26  }
27 
28  static void destroyCallback(wl_client *client, wl_resource *resource);
29  static void createInhibitorCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface);
30 
31  static const struct zwp_idle_inhibit_manager_v1_interface s_interface;
32  static const quint32 s_version;
33 };
34 
35 const quint32 IdleInhibitManagerUnstableV1Interface::Private::s_version = 1;
36 
37 #ifndef K_DOXYGEN
38 const struct zwp_idle_inhibit_manager_v1_interface IdleInhibitManagerUnstableV1Interface::Private::s_interface = {
39  destroyCallback,
40  createInhibitorCallback
41 };
42 #endif
43 
44 IdleInhibitManagerUnstableV1Interface::Private::Private(IdleInhibitManagerUnstableV1Interface *q, Display *d)
45  : IdleInhibitManagerInterface::Private(q, d, &zwp_idle_inhibit_manager_v1_interface, s_version, IdleInhibitManagerInterfaceVersion::UnstableV1)
46 {
47 }
48 
49 void IdleInhibitManagerUnstableV1Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
50 {
51  Q_UNUSED(client)
52  wl_resource_destroy(resource);
53 }
54 
55 void IdleInhibitManagerUnstableV1Interface::Private::createInhibitorCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
56 {
57  auto s = SurfaceInterface::get(surface);
58  if (!s) {
59  // send error?
60  return;
61  }
62  auto q = cast(resource);
63  auto inhibitor = new IdleInhibitorInterface(q->q, resource);
64  inhibitor->d_func()->create(q->display->getConnection(client), version, id);
65  s->d_func()->installIdleInhibitor(inhibitor);
66 }
67 
68 void IdleInhibitManagerUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
69 {
70  auto c = display->getConnection(client);
71  wl_resource *resource = c->createResource(&zwp_idle_inhibit_manager_v1_interface, qMin(version, s_version), id);
72  if (!resource) {
73  wl_client_post_no_memory(client);
74  return;
75  }
76  wl_resource_set_implementation(resource, &s_interface, this, unbind);
77  // TODO: should we track?
78 }
79 
80 void IdleInhibitManagerUnstableV1Interface::Private::unbind(wl_resource *resource)
81 {
82  Q_UNUSED(resource)
83  // TODO: implement?
84 }
85 
86 IdleInhibitManagerUnstableV1Interface::IdleInhibitManagerUnstableV1Interface(Display *display, QObject *parent)
87  : IdleInhibitManagerInterface(new Private(this, display), parent)
88 {
89 }
90 
91 IdleInhibitManagerUnstableV1Interface::~IdleInhibitManagerUnstableV1Interface() = default;
92 
93 #ifndef K_DOXYGEN
94 const struct zwp_idle_inhibitor_v1_interface IdleInhibitorInterface::Private::s_interface = {
95  resourceDestroyedCallback
96 };
97 #endif
98 
99 IdleInhibitorInterface::Private::Private(IdleInhibitorInterface *q, IdleInhibitManagerInterface *c, wl_resource *parentResource)
100  : Resource::Private(q, c, parentResource, &zwp_idle_inhibitor_v1_interface, &s_interface)
101 {
102 }
103 
104 IdleInhibitorInterface::Private::~Private()
105 {
106  if (resource) {
107  wl_resource_destroy(resource);
108  resource = nullptr;
109  }
110 }
111 
112 IdleInhibitorInterface::IdleInhibitorInterface(IdleInhibitManagerInterface *m, wl_resource *parentResource)
113  : Resource(new Private(this, m, parentResource))
114 {
115 }
116 
117 IdleInhibitorInterface::~IdleInhibitorInterface() = default;
118 
119 IdleInhibitorInterface::Private *IdleInhibitorInterface::d_func() const
120 {
121  return reinterpret_cast<Private*>(d.data());
122 }
123 
124 }
125 }
ClientConnection * getConnection(wl_client *client)
Gets the ClientConnection for the given client.
Definition: display.cpp:592
static SurfaceInterface * get(wl_resource *native)
T * data() const const
wl_resource * createResource(const wl_interface *interface, quint32 version, quint32 id)
Creates a new wl_resource for the provided interface.
IdleInhibitManagerInterfaceVersion
Enum describing the interface versions the IdleInhibitManagerInterface can support.
Display * display()
Definition: global.cpp:79
QObject * parent() const const
KDB_EXPORT KDbVersionInfo version()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.