1 /**************************************************************************** 2 Copyright © 2020 Roman Gilg <subdiff@gmail.com> 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) version 3, or any 8 later version accepted by the membership of KDE e.V. (or its 9 successor approved by the membership of KDE e.V.), which shall 10 act as a proxy defined in Section 6 of version 3 of the license. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library. If not, see <http://www.gnu.org/licenses/>. 19 ****************************************************************************/ 20 #pragma once 21 22 #include "pointer_constraints_v1.h" 23 24 #include "wayland/global.h" 25 26 #include <QRegion> 27 28 #include <wayland-pointer-constraints-unstable-v1-server-protocol.h> 29 30 namespace Wrapland::Server 31 { 32 33 constexpr uint32_t PointerConstraintsV1Version = 1; 34 using PointerConstraintsV1Global 35 = Wayland::Global<PointerConstraintsV1, PointerConstraintsV1Version>; 36 using PointerConstraintsV1Bind = Wayland::Bind<PointerConstraintsV1Global>; 37 38 class PointerConstraintsV1::Private : public PointerConstraintsV1Global 39 { 40 public: 41 Private(PointerConstraintsV1* q, Display* display); 42 43 static void destroyCallback(wl_client* client, wl_resource* resource); 44 static void lockPointerCallback(PointerConstraintsV1Bind* bind, 45 uint32_t id, 46 wl_resource* wlSurface, 47 wl_resource* wlPointer, 48 wl_resource* wlRegion, 49 uint32_t lifetime); 50 static void confinePointerCallback(PointerConstraintsV1Bind* bind, 51 uint32_t id, 52 wl_resource* wlSurface, 53 wl_resource* wlPointer, 54 wl_resource* wlRegion, 55 uint32_t lifetime); 56 57 template<class Constraint> 58 void createConstraint(wl_resource* wlResource, 59 uint32_t id, 60 wl_resource* wlSurface, 61 wl_resource* wlPointer, 62 wl_resource* wlRegion, 63 uint32_t lifetime); 64 65 private: 66 static const struct zwp_pointer_constraints_v1_interface s_interface; 67 68 PointerConstraintsV1* q_ptr; 69 }; 70 71 class LockedPointerV1::Private : public Wayland::Resource<LockedPointerV1> 72 { 73 public: 74 Private(Client* client, uint32_t version, uint32_t id, LockedPointerV1* q); 75 76 void update(); 77 void commit(); 78 79 LifeTime lifeTime; 80 QRegion region; 81 bool locked = false; 82 QPointF hint = QPointF(-1., -1.); 83 84 QRegion pendingRegion; 85 bool regionIsSet = false; 86 87 QPointF pendingHint; 88 bool hintIsSet = false; 89 90 private: 91 static const struct zwp_locked_pointer_v1_interface s_interface; 92 static void setCursorPositionHintCallback(wl_client* wlClient, 93 wl_resource* wlResource, 94 wl_fixed_t surface_x, 95 wl_fixed_t surface_y); 96 static void 97 setRegionCallback(wl_client* wlClient, wl_resource* wlResource, wl_resource* wlRegion); 98 99 LockedPointerV1* q_ptr; 100 }; 101 102 class ConfinedPointerV1::Private : public Wayland::Resource<ConfinedPointerV1> 103 { 104 public: 105 Private(Client* client, uint32_t version, uint32_t id, ConfinedPointerV1* q); 106 107 void update(); 108 void commit(); 109 110 LifeTime lifeTime; 111 QRegion region; 112 113 bool confined = false; 114 115 QRegion pendingRegion; 116 bool regionIsSet = false; 117 118 private: 119 static const struct zwp_confined_pointer_v1_interface s_interface; 120 static void 121 setRegionCallback(wl_client* wlClient, wl_resource* wlResource, wl_resource* wlRegion); 122 123 ConfinedPointerV1* q_ptr; 124 }; 125 126 } 127