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 "display.h"
7 #include "idleinhibit_interface_p.h"
8 #include "surface_interface_p.h"
9 
10 namespace KWayland
11 {
12 namespace Server
13 {
14 class Q_DECL_HIDDEN IdleInhibitManagerUnstableV1Interface::Private : public IdleInhibitManagerInterface::Private
15 {
16 public:
17  Private(IdleInhibitManagerUnstableV1Interface *q, Display *d);
18 
19 private:
20  void bind(wl_client *client, uint32_t version, uint32_t id) override;
21 
22  static void unbind(wl_resource *resource);
23  static Private *cast(wl_resource *r)
24  {
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 = {destroyCallback, createInhibitorCallback};
39 #endif
40 
41 IdleInhibitManagerUnstableV1Interface::Private::Private(IdleInhibitManagerUnstableV1Interface *q, Display *d)
42  : IdleInhibitManagerInterface::Private(q, d, &zwp_idle_inhibit_manager_v1_interface, s_version, IdleInhibitManagerInterfaceVersion::UnstableV1)
43 {
44 }
45 
46 void IdleInhibitManagerUnstableV1Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
47 {
48  Q_UNUSED(client)
49  wl_resource_destroy(resource);
50 }
51 
52 void IdleInhibitManagerUnstableV1Interface::Private::createInhibitorCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
53 {
54  auto s = SurfaceInterface::get(surface);
55  if (!s) {
56  // send error?
57  return;
58  }
59  auto q = cast(resource);
60  auto inhibitor = new IdleInhibitorInterface(q->q, resource);
61  inhibitor->d_func()->create(q->display->getConnection(client), version, id);
62  s->d_func()->installIdleInhibitor(inhibitor);
63 }
64 
65 void IdleInhibitManagerUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
66 {
67  auto c = display->getConnection(client);
68  wl_resource *resource = c->createResource(&zwp_idle_inhibit_manager_v1_interface, qMin(version, s_version), id);
69  if (!resource) {
70  wl_client_post_no_memory(client);
71  return;
72  }
73  wl_resource_set_implementation(resource, &s_interface, this, unbind);
74  // TODO: should we track?
75 }
76 
77 void IdleInhibitManagerUnstableV1Interface::Private::unbind(wl_resource *resource)
78 {
79  Q_UNUSED(resource)
80  // TODO: implement?
81 }
82 
83 IdleInhibitManagerUnstableV1Interface::IdleInhibitManagerUnstableV1Interface(Display *display, QObject *parent)
84  : IdleInhibitManagerInterface(new Private(this, display), parent)
85 {
86 }
87 
88 IdleInhibitManagerUnstableV1Interface::~IdleInhibitManagerUnstableV1Interface() = default;
89 
90 #ifndef K_DOXYGEN
91 const struct zwp_idle_inhibitor_v1_interface IdleInhibitorInterface::Private::s_interface = {resourceDestroyedCallback};
92 #endif
93 
94 IdleInhibitorInterface::Private::Private(IdleInhibitorInterface *q, IdleInhibitManagerInterface *c, wl_resource *parentResource)
95  : Resource::Private(q, c, parentResource, &zwp_idle_inhibitor_v1_interface, &s_interface)
96 {
97 }
98 
99 IdleInhibitorInterface::Private::~Private()
100 {
101  if (resource) {
102  wl_resource_destroy(resource);
103  resource = nullptr;
104  }
105 }
106 
107 IdleInhibitorInterface::IdleInhibitorInterface(IdleInhibitManagerInterface *m, wl_resource *parentResource)
108  : Resource(new Private(this, m, parentResource))
109 {
110 }
111 
112 IdleInhibitorInterface::~IdleInhibitorInterface() = default;
113 
114 IdleInhibitorInterface::Private *IdleInhibitorInterface::d_func() const
115 {
116  return reinterpret_cast<Private *>(d.data());
117 }
118 
119 }
120 }
static SurfaceInterface * get(wl_resource *native)
IdleInhibitManagerInterfaceVersion
Enum describing the interface versions the IdleInhibitManagerInterface can support.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.