From 40449fa64fcacb98372e576cc21e192ab783162f Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Mon, 23 May 2022 09:14:21 -0500 Subject: add a new function to get a client from a wlr_surface --- client.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'client.h') diff --git a/client.h b/client.h index e0964da..ec760ec 100644 --- a/client.h +++ b/client.h @@ -231,6 +231,13 @@ client_min_size(Client *c, int *width, int *height) *height = state->min_height; } +static inline Client * +client_from_wlr_surface(struct wlr_surface *surface) +{ + struct wlr_scene_node *n = surface->data; + return n ? n->data : NULL; +} + static inline Client * client_from_popup(struct wlr_xdg_popup *popup) { -- cgit v1.2.3 From a5a0674f6a92bc47eed51fa5e08279d9d6b1b369 Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Mon, 6 Jun 2022 22:50:50 -0500 Subject: improve client_from_wlr_surface() --- client.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'client.h') diff --git a/client.h b/client.h index ec760ec..6791a4d 100644 --- a/client.h +++ b/client.h @@ -232,10 +232,22 @@ client_min_size(Client *c, int *width, int *height) } static inline Client * -client_from_wlr_surface(struct wlr_surface *surface) +client_from_wlr_surface(struct wlr_surface *s) { - struct wlr_scene_node *n = surface->data; - return n ? n->data : NULL; + struct wlr_xdg_surface *surface; + +#ifdef XWAYLAND + struct wlr_xwayland_surface *xsurface; + if (s->role_data && wlr_surface_is_xwayland_surface(s) + && (xsurface = wlr_xwayland_surface_from_wlr_surface(s))) + return xsurface->data; +#endif + if (s->role_data && wlr_surface_is_xdg_surface(s) + && (surface = wlr_xdg_surface_from_wlr_surface(s)) + && surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) + return surface->data; + + return NULL; } static inline Client * -- cgit v1.2.3 From 4ae6d0f3873451306e1ef04d88e0fab4e2b04548 Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Thu, 16 Jun 2022 15:54:13 -0500 Subject: move ugglyness to client.h --- client.h | 11 +++++++++++ dwl.c | 10 +--------- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'client.h') diff --git a/client.h b/client.h index 6791a4d..d9bb7f3 100644 --- a/client.h +++ b/client.h @@ -231,6 +231,17 @@ client_min_size(Client *c, int *width, int *height) *height = state->min_height; } +static inline void +client_restack_surface(Client *c) +{ +#ifdef XWAYLAND + if (client_is_x11(c)) + wlr_xwayland_surface_restack(c->surface.xwayland, NULL, + XCB_STACK_MODE_ABOVE); +#endif + return; +} + static inline Client * client_from_wlr_surface(struct wlr_surface *s) { diff --git a/dwl.c b/dwl.c index d5bd989..04ba50f 100644 --- a/dwl.c +++ b/dwl.c @@ -1129,6 +1129,7 @@ focusclient(Client *c, int lift) wl_list_insert(&fstack, &c->flink); selmon = c->mon; c->isurgent = 0; + client_restack_surface(c); for (i = 0; i < 4; i++) wlr_scene_rect_set_color(c->border[i], focuscolor); @@ -1169,15 +1170,6 @@ focusclient(Client *c, int lift) return; } -#ifdef XWAYLAND - /* This resolves an issue where the last spawned xwayland client - * receives all pointer activity. - */ - if (c->type == X11Managed) - wlr_xwayland_surface_restack(c->surface.xwayland, NULL, - XCB_STACK_MODE_ABOVE); -#endif - /* Have a client, so focus its top-level wlr_surface */ kb = wlr_seat_get_keyboard(seat); if (kb) -- cgit v1.2.3 From 9b84940e37ec84933d1247bbf3eb76d9efe7c589 Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Mon, 20 Jun 2022 23:46:11 -0500 Subject: unconstrain layer shell popups also unconstrain popups from monitor's usable area --- client.h | 8 +++++--- dwl.c | 33 ++++++++++++++++----------------- 2 files changed, 21 insertions(+), 20 deletions(-) (limited to 'client.h') diff --git a/client.h b/client.h index d9bb7f3..4112fd6 100644 --- a/client.h +++ b/client.h @@ -261,15 +261,17 @@ client_from_wlr_surface(struct wlr_surface *s) return NULL; } -static inline Client * -client_from_popup(struct wlr_xdg_popup *popup) +static inline void * +toplevel_from_popup(struct wlr_xdg_popup *popup) { struct wlr_xdg_surface *surface = popup->base; while (1) { switch (surface->role) { case WLR_XDG_SURFACE_ROLE_POPUP: - if (!wlr_surface_is_xdg_surface(surface->popup->parent)) + if (wlr_surface_is_layer_surface(surface->popup->parent)) + return wlr_layer_surface_v1_from_wlr_surface(surface->popup->parent)->data; + else if (!wlr_surface_is_xdg_surface(surface->popup->parent)) return NULL; surface = wlr_xdg_surface_from_wlr_surface(surface->popup->parent); diff --git a/dwl.c b/dwl.c index 8a9f97d..0eb8fdb 100644 --- a/dwl.c +++ b/dwl.c @@ -90,8 +90,10 @@ typedef struct { typedef struct Monitor Monitor; typedef struct { - /* Must be first */ + /* Must keep these three elements in this order */ unsigned int type; /* XDGShell or X11* */ + struct wlr_box geom; /* layout-relative, includes border */ + Monitor *mon; struct wlr_scene_node *scene; struct wlr_scene_rect *border[4]; /* top, bottom, left, right */ struct wlr_scene_node *scene_surface; @@ -107,8 +109,7 @@ typedef struct { struct wl_listener destroy; struct wl_listener set_title; struct wl_listener fullscreen; - struct wlr_box geom, prev; /* layout-relative, includes border */ - Monitor *mon; + struct wlr_box prev; /* layout-relative, includes border */ #ifdef XWAYLAND struct wl_listener activate; struct wl_listener configure; @@ -146,19 +147,19 @@ typedef struct { } Keyboard; typedef struct { - /* Must be first */ + /* Must keep these three elements in this order */ unsigned int type; /* LayerShell */ - int mapped; + struct wlr_box geom; + Monitor *mon; struct wlr_scene_node *scene; struct wl_list link; + int mapped; struct wlr_layer_surface_v1 *layer_surface; struct wl_listener destroy; struct wl_listener map; struct wl_listener unmap; struct wl_listener surface_commit; - - struct wlr_box geo; } LayerSurface; typedef struct { @@ -559,7 +560,7 @@ arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int wlr_layer_surface_v1_destroy(wlr_layer_surface); continue; } - layersurface->geo = box; + layersurface->geom = box; if (state->exclusive_zone > 0) applyexclusive(usable_area, state->anchor, state->exclusive_zone, @@ -835,7 +836,6 @@ createlayersurface(struct wl_listener *listener, void *data) { struct wlr_layer_surface_v1 *wlr_layer_surface = data; LayerSurface *layersurface; - Monitor *m; struct wlr_layer_surface_v1_state old_state; if (!wlr_layer_surface->output) { @@ -855,14 +855,14 @@ createlayersurface(struct wl_listener *listener, void *data) layersurface->layer_surface = wlr_layer_surface; wlr_layer_surface->data = layersurface; - m = wlr_layer_surface->output->data; + layersurface->mon = wlr_layer_surface->output->data; layersurface->scene = wlr_layer_surface->surface->data = wlr_scene_subsurface_tree_create(layers[wlr_layer_surface->pending.layer], wlr_layer_surface->surface); layersurface->scene->data = layersurface; - wl_list_insert(&m->layers[wlr_layer_surface->pending.layer], + wl_list_insert(&layersurface->mon->layers[wlr_layer_surface->pending.layer], &layersurface->link); /* Temporarily set the layer's current state to pending @@ -870,7 +870,7 @@ createlayersurface(struct wl_listener *listener, void *data) */ old_state = wlr_layer_surface->current; wlr_layer_surface->current = wlr_layer_surface->pending; - arrangelayers(m); + arrangelayers(layersurface->mon); wlr_layer_surface->current = old_state; } @@ -955,9 +955,9 @@ createnotify(struct wl_listener *listener, void *data) struct wlr_box box; xdg_surface->surface->data = wlr_scene_xdg_surface_create( xdg_surface->popup->parent->data, xdg_surface); - if (!(c = client_from_popup(xdg_surface->popup)) || !c->mon) + if (!(c = toplevel_from_popup(xdg_surface->popup)) || !c->mon) return; - box = c->mon->m; + box = c->mon->w; box.x -= c->geom.x; box.y -= c->geom.y; wlr_xdg_popup_unconstrain_from_box(xdg_surface->popup, &box); @@ -1055,9 +1055,8 @@ destroylayersurfacenotify(struct wl_listener *listener, void *data) wl_list_remove(&layersurface->surface_commit.link); wlr_scene_node_destroy(layersurface->scene); if (layersurface->layer_surface->output) { - Monitor *m = layersurface->layer_surface->output->data; - if (m) - arrangelayers(m); + if (layersurface->mon) + arrangelayers(layersurface->mon); layersurface->layer_surface->output = NULL; } free(layersurface); -- cgit v1.2.3 From 72e0a560d9836c5e8658003f548203bcd722e565 Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Fri, 24 Jun 2022 19:15:24 -0500 Subject: respect size hints --- client.h | 83 +++++++++++++++++++++++++++++----------------------------------- dwl.c | 18 ++++++++------ 2 files changed, 49 insertions(+), 52 deletions(-) (limited to 'client.h') diff --git a/client.h b/client.h index 4112fd6..7301d25 100644 --- a/client.h +++ b/client.h @@ -81,6 +81,32 @@ client_get_geometry(Client *c, struct wlr_box *geom) wlr_xdg_surface_get_geometry(c->surface.xdg, geom); } +static inline void +client_get_size_hints(Client *c, struct wlr_box *max, struct wlr_box *min) +{ + struct wlr_xdg_toplevel *toplevel; + struct wlr_xdg_toplevel_state *state; +#ifdef XWAYLAND + if (client_is_x11(c)) { + struct wlr_xwayland_surface_size_hints *size_hints; + size_hints = c->surface.xwayland->size_hints; + if (size_hints) { + max->width = size_hints->max_width; + max->height = size_hints->max_height; + min->width = size_hints->min_width; + min->height = size_hints->min_height; + } + return; + } +#endif + toplevel = c->surface.xdg->toplevel; + state = &toplevel->current; + max->width = state->max_width; + max->height = state->max_height; + min->width = state->min_width; + min->height = state->min_height; +} + static inline const char * client_get_title(Client *c) { @@ -94,39 +120,31 @@ client_get_title(Client *c) static inline int client_is_float_type(Client *c) { - struct wlr_xdg_toplevel *toplevel; - struct wlr_xdg_toplevel_state state; + struct wlr_box min = {0}, max = {0}; + client_get_size_hints(c, &max, &min); #ifdef XWAYLAND if (client_is_x11(c)) { struct wlr_xwayland_surface *surface = c->surface.xwayland; - struct wlr_xwayland_surface_size_hints *size_hints; if (surface->modal) return 1; for (size_t i = 0; i < surface->window_type_len; i++) - if (surface->window_type[i] == netatom[NetWMWindowTypeDialog] || - surface->window_type[i] == netatom[NetWMWindowTypeSplash] || - surface->window_type[i] == netatom[NetWMWindowTypeToolbar] || - surface->window_type[i] == netatom[NetWMWindowTypeUtility]) + if (surface->window_type[i] == netatom[NetWMWindowTypeDialog] + || surface->window_type[i] == netatom[NetWMWindowTypeSplash] + || surface->window_type[i] == netatom[NetWMWindowTypeToolbar] + || surface->window_type[i] == netatom[NetWMWindowTypeUtility]) return 1; - size_hints = surface->size_hints; - if (size_hints && size_hints->min_width > 0 && size_hints->min_height > 0 - && (size_hints->max_width == size_hints->min_width || - size_hints->max_height == size_hints->min_height)) - return 1; - - return 0; + return ((min.width > 0 || min.height > 0 || max.width > 0 || max.height > 0) + && (min.width == max.width || min.height == max.height)) + || c->surface.xwayland->parent; } #endif - toplevel = c->surface.xdg->toplevel; - state = toplevel->current; - return (state.min_width != 0 && state.min_height != 0 - && (state.min_width == state.max_width - || state.min_height == state.max_height)) - || toplevel->parent; + return ((min.width > 0 || min.height > 0 || max.width > 0 || max.height > 0) + && (min.width == max.width || min.height == max.height)) + || c->surface.xdg->toplevel->parent; } static inline int @@ -206,31 +224,6 @@ client_surface_at(Client *c, double cx, double cy, double *sx, double *sy) return wlr_xdg_surface_surface_at(c->surface.xdg, cx, cy, sx, sy); } -static inline void -client_min_size(Client *c, int *width, int *height) -{ - struct wlr_xdg_toplevel *toplevel; - struct wlr_xdg_toplevel_state *state; -#ifdef XWAYLAND - if (client_is_x11(c)) { - struct wlr_xwayland_surface_size_hints *size_hints; - size_hints = c->surface.xwayland->size_hints; - if (size_hints) { - *width = size_hints->min_width; - *height = size_hints->min_height; - } else { - *width = 0; - *height = 0; - } - return; - } -#endif - toplevel = c->surface.xdg->toplevel; - state = &toplevel->current; - *width = state->min_width; - *height = state->min_height; -} - static inline void client_restack_surface(Client *c) { diff --git a/dwl.c b/dwl.c index e349d8b..36a7543 100644 --- a/dwl.c +++ b/dwl.c @@ -381,9 +381,15 @@ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; void applybounds(Client *c, struct wlr_box *bbox) { - /* set minimum possible */ - c->geom.width = MAX(1, c->geom.width); - c->geom.height = MAX(1, c->geom.height); + struct wlr_box min = {0}, max = {0}; + client_get_size_hints(c, &max, &min); + /* try to set size hints */ + c->geom.width = MAX(min.width + (2 * c->bw), c->geom.width); + c->geom.height = MAX(min.height + (2 * c->bw), c->geom.height); + if (max.width > 0) + c->geom.width = MIN(max.width + (2 * c->bw), c->geom.width); + if (max.height > 0) + c->geom.height = MIN(max.height + (2 * c->bw), c->geom.height); if (c->geom.x >= bbox->x + bbox->width) c->geom.x = bbox->x + bbox->width - c->geom.width; @@ -1721,13 +1727,11 @@ requeststartdrag(struct wl_listener *listener, void *data) void resize(Client *c, int x, int y, int w, int h, int interact) { - int min_width = 0, min_height = 0; struct wlr_box *bbox = interact ? &sgeom : &c->mon->w; - client_min_size(c, &min_width, &min_height); c->geom.x = x; c->geom.y = y; - c->geom.width = MAX(min_width + 2 * c->bw, w); - c->geom.height = MAX(min_height + 2 * c->bw, h); + c->geom.width = w; + c->geom.height = h; applybounds(c, bbox); /* Update scene-graph, including borders */ -- cgit v1.2.3 From e98719f5523597d02e82632a4af2676a1299497e Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Fri, 15 Jul 2022 00:48:28 -0500 Subject: remove a useless check if `s->role_data == NULL`, wlr_*_surface_from_wlr_surface() will return NULL and we are checking it --- client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'client.h') diff --git a/client.h b/client.h index 7301d25..681f842 100644 --- a/client.h +++ b/client.h @@ -242,11 +242,11 @@ client_from_wlr_surface(struct wlr_surface *s) #ifdef XWAYLAND struct wlr_xwayland_surface *xsurface; - if (s->role_data && wlr_surface_is_xwayland_surface(s) + if (wlr_surface_is_xwayland_surface(s) && (xsurface = wlr_xwayland_surface_from_wlr_surface(s))) return xsurface->data; #endif - if (s->role_data && wlr_surface_is_xdg_surface(s) + if (wlr_surface_is_xdg_surface(s) && (surface = wlr_xdg_surface_from_wlr_surface(s)) && surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) return surface->data; -- cgit v1.2.3 From 90a12c90a0aa0ac16327b0816de4d9dff69b357e Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Tue, 19 Jul 2022 20:13:56 -0500 Subject: always set the same monitor and tags for child clients of a client fixes #272 --- client.h | 52 +++++++++++++++++++++++++++++++++------------------- dwl.c | 11 +++++++++-- 2 files changed, 42 insertions(+), 21 deletions(-) (limited to 'client.h') diff --git a/client.h b/client.h index 681f842..dc4a6c4 100644 --- a/client.h +++ b/client.h @@ -26,6 +26,25 @@ client_surface(Client *c) return c->surface.xdg->surface; } +static inline Client * +client_from_wlr_surface(struct wlr_surface *s) +{ + struct wlr_xdg_surface *surface; + +#ifdef XWAYLAND + struct wlr_xwayland_surface *xsurface; + if (s && wlr_surface_is_xwayland_surface(s) + && (xsurface = wlr_xwayland_surface_from_wlr_surface(s))) + return xsurface->data; +#endif + if (s && wlr_surface_is_xdg_surface(s) + && (surface = wlr_xdg_surface_from_wlr_surface(s)) + && surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) + return surface->data; + + return NULL; +} + /* The others */ static inline void client_activate_surface(struct wlr_surface *s, int activated) @@ -117,6 +136,20 @@ client_get_title(Client *c) return c->surface.xdg->toplevel->title; } +static inline Client * +client_get_parent(Client *c) +{ + Client *p; +#ifdef XWAYLAND + if (client_is_x11(c) && c->surface.xwayland->parent) + return client_from_wlr_surface(c->surface.xwayland->parent->surface); +#endif + if (c->surface.xdg->toplevel->parent) + return client_from_wlr_surface(c->surface.xdg->toplevel->parent->surface); + + return NULL; +} + static inline int client_is_float_type(Client *c) { @@ -235,25 +268,6 @@ client_restack_surface(Client *c) return; } -static inline Client * -client_from_wlr_surface(struct wlr_surface *s) -{ - struct wlr_xdg_surface *surface; - -#ifdef XWAYLAND - struct wlr_xwayland_surface *xsurface; - if (wlr_surface_is_xwayland_surface(s) - && (xsurface = wlr_xwayland_surface_from_wlr_surface(s))) - return xsurface->data; -#endif - if (wlr_surface_is_xdg_surface(s) - && (surface = wlr_xdg_surface_from_wlr_surface(s)) - && surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) - return surface->data; - - return NULL; -} - static inline void * toplevel_from_popup(struct wlr_xdg_popup *popup) { diff --git a/dwl.c b/dwl.c index 65d7e24..727e6e1 100644 --- a/dwl.c +++ b/dwl.c @@ -1388,7 +1388,7 @@ void mapnotify(struct wl_listener *listener, void *data) { /* Called when the surface is mapped, or ready to display on-screen. */ - Client *c = wl_container_of(listener, c, map); + Client *p, *c = wl_container_of(listener, c, map); int i; /* Create scene tree for this client and its border */ @@ -1432,7 +1432,14 @@ mapnotify(struct wl_listener *listener, void *data) wl_list_insert(&fstack, &c->flink); /* Set initial monitor, tags, floating status, and focus */ - applyrules(c); + if ((p = client_get_parent(c))) { + /* Set the same monitor and tags than its parent */ + c->isfloating = 1; + wlr_scene_node_reparent(c->scene, layers[LyrFloat]); + setmon(c, p->mon, p->tags); + } else { + applyrules(c); + } printstatus(); if (c->isfullscreen) -- cgit v1.2.3 From 28af37cd1f6dce140df8e99659d0af07dc1d9985 Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Fri, 12 Aug 2022 23:58:11 -0500 Subject: handle client_from_wlr_surface() receiving a subsurface --- client.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'client.h') diff --git a/client.h b/client.h index dc4a6c4..c091b81 100644 --- a/client.h +++ b/client.h @@ -30,6 +30,7 @@ static inline Client * client_from_wlr_surface(struct wlr_surface *s) { struct wlr_xdg_surface *surface; + struct wlr_surface *parent; #ifdef XWAYLAND struct wlr_xwayland_surface *xsurface; @@ -42,6 +43,8 @@ client_from_wlr_surface(struct wlr_surface *s) && surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) return surface->data; + if (s && wlr_surface_is_subsurface(s)) + return client_from_wlr_surface(wlr_surface_get_root_surface(s)); return NULL; } -- cgit v1.2.3 From 07bf1832bf2c435107f4664c82efc756f3fdd784 Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Thu, 18 Aug 2022 16:59:38 -0500 Subject: set monitor for clients that don't have one in updatemons() only if selmon is enabled and the clients are mapped --- client.h | 10 ++++++++++ dwl.c | 6 ++++++ 2 files changed, 16 insertions(+) (limited to 'client.h') diff --git a/client.h b/client.h index c091b81..c54a2f3 100644 --- a/client.h +++ b/client.h @@ -183,6 +183,16 @@ client_is_float_type(Client *c) || c->surface.xdg->toplevel->parent; } +static inline int +client_is_mapped(Client *c) +{ +#ifdef XWAYLAND + if (client_is_x11(c)) + return c->surface.xwayland->mapped; +#endif + return c->surface.xdg->mapped; +} + static inline int client_wants_fullscreen(Client *c) { diff --git a/dwl.c b/dwl.c index cf7d307..3a044d3 100644 --- a/dwl.c +++ b/dwl.c @@ -2365,6 +2365,7 @@ updatemons(struct wl_listener *listener, void *data) */ struct wlr_output_configuration_v1 *config = wlr_output_configuration_v1_create(); + Client *c; Monitor *m; sgeom = *wlr_output_layout_get_box(output_layout, NULL); wl_list_for_each(m, &mons, link) { @@ -2388,6 +2389,11 @@ updatemons(struct wl_listener *listener, void *data) config_head->state.y = m->m.y; } + if (selmon && selmon->wlr_output->enabled) + wl_list_for_each(c, &clients, link) + if (!c->mon && client_is_mapped(c)) + setmon(c, selmon, c->tags); + wlr_output_manager_v1_set_configuration(output_mgr, config); } -- cgit v1.2.3