KWin
Loading...
Searching...
No Matches
cursorshape_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
9#include "wayland/display.h"
10#include "wayland/pointer.h"
11#include "wayland/surface.h"
12#include "wayland/tablet_v2.h"
13
14#include <QPointer>
15
16#include "qwayland-server-cursor-shape-v1.h"
17
18namespace KWin
19{
20
21static constexpr int s_version = 1;
22
23class CursorShapeManagerV1InterfacePrivate : public QtWaylandServer::wp_cursor_shape_manager_v1
24{
25public:
27
28protected:
29 void wp_cursor_shape_manager_v1_destroy(Resource *resource) override;
30 void wp_cursor_shape_manager_v1_get_pointer(Resource *resource, uint32_t cursor_shape_device, struct ::wl_resource *pointer) override;
31 void wp_cursor_shape_manager_v1_get_tablet_tool_v2(Resource *resource, uint32_t cursor_shape_device, struct ::wl_resource *tablet_tool) override;
32};
33
34class CursorShapeDeviceV1Interface : public QtWaylandServer::wp_cursor_shape_device_v1
35{
36public:
39
40 QPointer<PointerInterface> pointer;
41 QPointer<TabletToolV2Interface> tabletTool;
42
43protected:
44 void wp_cursor_shape_device_v1_destroy_resource(Resource *resource) override;
45 void wp_cursor_shape_device_v1_destroy(Resource *resource) override;
46 void wp_cursor_shape_device_v1_set_shape(Resource *resource, uint32_t serial, uint32_t shape) override;
47};
48
50 : QtWaylandServer::wp_cursor_shape_manager_v1(*display, s_version)
51{
52}
53
55{
56 wl_resource_destroy(resource->handle);
57}
58
59void CursorShapeManagerV1InterfacePrivate::wp_cursor_shape_manager_v1_get_pointer(Resource *resource, uint32_t cursor_shape_device, struct ::wl_resource *pointer)
60{
61 wl_resource *device = wl_resource_create(resource->client(), &wp_cursor_shape_device_v1_interface, resource->version(), cursor_shape_device);
62 if (!device) {
63 wl_resource_post_no_memory(resource->handle);
64 return;
65 }
67}
68
69void CursorShapeManagerV1InterfacePrivate::wp_cursor_shape_manager_v1_get_tablet_tool_v2(Resource *resource, uint32_t cursor_shape_device, struct ::wl_resource *tablet_tool)
70{
71 wl_resource *device = wl_resource_create(resource->client(), &wp_cursor_shape_device_v1_interface, resource->version(), cursor_shape_device);
72 if (!device) {
73 wl_resource_post_no_memory(resource->handle);
74 return;
75 }
77}
78
80 : QObject(parent)
81 , d(std::make_unique<CursorShapeManagerV1InterfacePrivate>(display))
82{
83}
84
88
90 : QtWaylandServer::wp_cursor_shape_device_v1(resource)
91 , pointer(pointer)
92{
93}
94
96 : QtWaylandServer::wp_cursor_shape_device_v1(resource)
97 , tabletTool(tabletTool)
98{
99}
100
102{
103 delete this;
104}
105
107{
108 wl_resource_destroy(resource->handle);
109}
110
111static QByteArray shapeName(uint32_t shape)
112{
113 switch (shape) {
114 case QtWaylandServer::wp_cursor_shape_device_v1::shape_default:
115 return QByteArrayLiteral("default");
116 case QtWaylandServer::wp_cursor_shape_device_v1::shape_context_menu:
117 return QByteArrayLiteral("context-menu");
118 case QtWaylandServer::wp_cursor_shape_device_v1::shape_help:
119 return QByteArrayLiteral("help");
120 case QtWaylandServer::wp_cursor_shape_device_v1::shape_pointer:
121 return QByteArrayLiteral("pointer");
122 case QtWaylandServer::wp_cursor_shape_device_v1::shape_progress:
123 return QByteArrayLiteral("progress");
124 case QtWaylandServer::wp_cursor_shape_device_v1::shape_wait:
125 return QByteArrayLiteral("wait");
126 case QtWaylandServer::wp_cursor_shape_device_v1::shape_cell:
127 return QByteArrayLiteral("cell");
128 case QtWaylandServer::wp_cursor_shape_device_v1::shape_crosshair:
129 return QByteArrayLiteral("crosshair");
130 case QtWaylandServer::wp_cursor_shape_device_v1::shape_text:
131 return QByteArrayLiteral("text");
132 case QtWaylandServer::wp_cursor_shape_device_v1::shape_vertical_text:
133 return QByteArrayLiteral("vertical-text");
134 case QtWaylandServer::wp_cursor_shape_device_v1::shape_alias:
135 return QByteArrayLiteral("alias");
136 case QtWaylandServer::wp_cursor_shape_device_v1::shape_copy:
137 return QByteArrayLiteral("copy");
138 case QtWaylandServer::wp_cursor_shape_device_v1::shape_move:
139 return QByteArrayLiteral("move");
140 case QtWaylandServer::wp_cursor_shape_device_v1::shape_no_drop:
141 return QByteArrayLiteral("no-drop");
142 case QtWaylandServer::wp_cursor_shape_device_v1::shape_not_allowed:
143 return QByteArrayLiteral("not-allowed");
144 case QtWaylandServer::wp_cursor_shape_device_v1::shape_grab:
145 return QByteArrayLiteral("grab");
146 case QtWaylandServer::wp_cursor_shape_device_v1::shape_grabbing:
147 return QByteArrayLiteral("grabbing");
148 case QtWaylandServer::wp_cursor_shape_device_v1::shape_e_resize:
149 return QByteArrayLiteral("e-resize");
150 case QtWaylandServer::wp_cursor_shape_device_v1::shape_n_resize:
151 return QByteArrayLiteral("n-resize");
152 case QtWaylandServer::wp_cursor_shape_device_v1::shape_ne_resize:
153 return QByteArrayLiteral("ne-resize");
154 case QtWaylandServer::wp_cursor_shape_device_v1::shape_nw_resize:
155 return QByteArrayLiteral("nw-resize");
156 case QtWaylandServer::wp_cursor_shape_device_v1::shape_s_resize:
157 return QByteArrayLiteral("s-resize");
158 case QtWaylandServer::wp_cursor_shape_device_v1::shape_se_resize:
159 return QByteArrayLiteral("se-resize");
160 case QtWaylandServer::wp_cursor_shape_device_v1::shape_sw_resize:
161 return QByteArrayLiteral("sw-resize");
162 case QtWaylandServer::wp_cursor_shape_device_v1::shape_w_resize:
163 return QByteArrayLiteral("w-resize");
164 case QtWaylandServer::wp_cursor_shape_device_v1::shape_ew_resize:
165 return QByteArrayLiteral("ew-resize");
166 case QtWaylandServer::wp_cursor_shape_device_v1::shape_ns_resize:
167 return QByteArrayLiteral("ns-resize");
168 case QtWaylandServer::wp_cursor_shape_device_v1::shape_nesw_resize:
169 return QByteArrayLiteral("nesw-resize");
170 case QtWaylandServer::wp_cursor_shape_device_v1::shape_nwse_resize:
171 return QByteArrayLiteral("nwse-resize");
172 case QtWaylandServer::wp_cursor_shape_device_v1::shape_col_resize:
173 return QByteArrayLiteral("col-resize");
174 case QtWaylandServer::wp_cursor_shape_device_v1::shape_row_resize:
175 return QByteArrayLiteral("row-resize");
176 case QtWaylandServer::wp_cursor_shape_device_v1::shape_all_scroll:
177 return QByteArrayLiteral("all-scroll");
178 case QtWaylandServer::wp_cursor_shape_device_v1::shape_zoom_in:
179 return QByteArrayLiteral("zoom-in");
180 case QtWaylandServer::wp_cursor_shape_device_v1::shape_zoom_out:
181 return QByteArrayLiteral("zoom-out");
182 default:
183 return QByteArrayLiteral("default");
184 }
185}
186
187void CursorShapeDeviceV1Interface::wp_cursor_shape_device_v1_set_shape(Resource *resource, uint32_t serial, uint32_t shape)
188{
189 if (shape < shape_default || shape > shape_zoom_out) {
190 wl_resource_post_error(resource->handle, error_invalid_shape, "unknown cursor shape");
191 return;
192 }
193 if (pointer) {
194 if (!pointer->focusedSurface() || pointer->focusedSurface()->client()->client() != resource->client()) {
195 return;
196 }
197 if (pointer->focusedSerial() == serial) {
198 Q_EMIT pointer->cursorChanged(shapeName(shape));
199 }
200 } else if (tabletTool) {
201 if (!tabletTool->currentSurface() || tabletTool->currentSurface()->client()->client() != resource->client()) {
202 return;
203 }
204 if (tabletTool->proximitySerial() == serial) {
205 Q_EMIT tabletTool->cursorChanged(shapeName(shape));
206 }
207 }
208}
209
210} // namespace KWin
void wp_cursor_shape_device_v1_destroy(Resource *resource) override
QPointer< PointerInterface > pointer
void wp_cursor_shape_device_v1_set_shape(Resource *resource, uint32_t serial, uint32_t shape) override
void wp_cursor_shape_device_v1_destroy_resource(Resource *resource) override
CursorShapeDeviceV1Interface(PointerInterface *pointer, wl_resource *resource)
QPointer< TabletToolV2Interface > tabletTool
CursorShapeManagerV1Interface(Display *display, QObject *parent=nullptr)
void wp_cursor_shape_manager_v1_destroy(Resource *resource) override
void wp_cursor_shape_manager_v1_get_pointer(Resource *resource, uint32_t cursor_shape_device, struct ::wl_resource *pointer) override
void wp_cursor_shape_manager_v1_get_tablet_tool_v2(Resource *resource, uint32_t cursor_shape_device, struct ::wl_resource *tablet_tool) override
Class holding the Wayland server display loop.
Definition display.h:34
static PointerInterface * get(wl_resource *native)
Definition pointer.cpp:370
static TabletToolV2Interface * get(wl_resource *resource)