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/wlr') 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 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/wlr') 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/wlr') 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