diff options
Diffstat (limited to 'rootston/cursor.c')
-rw-r--r-- | rootston/cursor.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index ef941730..00218064 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -1,6 +1,7 @@ #include <stdbool.h> #include <stdint.h> #include <string.h> +#include <math.h> // TODO: BSD et al #include <linux/input-event-codes.h> #include <wayland-server.h> @@ -25,15 +26,16 @@ const struct roots_input_event *get_input_event(struct roots_input *input, void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view) { input->mode = ROOTS_CURSOR_MOVE; - input->offs_x = cursor->x - view->x; - input->offs_y = cursor->y - view->y; + input->offs_x = cursor->x; + input->offs_y = cursor->y; + input->view_x = view->x; + input->view_y = view->y; wlr_seat_pointer_clear_focus(input->wl_seat); } void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view, uint32_t edges) { input->mode = ROOTS_CURSOR_RESIZE; - wlr_log(L_DEBUG, "begin resize"); input->offs_x = cursor->x; input->offs_y = cursor->y; input->view_x = view->x; @@ -46,6 +48,15 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, wlr_seat_pointer_clear_focus(input->wl_seat); } +void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, + struct roots_view *view) { + input->mode = ROOTS_CURSOR_ROTATE; + input->offs_x = cursor->x; + input->offs_y = cursor->y; + input->view_rotation = view->rotation; + wlr_seat_pointer_clear_focus(input->wl_seat); +} + void cursor_update_position(struct roots_input *input, uint32_t time) { struct roots_desktop *desktop = input->server->desktop; struct roots_view *view; @@ -64,16 +75,18 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { break; case ROOTS_CURSOR_MOVE: if (input->active_view) { - input->active_view->x = input->cursor->x - input->offs_x; - input->active_view->y = input->cursor->y - input->offs_y; + int dx = input->cursor->x - input->offs_x, + dy = input->cursor->y - input->offs_y; + input->active_view->x = input->view_x + dx; + input->active_view->y = input->view_y + dy; } break; case ROOTS_CURSOR_RESIZE: if (input->active_view) { - int dx = input->cursor->x - input->offs_x; - int dy = input->cursor->y - input->offs_y; - int width = input->view_width; - int height = input->view_height; + int dx = input->cursor->x - input->offs_x, + dy = input->cursor->y - input->offs_y; + int width = input->view_width, + height = input->view_height; if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { input->active_view->y = input->view_y + dy; height -= dy; @@ -92,6 +105,17 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { } break; case ROOTS_CURSOR_ROTATE: + if (input->active_view) { + struct roots_view *view = input->active_view; + int ox = view->x + view->wlr_surface->current->width/2, + oy = view->y + view->wlr_surface->current->height/2; + int ux = input->offs_x - ox, + uy = input->offs_y - oy; + int vx = input->cursor->x - ox, + vy = input->cursor->y - oy; + float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy); + view->rotation = input->view_rotation + angle; + } break; } } @@ -175,6 +199,8 @@ static void do_cursor_button_press(struct roots_input *input, ROOTS_CURSOR_RESIZE_EDGE_RIGHT | ROOTS_CURSOR_RESIZE_EDGE_BOTTOM); break; + case BTN_MIDDLE: + view_begin_rotate(input, cursor, view); } return; } |