From 18a539b372fe6713708f72c94f3b3879134bf285 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Thu, 16 Mar 2023 19:15:56 +0800 Subject: [PATCH] Add some more cases to handle window unusual size request As discussed on the ML, the test to check for CARD16 limit is probably innacurate. Check instead for maxH and maxW which are set by default to twice the size of the screen or to the max values passed by the window normal hints property. --- src/window.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/window.c b/src/window.c index 2ce5f10f..1f16f458 100644 --- a/src/window.c +++ b/src/window.c @@ -1901,25 +1901,20 @@ void wWindowConstrainSize(WWindow *wwin, unsigned int *nwidth, unsigned int *nhe int baseW = 0; int baseH = 0; - /* - * X11 proto defines width and height as a CARD16 - * if window size is guaranteed to fail, failsafe to a reasonable size - */ - if (width > USHRT_MAX && height > USHRT_MAX) { - width = 640; - height = 480; - return; - } - if (wwin->normal_hints) { if (!wwin->flags.maximized) { winc = wwin->normal_hints->width_inc; hinc = wwin->normal_hints->height_inc; } - minW = wwin->normal_hints->min_width; - minH = wwin->normal_hints->min_height; - maxW = wwin->normal_hints->max_width; - maxH = wwin->normal_hints->max_height; + if (wwin->normal_hints->min_width > minW) + minW = wwin->normal_hints->min_width; + if (wwin->normal_hints->min_height > minH) + minH = wwin->normal_hints->min_height; + if (wwin->normal_hints->max_width < maxW) + maxW = wwin->normal_hints->max_width; + if (wwin->normal_hints->max_height < maxH) + maxH = wwin->normal_hints->max_height; + if (wwin->normal_hints->flags & PAspect) { minAX = wwin->normal_hints->min_aspect.x; minAY = wwin->normal_hints->min_aspect.y; @@ -1938,11 +1933,14 @@ void wWindowConstrainSize(WWindow *wwin, unsigned int *nwidth, unsigned int *nhe height = minH; /* if only one dimension is over the top, set a default 4/3 ratio */ - if (width > maxW && height < maxH) { + if (width > maxW && height < maxH) width = height * 4 / 3; - } else { - if(height > maxH && width < maxW) - height = width * 3 / 4; + else if(height > maxH && width < maxW) + height = width * 3 / 4; + else if(width > maxW && height > maxH) { + /* if both are over the top, set size to almost fullscreen */ + height = wwin->screen_ptr->scr_height - 2 * wPreferences.icon_size; + width = wwin->screen_ptr->scr_width - 2 * wPreferences.icon_size; } /* aspect ratio code borrowed from olwm */