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 --- include/wlr/types/wlr_cursor.h | 20 ++++++++++++------- include/wlr/types/wlr_output.h | 45 ++++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 26 deletions(-) (limited to 'include') diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index e8c13b1d..be4f322f 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -48,10 +48,10 @@ void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur); * Returns true when the mouse warp was successful. */ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev, - double x, double y); + double x, double y); void wlr_cursor_warp_absolute(struct wlr_cursor *cur, - struct wlr_input_device *dev, double x_mm, double y_mm); + struct wlr_input_device *dev, double x_mm, double y_mm); /** * Move the cursor in the direction of the given x and y coordinates. @@ -60,7 +60,13 @@ void wlr_cursor_warp_absolute(struct wlr_cursor *cur, * device mapping constraints will be ignored. */ void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev, - double delta_x, double delta_y); + double delta_x, double delta_y); + +void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels, + int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, + int32_t hotspot_y); +void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface, + int32_t hotspot_x, int32_t hotspot_y); /** * Attaches this input device to this cursor. The input device must be one of: @@ -80,7 +86,7 @@ void wlr_cursor_detach_input_device(struct wlr_cursor *cur, * direction and do not support absolute input events. */ void wlr_cursor_attach_output_layout(struct wlr_cursor *cur, - struct wlr_output_layout *l); + struct wlr_output_layout *l); /** * Attaches this cursor to the given output, which must be among the outputs in @@ -88,7 +94,7 @@ void wlr_cursor_attach_output_layout(struct wlr_cursor *cur, * without an associated output layout. */ void wlr_cursor_map_to_output(struct wlr_cursor *cur, - struct wlr_output *output); + struct wlr_output *output); /** * Maps all input from a specific input device to a given output. The input @@ -96,7 +102,7 @@ void wlr_cursor_map_to_output(struct wlr_cursor *cur, * outputs in the attached output layout. */ void wlr_cursor_map_input_to_output(struct wlr_cursor *cur, - struct wlr_input_device *dev, struct wlr_output *output); + struct wlr_input_device *dev, struct wlr_output *output); /** * Maps this cursor to an arbitrary region on the associated wlr_output_layout. @@ -108,6 +114,6 @@ void wlr_cursor_map_to_region(struct wlr_cursor *cur, struct wlr_box *box); * wlr_output_layout. */ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur, - struct wlr_input_device *dev, struct wlr_box *box); + struct wlr_input_device *dev, struct wlr_box *box); #endif diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 74eb15ed..b6ea3a47 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -12,6 +12,21 @@ struct wlr_output_mode { struct wl_list link; }; +struct wlr_output_cursor { + struct wlr_output *output; + int32_t x, y; + int32_t hotspot_x, hotspot_y; + struct wl_list link; + + 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; +}; + struct wlr_output_impl; struct wlr_output { @@ -44,19 +59,8 @@ struct wlr_output { struct wl_signal destroy; } events; - struct { - bool is_sw; - int32_t x, y; - uint32_t width, height; - 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; + struct wl_list cursors; // wlr_output_cursor::link + struct wlr_output_cursor *hardware_cursor; // the output position in layout space reported to clients int32_t lx, ly; @@ -72,12 +76,6 @@ bool wlr_output_set_mode(struct wlr_output *output, void wlr_output_transform(struct wlr_output *output, enum wl_output_transform transform); void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly); -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); -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); void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height); @@ -87,4 +85,13 @@ void wlr_output_set_gamma(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t wlr_output_get_gamma_size(struct wlr_output *output); +struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output); +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); +void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, + struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y); +bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y); +void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); + #endif -- cgit v1.2.3 From 2e2d63a16482135bb61db6a24cd09cd04c068c22 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 29 Oct 2017 11:20:11 +0100 Subject: Manage wlr_output_cursor from wlr_cursor --- examples/pointer.c | 5 ++- include/wlr/types/wlr_output_layout.h | 5 +++ types/wlr_cursor.c | 60 +++++++++++++++++++++++++++++++++-- types/wlr_output_layout.c | 6 +++- 4 files changed, 69 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/examples/pointer.c b/examples/pointer.c index b2fef4e8..26d50b95 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -156,9 +156,8 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener, sample->cur_x = event->x_mm; sample->cur_y = event->y_mm; - struct wlr_xcursor_image *image = sample->xcursor->images[0]; - wlr_cursor_warp_absolute(sample->cursor, event->device, - sample->cur_x - image->hotspot_x, sample->cur_y - image->hotspot_y); + wlr_cursor_warp_absolute(sample->cursor, event->device, sample->cur_x, + sample->cur_y); } static void handle_cursor_button(struct wl_listener *listener, void *data) { diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index ea8dbcd2..a99debf6 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -12,6 +12,7 @@ struct wlr_output_layout { struct wlr_output_layout_state *state; struct { + struct wl_signal add; struct wl_signal change; struct wl_signal destroy; } events; @@ -24,6 +25,10 @@ struct wlr_output_layout_output { int x, y; struct wl_list link; struct wlr_output_layout_output_state *state; + + struct { + struct wl_signal destroy; + } events; }; struct wlr_output_layout *wlr_output_layout_create(); diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index f07b57ab..dac290cb 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -37,6 +37,8 @@ struct wlr_cursor_output_cursor { struct wlr_cursor *cursor; struct wlr_output_cursor *output_cursor; struct wl_list link; + + struct wl_listener layout_output_destroy; }; struct wlr_cursor_state { @@ -48,6 +50,7 @@ struct wlr_cursor_state { struct wlr_output *mapped_output; struct wlr_box *mapped_box; + struct wl_listener layout_add; struct wl_listener layout_change; struct wl_listener layout_destroy; }; @@ -70,6 +73,7 @@ struct wlr_cursor *wlr_cursor_create() { cur->state->mapped_output = NULL; wl_list_init(&cur->state->devices); + wl_list_init(&cur->state->output_cursors); // pointer signals wl_signal_init(&cur->events.motion); @@ -102,6 +106,7 @@ static void wlr_cursor_detach_output_layout(struct wlr_cursor *cur) { wl_list_remove(&cur->state->layout_destroy.link); wl_list_remove(&cur->state->layout_change.link); + wl_list_remove(&cur->state->layout_add.link); cur->state->layout = NULL; } @@ -263,12 +268,20 @@ void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev, void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { - // TODO + struct wlr_cursor_output_cursor *output_cursor; + wl_list_for_each(output_cursor, &cur->state->output_cursors, link) { + wlr_output_cursor_set_image(output_cursor->output_cursor, pixels, + stride, width, height, hotspot_x, hotspot_y); + } } void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { - // TODO + struct wlr_cursor_output_cursor *output_cursor; + wl_list_for_each(output_cursor, &cur->state->output_cursors, link) { + wlr_output_cursor_set_surface(output_cursor->output_cursor, surface, + hotspot_x, hotspot_y); + } } static void handle_pointer_motion(struct wl_listener *listener, void *data) { @@ -489,10 +502,50 @@ static void handle_layout_destroy(struct wl_listener *listener, void *data) { wlr_cursor_detach_output_layout(state->cursor); } +static void handle_layout_output_destroy(struct wl_listener *listener, + void *data) { + struct wlr_cursor_output_cursor *output_cursor = + wl_container_of(listener, output_cursor, layout_output_destroy); + //struct wlr_output_layout_output *l_output = data; + + 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); +} + +static void handle_layout_add(struct wl_listener *listener, void *data) { + struct wlr_cursor_state *state = + wl_container_of(listener, state, layout_add); + struct wlr_output_layout_output *l_output = data; + + struct wlr_cursor_output_cursor *output_cursor = + calloc(1, sizeof(struct wlr_cursor_output_cursor)); + if (output_cursor == NULL) { + wlr_log(L_ERROR, "Failed to allocate wlr_cursor_output_cursor"); + return; + } + output_cursor->cursor = state->cursor; + + output_cursor->output_cursor = wlr_output_cursor_create(l_output->output); + if (output_cursor->output_cursor == NULL) { + wlr_log(L_ERROR, "Failed to create wlr_output_cursor"); + free(output_cursor); + return; + } + + output_cursor->layout_output_destroy.notify = handle_layout_output_destroy; + wl_signal_add(&l_output->events.destroy, + &output_cursor->layout_output_destroy); + + wl_list_insert(&state->cursor->state->output_cursors, &output_cursor->link); +} + static void handle_layout_change(struct wl_listener *listener, void *data) { struct wlr_cursor_state *state = wl_container_of(listener, state, layout_change); struct wlr_output_layout *layout = data; + if (!wlr_output_layout_contains_point(layout, NULL, state->cursor->x, state->cursor->y)) { // the output we were on has gone away so go to the closest boundary @@ -513,9 +566,10 @@ void wlr_cursor_attach_output_layout(struct wlr_cursor *cur, return; } + wl_signal_add(&l->events.add, &cur->state->layout_add); + cur->state->layout_add.notify = handle_layout_add; wl_signal_add(&l->events.change, &cur->state->layout_change); cur->state->layout_change.notify = handle_layout_change; - wl_signal_add(&l->events.destroy, &cur->state->layout_destroy); cur->state->layout_destroy.notify = handle_layout_destroy; diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 817a03f6..190f2733 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -35,6 +35,7 @@ struct wlr_output_layout *wlr_output_layout_create() { } wl_list_init(&layout->outputs); + wl_signal_init(&layout->events.add); wl_signal_init(&layout->events.change); wl_signal_init(&layout->events.destroy); @@ -43,6 +44,7 @@ struct wlr_output_layout *wlr_output_layout_create() { static void wlr_output_layout_output_destroy( struct wlr_output_layout_output *l_output) { + wl_signal_emit(&l_output->events.destroy, l_output); wl_list_remove(&l_output->state->resolution.link); wl_list_remove(&l_output->state->output_destroy.link); wl_list_remove(&l_output->link); @@ -155,7 +157,7 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create( l_output->state->l_output = l_output; l_output->state->layout = layout; l_output->output = output; - + wl_signal_init(&l_output->events.destroy); wl_list_insert(&layout->outputs, &l_output->link); wl_signal_add(&output->events.resolution, &l_output->state->resolution); @@ -163,6 +165,8 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create( wl_signal_add(&output->events.destroy, &l_output->state->output_destroy); l_output->state->output_destroy.notify = handle_output_destroy; + wl_signal_emit(&layout->events.add, l_output); + return l_output; } -- 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 'include') 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 4230a577cc878607c2db1e6e5e7051b9e7653584 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 29 Oct 2017 18:14:58 +0100 Subject: Remove wlr_cursor_set_xcursor for now --- examples/pointer.c | 4 +++- include/wlr/types/wlr_cursor.h | 2 -- rootston/input.c | 5 ++++- types/wlr_cursor.c | 5 ----- 4 files changed, 7 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/examples/pointer.c b/examples/pointer.c index 26d50b95..77f5192f 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -321,7 +321,9 @@ int main(int argc, char *argv[]) { return 1; } - wlr_cursor_set_xcursor(state.cursor, state.xcursor); + struct wlr_xcursor_image *image = state.xcursor->images[0]; + wlr_cursor_set_image(state.cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y); compositor_init(&compositor); if (!wlr_backend_start(compositor.backend)) { diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index be4f322f..1aac2b94 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -36,8 +36,6 @@ struct wlr_cursor *wlr_cursor_create(); void wlr_cursor_destroy(struct wlr_cursor *cur); -void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur); - /** * Warp the cursor to the given x and y in layout coordinates. If x and y are * out of the layout boundaries or constraints, no warp will happen. diff --git a/rootston/input.c b/rootston/input.c index a6792bdb..8109d2b6 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -118,7 +118,10 @@ struct roots_input *input_create(struct roots_server *server, input->cursor = wlr_cursor_create(); cursor_initialize(input); - wlr_cursor_set_xcursor(input->cursor, xcursor); + + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_cursor_set_image(input->cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y); wlr_cursor_attach_output_layout(input->cursor, server->desktop->layout); wlr_cursor_map_to_region(input->cursor, config->cursor.mapped_box); diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 76e20e9e..ece3d842 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -46,7 +46,6 @@ struct wlr_cursor_state { struct wl_list devices; // wlr_cursor_device::link struct wl_list output_cursors; // wlr_cursor_output_cursor::link struct wlr_output_layout *layout; - struct wlr_xcursor *xcursor; struct wlr_output *mapped_output; struct wlr_box *mapped_box; @@ -123,10 +122,6 @@ void wlr_cursor_destroy(struct wlr_cursor *cur) { free(cur); } -void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur) { - cur->state->xcursor = xcur; -} - static struct wlr_cursor_device *get_cursor_device(struct wlr_cursor *cur, struct wlr_input_device *device) { struct wlr_cursor_device *c_device, *ret = NULL; -- 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 'include') 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