Reapply "respect size hints"

This reverts commit 31bf1cbaf6.

Fixes https://codeberg.org/dwl/dwl/issues/105
Fixes https://codeberg.org/dwl/dwl/issues/634
Fixes https://codeberg.org/dwl/dwl/issues/1171
This commit is contained in:
Guido Cella
2026-09-15 20:03:28 +02:00
parent 36c80aff03
commit 4de32d2d5c
2 changed files with 45 additions and 14 deletions
+32 -11
View File
@@ -15,6 +15,32 @@ client_is_x11(Client *c)
return 0; return 0;
} }
static inline void
client_get_size_hints(Client *c, struct wlr_box *max, struct wlr_box *min)
{
struct wlr_xdg_toplevel_state *state;
#ifdef XWAYLAND
if (client_is_x11(c)) {
xcb_size_hints_t *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
state = &c->surface.xdg->toplevel->current;
max->width = state->max_width;
max->height = state->max_height;
min->width = state->min_width;
min->height = state->min_height;
}
static inline struct wlr_surface * static inline struct wlr_surface *
client_surface(Client *c) client_surface(Client *c)
{ {
@@ -206,13 +232,12 @@ client_get_title(Client *c)
static inline int static inline int
client_is_float_type(Client *c) client_is_float_type(Client *c)
{ {
struct wlr_xdg_toplevel *toplevel; struct wlr_box min = {0}, max = {0};
struct wlr_xdg_toplevel_state state; client_get_size_hints(c, &max, &min);
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland; struct wlr_xwayland_surface *surface = c->surface.xwayland;
xcb_size_hints_t *size_hints = surface->size_hints;
if (surface->modal) if (surface->modal)
return 1; return 1;
@@ -223,17 +248,13 @@ client_is_float_type(Client *c)
return 1; return 1;
} }
return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0 return min.width && min.height &&
&& (size_hints->max_width == size_hints->min_width (min.width == max.width || min.height == max.height);
|| size_hints->max_height == size_hints->min_height);
} }
#endif #endif
toplevel = c->surface.xdg->toplevel; return c->surface.xdg->toplevel->parent || (min.width && min.height &&
state = toplevel->current; (min.width == max.width || min.height == max.height));
return toplevel->parent || (state.min_width != 0 && state.min_height != 0
&& (state.min_width == state.max_width
|| state.min_height == state.max_height));
} }
static inline int static inline int
+13 -3
View File
@@ -3,6 +3,7 @@
*/ */
#include <getopt.h> #include <getopt.h>
#include <libinput.h> #include <libinput.h>
#include <limits.h>
#include <linux/input-event-codes.h> #include <linux/input-event-codes.h>
#include <math.h> #include <math.h>
#include <signal.h> #include <signal.h>
@@ -483,9 +484,18 @@ static struct wlr_xwayland *xwayland;
void void
applybounds(Client *c, struct wlr_box *bbox) applybounds(Client *c, struct wlr_box *bbox)
{ {
/* set minimum possible */ if (!c->isfullscreen) {
c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width); struct wlr_box min = {0}, max = {0};
c->geom.height = MAX(1 + 2 * (int)c->bw, c->geom.height); client_get_size_hints(c, &max, &min);
c->geom.width = MAX(min.width + 2 * (int)c->bw, c->geom.width);
c->geom.height = MAX(min.height + 2 * (int)c->bw, c->geom.height);
/* Some clients set their max size to INT_MAX, which does not violate the
* protocol but it's unnecesary, as they can set their max size to zero. */
if (max.width && 2 * (int)c->bw <= INT_MAX - max.width) /* Checks for overflow */
c->geom.width = MIN(max.width + 2 * (int)c->bw, c->geom.width);
if (max.height && 2 * (int)c->bw <= INT_MAX - max.height) /* Checks for overflow */
c->geom.height = MIN(max.height + 2 * (int)c->bw, c->geom.height);
}
if (c->geom.x >= bbox->x + bbox->width) if (c->geom.x >= bbox->x + bbox->width)
c->geom.x = bbox->x + bbox->width - c->geom.width; c->geom.x = bbox->x + bbox->width - c->geom.width;