Tk Source Code

View Ticket
Login
Ticket UUID: 2257424
Title: screenwidth incorrect on multiple monitors
Type: Bug Version: obsolete: 8.4.19
Submitter: dwsmithsyn Created on: 2008-11-10 19:39:31
Subsystem: 68. Win Window Operations Assigned To: jan.nijtmans
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2014-03-13 09:12:32
Resolution: Invalid Closed By: nijtmans
    Closed on: 2012-05-05 15:54:28
Description:
The winfo screenwidth . returns 1920 on Windows XP SP2 with dual monitors and the screen spread across both monitors (and the . in the second monitor) whereas winfo geom . returns 200x200+2717+546. The geometry is correct but the screenwidth is not. How do I get the correct screen width in this case. Windows handles this as a single screen (at least it appears to).
User Comments: dkf added on 2012-05-05 23:16:02:
The window manager's allowed to completely ignore whatever [wm geometry] requests. You're allowed to ask for the window to be completely off the screen. Net result, you can get yourself in a pickle if you're dumb about saving the geometry, and there's not that much Tk itself can do about it.

Code to keep a window on the screen after a reload would be a reasonable addition to tklib (if it isn't there already).

nijtmans added on 2012-05-05 22:54:28:
> I would have expected wm geometry to clamp somewhat
> what it gets as an input. Since this is not the case
> I guess I'll have to parse and process [wm geometry ]
> output for bounds to compare to [winfo vroot... ] values.

Well, I tried it (both on Cygwin and Windows) and the
[wm geometry] doesn't do any clamping. It would
be impossible, because windows are allowed to be
partly invisible, the window manager is not allowed
to make the window fully visible if that's not what
is requested.

Thanks for your use case, it makes the
situation clear. So, this issue can be closed now.

fvogelnew1 added on 2012-05-05 18:04:11:
Sorry, once more:

I understand your point.
 
My use case is related to saving in a preferences file the geometry (position and size) of a toplevel across sessions of the application. Implementation is currently pretty simple:

I save [wm geometry $w] in a file when leaving the app
I feed this value again in wm geometry when creating the toplevel on application launch.

When a monitor was removed in the meantime the exit and the startup of the app (because this is a laptop that got undocked and now has only its own monitor), and the toplevel was on the now missing monitor at the time the app exited, then on startup the toplevel will be mapped on the missing area, which is outside of the existing monitors area.

I would have expected wm geometry to clamp somewhat what it gets as an input.
Since this is not the case I guess I'll have to parse and process [wm geometry ] output for bounds to compare to [winfo vroot... ] values.

fvogelnew1 added on 2012-05-05 17:57:07:
I understand your point.

My use case is related to saving in a preferences file the geometry (position and size) of a toplevel across sessions of the application. Implementation is currently pretty simple: I save [winfo geometry $w] when leaving the app, and feed this value aga

nijtmans added on 2012-05-05 05:56:51:
With #533519 and #2768586 fixed, the remaining issue
is: what is a screen under Windows. I would argue
that where this issue handles a "screen", actually
the "vroot"  is meant. On Windows, the "screen"
is equal to the main monitor, the vroot is the total
area occupied by all monitors together.

This means, the solution is not in Tk, but in the
application: If you want to know the size of
the whole area, use [winfo vroot(width|height)]
The offset can be found by
[winfo vroot(x|y)].

I believe that Tk is fixed now, using the
[winfo vroot...] in stead of [winfo screen..]
functions where appropriate.