From 4d7ff3cb48d1057765d7307081d8387648ab59b1 Mon Sep 17 00:00:00 2001 From: Versus Void Date: Fri, 6 Oct 2017 13:57:25 +0300 Subject: Activate only active xwayland views Fix #217 --- rootston/xwayland.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'rootston/xwayland.c') diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 7ecc4d4f..59bb2632 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -39,8 +39,10 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { } static void activate(struct roots_view *view, bool active) { - wlr_xwayland_surface_activate(view->desktop->xwayland, - view->xwayland_surface); + if (active) { + wlr_xwayland_surface_activate(view->desktop->xwayland, + view->xwayland_surface); + } } void handle_xwayland_surface(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From 528f000a7a5ed8b26a14ca09263dc0e7024aba8f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 6 Oct 2017 09:34:22 -0400 Subject: Deactivate xwayland when focus leaves there --- rootston/cursor.c | 5 ++++- rootston/xwayland.c | 2 ++ xwayland/xwm.c | 32 +++++++++++++++++++------------- 3 files changed, 25 insertions(+), 14 deletions(-) (limited to 'rootston/xwayland.c') diff --git a/rootston/cursor.c b/rootston/cursor.c index eec8eb5d..0ca45f16 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -137,11 +137,14 @@ static void set_view_focus(struct roots_input *input, size_t index = 0; for (size_t i = 0; i < desktop->views->length; ++i) { struct roots_view *_view = desktop->views->items[i]; - view_activate(_view, _view == view); + if (_view != view) { + view_activate(_view, false); + } if (view == _view) { index = i; } } + view_activate(view, true); // TODO: list_swap list_del(desktop->views, index); list_add(desktop->views, view); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 59bb2632..bb8ced8e 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -42,6 +42,8 @@ static void activate(struct roots_view *view, bool active) { if (active) { wlr_xwayland_surface_activate(view->desktop->xwayland, view->xwayland_surface); + } else { + wlr_xwayland_surface_activate(view->desktop->xwayland, NULL); } } diff --git a/xwayland/xwm.c b/xwayland/xwm.c index a4091d1f..3322f505 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -705,19 +705,25 @@ static void xcb_init_wm(struct wlr_xwm *xwm) { void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface) { struct wlr_xwm *xwm = wlr_xwayland->xwm; - xcb_client_message_event_t m = {0}; - m.response_type = XCB_CLIENT_MESSAGE; - m.format = 32; - m.window = surface->window_id; - m.type = xwm->atoms[WM_PROTOCOLS]; - m.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS]; - m.data.data32[1] = XCB_TIME_CURRENT_TIME; - xcb_send_event_checked(xwm->xcb_conn, 0, surface->window_id, - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&m); - xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, - surface->window_id, XCB_CURRENT_TIME); - xcb_configure_window_checked(xwm->xcb_conn, surface->window_id, - XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){XCB_STACK_MODE_ABOVE}); + if (surface) { + xcb_client_message_event_t m = {0}; + m.response_type = XCB_CLIENT_MESSAGE; + m.format = 32; + m.window = surface->window_id; + m.type = xwm->atoms[WM_PROTOCOLS]; + m.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS]; + m.data.data32[1] = XCB_TIME_CURRENT_TIME; + xcb_send_event_checked(xwm->xcb_conn, 0, surface->window_id, + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&m); + xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, + surface->window_id, XCB_CURRENT_TIME); + xcb_configure_window_checked(xwm->xcb_conn, surface->window_id, + XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){XCB_STACK_MODE_ABOVE}); + } else { + wlr_log(L_DEBUG, "Deactivating xwayland"); + xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_NONE, + -1, XCB_CURRENT_TIME); + } xcb_flush(xwm->xcb_conn); } -- cgit v1.2.3 From 972e9dbd1b2eb2853a60632d279bd754daf7c440 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 15:39:39 +0200 Subject: 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(-) (limited to 'rootston/xwayland.c') 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); } -- cgit v1.2.3 From b21f783c34f145545b0109b06b135cd1e9fa8b70 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 16:44:55 +0200 Subject: Disconnect wl_shell clients when closing --- rootston/wl_shell.c | 7 +++++++ rootston/xwayland.c | 44 ++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 22 deletions(-) (limited to 'rootston/xwayland.c') 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); -- cgit v1.2.3