diff --git a/include/rootston/input.h b/include/rootston/input.h index ae3e3b80c..09509e85d 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -81,7 +81,7 @@ struct roots_input { struct wlr_seat *wl_seat; enum roots_cursor_mode mode; - struct roots_view *active_view; + struct roots_view *active_view, *last_active_view; int offs_x, offs_y; int view_x, view_y, view_width, view_height; float view_rotation; diff --git a/include/rootston/view.h b/include/rootston/view.h index 39ff80db6..64aad45ef 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -65,11 +65,13 @@ struct roots_view { void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box); void (*activate)(struct roots_view *view, bool active); void (*resize)(struct roots_view *view, uint32_t width, uint32_t height); + void (*close)(struct roots_view *view); }; void view_get_size(struct roots_view *view, struct wlr_box *box); void view_get_input_bounds(struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_resize(struct roots_view *view, uint32_t width, uint32_t height); +void view_close(struct roots_view *view); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 0ca45f169..9c4b0dd8d 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -133,6 +133,7 @@ static void set_view_focus(struct roots_input *input, if (!view) { return; } + input->last_active_view = view; size_t index = 0; for (size_t i = 0; i < desktop->views->length; ++i) { diff --git a/rootston/desktop.c b/rootston/desktop.c index f99afaf56..d214e280d 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -58,6 +58,12 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { } } +void view_close(struct roots_view *view) { + if (view->close) { + view->close(view); + } +} + static struct wlr_subsurface *subsurface_at(struct wlr_surface *surface, double sx, double sy, double *sub_x, double *sub_y) { struct wlr_subsurface *subsurface; diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 8488e2086..6f4334af9 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -28,6 +28,10 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, struct roots_server *server = keyboard->input->server; if (strcmp(command, "exit") == 0) { wl_display_terminate(server->wl_display); + } else if (strcmp(command, "close") == 0) { + if (keyboard->input->last_active_view != NULL) { + view_close(keyboard->input->last_active_view); + } } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { const char *shell_cmd = command + strlen(exec_prefix); pid_t pid = fork(); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index bb8ced8ef..4b833ef1e 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -9,13 +9,6 @@ #include "rootston/desktop.h" #include "rootston/server.h" -static void resize(struct roots_view *view, uint32_t width, uint32_t height) { - assert(view->type == ROOTS_XWAYLAND_VIEW); - struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - xwayland_surface->x, xwayland_surface->y, width, height); -} - static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); @@ -39,6 +32,7 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { } static void activate(struct roots_view *view, bool active) { + assert(view->type == ROOTS_XWAYLAND_VIEW); if (active) { wlr_xwayland_surface_activate(view->desktop->xwayland, view->xwayland_surface); @@ -47,6 +41,18 @@ 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_XWAYLAND_VIEW); + struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, + xwayland_surface->x, xwayland_surface->y, width, height); +} + +static void close(struct roots_view *view) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); +} + void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, xwayland_surface); @@ -82,6 +88,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; view->activate = activate; view->resize = resize; + view->close = close; roots_surface->view = view; list_add(desktop->views, view); }