mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-02 11:55:59 +01:00
Fix cursor hotspot with rotated outputs on DRM backend
This commit is contained in:
parent
4230a577cc
commit
c3b09f73da
4 changed files with 44 additions and 55 deletions
|
@ -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) {
|
if (!update_pixels) {
|
||||||
// Only update the cursor hotspot
|
// Only update the cursor hotspot
|
||||||
return true;
|
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_connector *conn = (struct wlr_drm_connector *)output;
|
||||||
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
|
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;
|
int width, height, tmp;
|
||||||
wlr_output_effective_resolution(output, &width, &height);
|
wlr_output_effective_resolution(output, &width, &height);
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ struct wlr_drm_plane {
|
||||||
struct wlr_texture *wlr_tex;
|
struct wlr_texture *wlr_tex;
|
||||||
struct gbm_bo *cursor_bo;
|
struct gbm_bo *cursor_bo;
|
||||||
bool cursor_enabled;
|
bool cursor_enabled;
|
||||||
|
int32_t cursor_hotspot_x, cursor_hotspot_y;
|
||||||
|
|
||||||
union wlr_drm_plane_props props;
|
union wlr_drm_plane_props props;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "rootston/input.h"
|
#include "rootston/input.h"
|
||||||
|
|
||||||
struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme) {
|
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) {
|
struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme) {
|
||||||
|
|
|
@ -237,44 +237,6 @@ void wlr_output_make_current(struct wlr_output *output) {
|
||||||
output->impl->make_current(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) {
|
static void output_cursor_render(struct wlr_output_cursor *cursor) {
|
||||||
struct wlr_texture *texture = cursor->texture;
|
struct wlr_texture *texture = cursor->texture;
|
||||||
struct wlr_renderer *renderer = cursor->renderer;
|
struct wlr_renderer *renderer = cursor->renderer;
|
||||||
|
@ -290,13 +252,10 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) {
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
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];
|
float matrix[16];
|
||||||
wlr_texture_get_matrix(texture, &matrix,
|
wlr_texture_get_matrix(texture, &matrix,
|
||||||
&cursor->output->transform_matrix, cursor->x - hotspot_x,
|
&cursor->output->transform_matrix, cursor->x - cursor->hotspot_x,
|
||||||
cursor->y - hotspot_y);
|
cursor->y - cursor->hotspot_y);
|
||||||
wlr_render_with_matrix(renderer, texture, &matrix);
|
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 &&
|
if (cursor->output->hardware_cursor == NULL &&
|
||||||
cursor->output->impl->set_cursor) {
|
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,
|
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) {
|
if (ok) {
|
||||||
cursor->output->hardware_cursor = cursor;
|
cursor->output->hardware_cursor = cursor;
|
||||||
return true;
|
return true;
|
||||||
|
@ -438,11 +391,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
|
||||||
cursor->output->impl->set_cursor) {
|
cursor->output->impl->set_cursor) {
|
||||||
// If the surface hasn't changed and it's an hardware cursor, only
|
// If the surface hasn't changed and it's an hardware cursor, only
|
||||||
// update the hotspot
|
// 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->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0,
|
||||||
hotspot_eff_x, hotspot_eff_y, false);
|
hotspot_x, hotspot_y, false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue