KWaylandServer

relativepointer_v1_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Martin Gräßlin <[email protected]>
3  SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #include "relativepointer_v1_interface.h"
9 #include "clientconnection.h"
10 #include "display.h"
11 #include "pointer_interface_p.h"
12 #include "relativepointer_v1_interface_p.h"
13 #include "seat_interface.h"
14 #include "surface_interface.h"
15 
16 namespace KWaylandServer
17 {
18 static const int s_version = 1;
19 
20 RelativePointerManagerV1InterfacePrivate::RelativePointerManagerV1InterfacePrivate(Display *display)
21  : QtWaylandServer::zwp_relative_pointer_manager_v1(*display, s_version)
22 {
23 }
24 
25 void RelativePointerManagerV1InterfacePrivate::zwp_relative_pointer_manager_v1_destroy(Resource *resource)
26 {
27  wl_resource_destroy(resource->handle);
28 }
29 
30 void RelativePointerManagerV1InterfacePrivate::zwp_relative_pointer_manager_v1_get_relative_pointer(Resource *resource,
31  uint32_t id,
32  struct ::wl_resource *pointer_resource)
33 {
34  PointerInterface *pointer = PointerInterface::get(pointer_resource);
35  if (!pointer) {
36  wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "invalid pointer");
37  return;
38  }
39 
40  RelativePointerV1Interface *relativePointer = RelativePointerV1Interface::get(pointer);
41  relativePointer->add(resource->client(), id, resource->version());
42 }
43 
44 RelativePointerManagerV1Interface::RelativePointerManagerV1Interface(Display *display, QObject *parent)
45  : QObject(parent)
46  , d(new RelativePointerManagerV1InterfacePrivate(display))
47 {
48 }
49 
50 RelativePointerManagerV1Interface::~RelativePointerManagerV1Interface()
51 {
52 }
53 
54 RelativePointerV1Interface::RelativePointerV1Interface(PointerInterface *pointer)
55  : pointer(pointer)
56 {
57 }
58 
59 RelativePointerV1Interface *RelativePointerV1Interface::get(PointerInterface *pointer)
60 {
61  if (pointer) {
62  PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer);
63  return pointerPrivate->relativePointersV1.data();
64  }
65  return nullptr;
66 }
67 
68 void RelativePointerV1Interface::zwp_relative_pointer_v1_destroy(Resource *resource)
69 {
70  wl_resource_destroy(resource->handle);
71 }
72 
73 void RelativePointerV1Interface::sendRelativeMotion(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 microseconds)
74 {
75  if (!pointer->focusedSurface()) {
76  return;
77  }
78 
79  ClientConnection *focusedClient = pointer->focusedSurface()->client();
80  const QList<Resource *> pointerResources = resourceMap().values(focusedClient->client());
81  for (Resource *pointerResource : pointerResources) {
82  if (pointerResource->client() == focusedClient->client()) {
83  send_relative_motion(pointerResource->handle,
84  microseconds >> 32,
85  microseconds & 0xffffffff,
86  wl_fixed_from_double(delta.width()),
87  wl_fixed_from_double(delta.height()),
88  wl_fixed_from_double(deltaNonAccelerated.width()),
89  wl_fixed_from_double(deltaNonAccelerated.height()));
90  }
91  }
92 }
93 
94 } // namespace KWaylandServer
static PointerInterface * get(wl_resource *native)
qreal height() const const
QObject * parent() const const
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.