diff --git a/include/input/cursor.h b/include/input/cursor.h index 3727d2f..4719012 100644 --- a/include/input/cursor.h +++ b/include/input/cursor.h @@ -20,6 +20,7 @@ struct kiwmi_cursor { struct wl_listener cursor_button; struct wl_listener cursor_axis; struct wl_listener cursor_frame; + struct wl_listener request_set_cursor; }; struct kiwmi_cursor *cursor_create( diff --git a/kiwmi/input/cursor.c b/kiwmi/input/cursor.c index d2d6ed8..f533c29 100644 --- a/kiwmi/input/cursor.c +++ b/kiwmi/input/cursor.c @@ -139,6 +139,31 @@ cursor_frame_notify(struct wl_listener *listener, void *UNUSED(data)) wlr_seat_pointer_notify_frame(input->seat); } +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; + + 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); +} + struct kiwmi_cursor * cursor_create( struct kiwmi_server *server, @@ -182,5 +207,10 @@ cursor_create( cursor->cursor_frame.notify = cursor_frame_notify; wl_signal_add(&cursor->cursor->events.frame, &cursor->cursor_frame); + 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;