From 1b6c7293608717943a296675b1ab228fed72277c Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 29 Oct 2017 09:09:21 +0100 Subject: Add wlr_output_cursor --- backend/drm/drm.c | 61 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 27a8490c..e3f2bfe1 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -558,36 +558,37 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, } } - switch (output->transform) { - case WL_OUTPUT_TRANSFORM_90: - output->cursor.hotspot_x = hotspot_x; - output->cursor.hotspot_y = -plane->surf.height + hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_180: - output->cursor.hotspot_x = plane->surf.width - hotspot_x; - output->cursor.hotspot_y = plane->surf.height - hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_270: - output->cursor.hotspot_x = -plane->surf.height + hotspot_x; - output->cursor.hotspot_y = hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - output->cursor.hotspot_x = plane->surf.width - hotspot_x; - output->cursor.hotspot_y = hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - output->cursor.hotspot_x = hotspot_x; - output->cursor.hotspot_y = -hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - output->cursor.hotspot_x = hotspot_x; - output->cursor.hotspot_y = plane->surf.height - hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - output->cursor.hotspot_x = -plane->surf.height + hotspot_x; - output->cursor.hotspot_y = plane->surf.width - hotspot_y; - break; - } + // TODO: this doesn't belong here + // switch (output->transform) { + // case WL_OUTPUT_TRANSFORM_90: + // output->cursor.hotspot_x = hotspot_x; + // output->cursor.hotspot_y = -plane->surf.height + hotspot_y; + // break; + // case WL_OUTPUT_TRANSFORM_180: + // output->cursor.hotspot_x = plane->surf.width - hotspot_x; + // output->cursor.hotspot_y = plane->surf.height - hotspot_y; + // break; + // case WL_OUTPUT_TRANSFORM_270: + // output->cursor.hotspot_x = -plane->surf.height + hotspot_x; + // output->cursor.hotspot_y = hotspot_y; + // break; + // case WL_OUTPUT_TRANSFORM_FLIPPED: + // output->cursor.hotspot_x = plane->surf.width - hotspot_x; + // output->cursor.hotspot_y = hotspot_y; + // break; + // case WL_OUTPUT_TRANSFORM_FLIPPED_90: + // output->cursor.hotspot_x = hotspot_x; + // output->cursor.hotspot_y = -hotspot_y; + // break; + // case WL_OUTPUT_TRANSFORM_FLIPPED_180: + // output->cursor.hotspot_x = hotspot_x; + // output->cursor.hotspot_y = plane->surf.height - hotspot_y; + // break; + // case WL_OUTPUT_TRANSFORM_FLIPPED_270: + // output->cursor.hotspot_x = -plane->surf.height + hotspot_x; + // output->cursor.hotspot_y = plane->surf.width - hotspot_y; + // break; + // } if (!update_pixels) { // Only update the cursor hotspot -- cgit v1.2.3 From 6656e25fd4c5575400a2a3bc4d94a8f834630c5e Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 29 Oct 2017 11:42:09 +0100 Subject: Transform cursor hotspot --- backend/drm/drm.c | 32 ---------------------------- types/wlr_output.c | 62 ++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 45 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index e3f2bfe1..23b9a9fa 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -558,38 +558,6 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, } } - // TODO: this doesn't belong here - // switch (output->transform) { - // case WL_OUTPUT_TRANSFORM_90: - // output->cursor.hotspot_x = hotspot_x; - // output->cursor.hotspot_y = -plane->surf.height + hotspot_y; - // break; - // case WL_OUTPUT_TRANSFORM_180: - // output->cursor.hotspot_x = plane->surf.width - hotspot_x; - // output->cursor.hotspot_y = plane->surf.height - hotspot_y; - // break; - // case WL_OUTPUT_TRANSFORM_270: - // output->cursor.hotspot_x = -plane->surf.height + hotspot_x; - // output->cursor.hotspot_y = hotspot_y; - // break; - // case WL_OUTPUT_TRANSFORM_FLIPPED: - // output->cursor.hotspot_x = plane->surf.width - hotspot_x; - // output->cursor.hotspot_y = hotspot_y; - // break; - // case WL_OUTPUT_TRANSFORM_FLIPPED_90: - // output->cursor.hotspot_x = hotspot_x; - // output->cursor.hotspot_y = -hotspot_y; - // break; - // case WL_OUTPUT_TRANSFORM_FLIPPED_180: - // output->cursor.hotspot_x = hotspot_x; - // output->cursor.hotspot_y = plane->surf.height - hotspot_y; - // break; - // case WL_OUTPUT_TRANSFORM_FLIPPED_270: - // output->cursor.hotspot_x = -plane->surf.height + hotspot_x; - // output->cursor.hotspot_y = plane->surf.width - hotspot_y; - // break; - // } - if (!update_pixels) { // Only update the cursor hotspot return true; diff --git a/types/wlr_output.c b/types/wlr_output.c index 338494b6..cb48ad63 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -287,7 +287,7 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { return output->impl->get_gamma_size(output); } -static void wlr_output_cursor_reset(struct wlr_output_cursor *cursor) { +static void output_cursor_reset(struct wlr_output_cursor *cursor) { if (cursor->surface != NULL) { wl_list_remove(&cursor->surface_commit.link); wl_list_remove(&cursor->surface_destroy.link); @@ -295,17 +295,53 @@ static void wlr_output_cursor_reset(struct wlr_output_cursor *cursor) { } } +static void output_cursor_set_hotspot(struct wlr_output_cursor *cursor, + int32_t hotspot_x, int32_t hotspot_y, uint32_t width, uint32_t height) { + switch (cursor->output->transform) { + case WL_OUTPUT_TRANSFORM_90: + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = -height + hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_180: + cursor->hotspot_x = width - hotspot_x; + cursor->hotspot_y = height - hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_270: + cursor->hotspot_x = -height + hotspot_x; + cursor->hotspot_y = hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED: + cursor->hotspot_x = width - hotspot_x; + cursor->hotspot_y = hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = -hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = height - hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + cursor->hotspot_x = -height + hotspot_x; + cursor->hotspot_y = width - hotspot_y; + break; + default: // WL_OUTPUT_TRANSFORM_NORMAL + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = hotspot_y; + } +} + bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { - wlr_output_cursor_reset(cursor); - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = hotspot_y; + output_cursor_reset(cursor); + output_cursor_set_hotspot(cursor, hotspot_x, hotspot_y, width, height); if (cursor->output->hardware_cursor == NULL && cursor->output->impl->set_cursor && cursor->output->impl->set_cursor(cursor->output, pixels, stride, - width, height, hotspot_x, hotspot_y, true)) { + width, height, cursor->hotspot_x, cursor->hotspot_y, true)) { cursor->output->hardware_cursor = cursor; return true; } @@ -357,7 +393,7 @@ static void output_cursor_handle_destroy(struct wl_listener *listener, void *data) { struct wlr_output_cursor *cursor = wl_container_of(listener, cursor, surface_destroy); - wlr_output_cursor_reset(cursor); + output_cursor_reset(cursor); } void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, @@ -366,8 +402,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, return; } - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = hotspot_y; + output_cursor_set_hotspot(cursor, hotspot_x, hotspot_y, + surface->current->width, surface->current->height); if (surface && surface == cursor->surface) { if (cursor->output->hardware_cursor == cursor && @@ -375,19 +411,19 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, // If the surface hasn't changed and it's an hardware cursor, only // update the hotspot cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, - hotspot_x, hotspot_y, false); + cursor->hotspot_x, cursor->hotspot_y, false); } return; } - wlr_output_cursor_reset(cursor); + output_cursor_reset(cursor); // Disable hardware cursor for surfaces // TODO: support hardware cursors if (cursor->output->hardware_cursor == cursor && cursor->output->impl->set_cursor) { - cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, - hotspot_x, hotspot_y, true); + cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, 0, 0, + true); cursor->output->hardware_cursor = NULL; } @@ -435,7 +471,7 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { if (cursor == NULL) { return; } - wlr_output_cursor_reset(cursor); + output_cursor_reset(cursor); if (cursor->output->hardware_cursor == cursor) { // If this cursor was the hardware cursor, disable it if (cursor->output->impl->set_cursor) { -- cgit v1.2.3 From 95566c6bdfb7048b2460b701747f4c9d3fcd4ebd Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 29 Oct 2017 17:43:26 +0100 Subject: Transform cursor hotspot, fix wayland cursor hotspot --- backend/wayland/output.c | 108 ++++++++++++++++++---------------- backend/wayland/wl_seat.c | 4 +- include/backend/wayland.h | 17 +++--- include/wlr/types/wlr_output.h | 1 + types/wlr_cursor.c | 5 +- types/wlr_output.c | 129 +++++++++++++++++++++++++---------------- 6 files changed, 152 insertions(+), 112 deletions(-) (limited to 'backend') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 0dde343c..c336eeb7 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -55,25 +55,27 @@ 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, bool update_pixels) { - struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; + struct wlr_wl_backend_output *output = + (struct wlr_wl_backend_output *)_output; struct wlr_wl_backend *backend = output->backend; + output->cursor.hotspot_x = hotspot_x; + output->cursor.hotspot_y = hotspot_y; + if (!update_pixels) { // Update hotspot without changing cursor image - wlr_wl_output_update_cursor(output, output->enter_serial, hotspot_x, - hotspot_y); + wlr_wl_output_update_cursor(output); return true; } if (!buf) { // Hide cursor - if (output->cursor_surface) { - wl_surface_destroy(output->cursor_surface); - munmap(output->cursor_data, output->cursor_buf_size); - output->cursor_surface = NULL; - output->cursor_buf_size = 0; + if (output->cursor.surface) { + wl_surface_destroy(output->cursor.surface); + munmap(output->cursor.data, output->cursor.buf_size); + output->cursor.surface = NULL; + output->cursor.buf_size = 0; } - wlr_wl_output_update_cursor(output, output->enter_serial, hotspot_x, - hotspot_y); + wlr_wl_output_update_cursor(output); return true; } @@ -84,73 +86,77 @@ static bool wlr_wl_output_set_cursor(struct wlr_output *_output, return false; } - if (!output->cursor_surface) { - output->cursor_surface = wl_compositor_create_surface(output->backend->compositor); + if (!output->cursor.surface) { + output->cursor.surface = + wl_compositor_create_surface(output->backend->compositor); } uint32_t size = stride * height; - if (output->cursor_buf_size != size) { - if (output->cursor_buffer) { - wl_buffer_destroy(output->cursor_buffer); + if (output->cursor.buf_size != size) { + if (output->cursor.buffer) { + wl_buffer_destroy(output->cursor.buffer); } - if (size > output->cursor_buf_size) { - if (output->cursor_pool) { - wl_shm_pool_destroy(output->cursor_pool); - output->cursor_pool = NULL; - munmap(output->cursor_data, output->cursor_buf_size); + if (size > output->cursor.buf_size) { + if (output->cursor.pool) { + wl_shm_pool_destroy(output->cursor.pool); + output->cursor.pool = NULL; + munmap(output->cursor.data, output->cursor.buf_size); } } - if (!output->cursor_pool) { + if (!output->cursor.pool) { int fd = os_create_anonymous_file(size); if (fd < 0) { - wlr_log_errno(L_INFO, "creating anonymous file for cursor buffer failed"); + wlr_log_errno(L_INFO, + "creating anonymous file for cursor buffer failed"); return false; } - output->cursor_data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (output->cursor_data == MAP_FAILED) { + output->cursor.data = mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (output->cursor.data == MAP_FAILED) { close(fd); wlr_log_errno(L_INFO, "mmap failed"); return false; } - output->cursor_pool = wl_shm_create_pool(backend->shm, fd, size); + output->cursor.pool = wl_shm_create_pool(backend->shm, fd, size); close(fd); } - output->cursor_buffer = wl_shm_pool_create_buffer(output->cursor_pool, + output->cursor.buffer = wl_shm_pool_create_buffer(output->cursor.pool, 0, width, height, stride, WL_SHM_FORMAT_ARGB8888); - output->cursor_buf_size = size; + output->cursor.buf_size = size; } - memcpy(output->cursor_data, buf, size); - wl_surface_attach(output->cursor_surface, output->cursor_buffer, 0, 0); - wl_surface_damage(output->cursor_surface, 0, 0, width, height); - wl_surface_commit(output->cursor_surface); + memcpy(output->cursor.data, buf, size); + wl_surface_attach(output->cursor.surface, output->cursor.buffer, 0, 0); + wl_surface_damage(output->cursor.surface, 0, 0, width, height); + wl_surface_commit(output->cursor.surface); - wlr_wl_output_update_cursor(output, output->enter_serial, - hotspot_x, hotspot_y); + wlr_wl_output_update_cursor(output); return true; } static void wlr_wl_output_destroy(struct wlr_output *_output) { - struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; - wl_signal_emit(&output->backend->backend.events.output_remove, &output->wlr_output); - - if (output->cursor_buf_size != 0) { - assert(output->cursor_data); - assert(output->cursor_buffer); - assert(output->cursor_pool); - - wl_buffer_destroy(output->cursor_buffer); - munmap(output->cursor_data, output->cursor_buf_size); - wl_shm_pool_destroy(output->cursor_pool); + struct wlr_wl_backend_output *output = + (struct wlr_wl_backend_output *)_output; + wl_signal_emit(&output->backend->backend.events.output_remove, + &output->wlr_output); + + if (output->cursor.buf_size != 0) { + assert(output->cursor.data); + assert(output->cursor.buffer); + assert(output->cursor.pool); + + wl_buffer_destroy(output->cursor.buffer); + munmap(output->cursor.data, output->cursor.buf_size); + wl_shm_pool_destroy(output->cursor.pool); } - if (output->cursor_surface) { - wl_surface_destroy(output->cursor_surface); + if (output->cursor.surface) { + wl_surface_destroy(output->cursor.surface); } if (output->frame_callback) { @@ -164,11 +170,11 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) { free(output); } -void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output, - uint32_t serial, int32_t hotspot_x, int32_t hotspot_y) { - if (output->backend->pointer && serial) { - wl_pointer_set_cursor(output->backend->pointer, serial, - output->cursor_surface, hotspot_x, hotspot_y); +void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output) { + if (output->backend->pointer && output->enter_serial) { + wl_pointer_set_cursor(output->backend->pointer, output->enter_serial, + output->cursor.surface, output->cursor.hotspot_x, + output->cursor.hotspot_y); } } diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 903ca3ee..0d8e5b1f 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -23,8 +23,8 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, wlr_wl_output_for_surface(wlr_wl_dev->backend, surface); assert(output); wlr_wl_pointer->current_output = output; - wlr_wl_pointer->current_output->enter_serial = serial; - wlr_wl_output_update_cursor(wlr_wl_pointer->current_output, serial, 0, 0); + output->enter_serial = serial; + wlr_wl_output_update_cursor(output); } static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, diff --git a/include/backend/wayland.h b/include/backend/wayland.h index e1c89b11..1e8a55d2 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -43,11 +43,15 @@ struct wlr_wl_backend_output { struct wl_egl_window *egl_window; struct wl_callback *frame_callback; - struct wl_shm_pool *cursor_pool; - void *cursor_buffer; // actually a (client-side) struct wl_buffer* - uint8_t *cursor_data; - struct wl_surface *cursor_surface; - uint32_t cursor_buf_size; + struct { + struct wl_shm_pool *pool; + void *buffer; // actually a (client-side) struct wl_buffer* + uint32_t buf_size; + uint8_t *data; + struct wl_surface *surface; + int32_t hotspot_x, hotspot_y; + } cursor; + uint32_t enter_serial; void *egl_surface; @@ -68,8 +72,7 @@ struct wlr_wl_pointer { }; void wlr_wl_registry_poll(struct wlr_wl_backend *backend); -void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output, - uint32_t serial, int32_t hotspot_x, int32_t hotspot_y); +void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output); struct wlr_wl_backend_output *wlr_wl_output_for_surface( struct wlr_wl_backend *backend, struct wl_surface *surface); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index b6ea3a47..f9bce91f 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -15,6 +15,7 @@ struct wlr_output_mode { struct wlr_output_cursor { struct wlr_output *output; int32_t x, y; + uint32_t width, height; int32_t hotspot_x, hotspot_y; struct wl_list link; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index dac290cb..76e20e9e 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -150,9 +150,8 @@ static void wlr_cursor_warp_unchecked(struct wlr_cursor *cur, double output_y = y; wlr_output_layout_output_coords(cur->state->layout, output_cursor->output_cursor->output, &output_x, &output_y); - wlr_output_cursor_move(output_cursor->output_cursor, - output_x - output_cursor->output_cursor->hotspot_x, - output_y - output_cursor->output_cursor->hotspot_y); + wlr_output_cursor_move(output_cursor->output_cursor, output_x, + output_y); } cur->x = x; diff --git a/types/wlr_output.c b/types/wlr_output.c index cb48ad63..5862d0fa 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -237,6 +237,44 @@ void wlr_output_make_current(struct wlr_output *output) { output->impl->make_current(output); } +static void output_cursor_get_effective_hotspot( + struct wlr_output_cursor *cursor, int32_t *hotspot_x, + int32_t *hotspot_y) { + switch (cursor->output->transform) { + case WL_OUTPUT_TRANSFORM_90: + *hotspot_x = cursor->hotspot_x; + *hotspot_y = -cursor->height + cursor->hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_180: + *hotspot_x = cursor->width - cursor->hotspot_x; + *hotspot_y = cursor->height - cursor->hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_270: + *hotspot_x = -cursor->height + cursor->hotspot_x; + *hotspot_y = cursor->hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED: + *hotspot_x = cursor->width - cursor->hotspot_x; + *hotspot_y = cursor->hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + *hotspot_x = cursor->hotspot_x; + *hotspot_y = -cursor->hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + *hotspot_x = cursor->hotspot_x; + *hotspot_y = cursor->height - cursor->hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + *hotspot_x = -cursor->height + cursor->hotspot_x; + *hotspot_y = cursor->width - cursor->hotspot_y; + break; + default: // WL_OUTPUT_TRANSFORM_NORMAL + *hotspot_x = cursor->hotspot_x; + *hotspot_y = cursor->hotspot_y; + } +} + static void output_cursor_render(struct wlr_output_cursor *cursor) { struct wlr_texture *texture = cursor->texture; struct wlr_renderer *renderer = cursor->renderer; @@ -252,9 +290,13 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + int32_t hotspot_x, hotspot_y; + output_cursor_get_effective_hotspot(cursor, &hotspot_x, &hotspot_y); + float matrix[16]; wlr_texture_get_matrix(texture, &matrix, - &cursor->output->transform_matrix, cursor->x, cursor->y); + &cursor->output->transform_matrix, cursor->x - hotspot_x, + cursor->y - hotspot_y); wlr_render_with_matrix(renderer, texture, &matrix); } } @@ -295,55 +337,30 @@ static void output_cursor_reset(struct wlr_output_cursor *cursor) { } } -static void output_cursor_set_hotspot(struct wlr_output_cursor *cursor, - int32_t hotspot_x, int32_t hotspot_y, uint32_t width, uint32_t height) { - switch (cursor->output->transform) { - case WL_OUTPUT_TRANSFORM_90: - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = -height + hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_180: - cursor->hotspot_x = width - hotspot_x; - cursor->hotspot_y = height - hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_270: - cursor->hotspot_x = -height + hotspot_x; - cursor->hotspot_y = hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - cursor->hotspot_x = width - hotspot_x; - cursor->hotspot_y = hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = -hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = height - hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - cursor->hotspot_x = -height + hotspot_x; - cursor->hotspot_y = width - hotspot_y; - break; - default: // WL_OUTPUT_TRANSFORM_NORMAL - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = hotspot_y; - } -} - bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { output_cursor_reset(cursor); - output_cursor_set_hotspot(cursor, hotspot_x, hotspot_y, width, height); + + cursor->width = width; + cursor->height = height; + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = hotspot_y; if (cursor->output->hardware_cursor == NULL && - cursor->output->impl->set_cursor && - cursor->output->impl->set_cursor(cursor->output, pixels, stride, - width, height, cursor->hotspot_x, cursor->hotspot_y, true)) { - cursor->output->hardware_cursor = cursor; - return true; + cursor->output->impl->set_cursor) { + int32_t hotspot_eff_x, hotspot_eff_y; + output_cursor_get_effective_hotspot(cursor, &hotspot_eff_x, + &hotspot_eff_y); + + // TODO: also transform pixels with output->transform before calling + // set_cursor + int ok = cursor->output->impl->set_cursor(cursor->output, pixels, + stride, width, height, hotspot_eff_x, hotspot_eff_y, true); + if (ok) { + cursor->output->hardware_cursor = cursor; + return true; + } } wlr_log(L_INFO, "Falling back to software cursor"); @@ -366,6 +383,13 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, stride, width, height, pixels); } +static void output_cursor_commit(struct wlr_output_cursor *cursor) { + cursor->width = cursor->surface->current->width; + cursor->height = cursor->surface->current->height; + + // TODO: if hardware cursor, upload pixels +} + static inline int64_t timespec_to_msec(const struct timespec *a) { return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; } @@ -376,7 +400,7 @@ static void output_cursor_handle_commit(struct wl_listener *listener, surface_commit); struct wlr_surface *surface = data; - // TODO: if hardware cursor, upload pixels + output_cursor_commit(cursor); struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -402,16 +426,23 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, return; } - output_cursor_set_hotspot(cursor, hotspot_x, hotspot_y, - surface->current->width, surface->current->height); + if (surface) { + cursor->width = surface->current->width; + cursor->height = surface->current->height; + } + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = hotspot_y; if (surface && surface == cursor->surface) { if (cursor->output->hardware_cursor == cursor && cursor->output->impl->set_cursor) { // If the surface hasn't changed and it's an hardware cursor, only // update the hotspot + int32_t hotspot_eff_x, hotspot_eff_y; + output_cursor_get_effective_hotspot(cursor, &hotspot_eff_x, + &hotspot_eff_y); cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, - cursor->hotspot_x, cursor->hotspot_y, false); + hotspot_eff_x, hotspot_eff_y, false); } return; } @@ -432,7 +463,7 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, if (surface != NULL) { wl_signal_add(&surface->events.commit, &cursor->surface_commit); wl_signal_add(&surface->events.destroy, &cursor->surface_destroy); - // TODO: if hardware cursor, upload pixels + output_cursor_commit(cursor); } else { // TODO: if hardware cursor, disable cursor } -- cgit v1.2.3 From c3b09f73da0d1fc4815f4b085ca07e30d175f549 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 29 Oct 2017 18:45:53 +0100 Subject: Fix cursor hotspot with rotated outputs on DRM backend --- backend/drm/drm.c | 38 +++++++++++++++++++++++++++++++ include/backend/drm/drm.h | 1 + rootston/xcursor.c | 2 +- types/wlr_output.c | 58 ++++------------------------------------------- 4 files changed, 44 insertions(+), 55 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 23b9a9fa..6cbb0535 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -558,6 +558,40 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, } } + switch (output->transform) { + case WL_OUTPUT_TRANSFORM_90: + plane->cursor_hotspot_x = hotspot_x; + plane->cursor_hotspot_y = -plane->surf.height + hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_180: + plane->cursor_hotspot_x = plane->surf.width - hotspot_x; + plane->cursor_hotspot_y = plane->surf.height - hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_270: + plane->cursor_hotspot_x = -plane->surf.height + hotspot_x; + plane->cursor_hotspot_y = hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED: + plane->cursor_hotspot_x = plane->surf.width - hotspot_x; + plane->cursor_hotspot_y = hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + plane->cursor_hotspot_x = hotspot_x; + plane->cursor_hotspot_y = -hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + plane->cursor_hotspot_x = hotspot_x; + plane->cursor_hotspot_y = plane->surf.height - hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + plane->cursor_hotspot_x = -plane->surf.height + hotspot_x; + plane->cursor_hotspot_y = plane->surf.width - hotspot_y; + break; + default: // WL_OUTPUT_TRANSFORM_NORMAL + plane->cursor_hotspot_x = hotspot_x; + plane->cursor_hotspot_y = hotspot_y; + } + if (!update_pixels) { // Only update the cursor hotspot return true; @@ -605,6 +639,10 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output, struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_plane *plane = conn->crtc->cursor; + x -= plane->cursor_hotspot_x; + y -= plane->cursor_hotspot_y; + int width, height, tmp; wlr_output_effective_resolution(output, &width, &height); diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index a6dd247c..e08965e5 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -34,6 +34,7 @@ struct wlr_drm_plane { struct wlr_texture *wlr_tex; struct gbm_bo *cursor_bo; bool cursor_enabled; + int32_t cursor_hotspot_x, cursor_hotspot_y; union wlr_drm_plane_props props; }; diff --git a/rootston/xcursor.c b/rootston/xcursor.c index 43cbfc51..0d18e1f0 100644 --- a/rootston/xcursor.c +++ b/rootston/xcursor.c @@ -2,7 +2,7 @@ #include "rootston/input.h" struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme) { - return wlr_xcursor_theme_get_cursor(theme, "left_ptr"); + return wlr_xcursor_theme_get_cursor(theme, "grabbing"); } struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme) { diff --git a/types/wlr_output.c b/types/wlr_output.c index 5862d0fa..3cdeecfe 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -237,44 +237,6 @@ void wlr_output_make_current(struct wlr_output *output) { output->impl->make_current(output); } -static void output_cursor_get_effective_hotspot( - struct wlr_output_cursor *cursor, int32_t *hotspot_x, - int32_t *hotspot_y) { - switch (cursor->output->transform) { - case WL_OUTPUT_TRANSFORM_90: - *hotspot_x = cursor->hotspot_x; - *hotspot_y = -cursor->height + cursor->hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_180: - *hotspot_x = cursor->width - cursor->hotspot_x; - *hotspot_y = cursor->height - cursor->hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_270: - *hotspot_x = -cursor->height + cursor->hotspot_x; - *hotspot_y = cursor->hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - *hotspot_x = cursor->width - cursor->hotspot_x; - *hotspot_y = cursor->hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - *hotspot_x = cursor->hotspot_x; - *hotspot_y = -cursor->hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - *hotspot_x = cursor->hotspot_x; - *hotspot_y = cursor->height - cursor->hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - *hotspot_x = -cursor->height + cursor->hotspot_x; - *hotspot_y = cursor->width - cursor->hotspot_y; - break; - default: // WL_OUTPUT_TRANSFORM_NORMAL - *hotspot_x = cursor->hotspot_x; - *hotspot_y = cursor->hotspot_y; - } -} - static void output_cursor_render(struct wlr_output_cursor *cursor) { struct wlr_texture *texture = cursor->texture; struct wlr_renderer *renderer = cursor->renderer; @@ -290,13 +252,10 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - int32_t hotspot_x, hotspot_y; - output_cursor_get_effective_hotspot(cursor, &hotspot_x, &hotspot_y); - float matrix[16]; wlr_texture_get_matrix(texture, &matrix, - &cursor->output->transform_matrix, cursor->x - hotspot_x, - cursor->y - hotspot_y); + &cursor->output->transform_matrix, cursor->x - cursor->hotspot_x, + cursor->y - cursor->hotspot_y); wlr_render_with_matrix(renderer, texture, &matrix); } } @@ -349,14 +308,8 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, if (cursor->output->hardware_cursor == NULL && cursor->output->impl->set_cursor) { - int32_t hotspot_eff_x, hotspot_eff_y; - output_cursor_get_effective_hotspot(cursor, &hotspot_eff_x, - &hotspot_eff_y); - - // TODO: also transform pixels with output->transform before calling - // set_cursor int ok = cursor->output->impl->set_cursor(cursor->output, pixels, - stride, width, height, hotspot_eff_x, hotspot_eff_y, true); + stride, width, height, hotspot_x, hotspot_y, true); if (ok) { cursor->output->hardware_cursor = cursor; return true; @@ -438,11 +391,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, cursor->output->impl->set_cursor) { // If the surface hasn't changed and it's an hardware cursor, only // update the hotspot - int32_t hotspot_eff_x, hotspot_eff_y; - output_cursor_get_effective_hotspot(cursor, &hotspot_eff_x, - &hotspot_eff_y); cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, - hotspot_eff_x, hotspot_eff_y, false); + hotspot_x, hotspot_y, false); } return; } -- cgit v1.2.3 From 2c63aa2056d564be2fee50a175b3400bdfb96660 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 31 Oct 2017 14:21:12 +0100 Subject: Destroy x11 output with backend --- backend/x11/backend.c | 5 ++++- types/wlr_cursor.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'backend') diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 37bbdaec..97b0dd8c 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -298,6 +298,9 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) { struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + struct wlr_x11_output *output = &x11->output; + wlr_output_destroy(&output->wlr_output); + wl_event_source_remove(x11->frame_timer); wlr_egl_free(&x11->egl); @@ -331,7 +334,7 @@ static void output_destroy(struct wlr_output *wlr_output) { eglDestroySurface(x11->egl.display, output->surf); xcb_destroy_window(x11->xcb_conn, output->win); - free(wlr_output); + // output has been allocated on the stack, do not free it } static void output_make_current(struct wlr_output *wlr_output) { diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 70ddea47..e44b957a 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -100,9 +100,9 @@ struct wlr_cursor *wlr_cursor_create() { static void output_cursor_remove( struct wlr_cursor_output_cursor *output_cursor) { + wl_list_remove(&output_cursor->layout_output_destroy.link); wl_list_remove(&output_cursor->link); wlr_output_cursor_destroy(output_cursor->output_cursor); - wl_list_remove(&output_cursor->layout_output_destroy.link); free(output_cursor); } -- cgit v1.2.3 From ec22fe713445977c1a122572107495b584117b16 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 31 Oct 2017 15:19:55 +0100 Subject: Make wlr_output_interface.enable optional --- backend/wayland/output.c | 2 +- types/wlr_output.c | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'backend') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index c336eeb7..494e0522 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -189,7 +189,7 @@ static struct wlr_output_impl output_impl = { .make_current = wlr_wl_output_make_current, .swap_buffers = wlr_wl_output_swap_buffers, .set_cursor = wlr_wl_output_set_cursor, - .move_cursor = wlr_wl_output_move_cursor + .move_cursor = wlr_wl_output_move_cursor, }; static void xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *xdg_surface, diff --git a/types/wlr_output.c b/types/wlr_output.c index abfc6d26..44d24ae3 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -136,7 +136,9 @@ static void wlr_output_update_matrix(struct wlr_output *output) { } void wlr_output_enable(struct wlr_output *output, bool enable) { - output->impl->enable(output, enable); + if (output->impl->enable) { + output->impl->enable(output, enable); + } } bool wlr_output_set_mode(struct wlr_output *output, @@ -191,8 +193,7 @@ void wlr_output_set_position(struct wlr_output *output, int32_t lx, void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, const struct wlr_output_impl *impl) { - assert(impl->enable && impl->make_current && impl->swap_buffers && - impl->transform); + assert(impl->make_current && impl->swap_buffers && impl->transform); output->backend = backend; output->impl = impl; wl_list_init(&output->modes); @@ -337,12 +338,12 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, if (cursor->output->hardware_cursor == NULL && cursor->output->impl->set_cursor) { - // int ok = cursor->output->impl->set_cursor(cursor->output, pixels, - // stride, width, height, hotspot_x, hotspot_y, true); - // if (ok) { - // cursor->output->hardware_cursor = cursor; - // return true; - // } + int ok = cursor->output->impl->set_cursor(cursor->output, pixels, + stride, width, height, hotspot_x, hotspot_y, true); + if (ok) { + cursor->output->hardware_cursor = cursor; + return true; + } } wlr_log(L_INFO, "Falling back to software cursor"); -- cgit v1.2.3