Skip to content

Commit 746bc7e

Browse files
akliuxingyuanammen99
authored andcommitted
feat: support cursor-shape-v1 protocol (#2852)
* feat: support cursor-shape-v1 protocol * fix code style
1 parent ed46b78 commit 746bc7e

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

proto/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ server_protocols = [
3232
[wl_protocol_dir, 'unstable/input-method/input-method-unstable-v1.xml'],
3333
[wl_protocol_dir, 'staging/ext-session-lock/ext-session-lock-v1.xml'],
3434
[wl_protocol_dir, 'unstable/text-input/text-input-unstable-v1.xml'],
35+
[wl_protocol_dir, 'staging/cursor-shape/cursor-shape-v1.xml'],
3536
'wayfire-shell-unstable-v2.xml',
3637
'gtk-shell.xml',
3738
'wlr-layer-shell-unstable-v1.xml',

src/api/wayfire/nonstd/wlroots-full.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ extern "C"
155155
#include <wlr/types/wlr_fractional_scale_v1.h>
156156
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
157157
#include <wlr/types/wlr_session_lock_v1.h>
158+
#if __has_include(<cursor-shape-v1-protocol.h>)
159+
#include <wlr/types/wlr_cursor_shape_v1.h>
160+
#endif
158161

159162
// Activation plugin
160163
#include <wlr/types/wlr_xdg_activation_v1.h>

src/api/wayfire/nonstd/wlroots.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C"
3939
struct wlr_primary_selection_v1_device_manager;
4040
struct wlr_drm_lease_v1_manager;
4141
struct wlr_session_lock_manager_v1;
42+
struct wlr_cursor_shape_manager_v1;
4243

4344
struct wlr_xdg_foreign_v1;
4445
struct wlr_xdg_foreign_v2;

src/core/seat/cursor.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ wf::cursor_t::cursor_t(wf::seat_t *seat)
1919
wlr_cursor_map_to_output(cursor, NULL);
2020
wlr_cursor_warp(cursor, NULL, cursor->x, cursor->y);
2121
init_xcursor();
22+
init_cursor_shape_manager();
2223

2324
config_reloaded = [=] (auto)
2425
{
@@ -128,14 +129,46 @@ void wf::cursor_t::init_xcursor()
128129
set_cursor("default");
129130
}
130131

131-
void wf::cursor_t::set_cursor(std::string name)
132+
bool wf::cursor_t::can_client_set_cursor()
132133
{
134+
if (this->touchscreen_mode_active)
135+
{
136+
return false;
137+
}
138+
133139
if (this->hide_ref_counter)
134140
{
135-
return;
141+
return false;
136142
}
137143

138-
if (this->touchscreen_mode_active)
144+
return true;
145+
}
146+
147+
void wf::cursor_t::init_cursor_shape_manager()
148+
{
149+
cursor_shape_manager = wlr_cursor_shape_manager_v1_create(seat->seat->display, 1);
150+
request_set_cursor_shape.set_callback([&] (void *data)
151+
{
152+
auto event = (wlr_cursor_shape_manager_v1_request_set_shape_event*)data;
153+
const char *shape_name = wlr_cursor_shape_v1_name(event->shape);
154+
struct wlr_seat_client *focused_client = seat->seat->pointer_state.focused_client;
155+
156+
if (focused_client != event->seat_client)
157+
{
158+
return;
159+
}
160+
161+
if (can_client_set_cursor())
162+
{
163+
wlr_cursor_set_xcursor(cursor, xcursor, shape_name);
164+
}
165+
});
166+
request_set_cursor_shape.connect(&cursor_shape_manager->events.request_set_shape);
167+
}
168+
169+
void wf::cursor_t::set_cursor(std::string name)
170+
{
171+
if (!can_client_set_cursor())
139172
{
140173
return;
141174
}
@@ -189,12 +222,7 @@ wf::pointf_t wf::cursor_t::get_cursor_position()
189222
void wf::cursor_t::set_cursor(
190223
wlr_seat_pointer_request_set_cursor_event *ev, bool validate_request)
191224
{
192-
if (this->hide_ref_counter)
193-
{
194-
return;
195-
}
196-
197-
if (this->touchscreen_mode_active)
225+
if (!can_client_set_cursor())
198226
{
199227
return;
200228
}

src/core/seat/cursor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct cursor_t
2626
void set_cursor(wlr_seat_pointer_request_set_cursor_event *ev,
2727
bool validate_request);
2828
void set_cursor(std::string name);
29+
bool can_client_set_cursor();
2930
void unhide_cursor();
3031
void hide_cursor();
3132
int hide_ref_counter = 0;
@@ -48,6 +49,7 @@ struct cursor_t
4849
wf::pointf_t get_cursor_position();
4950

5051
void init_xcursor();
52+
void init_cursor_shape_manager();
5153
void setup_listeners();
5254

5355
// Device event listeners
@@ -63,12 +65,14 @@ struct cursor_t
6365

6466
// Seat events
6567
wf::wl_listener_wrapper request_set_cursor;
68+
wf::wl_listener_wrapper request_set_cursor_shape;
6669

6770
wf::signal::connection_t<wf::reload_config_signal> config_reloaded;
6871
wf::seat_t *seat;
6972

7073
wlr_cursor *cursor = NULL;
7174
wlr_xcursor_manager *xcursor = NULL;
75+
wlr_cursor_shape_manager_v1 *cursor_shape_manager = NULL;
7276

7377
std::string last_cursor_name;
7478

0 commit comments

Comments
 (0)