KWayland

idle.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 "idle.h"
7 #include "event_queue.h"
8 #include "seat.h"
9 #include "wayland_pointer_p.h"
10 
11 #include <wayland-idle-client-protocol.h>
12 
13 namespace KWayland
14 {
15 namespace Client
16 {
17 class Q_DECL_HIDDEN Idle::Private
18 {
19 public:
20  WaylandPointer<org_kde_kwin_idle, org_kde_kwin_idle_destroy> manager;
21  EventQueue *queue = nullptr;
22 };
23 
25  : QObject(parent)
26  , d(new Private)
27 {
28 }
29 
30 Idle::~Idle()
31 {
32  release();
33 }
34 
36 {
37  d->manager.release();
38 }
39 
41 {
42  d->manager.destroy();
43 }
44 
45 bool Idle::isValid() const
46 {
47  return d->manager.isValid();
48 }
49 
50 void Idle::setup(org_kde_kwin_idle *manager)
51 {
52  Q_ASSERT(manager);
53  Q_ASSERT(!d->manager.isValid());
54  d->manager.setup(manager);
55 }
56 
58 {
59  return d->queue;
60 }
61 
63 {
64  d->queue = queue;
65 }
66 
68 {
69  Q_ASSERT(isValid());
70  Q_ASSERT(seat);
71  IdleTimeout *idle = new IdleTimeout(parent);
72  auto i = org_kde_kwin_idle_get_idle_timeout(d->manager, *seat, msecs);
73  if (d->queue) {
74  d->queue->addProxy(i);
75  }
76  idle->setup(i);
77  return idle;
78 }
79 
80 Idle::operator org_kde_kwin_idle *() const
81 {
82  return d->manager;
83 }
84 
85 Idle::operator org_kde_kwin_idle *()
86 {
87  return d->manager;
88 }
89 
90 class Q_DECL_HIDDEN IdleTimeout::Private
91 {
92 public:
93  explicit Private(IdleTimeout *q);
94  void setup(org_kde_kwin_idle_timeout *d);
95 
96  WaylandPointer<org_kde_kwin_idle_timeout, org_kde_kwin_idle_timeout_release> timeout;
97 
98 private:
99  static void idleCallback(void *data, org_kde_kwin_idle_timeout *org_kde_kwin_idle_timeout);
100  static void resumedCallback(void *data, org_kde_kwin_idle_timeout *org_kde_kwin_idle_timeout);
101  static const struct org_kde_kwin_idle_timeout_listener s_listener;
102 
103  IdleTimeout *q;
104 };
105 
106 const org_kde_kwin_idle_timeout_listener IdleTimeout::Private::s_listener = {idleCallback, resumedCallback};
107 
108 void IdleTimeout::Private::idleCallback(void *data, org_kde_kwin_idle_timeout *org_kde_kwin_idle_timeout)
109 {
110  Q_UNUSED(org_kde_kwin_idle_timeout)
111  Q_EMIT reinterpret_cast<Private *>(data)->q->idle();
112 }
113 
114 void IdleTimeout::Private::resumedCallback(void *data, org_kde_kwin_idle_timeout *org_kde_kwin_idle_timeout)
115 {
116  Q_UNUSED(org_kde_kwin_idle_timeout)
117  Q_EMIT reinterpret_cast<Private *>(data)->q->resumeFromIdle();
118 }
119 
120 IdleTimeout::Private::Private(IdleTimeout *q)
121  : q(q)
122 {
123 }
124 
125 void IdleTimeout::Private::setup(org_kde_kwin_idle_timeout *d)
126 {
127  Q_ASSERT(d);
128  Q_ASSERT(!timeout.isValid());
129  timeout.setup(d);
130  org_kde_kwin_idle_timeout_add_listener(timeout, &s_listener, this);
131 }
132 
134  : QObject(parent)
135  , d(new Private(this))
136 {
137 }
138 
139 IdleTimeout::~IdleTimeout()
140 {
141  release();
142 }
143 
145 {
146  d->timeout.destroy();
147 }
148 
150 {
151  d->timeout.release();
152 }
153 
155 {
156  return d->timeout.isValid();
157 }
158 
159 void IdleTimeout::setup(org_kde_kwin_idle_timeout *dataDevice)
160 {
161  d->setup(dataDevice);
162 }
163 
165 {
166  Q_ASSERT(isValid());
167  org_kde_kwin_idle_timeout_simulate_user_activity(d->timeout);
168 }
169 
170 IdleTimeout::operator org_kde_kwin_idle_timeout *()
171 {
172  return d->timeout;
173 }
174 
175 IdleTimeout::operator org_kde_kwin_idle_timeout *() const
176 {
177  return d->timeout;
178 }
179 
180 }
181 }
bool isValid() const
Definition: idle.cpp:45
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
void setup(org_kde_kwin_idle_timeout *timeout)
Setup this IdleTimeout to manage the timeout.
Definition: idle.cpp:159
void release()
Releases the org_kde_kwin_idle interface.
Definition: idle.cpp:35
Wrapper for the wl_seat interface.
Definition: seat.h:51
Wrapper for the org_kde_kwin_idle_timeout interface.
Definition: idle.h:147
void destroy()
Destroys the data held by this IdleTimeout.
Definition: idle.cpp:144
IdleTimeout * getTimeout(quint32 msecs, Seat *seat, QObject *parent=nullptr)
Creates a new IdleTimeout for the seat.
Definition: idle.cpp:67
void destroy()
Destroys the data held by this Idle.
Definition: idle.cpp:40
void setup(org_kde_kwin_idle *manager)
Setup this Idle to manage the manager.
Definition: idle.cpp:50
void release()
Releases the org_kde_kwin_idle_timeout interface.
Definition: idle.cpp:149
EventQueue * eventQueue()
Definition: idle.cpp:57
IdleTimeout(QObject *parent=nullptr)
To create an IdleTimeout prefer using Idle::getTimeout which sets up the IdleTimeout to be fully func...
Definition: idle.cpp:133
Idle(QObject *parent=nullptr)
Creates a new Idle.
Definition: idle.cpp:24
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating a IdleTimeout.
Definition: idle.cpp:62
QObject * parent() const const
void simulateUserActivity()
Simulates user activity.
Definition: idle.cpp:164
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Nov 29 2021 22:45:32 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.