mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-30 00:15:58 +01:00
Merge pull request #365 from emersion/wayland-backend-transform
Cursors ✕ Output Transformations fixes
This commit is contained in:
commit
0d9d670dbd
6 changed files with 118 additions and 74 deletions
|
@ -533,13 +533,14 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!wlr_drm_surface_init(&plane->surf, renderer, w, h, GBM_FORMAT_ARGB8888, 0)) {
|
||||
if (!wlr_drm_surface_init(&plane->surf, renderer, w, h,
|
||||
GBM_FORMAT_ARGB8888, 0)) {
|
||||
wlr_log(L_ERROR, "Cannot allocate cursor resources");
|
||||
return false;
|
||||
}
|
||||
|
||||
plane->cursor_bo = gbm_bo_create(renderer->gbm, w, h, GBM_FORMAT_ARGB8888,
|
||||
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
|
||||
plane->cursor_bo = gbm_bo_create(renderer->gbm, w, h,
|
||||
GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
|
||||
if (!plane->cursor_bo) {
|
||||
wlr_log_errno(L_ERROR, "Failed to create cursor bo");
|
||||
return false;
|
||||
|
@ -552,45 +553,26 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
|
|||
|
||||
// TODO the image needs to be rotated depending on the output rotation
|
||||
|
||||
plane->wlr_tex = wlr_render_texture_create(plane->surf.renderer->wlr_rend);
|
||||
plane->wlr_tex =
|
||||
wlr_render_texture_create(plane->surf.renderer->wlr_rend);
|
||||
if (!plane->wlr_tex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
struct wlr_box hotspot = {
|
||||
.width = plane->surf.width,
|
||||
.height = plane->surf.height,
|
||||
.x = hotspot_x,
|
||||
.y = hotspot_y,
|
||||
};
|
||||
enum wl_output_transform transform =
|
||||
wlr_output_transform_invert(output->transform);
|
||||
struct wlr_box transformed_hotspot;
|
||||
wlr_output_transform_apply_to_box(transform, &hotspot,
|
||||
&transformed_hotspot);
|
||||
plane->cursor_hotspot_x = transformed_hotspot.x;
|
||||
plane->cursor_hotspot_y = transformed_hotspot.y;
|
||||
|
||||
if (!update_pixels) {
|
||||
// Only update the cursor hotspot
|
||||
|
@ -620,11 +602,13 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
|
|||
|
||||
float matrix[16];
|
||||
wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0);
|
||||
wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, &matrix);
|
||||
wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex,
|
||||
&matrix);
|
||||
|
||||
glFinish();
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride);
|
||||
glReadPixels(0, 0, plane->surf.width, plane->surf.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bo_data);
|
||||
glReadPixels(0, 0, plane->surf.width, plane->surf.height, GL_BGRA_EXT,
|
||||
GL_UNSIGNED_BYTE, bo_data);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
|
||||
|
||||
wlr_drm_surface_swap_buffers(&plane->surf);
|
||||
|
@ -638,35 +622,23 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output,
|
|||
int x, int y) {
|
||||
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);
|
||||
struct wlr_box box;
|
||||
box.x = x;
|
||||
box.y = y;
|
||||
wlr_output_effective_resolution(output, &box.width, &box.height);
|
||||
|
||||
switch (output->transform) {
|
||||
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||||
// nothing to do
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_270:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||
tmp = x;
|
||||
x = y;
|
||||
y = -(tmp - width);
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_90:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||
tmp = x;
|
||||
x = -(y - height);
|
||||
y = tmp;
|
||||
break;
|
||||
}
|
||||
enum wl_output_transform transform =
|
||||
wlr_output_transform_invert(output->transform);
|
||||
struct wlr_box transformed_box;
|
||||
wlr_output_transform_apply_to_box(transform, &box, &transformed_box);
|
||||
|
||||
return drm->iface->crtc_move_cursor(drm, conn->crtc, x, y);
|
||||
transformed_box.x -= plane->cursor_hotspot_x;
|
||||
transformed_box.y -= plane->cursor_hotspot_y;
|
||||
|
||||
return drm->iface->crtc_move_cursor(drm, conn->crtc, transformed_box.x,
|
||||
transformed_box.y);
|
||||
}
|
||||
|
||||
static void wlr_drm_connector_destroy(struct wlr_output *output) {
|
||||
|
|
|
@ -59,6 +59,7 @@ static bool wlr_wl_output_set_cursor(struct wlr_output *_output,
|
|||
(struct wlr_wl_backend_output *)_output;
|
||||
struct wlr_wl_backend *backend = output->backend;
|
||||
|
||||
// TODO: use output->wlr_output.transform to transform pixels and hotpot
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = hotspot_y;
|
||||
|
||||
|
|
|
@ -42,21 +42,30 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
|
|||
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||
struct wlr_input_device *dev = data;
|
||||
assert(dev && dev->pointer);
|
||||
struct wlr_wl_pointer *wlr_wl_pointer = (struct wlr_wl_pointer *)dev->pointer;
|
||||
struct wlr_wl_pointer *wlr_wl_pointer =
|
||||
(struct wlr_wl_pointer *)dev->pointer;
|
||||
if (!wlr_wl_pointer->current_output) {
|
||||
wlr_log(L_ERROR, "pointer motion event without current output");
|
||||
return;
|
||||
}
|
||||
int width, height;
|
||||
|
||||
struct wlr_box box;
|
||||
wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window,
|
||||
&width, &height);
|
||||
&box.width, &box.height);
|
||||
box.x = wl_fixed_to_int(surface_x);
|
||||
box.y = wl_fixed_to_int(surface_y);
|
||||
struct wlr_box transformed;
|
||||
wlr_output_transform_apply_to_box(
|
||||
wlr_wl_pointer->current_output->wlr_output.transform, &box,
|
||||
&transformed);
|
||||
|
||||
struct wlr_event_pointer_motion_absolute wlr_event;
|
||||
wlr_event.device = dev;
|
||||
wlr_event.time_msec = time;
|
||||
wlr_event.width_mm = width;
|
||||
wlr_event.height_mm = height;
|
||||
wlr_event.x_mm = wl_fixed_to_double(surface_x);
|
||||
wlr_event.y_mm = wl_fixed_to_double(surface_y);
|
||||
wlr_event.width_mm = transformed.width;
|
||||
wlr_event.height_mm = transformed.height;
|
||||
wlr_event.x_mm = transformed.x;
|
||||
wlr_event.y_mm = transformed.y;
|
||||
wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define WLR_INTERFACES_WLR_OUTPUT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/backend.h>
|
||||
|
||||
|
@ -31,4 +32,8 @@ struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output,
|
|||
struct wl_display *display);
|
||||
void wlr_output_destroy_global(struct wlr_output *wlr_output);
|
||||
|
||||
void wlr_output_transform_apply_to_box(enum wl_output_transform transform,
|
||||
struct wlr_box *box, struct wlr_box *dest);
|
||||
enum wl_output_transform wlr_output_transform_invert(enum wl_output_transform);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -228,7 +228,9 @@ static int config_ini_handler(void *user, const char *section, const char *name,
|
|||
} else if (strcmp(name, "y") == 0) {
|
||||
oc->y = strtol(value, NULL, 10);
|
||||
} else if (strcmp(name, "rotate") == 0) {
|
||||
if (strcmp(value, "90") == 0) {
|
||||
if (strcmp(value, "normal") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
} else if (strcmp(value, "90") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_90;
|
||||
} else if (strcmp(value, "180") == 0) {
|
||||
oc->transform = WL_OUTPUT_TRANSFORM_180;
|
||||
|
|
|
@ -267,8 +267,8 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) {
|
|||
|
||||
struct wlr_box output_box;
|
||||
output_box.x = output_box.y = 0;
|
||||
output_box.width = cursor->output->width;
|
||||
output_box.height = cursor->output->height;
|
||||
wlr_output_effective_resolution(cursor->output, &output_box.width,
|
||||
&output_box.height);
|
||||
|
||||
struct wlr_box cursor_box;
|
||||
output_cursor_get_box(cursor, &cursor_box);
|
||||
|
@ -500,3 +500,58 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) {
|
|||
wl_list_remove(&cursor->link);
|
||||
free(cursor);
|
||||
}
|
||||
|
||||
void wlr_output_transform_apply_to_box(enum wl_output_transform transform,
|
||||
struct wlr_box *box, struct wlr_box *dest) {
|
||||
if (transform % 2 == 0) {
|
||||
dest->width = box->width;
|
||||
dest->height = box->height;
|
||||
} else {
|
||||
dest->width = box->height;
|
||||
dest->height = box->width;
|
||||
}
|
||||
|
||||
switch (transform) {
|
||||
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||||
dest->x = box->x;
|
||||
dest->y = box->y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_90:
|
||||
dest->x = box->y;
|
||||
dest->y = box->width - box->x;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_180:
|
||||
dest->x = box->width - box->x;
|
||||
dest->y = box->height - box->y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_270:
|
||||
dest->x = box->height - box->y;
|
||||
dest->y = box->x;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||||
dest->x = box->width - box->x;
|
||||
dest->y = box->y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||
dest->x = box->y;
|
||||
dest->y = box->x;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||||
dest->x = box->x;
|
||||
dest->y = box->height - box->y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||
dest->x = box->height - box->y;
|
||||
dest->y = box->width - box->x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
enum wl_output_transform wlr_output_transform_invert(
|
||||
enum wl_output_transform transform) {
|
||||
if ((transform & WL_OUTPUT_TRANSFORM_90) &&
|
||||
!(transform & WL_OUTPUT_TRANSFORM_FLIPPED)) {
|
||||
transform ^= WL_OUTPUT_TRANSFORM_180;
|
||||
}
|
||||
return transform;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue