2020-11-03 16:24:03 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "relativepointer_v1_interface.h"
|
2021-02-12 22:29:45 +00:00
|
|
|
#include "clientconnection.h"
|
2020-11-03 16:24:03 +00:00
|
|
|
#include "display.h"
|
|
|
|
#include "pointer_interface_p.h"
|
|
|
|
#include "relativepointer_v1_interface_p.h"
|
2021-02-12 22:29:45 +00:00
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "surface_interface.h"
|
2020-11-03 16:24:03 +00:00
|
|
|
|
|
|
|
namespace KWaylandServer
|
|
|
|
{
|
|
|
|
|
|
|
|
static const int s_version = 1;
|
|
|
|
|
|
|
|
RelativePointerManagerV1InterfacePrivate::RelativePointerManagerV1InterfacePrivate(Display *display)
|
|
|
|
: QtWaylandServer::zwp_relative_pointer_manager_v1(*display, s_version)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RelativePointerManagerV1InterfacePrivate::zwp_relative_pointer_manager_v1_destroy(Resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RelativePointerManagerV1InterfacePrivate::zwp_relative_pointer_manager_v1_get_relative_pointer(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource)
|
|
|
|
{
|
|
|
|
PointerInterface *pointer = PointerInterface::get(pointer_resource);
|
|
|
|
if (!pointer) {
|
|
|
|
wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"invalid pointer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
RelativePointerV1Interface *relativePointer = RelativePointerV1Interface::get(pointer);
|
|
|
|
relativePointer->add(resource->client(), id, resource->version());
|
2020-11-03 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RelativePointerManagerV1Interface::RelativePointerManagerV1Interface(Display *display, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new RelativePointerManagerV1InterfacePrivate(display))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RelativePointerManagerV1Interface::~RelativePointerManagerV1Interface()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
RelativePointerV1Interface::RelativePointerV1Interface(PointerInterface *pointer)
|
|
|
|
: pointer(pointer)
|
2020-11-03 16:24:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
RelativePointerV1Interface *RelativePointerV1Interface::get(PointerInterface *pointer)
|
2020-11-03 16:24:03 +00:00
|
|
|
{
|
|
|
|
if (pointer) {
|
2021-02-12 22:29:45 +00:00
|
|
|
PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer);
|
|
|
|
return pointerPrivate->relativePointersV1.data();
|
2020-11-03 16:24:03 +00:00
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
return nullptr;
|
2020-11-03 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void RelativePointerV1Interface::zwp_relative_pointer_v1_destroy(Resource *resource)
|
2020-11-03 16:24:03 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
wl_resource_destroy(resource->handle);
|
2020-11-03 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void RelativePointerV1Interface::sendRelativeMotion(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 microseconds)
|
2020-11-03 16:24:03 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
if (!pointer->focusedSurface()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientConnection *focusedClient = pointer->focusedSurface()->client();
|
|
|
|
const QList<Resource *> pointerResources = resourceMap().values(focusedClient->client());
|
|
|
|
for (Resource *pointerResource : pointerResources) {
|
|
|
|
if (pointerResource->client() == focusedClient->client()) {
|
|
|
|
send_relative_motion(pointerResource->handle, microseconds >> 32, microseconds & 0xffffffff,
|
|
|
|
wl_fixed_from_double(delta.width()),
|
|
|
|
wl_fixed_from_double(delta.height()),
|
|
|
|
wl_fixed_from_double(deltaNonAccelerated.width()),
|
|
|
|
wl_fixed_from_double(deltaNonAccelerated.height()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-11-03 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWaylandServer
|