KWayland

relativepointer.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 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 "relativepointer.h"
7 #include "event_queue.h"
8 #include "pointer.h"
9 #include "wayland_pointer_p.h"
10 #include <wayland-relativepointer-unstable-v1-client-protocol.h>
11 #include <QSizeF>
12 
13 namespace KWayland
14 {
15 namespace Client
16 {
17 
18 class Q_DECL_HIDDEN RelativePointerManager::Private
19 {
20 public:
21  Private() = default;
22 
23  WaylandPointer<zwp_relative_pointer_manager_v1, zwp_relative_pointer_manager_v1_destroy> relativepointermanagerunstablev1;
24  EventQueue *queue = nullptr;
25 };
26 
28  : QObject(parent)
29  , d(new Private)
30 {
31 }
32 
33 RelativePointerManager::~RelativePointerManager()
34 {
35  release();
36 }
37 
38 void RelativePointerManager::setup(zwp_relative_pointer_manager_v1 *relativepointermanagerunstablev1)
39 {
40  Q_ASSERT(relativepointermanagerunstablev1);
41  Q_ASSERT(!d->relativepointermanagerunstablev1);
42  d->relativepointermanagerunstablev1.setup(relativepointermanagerunstablev1);
43 }
44 
46 {
47  d->relativepointermanagerunstablev1.release();
48 }
49 
51 {
52  d->relativepointermanagerunstablev1.destroy();
53 }
54 
56 {
57  d->queue = queue;
58 }
59 
61 {
62  return d->queue;
63 }
64 
65 RelativePointerManager::operator zwp_relative_pointer_manager_v1*() {
66  return d->relativepointermanagerunstablev1;
67 }
68 
69 RelativePointerManager::operator zwp_relative_pointer_manager_v1*() const {
70  return d->relativepointermanagerunstablev1;
71 }
72 
74 {
75  return d->relativepointermanagerunstablev1.isValid();
76 }
77 
79 {
80  Q_ASSERT(isValid());
81  RelativePointer *p = new RelativePointer(parent);
82  auto w = zwp_relative_pointer_manager_v1_get_relative_pointer(d->relativepointermanagerunstablev1, *pointer);
83  if (d->queue) {
84  d->queue->addProxy(w);
85  }
86  p->setup(w);
87  return p;
88 }
89 
90 class Q_DECL_HIDDEN RelativePointer::Private
91 {
92 public:
93  Private(RelativePointer *q);
94 
95  void setup(zwp_relative_pointer_v1 *relativepointerunstablev1);
96 
97  WaylandPointer<zwp_relative_pointer_v1, zwp_relative_pointer_v1_destroy> relativepointerunstablev1;
98 
99 private:
100  static void relativeMotionCallback(void *data, zwp_relative_pointer_v1 *zwp_relative_pointer_v1,
101  uint32_t utime_hi, uint32_t utime_lo,
102  wl_fixed_t dx, wl_fixed_t dy,
103  wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel);
104 
105  RelativePointer *q;
106 
107  static const zwp_relative_pointer_v1_listener s_listener;
108 };
109 
110 RelativePointer::Private::Private(RelativePointer *q)
111  : q(q)
112 {
113 }
114 
115 const zwp_relative_pointer_v1_listener RelativePointer::Private::s_listener = {
116  relativeMotionCallback
117 };
118 
119 void RelativePointer::Private::relativeMotionCallback(void *data, zwp_relative_pointer_v1 *zwp_relative_pointer_v1,
120  uint32_t utime_hi, uint32_t utime_lo,
121  wl_fixed_t dx, wl_fixed_t dy,
122  wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel)
123 {
124  auto p = reinterpret_cast<RelativePointer::Private*>(data);
125  Q_ASSERT(p->relativepointerunstablev1 == zwp_relative_pointer_v1);
126  const QSizeF delta(wl_fixed_to_double(dx), wl_fixed_to_double(dy));
127  const QSizeF deltaNonAccel(wl_fixed_to_double(dx_unaccel), wl_fixed_to_double(dy_unaccel));
128  const quint64 timestamp = quint64(utime_lo) | (quint64(utime_hi) << 32);
129  emit p->q->relativeMotion(delta, deltaNonAccel, timestamp);
130 }
131 
132 void RelativePointer::Private::setup(zwp_relative_pointer_v1 *v1)
133 {
134  Q_ASSERT(v1);
135  Q_ASSERT(!relativepointerunstablev1);
136  relativepointerunstablev1.setup(v1);
137  zwp_relative_pointer_v1_add_listener(relativepointerunstablev1, &s_listener, this);
138 }
139 
140 RelativePointer::RelativePointer(QObject *parent)
141  : QObject(parent)
142  , d(new Private(this))
143 {
144 }
145 
146 RelativePointer::~RelativePointer()
147 {
148  release();
149 }
150 
151 void RelativePointer::setup(zwp_relative_pointer_v1 *relativepointerunstablev1)
152 {
153  d->setup(relativepointerunstablev1);
154 }
155 
157 {
158  d->relativepointerunstablev1.release();
159 }
160 
162 {
163  d->relativepointerunstablev1.destroy();
164 }
165 
166 RelativePointer::operator zwp_relative_pointer_v1*() {
167  return d->relativepointerunstablev1;
168 }
169 
170 RelativePointer::operator zwp_relative_pointer_v1*() const {
171  return d->relativepointerunstablev1;
172 }
173 
175 {
176  return d->relativepointerunstablev1.isValid();
177 }
178 
179 }
180 }
RelativePointerManager(QObject *parent=nullptr)
Creates a new RelativePointerManager.
void destroy()
Destroys the data held by this RelativePointerUnstableV1.
void release()
Releases the zwp_relative_pointer_manager_v1 interface.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
void setup(zwp_relative_pointer_v1 *relativepointerunstablev1)
Setup this RelativePointerUnstableV1 to manage the relativepointerunstablev1.
Wrapper for the zwp_relative_pointer_v1 interface.
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this RelativePointerManagerUnstableV1.
void release()
Releases the zwp_relative_pointer_v1 interface.
void setup(zwp_relative_pointer_manager_v1 *relativepointermanagerunstablev1)
Setup this RelativePointerManagerUnstableV1 to manage the relativepointermanagerunstablev1.
Wrapper for the wl_pointer interface.
Definition: pointer.h:32
void destroy()
Destroys the data held by this RelativePointerManagerUnstableV1.
RelativePointer * createRelativePointer(Pointer *pointer, QObject *parent=nullptr)
Creates a RelativePointer for the given pointer.
QObject(QObject *parent)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 3 2020 22:49:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.