From 0bdfdde29b8a4fddd8416051a11f30e06bedc6ed Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sun, 29 Dec 2019 01:00:35 -0700 Subject: [PATCH 1/2] Basic implementation of request_set_cursor Requires moving wlr_seat initialization above cursor creation, so we can add listeners to it. Currently does no verification that the client actually has focus. --- include/input/cursor.h | 1 + kiwmi/input/cursor.c | 16 ++++++++++++++++ kiwmi/input/input.c | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/input/cursor.h b/include/input/cursor.h index 3c0feda..8ae6c63 100644 --- a/include/input/cursor.h +++ b/include/input/cursor.h @@ -18,6 +18,7 @@ struct kiwmi_cursor { struct wl_listener cursor_motion; struct wl_listener cursor_motion_absolute; struct wl_listener cursor_button; + struct wl_listener request_set_cursor; }; struct kiwmi_cursor *cursor_create( diff --git a/kiwmi/input/cursor.c b/kiwmi/input/cursor.c index 4cd466b..e63e518 100644 --- a/kiwmi/input/cursor.c +++ b/kiwmi/input/cursor.c @@ -110,6 +110,17 @@ cursor_button_notify(struct wl_listener *listener, void *data) } } +static void +request_set_cursor_notify(struct wl_listener *listener, void *data) +{ + struct kiwmi_cursor *cursor = + wl_container_of(listener, cursor, request_set_cursor); + struct wlr_seat_pointer_request_set_cursor_event *event = data; + // FIXME: this should verify if the window has focus + wlr_cursor_set_surface( + cursor->cursor, event->surface, event->hotspot_x, event->hotspot_y); +} + struct kiwmi_cursor * cursor_create( struct kiwmi_server *server, @@ -147,5 +158,10 @@ cursor_create( cursor->cursor_button.notify = cursor_button_notify; wl_signal_add(&cursor->cursor->events.button, &cursor->cursor_button); + cursor->request_set_cursor.notify = request_set_cursor_notify; + wl_signal_add( + &server->input.seat->events.request_set_cursor, + &cursor->request_set_cursor); + return cursor; } diff --git a/kiwmi/input/input.c b/kiwmi/input/input.c index 07dfc30..11b291c 100644 --- a/kiwmi/input/input.c +++ b/kiwmi/input/input.c @@ -71,14 +71,14 @@ input_init(struct kiwmi_input *input) { struct kiwmi_server *server = wl_container_of(input, server, input); + input->seat = wlr_seat_create(server->wl_display, "seat-0"); + input->cursor = cursor_create(server, server->desktop.output_layout); if (!input->cursor) { wlr_log(WLR_ERROR, "Failed to create cursor"); return false; } - input->seat = wlr_seat_create(server->wl_display, "seat-0"); - wl_list_init(&input->keyboards); input->new_input.notify = new_input_notify; From 9dfbb462ca96007b42dc69dfd2c5ee6b10c12c6c Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sun, 29 Dec 2019 01:16:56 -0700 Subject: [PATCH 2/2] Verify focus on cursor image changes --- kiwmi/input/cursor.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kiwmi/input/cursor.c b/kiwmi/input/cursor.c index e63e518..b532426 100644 --- a/kiwmi/input/cursor.c +++ b/kiwmi/input/cursor.c @@ -116,7 +116,21 @@ request_set_cursor_notify(struct wl_listener *listener, void *data) struct kiwmi_cursor *cursor = wl_container_of(listener, cursor, request_set_cursor); struct wlr_seat_pointer_request_set_cursor_event *event = data; - // FIXME: this should verify if the window has focus + + struct wlr_surface *focused_surface = + event->seat_client->seat->pointer_state.focused_surface; + struct wl_client *focused_client = NULL; + + if (focused_surface && focused_surface->resource) { + focused_client = wl_resource_get_client(focused_surface->resource); + } + + if (event->seat_client->client != focused_client) { + wlr_log( + WLR_DEBUG, "Ignoring request to set cursor on unfocused client"); + return; + } + wlr_cursor_set_surface( cursor->cursor, event->surface, event->hotspot_x, event->hotspot_y); }