diff options
author | emersion <contact@emersion.fr> | 2017-10-04 21:05:00 +0200 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-10-04 21:05:00 +0200 |
commit | dd07618727bab35daf1e561d40485ec568535ea5 (patch) | |
tree | c8cc0fd9e7ff8ae0ef1fe9d1a100bcc231e5e1b8 /rootston/desktop.c | |
parent | f9dbc1841d0a2b4a93cfb9a1783a34ebed426c59 (diff) |
rootston: rotate cursor coordinates
Diffstat (limited to 'rootston/desktop.c')
-rw-r--r-- | rootston/desktop.c | 16 |
1 files changed, 13 insertions, 3 deletions
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 <assert.h> #include <time.h> #include <stdlib.h> +#include <math.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_cursor.h> @@ -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; |