From 78d3582b70dcd823c3675806bcbda6776282eb6f Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Oct 2017 13:11:51 +0200 Subject: Add request_set_cursor event --- include/wlr/types/wlr_seat.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index d3d3e00d..d267924c 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -125,11 +125,20 @@ struct wlr_seat { struct wl_signal keyboard_grab_begin; struct wl_signal keyboard_grab_end; + + struct wl_signal request_set_cursor; } events; void *data; }; +struct wlr_seat_pointer_request_set_cursor_event { + struct wl_client *client; + struct wlr_seat_handle *seat_handle; + struct wlr_surface *surface; + int32_t hotspot_x, hotspot_y; +}; + /** * Allocates a new wlr_seat and adds a wl_seat global to the display. */ -- cgit v1.2.3 From 65d57920e534acb231bb04964b257b2186c7ce73 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 7 Oct 2017 10:55:17 +0200 Subject: rootston: handle request_set_cursor --- include/rootston/input.h | 2 ++ rootston/cursor.c | 23 +++++++++++++++++++++++ types/wlr_seat.c | 5 ++++- 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/rootston/input.h b/include/rootston/input.h index 9caf66c0..bdd2a104 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -107,6 +107,8 @@ struct roots_input { struct wl_listener cursor_tool_tip; 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/cursor.c b/rootston/cursor.c index 605920cc..3423d33b 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -274,6 +274,24 @@ static void handle_pointer_grab_end(struct wl_listener *listener, void *data) { cursor_update_position(input, 0); } +static void handle_request_set_cursor(struct wl_listener *listener, + void *data) { + struct roots_input *input = wl_container_of(listener, input, + request_set_cursor); + //struct wlr_seat_pointer_request_set_cursor_event *event = data; + + struct wlr_xcursor_image *image = input->xcursor->images[0]; + struct roots_output *output; + wl_list_for_each(output, &input->server->desktop->outputs, link) { + if (!wlr_output_set_cursor(output->wlr_output, image->buffer, + image->width, image->width, image->height, + image->hotspot_x, image->hotspot_y)) { + wlr_log(L_DEBUG, "Failed to set hardware cursor"); + return; + } + } +} + void cursor_initialize(struct roots_input *input) { struct wlr_cursor *cursor = input->cursor; @@ -304,6 +322,11 @@ void cursor_initialize(struct roots_input *input) { wl_signal_add(&input->wl_seat->events.pointer_grab_end, &input->pointer_grab_end); input->pointer_grab_end.notify = handle_pointer_grab_end; + + wl_list_init(&input->request_set_cursor.link); + wl_signal_add(&input->wl_seat->events.request_set_cursor, + &input->request_set_cursor); + input->request_set_cursor.notify = handle_request_set_cursor; } static void reset_device_mappings(struct roots_config *config, diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 25c39235..a543936d 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -24,7 +24,10 @@ static void wl_pointer_set_cursor(struct wl_client *client, struct wl_resource *surface_resource, int32_t hotspot_x, int32_t hotspot_y) { struct wlr_seat_handle *handle = wl_resource_get_user_data(resource); - struct wlr_surface *surface = wl_resource_get_user_data(surface_resource); + struct wlr_surface *surface = NULL; + if (surface_resource != NULL) { + surface = wl_resource_get_user_data(surface_resource); + } struct wlr_seat_pointer_request_set_cursor_event *event = calloc(1, sizeof(struct wlr_seat_pointer_request_set_cursor_event)); -- cgit v1.2.3 From 9b83caa658de2b51e36266beac048c96a556037c Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Oct 2017 21:21:06 +0200 Subject: Add wlr_output_set_cursor_surface --- backend/wayland/output.c | 8 +++++++- include/wlr/types/wlr_output.h | 14 +++++++++----- rootston/cursor.c | 14 +++++++++----- types/wlr_output.c | 26 +++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 062a91a1..03b43b35 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -55,9 +55,15 @@ static void wlr_wl_output_transform(struct wlr_output *_output, static bool wlr_wl_output_set_cursor(struct wlr_output *_output, const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { - struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; struct wlr_wl_backend *backend = output->backend; + + if (!buf) { + wl_pointer_set_cursor(output->backend->pointer, output->enter_serial, + NULL, 0, 0); + return true; + } + stride *= 4; // stride is given in pixels, we need it in bytes if (!backend->shm || !backend->pointer) { diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 52d377e3..c25e2fb8 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -54,18 +54,22 @@ struct wlr_output { void *data; }; +struct wlr_surface; + void wlr_output_enable(struct wlr_output *output, bool enable); bool wlr_output_set_mode(struct wlr_output *output, - struct wlr_output_mode *mode); + struct wlr_output_mode *mode); void wlr_output_transform(struct wlr_output *output, - enum wl_output_transform transform); + enum wl_output_transform transform); bool wlr_output_set_cursor(struct wlr_output *output, - const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height, - int32_t hotspot_x, int32_t hotspot_y); + const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y); +bool wlr_output_set_cursor_surface(struct wlr_output *output, + struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y); bool wlr_output_move_cursor(struct wlr_output *output, int x, int y); void wlr_output_destroy(struct wlr_output *output); void wlr_output_effective_resolution(struct wlr_output *output, - int *width, int *height); + int *width, int *height); void wlr_output_make_current(struct wlr_output *output); void wlr_output_swap_buffers(struct wlr_output *output); void wlr_output_set_gamma(struct wlr_output *output, diff --git a/rootston/cursor.c b/rootston/cursor.c index 3423d33b..f9372f7f 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -278,14 +278,18 @@ static void handle_request_set_cursor(struct wl_listener *listener, void *data) { struct roots_input *input = wl_container_of(listener, input, request_set_cursor); - //struct wlr_seat_pointer_request_set_cursor_event *event = data; + struct wlr_seat_pointer_request_set_cursor_event *event = data; + if (event->surface == NULL) { + wlr_log(L_DEBUG, "handle_request_set_cursor with NULL surface"); + return; + } + + wlr_log(L_DEBUG, "handle_request_set_cursor"); - struct wlr_xcursor_image *image = input->xcursor->images[0]; struct roots_output *output; wl_list_for_each(output, &input->server->desktop->outputs, link) { - if (!wlr_output_set_cursor(output->wlr_output, image->buffer, - image->width, image->width, image->height, - image->hotspot_x, image->hotspot_y)) { + if (!wlr_output_set_cursor_surface(output->wlr_output, + event->surface, event->hotspot_x, event->hotspot_y)) { wlr_log(L_DEBUG, "Failed to set hardware cursor"); return; } diff --git a/types/wlr_output.c b/types/wlr_output.c index 64f67f2d..67bd826f 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -158,7 +159,8 @@ bool wlr_output_set_cursor(struct wlr_output *output, } if (!output->cursor.texture) { - output->cursor.texture = wlr_render_texture_create(output->cursor.renderer); + output->cursor.texture = + wlr_render_texture_create(output->cursor.renderer); if (!output->cursor.texture) { return false; } @@ -168,6 +170,28 @@ bool wlr_output_set_cursor(struct wlr_output *output, WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); } +bool wlr_output_set_cursor_surface(struct wlr_output *output, + struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { + if (output->impl->set_cursor) { + output->impl->set_cursor(output, NULL, 0, 0, 0, 0, 0); + wlr_log(L_INFO, "TODO: wlr_output_set_cursor_surface for hw cursors"); + } + + output->cursor.is_sw = true; + output->cursor.width = surface->current->width; + output->cursor.height = surface->current->height; + output->cursor.hotspot_x = hotspot_x; + output->cursor.hotspot_y = hotspot_y; + + wlr_texture_destroy(output->cursor.texture); + output->cursor.texture = surface->texture; + + wlr_renderer_destroy(output->cursor.renderer); + output->cursor.renderer = surface->renderer; + + return true; +} + bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { output->cursor.x = x; output->cursor.y = y; -- cgit v1.2.3 From 8a77d1b6a2b28b90c8bb5ef079077aec1a44407c Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Oct 2017 23:11:59 +0200 Subject: Listen to cursor surface commit & destroy events --- include/wlr/types/wlr_output.h | 7 +++- rootston/cursor.c | 7 +--- types/wlr_output.c | 85 +++++++++++++++++++++++++++++++----------- 3 files changed, 72 insertions(+), 27 deletions(-) (limited to 'include') diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index c25e2fb8..dc637e26 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -49,6 +49,11 @@ struct wlr_output { int32_t hotspot_x, hotspot_y; struct wlr_renderer *renderer; struct wlr_texture *texture; + + // only when using a cursor surface + struct wlr_surface *surface; + struct wl_listener surface_commit; + struct wl_listener surface_destroy; } cursor; void *data; @@ -64,7 +69,7 @@ void wlr_output_transform(struct wlr_output *output, bool wlr_output_set_cursor(struct wlr_output *output, const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y); -bool wlr_output_set_cursor_surface(struct wlr_output *output, +void wlr_output_set_cursor_surface(struct wlr_output *output, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y); bool wlr_output_move_cursor(struct wlr_output *output, int x, int y); void wlr_output_destroy(struct wlr_output *output); diff --git a/rootston/cursor.c b/rootston/cursor.c index f9372f7f..97f9ca83 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -288,11 +288,8 @@ static void handle_request_set_cursor(struct wl_listener *listener, struct roots_output *output; wl_list_for_each(output, &input->server->desktop->outputs, link) { - if (!wlr_output_set_cursor_surface(output->wlr_output, - event->surface, event->hotspot_x, event->hotspot_y)) { - wlr_log(L_DEBUG, "Failed to set hardware cursor"); - return; - } + wlr_output_set_cursor_surface(output->wlr_output, event->surface, + event->hotspot_x, event->hotspot_y); } } diff --git a/types/wlr_output.c b/types/wlr_output.c index ef80e143..06593514 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -99,18 +99,6 @@ void wlr_output_update_matrix(struct wlr_output *output) { wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform); } -void wlr_output_init(struct wlr_output *output, - const struct wlr_output_impl *impl) { - output->impl = impl; - output->modes = list_create(); - output->transform = WL_OUTPUT_TRANSFORM_NORMAL; - output->scale = 1; - wl_signal_init(&output->events.frame); - wl_signal_init(&output->events.swap_buffers); - wl_signal_init(&output->events.resolution); - wl_signal_init(&output->events.destroy); -} - void wlr_output_enable(struct wlr_output *output, bool enable) { output->impl->enable(output, enable); } @@ -167,29 +155,67 @@ bool wlr_output_set_cursor(struct wlr_output *output, } return wlr_texture_upload_pixels(output->cursor.texture, - WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); + WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); } -bool wlr_output_set_cursor_surface(struct wlr_output *output, - struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { +static void handle_cursor_surface_commit(struct wl_listener *listener, + void *data) { + struct wlr_output *output = wl_container_of(listener, output, + cursor.surface_commit); + struct wlr_surface *surface = data; + struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer); if (buffer == NULL) { - return false; + return; } uint32_t format = wl_shm_buffer_get_format(buffer); if (format != WL_SHM_FORMAT_ARGB8888) { - return false; + return; } - void *data = wl_shm_buffer_get_data(buffer); + void *buffer_data = wl_shm_buffer_get_data(buffer); int32_t width = wl_shm_buffer_get_width(buffer); int32_t height = wl_shm_buffer_get_height(buffer); wl_shm_buffer_begin_access(buffer); - bool ok = wlr_output_set_cursor(output, data, width, width, height, - hotspot_x, hotspot_y); + wlr_output_set_cursor(output, buffer_data, width, width, height, + output->cursor.hotspot_x, output->cursor.hotspot_y); wl_shm_buffer_end_access(buffer); - return ok; +} + +static void handle_cursor_surface_destroy(struct wl_listener *listener, + void *data) { + struct wlr_output *output = wl_container_of(listener, output, + cursor.surface_destroy); + struct wlr_surface *surface = data; + + if (output->cursor.surface == surface) { + wl_list_remove(&output->cursor.surface_commit.link); + wl_list_remove(&output->cursor.surface_destroy.link); + output->cursor.surface = NULL; + } +} + +void wlr_output_set_cursor_surface(struct wlr_output *output, + struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { + output->cursor.hotspot_x = hotspot_x; + output->cursor.hotspot_y = hotspot_y; + + if (output->cursor.surface == surface) { + return; + } + output->cursor.surface = surface; + + if (output->cursor.surface) { + wl_list_remove(&output->cursor.surface_commit.link); + wl_list_remove(&output->cursor.surface_destroy.link); + output->cursor.surface = NULL; + } + + if (surface != NULL) { + wl_signal_add(&surface->events.commit, &output->cursor.surface_commit); + wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy); + } } bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { @@ -207,6 +233,23 @@ bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { return output->impl->move_cursor(output, x, y); } +void wlr_output_init(struct wlr_output *output, + const struct wlr_output_impl *impl) { + output->impl = impl; + output->modes = list_create(); + output->transform = WL_OUTPUT_TRANSFORM_NORMAL; + output->scale = 1; + wl_signal_init(&output->events.frame); + wl_signal_init(&output->events.swap_buffers); + wl_signal_init(&output->events.resolution); + wl_signal_init(&output->events.destroy); + + wl_list_init(&output->cursor.surface_commit.link); + output->cursor.surface_commit.notify = handle_cursor_surface_commit; + wl_list_init(&output->cursor.surface_destroy.link); + output->cursor.surface_destroy.notify = handle_cursor_surface_destroy; +} + void wlr_output_destroy(struct wlr_output *output) { if (!output) { return; -- cgit v1.2.3 From 4d157fe5de78d632548df8f523f04a53b5688417 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 9 Oct 2017 12:51:28 +0200 Subject: Switch back to compositor cursor when leaving view --- include/rootston/input.h | 1 + rootston/cursor.c | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/rootston/input.h b/include/rootston/input.h index bdd2a104..43408516 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -79,6 +79,7 @@ struct roots_input { struct wlr_xcursor_theme *theme; struct wlr_xcursor *xcursor; struct wlr_seat *wl_seat; + bool client_cursor; enum roots_cursor_mode mode; struct roots_view *active_view, *last_active_view; diff --git a/rootston/cursor.c b/rootston/cursor.c index 97f9ca83..106e054f 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -58,6 +58,21 @@ void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, wlr_seat_pointer_clear_focus(input->wl_seat); } +static void cursor_set_xcursor_image(struct roots_input *input, + struct wlr_xcursor_image *image) { + struct roots_output *output; + wl_list_for_each(output, &input->server->desktop->outputs, link) { + if (!wlr_output_set_cursor(output->wlr_output, image->buffer, + image->width, image->width, image->height, + image->hotspot_x, image->hotspot_y)) { + wlr_log(L_DEBUG, "Failed to set hardware cursor"); + return; + } + } + + input->client_cursor = false; +} + void cursor_update_position(struct roots_input *input, uint32_t time) { struct roots_desktop *desktop = input->server->desktop; struct roots_view *view; @@ -72,6 +87,10 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { wlr_seat_pointer_notify_motion(input->wl_seat, time, sx, sy); } else { wlr_seat_pointer_clear_focus(input->wl_seat); + if (input->client_cursor) { + wlr_log(L_DEBUG, "Switching to compositor cursor"); + cursor_set_xcursor_image(input, input->xcursor->images[0]); + } } break; case ROOTS_CURSOR_MOVE: @@ -279,18 +298,16 @@ static void handle_request_set_cursor(struct wl_listener *listener, struct roots_input *input = wl_container_of(listener, input, request_set_cursor); struct wlr_seat_pointer_request_set_cursor_event *event = data; - if (event->surface == NULL) { - wlr_log(L_DEBUG, "handle_request_set_cursor with NULL surface"); - return; - } - wlr_log(L_DEBUG, "handle_request_set_cursor"); + wlr_log(L_DEBUG, "Setting client cursor"); struct roots_output *output; wl_list_for_each(output, &input->server->desktop->outputs, link) { wlr_output_set_cursor_surface(output->wlr_output, event->surface, event->hotspot_x, event->hotspot_y); } + + input->client_cursor = true; } void cursor_initialize(struct roots_input *input) { -- cgit v1.2.3 From 84921740881f638622c6a0c1b4ab319218f1f7ac Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 9 Oct 2017 13:12:38 +0200 Subject: Switch back to compositor cursor when switching from one view to another --- include/rootston/input.h | 2 +- rootston/cursor.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/rootston/input.h b/include/rootston/input.h index 43408516..fbabbdb6 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -79,7 +79,7 @@ struct roots_input { struct wlr_xcursor_theme *theme; struct wlr_xcursor *xcursor; struct wlr_seat *wl_seat; - bool client_cursor; + struct roots_view *client_cursor_view; enum roots_cursor_mode mode; struct roots_view *active_view, *last_active_view; diff --git a/rootston/cursor.c b/rootston/cursor.c index 2df9bcb5..eeb657ad 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -69,8 +69,6 @@ static void cursor_set_xcursor_image(struct roots_input *input, return; } } - - input->client_cursor = false; } void cursor_update_position(struct roots_input *input, uint32_t time) { @@ -82,15 +80,16 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { case ROOTS_CURSOR_PASSTHROUGH: view = view_at(desktop, input->cursor->x, input->cursor->y, &surface, &sx, &sy); + if (view != input->client_cursor_view) { + wlr_log(L_DEBUG, "Switching to compositor cursor"); + cursor_set_xcursor_image(input, input->xcursor->images[0]); + input->client_cursor_view = NULL; + } if (view) { wlr_seat_pointer_notify_enter(input->wl_seat, surface, sx, sy); wlr_seat_pointer_notify_motion(input->wl_seat, time, sx, sy); } else { wlr_seat_pointer_clear_focus(input->wl_seat); - if (input->client_cursor) { - wlr_log(L_DEBUG, "Switching to compositor cursor"); - cursor_set_xcursor_image(input, input->xcursor->images[0]); - } } break; case ROOTS_CURSOR_MOVE: @@ -301,8 +300,8 @@ static void handle_request_set_cursor(struct wl_listener *listener, struct wlr_surface *focused_surface = NULL; double sx, sy; - view_at(input->server->desktop, input->cursor->x, input->cursor->y, - &focused_surface, &sx, &sy); + struct roots_view *focused_view = view_at(input->server->desktop, + input->cursor->x, input->cursor->y, &focused_surface, &sx, &sy); bool ok = focused_surface != NULL; if (focused_surface != NULL) { struct wl_client *focused_client = @@ -322,7 +321,7 @@ static void handle_request_set_cursor(struct wl_listener *listener, event->hotspot_x, event->hotspot_y); } - input->client_cursor = true; + input->client_cursor_view = focused_view; } void cursor_initialize(struct roots_input *input) { -- cgit v1.2.3