From 8ff548cdbaf5ea4e20758d6ee58d6db0c4daf8cd Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 15:04:05 +0200 Subject: [PATCH 1/7] Require exec prefix to execute shell commands --- rootston/keyboard.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 6f6fa0e8..8488e208 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -21,19 +21,24 @@ static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard, return -1; } +static const char *exec_prefix = "exec "; + static void keyboard_binding_execute(struct roots_keyboard *keyboard, - char *command) { + const char *command) { struct roots_server *server = keyboard->input->server; if (strcmp(command, "exit") == 0) { wl_display_terminate(server->wl_display); - } else { + } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { + const char *shell_cmd = command + strlen(exec_prefix); pid_t pid = fork(); if (pid < 0) { wlr_log(L_ERROR, "cannot execute binding command: fork() failed"); return; } else if (pid == 0) { - execl("/bin/sh", "/bin/sh", "-c", command, (void *)NULL); + execl("/bin/sh", "/bin/sh", "-c", shell_cmd, (void *)NULL); } + } else { + wlr_log(L_ERROR, "unknown binding command: %s", command); } } From 972e9dbd1b2eb2853a60632d279bd754daf7c440 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 15:39:39 +0200 Subject: [PATCH 2/7] Add close command, add close for xwayland --- include/rootston/input.h | 2 +- include/rootston/view.h | 2 ++ rootston/cursor.c | 1 + rootston/desktop.c | 6 ++++++ rootston/keyboard.c | 4 ++++ rootston/xwayland.c | 21 ++++++++++++++------- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/include/rootston/input.h b/include/rootston/input.h index ae3e3b80..09509e85 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 39ff80db..64aad45e 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 0ca45f16..9c4b0dd8 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 f99afaf5..d214e280 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 8488e208..6f4334af 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 bb8ced8e..4b833ef1 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); } From 69aff9b35e0e5ce1031aaa65a0166423bc95d192 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 15:58:49 +0200 Subject: [PATCH 3/7] Implement wlr_xdg_toplevel_v6_send_close --- include/wlr/types/wlr_xdg_shell_v6.h | 5 +++++ rootston/xdg_shell_v6.c | 9 +++++++++ types/wlr_xdg_shell_v6.c | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index cc52d9c7..de8dfca7 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -172,4 +172,9 @@ void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing); +/** + * Request that this toplevel surface closes. + */ +void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface); + #endif diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ab34f52a..c7072354 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -33,6 +33,14 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) { } } +static void close(struct roots_view *view) { + 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_send_close(surf); + } +} + 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); @@ -107,6 +115,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->get_size = get_size; view->activate = activate; view->resize = resize; + view->close = close; view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index c30291d1..fc029f2d 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -807,3 +807,8 @@ void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, wlr_xdg_surface_v6_schedule_configure(surface, false); } + +void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) { + assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + zxdg_toplevel_v6_send_close(surface->toplevel_state->resource); +} From ecc0f712af823e1017f000ddf65d79f4e2ecd601 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 16:09:43 +0200 Subject: [PATCH 4/7] Update rootston.ini.example --- rootston/rootston.ini.example | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example index 9960cae1..9769a495 100644 --- a/rootston/rootston.ini.example +++ b/rootston/rootston.ini.example @@ -30,6 +30,7 @@ meta-key = Logo # Keybindings # Maps key combinations with commands to execute -# The special command "exit" stops the compositor +# Use the prefix "exec" to execute a shell command [bindings] -Logo+q = exit +Logo+q = exit # Stops the compositor +Logo+w = close # Closes the current view From b21f783c34f145545b0109b06b135cd1e9fa8b70 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 16:44:55 +0200 Subject: [PATCH 5/7] Disconnect wl_shell clients when closing --- rootston/wl_shell.c | 7 +++++++ rootston/xwayland.c | 44 ++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 1991d332..55ffd2eb 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -17,6 +17,12 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) { height); } +static void close(struct roots_view *view) { + assert(view->type == ROOTS_WL_SHELL_VIEW); + struct wlr_wl_shell_surface *surf = view->wl_shell_surface; + wl_client_destroy(surf->client); +} + 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); @@ -88,6 +94,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->roots_wl_shell_surface = roots_surface; view->wlr_surface = surface->surface; view->resize = resize; + view->close = close; view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 4b833ef1..c32ee15b 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -9,28 +9,6 @@ #include "rootston/desktop.h" #include "rootston/server.h" -static void handle_destroy(struct wl_listener *listener, void *data) { - struct roots_xwayland_surface *roots_surface = - wl_container_of(listener, roots_surface, destroy); - wl_list_remove(&roots_surface->destroy.link); - view_destroy(roots_surface->view); - free(roots_surface); -} - -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 = - roots_surface->view->xwayland_surface; - struct wlr_xwayland_surface_configure_event *event = data; - - roots_surface->view->x = (double)event->x; - roots_surface->view->y = (double)event->y; - - wlr_xwayland_surface_configure(roots_surface->view->desktop->xwayland, - xwayland_surface, event->x, event->y, event->width, event->height); -} - static void activate(struct roots_view *view, bool active) { assert(view->type == ROOTS_XWAYLAND_VIEW); if (active) { @@ -53,6 +31,28 @@ static void close(struct roots_view *view) { wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); } +static void handle_destroy(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, destroy); + wl_list_remove(&roots_surface->destroy.link); + view_destroy(roots_surface->view); + free(roots_surface); +} + +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 = + roots_surface->view->xwayland_surface; + struct wlr_xwayland_surface_configure_event *event = data; + + roots_surface->view->x = (double)event->x; + roots_surface->view->y = (double)event->y; + + wlr_xwayland_surface_configure(roots_surface->view->desktop->xwayland, + xwayland_surface, event->x, event->y, event->width, event->height); +} + void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, xwayland_surface); From fbca2809496bf68b6c3e50957c5c9b9a62813943 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 16:51:16 +0200 Subject: [PATCH 6/7] Unset input->active_view when view is destroyed --- rootston/desktop.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rootston/desktop.c b/rootston/desktop.c index d214e280..691d5809 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -16,6 +16,16 @@ void view_destroy(struct roots_view *view) { struct roots_desktop *desktop = view->desktop; + + struct roots_input *input = desktop->server->input; + if (input->active_view == view) { + input->active_view = NULL; + input->mode = ROOTS_CURSOR_PASSTHROUGH; + } + if (input->last_active_view == view) { + input->last_active_view = NULL; + } + for (size_t i = 0; i < desktop->views->length; ++i) { struct roots_view *_view = desktop->views->items[i]; if (view == _view) { From f402598ee115e06a9d7595042495e9b061d7530a Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 17:10:24 +0200 Subject: [PATCH 7/7] Match default keybindings with sway's --- rootston/rootston.ini.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example index 9769a495..8ac474d4 100644 --- a/rootston/rootston.ini.example +++ b/rootston/rootston.ini.example @@ -32,5 +32,5 @@ meta-key = Logo # Maps key combinations with commands to execute # Use the prefix "exec" to execute a shell command [bindings] -Logo+q = exit # Stops the compositor -Logo+w = close # Closes the current view +Logo+Shift+e = exit # Stop the compositor +Logo+q = close # Close the current view