File indexing completed on 2024-11-10 04:57:31
0001 /* 0002 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "relativepointer_v1.h" 0009 #include "clientconnection.h" 0010 #include "display.h" 0011 #include "pointer_p.h" 0012 #include "relativepointer_v1_p.h" 0013 #include "seat.h" 0014 #include "surface.h" 0015 0016 namespace KWin 0017 { 0018 static const int s_version = 1; 0019 0020 RelativePointerManagerV1InterfacePrivate::RelativePointerManagerV1InterfacePrivate(Display *display) 0021 : QtWaylandServer::zwp_relative_pointer_manager_v1(*display, s_version) 0022 { 0023 } 0024 0025 void RelativePointerManagerV1InterfacePrivate::zwp_relative_pointer_manager_v1_destroy(Resource *resource) 0026 { 0027 wl_resource_destroy(resource->handle); 0028 } 0029 0030 void RelativePointerManagerV1InterfacePrivate::zwp_relative_pointer_manager_v1_get_relative_pointer(Resource *resource, 0031 uint32_t id, 0032 struct ::wl_resource *pointer_resource) 0033 { 0034 PointerInterface *pointer = PointerInterface::get(pointer_resource); 0035 if (!pointer) { 0036 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "invalid pointer"); 0037 return; 0038 } 0039 0040 RelativePointerV1Interface *relativePointer = RelativePointerV1Interface::get(pointer); 0041 relativePointer->add(resource->client(), id, resource->version()); 0042 } 0043 0044 RelativePointerManagerV1Interface::RelativePointerManagerV1Interface(Display *display, QObject *parent) 0045 : QObject(parent) 0046 , d(new RelativePointerManagerV1InterfacePrivate(display)) 0047 { 0048 } 0049 0050 RelativePointerManagerV1Interface::~RelativePointerManagerV1Interface() 0051 { 0052 } 0053 0054 RelativePointerV1Interface::RelativePointerV1Interface(PointerInterface *pointer) 0055 : pointer(pointer) 0056 { 0057 } 0058 0059 RelativePointerV1Interface *RelativePointerV1Interface::get(PointerInterface *pointer) 0060 { 0061 if (pointer) { 0062 PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer); 0063 return pointerPrivate->relativePointersV1.get(); 0064 } 0065 return nullptr; 0066 } 0067 0068 void RelativePointerV1Interface::zwp_relative_pointer_v1_destroy(Resource *resource) 0069 { 0070 wl_resource_destroy(resource->handle); 0071 } 0072 0073 void RelativePointerV1Interface::sendRelativeMotion(const QPointF &delta, const QPointF &deltaNonAccelerated, std::chrono::microseconds time) 0074 { 0075 if (!pointer->focusedSurface()) { 0076 return; 0077 } 0078 0079 auto scaleOverride = pointer->focusedSurface()->scaleOverride(); 0080 0081 ClientConnection *focusedClient = pointer->focusedSurface()->client(); 0082 const QList<Resource *> pointerResources = resourceMap().values(focusedClient->client()); 0083 for (Resource *pointerResource : pointerResources) { 0084 if (pointerResource->client() == focusedClient->client()) { 0085 send_relative_motion(pointerResource->handle, 0086 time.count() >> 32, 0087 time.count() & 0xffffffff, 0088 wl_fixed_from_double(delta.x() * scaleOverride), 0089 wl_fixed_from_double(delta.y() * scaleOverride), 0090 wl_fixed_from_double(deltaNonAccelerated.x() * scaleOverride), 0091 wl_fixed_from_double(deltaNonAccelerated.y() * scaleOverride)); 0092 } 0093 } 0094 } 0095 0096 } // namespace KWin 0097 0098 #include "moc_relativepointer_v1.cpp"