Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initial position of X11 override-redirects #283

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ 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)) {
/* 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)) {
view_maximize(view, &layout_box);
} else {
Expand All @@ -112,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;
Expand All @@ -130,14 +142,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);
Expand Down
23 changes: 18 additions & 5 deletions xwayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ 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;
view_position(view);
}
}

static void
handle_xwayland_surface_unmap(struct wl_listener *listener, void *data)
{
Expand All @@ -118,11 +131,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);
}

Expand All @@ -136,6 +144,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);
Expand Down Expand Up @@ -165,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;
Comment on lines +177 to +178
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, should we add a if (!xwayland_view_should_manage(view)) here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it wouldn't cover the case where override_redirect is set between creating and mapping the window, e.g.:

Window w = XCreateSimpleWindow(dpy, root, 100, 100, 50, 50, 3, 0xffff00, 0xff00ff);

XSetWindowAttributes attrs = { .override_redirect = True };
XChangeWindowAttributes(dpy, w, CWOverrideRedirect, &attrs);

// Should appear at position (100, 100)
XMapWindow(dpy, w);
XFlush(dpy);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm… What about override redirect changing after the window is unmapped? Sounds like we should probably set up a set_override_redirect listener to handle all cases correctly?

I'd be more comfortable only copying the X11 position when the window is O-R.


xwayland_view->map.notify = handle_xwayland_surface_map;
wl_signal_add(&xwayland_surface->events.map, &xwayland_view->map);
Expand All @@ -174,4 +185,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);
}
1 change: 1 addition & 0 deletions xwayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down