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

KDE's Doxygen guidelines are available online.