diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 062a91a1a..03b43b355 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 52d377e3f..c25e2fb83 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 3423d33b8..f9372f7fa 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 64f67f2d7..67bd826f7 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;