Changeset View
Changeset View
Standalone View
Standalone View
src/client/pointer.cpp
Show All 25 Lines | |||||
26 | // wayland | 26 | // wayland | ||
27 | #include <wayland-client-protocol.h> | 27 | #include <wayland-client-protocol.h> | ||
28 | 28 | | |||
29 | namespace KWayland | 29 | namespace KWayland | ||
30 | { | 30 | { | ||
31 | namespace Client | 31 | namespace Client | ||
32 | { | 32 | { | ||
33 | 33 | | |||
34 | static Pointer::Axis wlAxisToPointerAxis(uint32_t axis) | ||||
35 | { | ||||
36 | switch (axis) { | ||||
37 | case WL_POINTER_AXIS_VERTICAL_SCROLL: | ||||
38 | return Pointer::Axis::Vertical; | ||||
39 | case WL_POINTER_AXIS_HORIZONTAL_SCROLL: | ||||
40 | return Pointer::Axis::Horizontal; | ||||
41 | } | ||||
42 | | ||||
43 | Q_UNREACHABLE(); | ||||
44 | } | ||||
45 | | ||||
34 | class Q_DECL_HIDDEN Pointer::Private | 46 | class Q_DECL_HIDDEN Pointer::Private | ||
35 | { | 47 | { | ||
36 | public: | 48 | public: | ||
37 | Private(Pointer *q); | 49 | Private(Pointer *q); | ||
38 | void setup(wl_pointer *p); | 50 | void setup(wl_pointer *p); | ||
39 | 51 | | |||
40 | WaylandPointer<wl_pointer, wl_pointer_release> pointer; | 52 | WaylandPointer<wl_pointer, wl_pointer_release> pointer; | ||
41 | QPointer<Surface> enteredSurface; | 53 | QPointer<Surface> enteredSurface; | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 162 | { | |||
159 | }; | 171 | }; | ||
160 | emit p->q->buttonStateChanged(serial, time, button, toState()); | 172 | emit p->q->buttonStateChanged(serial, time, button, toState()); | ||
161 | } | 173 | } | ||
162 | 174 | | |||
163 | void Pointer::Private::axisCallback(void *data, wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) | 175 | void Pointer::Private::axisCallback(void *data, wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) | ||
164 | { | 176 | { | ||
165 | auto p = reinterpret_cast<Pointer::Private*>(data); | 177 | auto p = reinterpret_cast<Pointer::Private*>(data); | ||
166 | Q_ASSERT(p->pointer == pointer); | 178 | Q_ASSERT(p->pointer == pointer); | ||
167 | auto toAxis = [axis] { | 179 | emit p->q->axisChanged(time, wlAxisToPointerAxis(axis), wl_fixed_to_double(value)); | ||
168 | if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { | | |||
169 | return Axis::Horizontal; | | |||
170 | } else { | | |||
171 | return Axis::Vertical; | | |||
172 | } | | |||
173 | }; | | |||
174 | emit p->q->axisChanged(time, toAxis(), wl_fixed_to_double(value)); | | |||
175 | } | 180 | } | ||
176 | 181 | | |||
177 | void Pointer::Private::frameCallback(void *data, wl_pointer *pointer) | 182 | void Pointer::Private::frameCallback(void *data, wl_pointer *pointer) | ||
178 | { | 183 | { | ||
179 | auto p = reinterpret_cast<Pointer::Private*>(data); | 184 | auto p = reinterpret_cast<Pointer::Private*>(data); | ||
180 | Q_ASSERT(p->pointer == pointer); | 185 | Q_ASSERT(p->pointer == pointer); | ||
181 | emit p->q->frame(); | 186 | emit p->q->frame(); | ||
182 | } | 187 | } | ||
183 | 188 | | |||
184 | void Pointer::Private::axisSourceCallback(void *data, wl_pointer *pointer, uint32_t axis_source) | 189 | void Pointer::Private::axisSourceCallback(void *data, wl_pointer *pointer, uint32_t axis_source) | ||
185 | { | 190 | { | ||
186 | Q_UNUSED(data) | 191 | auto p = reinterpret_cast<Pointer::Private*>(data); | ||
187 | Q_UNUSED(pointer) | 192 | Q_ASSERT(p->pointer == pointer); | ||
188 | Q_UNUSED(axis_source) | 193 | AxisSource source; | ||
189 | // TODO: implement | 194 | switch (axis_source) { | ||
195 | case WL_POINTER_AXIS_SOURCE_WHEEL: | ||||
196 | source = AxisSource::Wheel; | ||||
197 | break; | ||||
198 | case WL_POINTER_AXIS_SOURCE_FINGER: | ||||
199 | source = AxisSource::Finger; | ||||
200 | break; | ||||
201 | case WL_POINTER_AXIS_SOURCE_CONTINUOUS: | ||||
202 | source = AxisSource::Continuous; | ||||
203 | break; | ||||
204 | case WL_POINTER_AXIS_SOURCE_WHEEL_TILT: | ||||
205 | source = AxisSource::WheelTilt; | ||||
206 | break; | ||||
207 | default: | ||||
208 | Q_UNREACHABLE(); | ||||
209 | break; | ||||
210 | } | ||||
211 | emit p->q->axisSourceChanged(source); | ||||
190 | } | 212 | } | ||
191 | 213 | | |||
192 | void Pointer::Private::axisStopCallback(void *data, wl_pointer *pointer, uint32_t time, uint32_t axis) | 214 | void Pointer::Private::axisStopCallback(void *data, wl_pointer *pointer, uint32_t time, uint32_t axis) | ||
193 | { | 215 | { | ||
194 | Q_UNUSED(data) | 216 | auto p = reinterpret_cast<Pointer::Private*>(data); | ||
195 | Q_UNUSED(pointer) | 217 | Q_ASSERT(p->pointer == pointer); | ||
196 | Q_UNUSED(time) | 218 | emit p->q->axisStopped(time, wlAxisToPointerAxis(axis)); | ||
197 | Q_UNUSED(axis) | | |||
198 | // TODO: implement | | |||
199 | } | 219 | } | ||
200 | 220 | | |||
201 | void Pointer::Private::axisDiscreteCallback(void *data, wl_pointer *pointer, uint32_t axis, int32_t discrete) | 221 | void Pointer::Private::axisDiscreteCallback(void *data, wl_pointer *pointer, uint32_t axis, int32_t discrete) | ||
202 | { | 222 | { | ||
203 | Q_UNUSED(data) | 223 | auto p = reinterpret_cast<Pointer::Private*>(data); | ||
204 | Q_UNUSED(pointer) | 224 | Q_ASSERT(p->pointer == pointer); | ||
205 | Q_UNUSED(axis) | 225 | emit p->q->axisDiscreteChanged(wlAxisToPointerAxis(axis), discrete); | ||
206 | Q_UNUSED(discrete) | | |||
207 | // TODO: implement | | |||
208 | } | 226 | } | ||
209 | 227 | | |||
210 | void Pointer::setCursor(Surface *surface, const QPoint &hotspot) | 228 | void Pointer::setCursor(Surface *surface, const QPoint &hotspot) | ||
211 | { | 229 | { | ||
212 | Q_ASSERT(isValid()); | 230 | Q_ASSERT(isValid()); | ||
213 | wl_surface *s = nullptr; | 231 | wl_surface *s = nullptr; | ||
214 | if (surface) { | 232 | if (surface) { | ||
215 | s = *surface; | 233 | s = *surface; | ||
Show All 36 Lines |