From 6bd11ad0dfb11f8cf7e0ab5330cd2488851c5614 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 5 May 2023 16:34:35 +0200 Subject: Add support for cursor-shape-v1 References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4106 --- sway/input/cursor.c | 24 ++++++++++++++++++++++++ sway/server.c | 7 +++++++ 2 files changed, 31 insertions(+) (limited to 'sway') diff --git a/sway/input/cursor.c b/sway/input/cursor.c index f970e6a2..62c74d04 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1467,3 +1468,26 @@ void sway_cursor_constrain(struct sway_cursor *cursor, wl_signal_add(&constraint->surface->events.commit, &cursor->constraint_commit); } + +void handle_request_set_cursor_shape(struct wl_listener *listener, void *data) { + const struct wlr_cursor_shape_manager_v1_request_set_shape_event *event = data; + struct sway_seat *seat = event->seat_client->seat->data; + + if (!seatop_allows_set_cursor(seat)) { + return; + } + + struct wl_client *focused_client = NULL; + struct wlr_surface *focused_surface = seat->wlr_seat->pointer_state.focused_surface; + if (focused_surface != NULL) { + focused_client = wl_resource_get_client(focused_surface->resource); + } + + // TODO: check cursor mode + if (focused_client == NULL || event->seat_client->client != focused_client) { + sway_log(SWAY_DEBUG, "denying request to set cursor from unfocused client"); + return; + } + + cursor_set_image(seat->cursor, wlr_cursor_shape_v1_name(event->shape), focused_client); +} diff --git a/sway/server.c b/sway/server.c index 3a11088a..50f0a702 100644 --- a/sway/server.c +++ b/sway/server.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ #include "sway/input/input-manager.h" #include "sway/output.h" #include "sway/server.h" +#include "sway/input/cursor.h" #include "sway/tree/root.h" #if HAVE_XWAYLAND @@ -235,6 +237,11 @@ bool server_init(struct sway_server *server) { wl_signal_add(&server->xdg_activation_v1->events.new_token, &server->xdg_activation_v1_new_token); + struct wlr_cursor_shape_manager_v1 *cursor_shape_manager = + wlr_cursor_shape_manager_v1_create(server->wl_display, 1); + server->request_set_cursor_shape.notify = handle_request_set_cursor_shape; + wl_signal_add(&cursor_shape_manager->events.request_set_shape, &server->request_set_cursor_shape); + wl_list_init(&server->pending_launcher_ctxs); // Avoid using "wayland-0" as display socket -- cgit v1.2.3-54-g00ecf