KWin
Loading...
Searching...
No Matches
relativepointer_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
3 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
9#include "clientconnection.h"
10#include "display.h"
11#include "pointer_p.h"
13#include "seat.h"
14#include "surface.h"
15
16namespace KWin
17{
18static const int s_version = 1;
19
21 : QtWaylandServer::zwp_relative_pointer_manager_v1(*display, s_version)
22{
23}
24
26{
27 wl_resource_destroy(resource->handle);
28}
29
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
41 relativePointer->add(resource->client(), id, resource->version());
42}
43
45 : QObject(parent)
47{
48}
49
53
58
60{
61 if (pointer) {
63 return pointerPrivate->relativePointersV1.get();
64 }
65 return nullptr;
66}
67
69{
70 wl_resource_destroy(resource->handle);
71}
72
73void RelativePointerV1Interface::sendRelativeMotion(const QPointF &delta, const QPointF &deltaNonAccelerated, std::chrono::microseconds time)
74{
75 if (!pointer->focusedSurface()) {
76 return;
77 }
78
79 auto scaleOverride = pointer->focusedSurface()->scaleOverride();
80
81 ClientConnection *focusedClient = pointer->focusedSurface()->client();
82 const QList<Resource *> pointerResources = resourceMap().values(focusedClient->client());
83 for (Resource *pointerResource : pointerResources) {
84 if (pointerResource->client() == focusedClient->client()) {
85 send_relative_motion(pointerResource->handle,
86 time.count() >> 32,
87 time.count() & 0xffffffff,
88 wl_fixed_from_double(delta.x() * scaleOverride),
89 wl_fixed_from_double(delta.y() * scaleOverride),
90 wl_fixed_from_double(deltaNonAccelerated.x() * scaleOverride),
91 wl_fixed_from_double(deltaNonAccelerated.y() * scaleOverride));
92 }
93 }
94}
95
96} // namespace KWin
97
98#include "moc_relativepointer_v1.cpp"
Convenient Class which represents a wl_client.
wl_client * client() const
Class holding the Wayland server display loop.
Definition display.h:34
SurfaceInterface * focusedSurface() const
Definition pointer.cpp:158
static PointerInterface * get(wl_resource *native)
Definition pointer.cpp:370
std::unique_ptr< RelativePointerV1Interface > relativePointersV1
Definition pointer_p.h:70
static PointerInterfacePrivate * get(PointerInterface *pointer)
Definition pointer.cpp:29
RelativePointerManagerV1Interface(Display *display, QObject *parent=nullptr)
void zwp_relative_pointer_manager_v1_get_relative_pointer(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource) override
void zwp_relative_pointer_manager_v1_destroy(Resource *resource) override
static RelativePointerV1Interface * get(PointerInterface *pointer)
RelativePointerV1Interface(PointerInterface *pointer)
void sendRelativeMotion(const QPointF &delta, const QPointF &deltaNonAccelerated, std::chrono::microseconds time)
void zwp_relative_pointer_v1_destroy(Resource *resource) override
ClientConnection * client() const
Definition surface.cpp:444
qreal scaleOverride() const
Definition surface.cpp:1066