From 2f4801aea08b4eb284b88a972e6abc15e4b6e585 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 16 Oct 2023 15:57:14 -0500 Subject: [PATCH 1/3] Fix initial position of X11 override-redirects Presumably this fixes #228. The position of the scene node for XWayland override-redirect windows was never being set. --- view.c | 16 ++++++++-------- xwayland.c | 20 +++++++++++++++----- xwayland.h | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/view.c b/view.c index 8948580d..4c913a46 100644 --- a/view.c +++ b/view.c @@ -90,6 +90,13 @@ view_position(struct cg_view *view) struct wlr_box layout_box; wlr_output_layout_get_box(view->server->output_layout, NULL, &layout_box); +#if CAGE_HAS_XWAYLAND + /* We shouldn't position override-redirect windows. They set + their own (x,y) coordinates in handle_xwayland_surface_set_geometry. */ + if (view->type == CAGE_XWAYLAND_VIEW && !xwayland_view_should_manage(view)) { + wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly); + } else +#endif if (view_is_primary(view) || view_extends_output_layout(view, &layout_box)) { view_maximize(view, &layout_box); } else { @@ -130,14 +137,7 @@ view_map(struct cg_view *view, struct wlr_surface *surface) view->wlr_surface = surface; surface->data = view; -#if CAGE_HAS_XWAYLAND - /* We shouldn't position override-redirect windows. They set - their own (x,y) coordinates in handle_wayland_surface_map. */ - if (view->type != CAGE_XWAYLAND_VIEW || xwayland_view_should_manage(view)) -#endif - { - view_position(view); - } + view_position(view); wl_list_insert(&view->server->views, &view->link); seat_set_focus(view->server->seat, view); diff --git a/xwayland.c b/xwayland.c index ef37a497..f8e0bd58 100644 --- a/xwayland.c +++ b/xwayland.c @@ -103,6 +103,18 @@ handle_xwayland_surface_request_fullscreen(struct wl_listener *listener, void *d wlr_xwayland_surface_set_fullscreen(xwayland_view->xwayland_surface, xwayland_surface->fullscreen); } +static void +handle_xwayland_surface_set_geometry(struct wl_listener *listener, void *data) +{ + struct cg_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, set_geometry); + struct cg_view *view = &xwayland_view->view; + + if (!xwayland_view_should_manage(view)) { + view->lx = xwayland_view->xwayland_surface->x; + view->ly = xwayland_view->xwayland_surface->y; + } +} + static void handle_xwayland_surface_unmap(struct wl_listener *listener, void *data) { @@ -118,11 +130,6 @@ handle_xwayland_surface_map(struct wl_listener *listener, void *data) struct cg_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, map); struct cg_view *view = &xwayland_view->view; - if (!xwayland_view_should_manage(view)) { - view->lx = xwayland_view->xwayland_surface->x; - view->ly = xwayland_view->xwayland_surface->y; - } - view_map(view, xwayland_view->xwayland_surface->surface); } @@ -136,6 +143,7 @@ handle_xwayland_surface_destroy(struct wl_listener *listener, void *data) wl_list_remove(&xwayland_view->unmap.link); wl_list_remove(&xwayland_view->destroy.link); wl_list_remove(&xwayland_view->request_fullscreen.link); + wl_list_remove(&xwayland_view->set_geometry.link); xwayland_view->xwayland_surface = NULL; view_destroy(view); @@ -174,4 +182,6 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data) wl_signal_add(&xwayland_surface->events.destroy, &xwayland_view->destroy); xwayland_view->request_fullscreen.notify = handle_xwayland_surface_request_fullscreen; wl_signal_add(&xwayland_surface->events.request_fullscreen, &xwayland_view->request_fullscreen); + xwayland_view->set_geometry.notify = handle_xwayland_surface_set_geometry; + wl_signal_add(&xwayland_surface->events.set_geometry, &xwayland_view->set_geometry); } diff --git a/xwayland.h b/xwayland.h index 31edb8f6..ff157ecb 100644 --- a/xwayland.h +++ b/xwayland.h @@ -13,6 +13,7 @@ struct cg_xwayland_view { struct wl_listener unmap; struct wl_listener map; struct wl_listener request_fullscreen; + struct wl_listener set_geometry; }; struct cg_xwayland_view *xwayland_view_from_view(struct cg_view *view); From 31c129b21839c961bbe13588300a89061bff1087 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 16 Oct 2023 16:55:17 -0500 Subject: [PATCH 2/3] Update scene node when an unmanaged window moves A null check had to be added because, since a view's scene isn't created until .map, there's a possibility that .set_geometry is called before the scene node exists. --- view.c | 7 ++++++- xwayland.c | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/view.c b/view.c index 4c913a46..ffd502a3 100644 --- a/view.c +++ b/view.c @@ -94,7 +94,11 @@ view_position(struct cg_view *view) /* We shouldn't position override-redirect windows. They set their own (x,y) coordinates in handle_xwayland_surface_set_geometry. */ if (view->type == CAGE_XWAYLAND_VIEW && !xwayland_view_should_manage(view)) { - wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly); + /* The scene is created in .map, but .set_geometry can come + * before that. */ + if (view->scene_tree != NULL) { + wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly); + } } else #endif if (view_is_primary(view) || view_extends_output_layout(view, &layout_box)) { @@ -119,6 +123,7 @@ view_unmap(struct cg_view *view) wl_list_remove(&view->link); wlr_scene_node_destroy(&view->scene_tree->node); + view->scene_tree = NULL; view->wlr_surface->data = NULL; view->wlr_surface = NULL; diff --git a/xwayland.c b/xwayland.c index f8e0bd58..3697566e 100644 --- a/xwayland.c +++ b/xwayland.c @@ -112,6 +112,7 @@ handle_xwayland_surface_set_geometry(struct wl_listener *listener, void *data) if (!xwayland_view_should_manage(view)) { view->lx = xwayland_view->xwayland_surface->x; view->ly = xwayland_view->xwayland_surface->y; + view_position(view); } } From 14ba8d33652fe7c3e0dd18a9a8a174597b03b4cb Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 16 Oct 2023 18:28:44 -0500 Subject: [PATCH 3/3] populate lx/ly when Xwayland view is created --- xwayland.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xwayland.c b/xwayland.c index 3697566e..6ec220a5 100644 --- a/xwayland.c +++ b/xwayland.c @@ -174,6 +174,8 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data) view_init(&xwayland_view->view, server, CAGE_XWAYLAND_VIEW, &xwayland_view_impl); xwayland_view->xwayland_surface = xwayland_surface; + xwayland_view->view.lx = xwayland_surface->x; + xwayland_view->view.ly = xwayland_surface->y; xwayland_view->map.notify = handle_xwayland_surface_map; wl_signal_add(&xwayland_surface->events.map, &xwayland_view->map);