From 33a97576ca3169b7771a0bd574383f5cf502f583 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 30 Sep 2017 11:57:39 +0200 Subject: Add view_resize --- rootston/cursor.c | 16 ++++++++++------ rootston/desktop.c | 6 ++++++ rootston/xdg_shell_v6.c | 11 ++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) (limited to 'rootston') diff --git a/rootston/cursor.c b/rootston/cursor.c index d5f1f7f5..c57bff52 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -30,10 +30,12 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, } void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, - struct roots_view *view) { + struct roots_view *view, uint32_t edges) { input->mode = ROOTS_CURSOR_RESIZE; - input->offs_x = cursor->x - view->x; - input->offs_y = cursor->y - view->y; + wlr_log(L_DEBUG, "begin resize"); + input->offs_x = cursor->x - (double)view->wlr_surface->current.width - view->x; + input->offs_y = cursor->y - (double)view->wlr_surface->current.height - view->y; + input->resize_edges = edges; wlr_seat_pointer_clear_focus(input->wl_seat); } @@ -61,9 +63,11 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { } break; case ROOTS_CURSOR_RESIZE: - // TODO: this is just for testing - if (input->active_view && input->active_view->type == ROOTS_XDG_SHELL_V6_VIEW) { - wlr_xdg_toplevel_v6_set_size(input->active_view->xdg_surface_v6, input->cursor->x - input->offs_x, input->cursor->y - input->offs_y); + if (input->active_view) { + // TODO: edges + uint32_t width = input->cursor->x - input->offs_x; + uint32_t height = input->cursor->y - input->offs_y; + view_resize(input->active_view, width, height); } break; case ROOTS_CURSOR_ROTATE: diff --git a/rootston/desktop.c b/rootston/desktop.c index cd417755..00657bc6 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -41,6 +41,12 @@ void view_activate(struct roots_view *view, bool activate) { } } +void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { + if (view->resize) { + view->resize(view, width, height); + } +} + struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) { for (size_t i = 0; i < desktop->views->length; ++i) { struct roots_view *view = desktop->views->items[i]; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 814c5642..a18aa501 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -29,6 +29,14 @@ static void activate(struct roots_view *view, bool active) { } } +static void resize(struct roots_view *view, uint32_t width, uint32_t height) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; + if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_v6_set_size(surf, width, height); + } +} + static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, request_move); @@ -52,7 +60,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { return; } - view_begin_resize(input, event->cursor, view); + view_begin_resize(input, event->cursor, view, e->edges); } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -102,6 +110,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->wlr_surface = surface->surface; view->get_input_bounds = get_input_bounds; view->activate = activate; + view->resize = resize; view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); -- cgit v1.2.3