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

KDE's Doxygen guidelines are available online.