GTK windows change scale too early when dragging between monitors
Steps to reproduce
- Configure your system with Gnome Shell in Wayland mode, and two screens. Set the left screen to 200% scale, and the right screen to 100% scale. Disable fractional scaling.
- Configure a theme with big shadows (guessing, I haven't confirmed this is the cause but i have strong suspicions...)
- Open a GTK window, ensure it's rendering with Wayland backend. Drag it so its left edge is near the left edge of the right 100% screen.
- There will be a point, seems to be coincidentally about the width of the window shadow, where the text on your test window becomes a bit more fuzzy. What is happening here is the window is being drawn at scale factor 2, and then scaled down to 1. If you move the window further into the right 100% screen, it will revert to rendering at scale factor 1 and get rendered crisply/properly.
A recording with a demo python program demonstrating this is attached, but I can see this behaviour with all Gtk apps on my system (and Firefox..)
I believe the cause of this is in gdk_display_get_monitor_at_surface (https://gitlab.gnome.org/GNOME/gtk/blob/master/gdk/wayland/gdkdisplay-wayland.c#L907) - it seems to just get the first output in the list of outputs that window is on, which is not correct (e.g. here I guess shadows are throwing it off, again that's just a guess). Maybe better behaviour would be to get the output that contains the biggest proportion of the window (Qt does this), or at least to exclude outputs that don't contain the window's contents (like we're seeing here).
Screencast_from_26-10-21_14_29_13
Version information
GTK 4.4.0+ds1-5 from Ubuntu 21.10 (actually from Pop OS 21.10)
Demo app: gtk.py