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