Tk Source Code

View Ticket
Login
Ticket UUID: 90d85ad8ce7ade9d424abf4530dbfb36ca37d00e
Title: Wayland branch: at a display scale above 100%, wm maxsize, winfo screenwidth and winfo vrootwidth use different units (wm-maxsize-1.7, 2.6 and 2.7 fail)
Type: Bug Version: wayland
Submitter: serhiy.storchaka Created on: 2026-11-13 12:01:14
Subsystem: (unused) Assigned To: kevin_walzer
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-11-13 18:33:32
Resolution: Fixed Closed By: kevin_walzer
    Closed on: 2026-11-13 18:33:32
Description:

At a display scale other than 100%, wm-maxsize-1.7, wm-maxsize-2.6 and wm-maxsize-2.7 fail. Tk reports the screen and window sizes in different units. On KWin on a real screen with the scale 150% (2560x1600 physical pixels, 1707x1067 logical):

wm maxsize .t                   2560 1552   (physical pixels)
winfo vrootwidth/vrootheight    2560 1600   (physical pixels)
winfo screenwidth/screenheight  1280 800    (physical pixels / 2)
zoomed .t                       1707 995    (logical pixels)
  • Since [46929db12a], the default wm maxsize is computed by GetUsableScreenSize() from the video mode of the monitor, which GLFW reports in physical pixels. It is only divided by the scale if TKWL_VIDMODE_IS_PHYSICAL is defined, and it is not defined by default. So the maximal size is larger than a zoomed window and than the screen at any scale above 100%.
  • The screen size is the video mode divided by the content scale. GLFW 3.4 reports as the content scale the integer scale of the output, the scale rounded up (2 for 125%-200%, 3 for 250% and 300%, 4 for 350%), so at a fractional scale winfo screenwidth is smaller than a zoomed window.
  • The virtual root size is the video mode, not divided at all.

The same happens in headless KWin, sway and GNOME Shell with a 2560x1600 output:

scale            content scale  wm maxsize   screen     vroot      zoomed
1                1              2560 1552    2560x1600  2560x1600  2560x1564
1.25 (KWin)      2              2560 1552    1280x800   2560x1600  2048x1243
1.5  (KWin)      2              2560 1552    1280x800   2560x1600  1707x1031
2    (KWin)      2              2560 1552    1280x800   2560x1600  1280x764
2.5  (KWin)      3              2560 1552    853x533    2560x1600  1024x604
3    (KWin)      3              2560 1552    853x533    2560x1600  853x497
3.5  (KWin)      4              2560 1552    640x400    2560x1600  731x421

On X11 (Xwayland of headless KWin, scales 100% to 350%) all these sizes are in the same (physical) pixels, and the default maximal size is the size of a zoomed window.

GLFW does not give the logical size of a fractionally scaled output; it would need to be taken from somewhere else (e.g. xdg-output).

User Comments: kevin_walzer added on 2026-11-13 18:33:32:
I have pulled in the other updates you have made - sorry for missing them - and I am now back to zero failures. Thank you for being so thorough. I will close this ticket as fixed.

kevin_walzer added on 2026-11-13 18:12:56:
After merging trunk and then trying again with this branch, failures increase from two to four:

unixWm-6.3
unixWm-40.2
unixWm-41.4
wm-minsize-2.4

I don't see the failures this test is intended to correct, but I was not seeing them before, either. I am not comfortable accepting this patch given the regressions I am seeing.

serhiy.storchaka added on 2026-11-13 18:02:40:

unixWm-6.3 is not caused by this branch, but by my fix for [88dcdc8f96]; see the comment there.

unixWm-40.2 fails if the natural width of the listbox (40 characters) is less than the minimal width of a window with client-side decorations (TK_WAYLAND_CSD_MIN_WIDTH, 180 pixels): the window is then made 180 pixels wide, e.g. 44x20 grid units instead of 40x20. This branch computes tk scaling from the real size of the screen, so the fonts can become smaller than before. It fails in the same way without this branch with tk scaling 0.6. The test is fixed in branch unixWm-40.2-wider-listbox (based on main).


kevin_walzer added on 2026-11-13 16:28:06:
Thank you, Serhiy. I was working on a similar patch but you beat me to it.

Merging this appears to cause a regression on my system. Running the test suite before, there are no failures. After applying this branch, I see the following failures:

unixWm-6.3
unixWm-40.2

I'm reluctant to bring these back. Any insight here? I am on Debian 13, Gnome Shell.

serhiy.storchaka added on 2026-11-13 15:21:32:

Proposed fix in branch wayland-logical-screen-size: the screen size is taken in logical pixels, the units of the window sizes, from the xdg-output protocol (supported by KWin, GNOME Shell and sway). GLFW does not give it. As on X11, winfo screenwidth/screenheight, winfo vroot* and the default wm maxsize cover all outputs, which can have different scales. tk scaling is computed for the largest output.

On KWin on a real screen with the scale 150%:

                 before        after
wm maxsize       2560 1552     1707 1019
winfo screen     1280x800      1707x1067
winfo vroot      2560x1600     1707x1067
tk scaling       1.164         1.552

With it, wm-maxsize-1.7 and wm-maxsize-2.6 pass at all tested scales (1 to 2.5) in headless KWin, GNOME Shell and sway, and on KWin on a real screen. With two outputs with different scales, the sizes are the same as for X11 Tk under the same compositor (checked in sway).

wm-maxsize-2.7 still fails on KWin on a real screen: Wayland clients do not know the work area, and the allowance for the panel (48 pixels) is smaller than the real panel and title bar (72 pixels).