From dd07618727bab35daf1e561d40485ec568535ea5 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 4 Oct 2017 21:05:00 +0200 Subject: rootston: rotate cursor coordinates --- rootston/desktop.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index 8d1d34d6..a216f7f9 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -105,9 +106,18 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_box box; view_get_input_bounds(view, &box); - box.x += view->x; - box.y += view->y; - if (wlr_box_contains_point(&box, lx, ly)) { + if (view->rotation != 0.0) { + // Coordinates relative to the center of the view + double ox = view_sx - (double)box.width/2, + oy = view_sy - (double)box.height/2; + // Rotated coordinates + double rx = cos(view->rotation)*ox - sin(view->rotation)*oy, + ry = cos(view->rotation)*oy + sin(view->rotation)*ox; + view_sx = (double)box.width/2 + rx; + view_sy = (double)box.height/2 + ry; + } + + if (wlr_box_contains_point(&box, view_sx, view_sy)) { *sx = view_sx; *sy = view_sy; *surface = view->wlr_surface; -- cgit v1.2.3 From 09a6d863cf9b6e7fba459ede2b9769e78535b11a Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 4 Oct 2017 21:17:16 +0200 Subject: rootston: fix cursor coordinates for rotated subsurfaces --- rootston/desktop.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index a216f7f9..1e7d1171 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -93,17 +93,6 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, double view_sx = lx - view->x; double view_sy = ly - view->y; - double sub_x, sub_y; - struct wlr_subsurface *subsurface = - subsurface_at(view->wlr_surface, view_sx, view_sy, &sub_x, &sub_y); - - if (subsurface) { - *sx = view_sx - sub_x; - *sy = view_sy - sub_y; - *surface = subsurface->surface; - return view; - } - struct wlr_box box; view_get_input_bounds(view, &box); if (view->rotation != 0.0) { @@ -117,6 +106,16 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, view_sy = (double)box.height/2 + ry; } + double sub_x, sub_y; + struct wlr_subsurface *subsurface = + subsurface_at(view->wlr_surface, view_sx, view_sy, &sub_x, &sub_y); + if (subsurface) { + *sx = view_sx - sub_x; + *sy = view_sy - sub_y; + *surface = subsurface->surface; + return view; + } + if (wlr_box_contains_point(&box, view_sx, view_sy)) { *sx = view_sx; *sy = view_sy; -- cgit v1.2.3 From 1a775adbde0ba81e6dcd2878a660a1386a8f972f Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 4 Oct 2017 23:05:57 +0200 Subject: rootston: fix rotated subsurfaces --- rootston/desktop.c | 4 ++-- rootston/output.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index 1e7d1171..f99afaf5 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -102,8 +102,8 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, // Rotated coordinates double rx = cos(view->rotation)*ox - sin(view->rotation)*oy, ry = cos(view->rotation)*oy + sin(view->rotation)*ox; - view_sx = (double)box.width/2 + rx; - view_sy = (double)box.height/2 + ry; + view_sx = rx + (double)box.width/2; + view_sy = ry + (double)box.height/2; } double sub_x, sub_y; diff --git a/rootston/output.c b/rootston/output.c index b3cbaf10..a1882f3d 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -56,9 +56,24 @@ static void render_surface(struct wlr_surface *surface, struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + double sx = subsurface->surface->current->subsurface_position.x, + sy = subsurface->surface->current->subsurface_position.y; + double sw = subsurface->surface->current->buffer_width, + sh = subsurface->surface->current->buffer_height; + if (rotation != 0.0) { + // Coordinates relative to the center of the subsurface + double ox = sx - (double)width/2 + sw/2, + oy = sy - (double)height/2 + sh/2; + // Rotated coordinates + double rx = cos(-rotation)*ox - sin(-rotation)*oy, + ry = cos(-rotation)*oy + sin(-rotation)*ox; + sx = rx + (double)width/2 - sw/2; + sy = ry + (double)height/2 - sh/2; + } + render_surface(subsurface->surface, desktop, wlr_output, when, - lx + subsurface->surface->current->subsurface_position.x, - ly + subsurface->surface->current->subsurface_position.y, + lx + sx, + ly + sy, rotation); } } -- cgit v1.2.3