From 428bf18ec70a29d6e3d778ab3baf175a3cead0af Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 8 Nov 2017 15:23:56 -0500 Subject: rootston: request set cursor --- include/rootston/cursor.h | 8 ++++++++ include/rootston/input.h | 5 ----- rootston/roots_cursor.c | 21 +++++++++++++++++++++ rootston/seat.c | 23 ++++++++++++++++++----- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index 18d5f720..3bc8c08b 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -53,6 +53,11 @@ struct roots_cursor { struct wl_listener tool_axis; struct wl_listener tool_tip; + + struct wl_listener pointer_grab_begin; + struct wl_listener pointer_grab_end; + + struct wl_listener request_set_cursor; }; struct roots_cursor *roots_cursor_create(struct roots_seat *seat); @@ -86,4 +91,7 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor, void roots_cursor_handle_tool_tip(struct roots_cursor *cursor, struct wlr_event_tablet_tool_tip *event); +void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, + struct wlr_seat_pointer_request_set_cursor_event *event); + #endif diff --git a/include/rootston/input.h b/include/rootston/input.h index e073a59d..ea0bbeb6 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -17,11 +17,6 @@ struct roots_input { struct wl_listener input_remove; struct wl_list seats; - - struct wl_listener pointer_grab_begin; - struct wl_listener pointer_grab_end; - - struct wl_listener request_set_cursor; }; struct roots_input *input_create(struct roots_server *server, diff --git a/rootston/roots_cursor.c b/rootston/roots_cursor.c index 833551d1..c44b0e7f 100644 --- a/rootston/roots_cursor.c +++ b/rootston/roots_cursor.c @@ -281,3 +281,24 @@ void roots_cursor_handle_tool_tip(struct roots_cursor *cursor, roots_cursor_press_button(cursor, event->device, event->time_msec, BTN_LEFT, event->state); } + +void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, + struct wlr_seat_pointer_request_set_cursor_event *event) { + struct wlr_surface *focused_surface = + event->seat_client->seat->pointer_state.focused_surface; + bool has_focused = focused_surface != NULL && focused_surface->resource != NULL; + struct wl_client *focused_client = NULL; + if (has_focused) { + focused_client = wl_resource_get_client(focused_surface->resource); + } + if (event->seat_client->client != focused_client || + cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { + wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client"); + return; + } + + wlr_log(L_DEBUG, "Setting client cursor"); + wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x, + event->hotspot_y); + cursor->cursor_client = event->seat_client->client; +} diff --git a/rootston/seat.c b/rootston/seat.c index b4d7887e..12f12a69 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -89,6 +89,14 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { roots_cursor_handle_tool_tip(cursor, event); } +static void handle_request_set_cursor(struct wl_listener *listener, + void *data) { + struct roots_cursor *cursor = + wl_container_of(listener, cursor, request_set_cursor); + struct wlr_seat_pointer_request_set_cursor_event *event = data; + roots_cursor_handle_request_set_cursor(cursor, event); +} + static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) { struct wlr_cursor *cursor = seat->cursor->cursor; struct roots_config *config = seat->input->config; @@ -224,6 +232,10 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &seat->cursor->tool_tip); seat->cursor->tool_tip.notify = handle_tool_tip; + + wl_signal_add(&seat->seat->events.request_set_cursor, + &seat->cursor->request_set_cursor); + seat->cursor->request_set_cursor.notify = handle_request_set_cursor; } struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { @@ -240,16 +252,17 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { seat->input = input; - roots_seat_init_cursor(seat); - if (!seat->cursor) { + seat->seat = wlr_seat_create(input->server->wl_display, name); + if (!seat->seat) { free(seat); + roots_cursor_destroy(seat->cursor); return NULL; } - seat->seat = wlr_seat_create(input->server->wl_display, name); - if (!seat->seat) { + roots_seat_init_cursor(seat); + if (!seat->cursor) { + wlr_seat_destroy(seat->seat); free(seat); - roots_cursor_destroy(seat->cursor); return NULL; } -- cgit v1.2.3