diff --git a/include/rootston/input.h b/include/rootston/input.h index aeab9c0d..b4d6de65 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -110,5 +110,7 @@ const struct roots_input_event *get_input_event(struct roots_input *input, uint32_t serial); void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view); +void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, + struct roots_view *view); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 2742e7cd..d5f1f7f5 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -29,6 +29,14 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, wlr_seat_pointer_clear_focus(input->wl_seat); } +void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, + struct roots_view *view) { + input->mode = ROOTS_CURSOR_RESIZE; + input->offs_x = cursor->x - view->x; + input->offs_y = cursor->y - view->y; + 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; @@ -53,6 +61,10 @@ 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); + } break; case ROOTS_CURSOR_ROTATE: break; diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 4189e910..d70f59f2 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -10,7 +10,7 @@ #include "rootston/server.h" #include "rootston/input.h" -static void handle_move(struct wl_listener *listener, void *data) { +static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, request_move); struct roots_view *view = roots_surface->view; @@ -53,7 +53,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { wl_signal_add(&surface->events.destroy, &roots_surface->destroy); wl_list_init(&roots_surface->ping_timeout.link); wl_list_init(&roots_surface->request_move.link); - roots_surface->request_move.notify = handle_move; + roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); wl_list_init(&roots_surface->request_resize.link); wl_list_init(&roots_surface->request_set_fullscreen.link); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index e8edaa8f..814c5642 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -14,6 +14,11 @@ static void get_input_bounds(struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; memcpy(box, surf->geometry, sizeof(struct wlr_box)); + // TODO: real input bounds + box->x -= 10; + box->y -= 10; + box->width += 20; + box->height += 20; } static void activate(struct roots_view *view, bool active) { @@ -37,6 +42,19 @@ static void handle_request_move(struct wl_listener *listener, void *data) { view_begin_move(input, event->cursor, view); } +static void handle_request_resize(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, request_resize); + struct roots_view *view = roots_xdg_surface->view; + struct roots_input *input = view->desktop->server->input; + struct wlr_xdg_toplevel_v6_resize_event *e = data; + const struct roots_input_event *event = get_input_event(input, e->serial); + if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + return; + } + view_begin_resize(input, event->cursor, view); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); @@ -71,6 +89,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); wl_list_init(&roots_surface->request_resize.link); + roots_surface->request_resize.notify = handle_request_resize; + wl_signal_add(&surface->events.request_resize, + &roots_surface->request_resize); wl_list_init(&roots_surface->request_show_window_menu.link); struct roots_view *view = calloc(1, sizeof(struct roots_view)); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 181b959d..4e42a925 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -17,7 +17,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { free(roots_surface); } -static void handle_configure(struct wl_listener *listener, void *data) { +static void handle_request_configure(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, request_configure); struct wlr_xwayland_surface *xwayland_surface = @@ -58,7 +58,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); wl_list_init(&roots_surface->request_configure.link); - roots_surface->request_configure.notify = handle_configure; + roots_surface->request_configure.notify = handle_request_configure; wl_signal_add(&surface->events.request_configure, &roots_surface->request_configure);