1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

GTK: stop using geometry hints when not on X11.

While re-testing on Wayland after all this churn of the window
resizing code, I discovered that the window constantly came out a few
pixels too small, losing a character cell in width and height. This
stopped happening once I experimentally stopped setting geometry
hints.

Source-diving in GTK, it turns out that this is because the GDK
Wayland backend is applying the geometry hints to the size of the
window including 'margins', which are a very large extra space around
a window beyond even the visible 'non-client-area' furniture like the
title bar. And I have no idea how you find out the size of those
margins, so I can't allow for them in the geometry hints.

I also noticed that gtk_window_set_geometry_hints is removed in GTK 4,
which suggests that GTK upstream are probably not interested in
fiddling with them until they work more usefully (even if they would
agree with me that this is a bug in the first place, which I have no
idea). A simpler workaround is to avoid setting geometry hints at all
on any GDK backend other than X11.

So, that's what this commit does. On Wayland (or other backends), the
window can now be resized a pixel at a time, and if its size doesn't
work out to a whole number of character cells, then you just get some
dead space at the edges. Not especially nice, but better than the
alternatives I can see.

One other job the geometry hints were doing was to forbid resizing if
the backend sets the BACKEND_RESIZE_FORBIDDEN flag (which SUPDUP
does). That's now done at window creation time, via
gtk_window_set_resizable.
This commit is contained in:
Simon Tatham 2021-12-20 11:06:57 +00:00
parent 18a3a999f6
commit 99aac9c4f4

View File

@ -4488,6 +4488,35 @@ static void compute_geom_hints(GtkFrontend *inst, GdkGeometry *geom)
void set_geom_hints(GtkFrontend *inst)
{
/*
* 2021-12-20: I've found that on Ubuntu 20.04 Wayland (using GTK
* 3.24.20), setting geometry hints causes the window size to come
* out wrong. As far as I can tell, that's because the GDK Wayland
* backend internally considers windows to be a lot larger than
* their obvious display size (*even* considering visible window
* furniture like title bars), with an extra margin on every side
* to account for surrounding effects like shadows. And the
* geometry hints like base size and resize increment are applied
* to that larger size rather than the more obvious 'client area'
* size. So when we ask for a window of exactly the size we want,
* it gets modified by GDK based on the geometry hints, but
* applying this extra margin, which causes the size to be a
* little bit too small.
*
* I don't know how you can sensibly find out the size of that
* margin. If I did, I could account for it in the geometry hints.
* But I also see that gtk_window_set_geometry_hints is removed in
* GTK 4, which suggests that probably doing a lot of hard work to
* fix this is not the way forward.
*
* So instead, I simply avoid setting geometry hints at all on any
* GDK backend other than X11, and hopefully that's a workaround.
*/
#if GTK_CHECK_VERSION(3,0,0)
if (!GDK_IS_X11_DISPLAY(gdk_display_get_default()))
return;
#endif
const struct BackendVtable *vt;
GdkGeometry geom;
gint flags = GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE | GDK_HINT_RESIZE_INC;
@ -5272,6 +5301,14 @@ void new_session_window(Conf *conf, const char *geometry_string)
}
}
#if GTK_CHECK_VERSION(2,0,0)
{
const BackendVtable *vt = select_backend(inst->conf);
if (vt && vt->flags & BACKEND_RESIZE_FORBIDDEN)
gtk_window_set_resizable(GTK_WINDOW(inst->window), false);
}
#endif
inst->width = conf_get_int(inst->conf, CONF_width);
inst->height = conf_get_int(inst->conf, CONF_height);
cache_conf_values(inst);