Tk Source Code

View Ticket
Login
Ticket UUID: 3141377
Title: [winfo screenwidth/height] fail to track resolution changes
Type: Bug Version: 8.6.1
Submitter: teopetuk Created on: 2010-12-21 19:09:06
Subsystem: 65. Generic Window Operations Assigned To: nobody
Priority: 6 Severity: Minor
Status: Open Last Modified: 2026-11-15 19:45:28
Resolution: None Closed By: nobody
    Closed on:
Description:
Hi!

After I change a screen resolution on my Debian GNU/Linux system (by xrandr, e.g. xrandr -s 800x600) [winfo screenwidth .] and [winfo screenheight .] are still reporting the old width and height values.

I've tried 8.4.19 and 8.5.9 (didn't 8.6 or HEAD though).
User Comments: serhiy.storchaka added on 2026-11-15 19:45:28:

On X11 the window system does not enforce such a limit: on KDE Plasma with two monitors, I could resize a Tk window to be wider than both monitors together. So neither the width of a monitor nor the width of the screen is the maximal width of a window; only the default wm maxsize is.

A window can also stay across two monitors, not only while it is being moved. Then "the monitor containing the window" is not well defined: it could be the monitor with the larger part of the window, or the one with its top left corner or with the pointer, and the result changes when the window is moved a little.

I would keep winfo screenwidth as the width of the screen (all monitors on X11 with XRandR, on Windows and on macOS it differs already), for compatibility. Information about the monitors (geometry, work area, which monitor a window is on) would be better provided by a new command than by changing the meaning of winfo screenwidth.


marc_culler (claiming to be Marc Culler) added on 2026-11-15 16:39:51:
Thanks for telling me about that setting.  Presumably the value of that
setting should be considered when computing the maximum width of a
window.

chrstphrchvz added on 2026-11-15 05:20:18:

If a macOS window extends outside of its monitor it is truncated at the edge of the monitor except when it is being moved. When it is being moved the part of it which falls inside the rectangle of another monitor becomes visible.

This is only the case when "Displays have separate Spaces" is turned on in the Settings app. If that setting is turned off, then windows can always visibly span multiple displays. That setting seems to be turned on by default nowadays, however.


marc_culler (claiming to be Marc Culler) added on 2026-11-15 03:34:27:
I think there should be a discussion about what [winfo screenwidth $w]
should be when there are multiple monitors.  One logical proposal might
be that it is the width of the monitor on which the window is displayed.

The manual says:
winfo screenwidth window
    Returns a decimal string giving the width of window's screen, in pixels. 

That is presumably referring to the traditional X11 setup where each
monitor is a separate screen.  But the XrandR extension and macOS and
Windows all have a single screen and put all monitors into one coordinate
system.  And of course they all disagree about that coordinate system.
Does increasing y move up or down? Is the origin in the main monitor or
at the upper left corner of the bounding box of all monitors?

There are built-in false assumptions about how screenwidth relates
to window width. One of those is the assumption that a window cannot
be wider than its screenwidth, which could be enforced by Tk with this
meaning of screenwidth, but is not necessarily enforced by the
windowing system.  On macOS the Tk test which verifies this condition
always fails with multiple monitors. It is possible to make a window
wider that the monitor containing it.  But maybe it shouldn't be. If
a macOS window extends outside of its monitor it is truncated at the
edge of the monitor except when it is being moved.  When it is being
moved the part of it which falls inside the rectangle of another
monitor becomes visible.

serhiy.storchaka added on 2026-11-13 16:05:16:

This also breaks menus after a monitor is added or the monitors are rearranged. TkpPostMenu() keeps a menu inside the virtual root, whose size is taken from the outdated DisplayWidth() and DisplayHeight(). So every menu posted to the right of the old screen width is moved left until its right edge is at the old width, and a menu wider than the space left of it is partially off its monitor; with monitors arranged vertically, the same happens with the Y coordinate. This affects cascades and tk_popup too.

Branch x11-randr-screen-size fixes this too, so, contrary to what I wrote above, it does help with multiple monitors.


serhiy.storchaka added on 2026-09-18 09:39:25:

Fixed on branch x11-randr-screen-size in [ae3b099be2]: Tk now selects RRScreenChangeNotify and updates the screen size recorded by Xlib with XRRUpdateConfiguration(). The millimeter size is scaled with it, so tk scaling does not change on a resolution change. Requires libXrandr at build time (--disable-xrandr to opt out); without it the old behaviour remains. Windows and macOS already track display changes. This does not touch multi-monitor support (the "multiscreens" branch, [c95d4691ff]).


fvogel added on 2017-12-15 07:11:01:

Same issue in another ticket, see [2524085333]


fvogel added on 2016-08-17 14:13:33:

See (stalled) attempt in [c95d4691ff] and commit [671c976f] in branch "multiscreens".


ChlorideCull added on 2013-11-21 11:31:08:
As for the related RandR extension specification among other things, see http://www.x.org/wiki/Projects/XRandR/

ChlorideCull (claiming to be Chloride Cull) added on 2013-11-21 11:23:30:
Still present in 8.6.1

dkf added on 2010-12-23 19:23:44:
Currently we're just returning the information out of the X11 Screen structure (on all versions; that part of the code has not changed since as long as there's been a [winfo] command). That's obviously become insufficient; pointers (URLs) for where to get the info when xrandr is present would be very helpful.

There's probably a bunch of other things that should be revised at the same time; whoever sorts this out needs to examine carefully what's involved.