KWayland

relativepointer_interface_v1.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 "display.h"
7 #include "pointer_interface_p.h"
8 #include "relativepointer_interface_p.h"
9 #include <QSizeF>
10 #include <wayland-relativepointer-unstable-v1-server-protocol.h>
11 
12 namespace KWayland
13 {
14 namespace Server
15 {
16 class RelativePointerManagerUnstableV1Interface::Private : public RelativePointerManagerInterface::Private
17 {
18 public:
19  Private(RelativePointerManagerUnstableV1Interface *q, Display *d);
20 
21 private:
22  void bind(wl_client *client, uint32_t version, uint32_t id) override;
23 
24  static void unbind(wl_resource *resource);
25  static Private *cast(wl_resource *r)
26  {
27  return reinterpret_cast<Private *>(wl_resource_get_user_data(r));
28  }
29 
30  static void destroyCallback(wl_client *client, wl_resource *resource);
31  static void getRelativePointerCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *pointer);
32 
33  RelativePointerManagerUnstableV1Interface *q;
34 
35  static const struct zwp_relative_pointer_manager_v1_interface s_interface;
36  static const quint32 s_version;
37 };
38 
39 const quint32 RelativePointerManagerUnstableV1Interface::Private::s_version = 1;
40 
41 #ifndef K_DOXYGEN
42 const struct zwp_relative_pointer_manager_v1_interface RelativePointerManagerUnstableV1Interface::Private::s_interface = {destroyCallback,
43  getRelativePointerCallback};
44 #endif
45 
46 void RelativePointerManagerUnstableV1Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
47 {
48  Q_UNUSED(client)
49  wl_resource_destroy(resource);
50 }
51 
52 void RelativePointerManagerUnstableV1Interface::Private::getRelativePointerCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *pointer)
53 {
54  PointerInterface *p = PointerInterface::get(pointer);
55  if (!p) {
56  // TODO: raise error?
57  return;
58  }
59  auto m = cast(resource);
60  auto *r = new RelativePointerUnstableV1Interface(m->q, resource);
61  r->d->create(m->display->getConnection(client), version, id);
62  p->d_func()->registerRelativePointer(r);
63 }
64 
65 RelativePointerManagerUnstableV1Interface::Private::Private(RelativePointerManagerUnstableV1Interface *q, Display *d)
66  : RelativePointerManagerInterface::Private(RelativePointerInterfaceVersion::UnstableV1, q, d, &zwp_relative_pointer_manager_v1_interface, s_version)
67  , q(q)
68 {
69 }
70 
71 void RelativePointerManagerUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
72 {
73  auto c = display->getConnection(client);
74  wl_resource *resource = c->createResource(&zwp_relative_pointer_manager_v1_interface, qMin(version, s_version), id);
75  if (!resource) {
76  wl_client_post_no_memory(client);
77  return;
78  }
79  wl_resource_set_implementation(resource, &s_interface, this, unbind);
80  // TODO: should we track?
81 }
82 
83 void RelativePointerManagerUnstableV1Interface::Private::unbind(wl_resource *resource)
84 {
85  Q_UNUSED(resource)
86  // TODO: implement?
87 }
88 
89 RelativePointerManagerUnstableV1Interface::RelativePointerManagerUnstableV1Interface(Display *display, QObject *parent)
90  : RelativePointerManagerInterface(new Private(this, display), parent)
91 {
92 }
93 
94 RelativePointerManagerUnstableV1Interface::~RelativePointerManagerUnstableV1Interface() = default;
95 
96 class RelativePointerUnstableV1Interface::Private : public RelativePointerInterface::Private
97 {
98 public:
99  Private(RelativePointerUnstableV1Interface *q, RelativePointerManagerUnstableV1Interface *c, wl_resource *parentResource);
100  ~Private() override;
101  void relativeMotion(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 microseconds) override;
102 
103 private:
104  RelativePointerUnstableV1Interface *q_func()
105  {
106  return reinterpret_cast<RelativePointerUnstableV1Interface *>(q);
107  }
108 
109  static const struct zwp_relative_pointer_v1_interface s_interface;
110 };
111 
112 #ifndef K_DOXYGEN
113 const struct zwp_relative_pointer_v1_interface RelativePointerUnstableV1Interface::Private::s_interface = {resourceDestroyedCallback};
114 #endif
115 
116 RelativePointerUnstableV1Interface::Private::Private(RelativePointerUnstableV1Interface *q,
117  RelativePointerManagerUnstableV1Interface *c,
118  wl_resource *parentResource)
119  : RelativePointerInterface::Private(q, c, parentResource, &zwp_relative_pointer_v1_interface, &s_interface)
120 {
121 }
122 
123 RelativePointerUnstableV1Interface::Private::~Private() = default;
124 
125 void RelativePointerUnstableV1Interface::Private::relativeMotion(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 microseconds)
126 {
127  if (!resource) {
128  return;
129  }
130  zwp_relative_pointer_v1_send_relative_motion(resource,
131  (microseconds >> 32),
132  microseconds,
133  wl_fixed_from_double(delta.width()),
134  wl_fixed_from_double(delta.height()),
135  wl_fixed_from_double(deltaNonAccelerated.width()),
136  wl_fixed_from_double(deltaNonAccelerated.height()));
137 }
138 
139 RelativePointerUnstableV1Interface::RelativePointerUnstableV1Interface(RelativePointerManagerUnstableV1Interface *parent, wl_resource *parentResource)
140  : RelativePointerInterface(new Private(this, parent, parentResource))
141 {
142 }
143 
144 RelativePointerUnstableV1Interface::~RelativePointerUnstableV1Interface() = default;
145 
146 }
147 }
qreal height() const const
static PointerInterface * get(wl_resource *native)
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.