Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get on MS Windows the monitor/screen the Tk window is on? And its usable dimensions?

102 views
Skip to first unread message

MartinLemburg@Siemens-PLM

unread,
Jul 13, 2016, 4:23:57 AM7/13/16
to
Hi,

is there a way on MS Windows, without using TWAPI to get the monitor/screen a Tk window is displayed on?

winfo screen .

returns always ":0.0", no matter on which monitor/screen the Tk window gets displayed.

And if the Tk window is on the monitor/screen with the taskbar, the usable area is limited, but how to get the "real" size of the monitor/screen.

In other words:

1. Why "winfo screen" does not return on MS Windows the current used monitor/screen?
2. Why "winfo screenwidth" and "winfo screenheight" does not return the usable width or height, but really the physical dimensions?

Best regards,

Martin

MartinLemburg@Siemens-PLM

unread,
Jul 13, 2016, 4:39:59 AM7/13/16
to
Here an example on how to get the usable area of the used monitor/screen with twapi:

package require twapi

lassign [dict get \
[twapi::get_display_monitor_info \
[twapi::get_display_monitor_from_window .] \
] \
-workarea \
] left top right bottom

set width [expr {$right - $left}]
set height [expr {$bottom - $top}]

Perhaps I simply should rely on twapi.

Brad Lanam

unread,
Jul 13, 2016, 11:02:30 AM7/13/16
to
On Wednesday, July 13, 2016 at 1:39:59 AM UTC-7, MartinLemburg@Siemens-PLM wrote:
> Am Mittwoch, 13. Juli 2016 10:23:57 UTC+2 schrieb MartinLemburg@Siemens-PLM:
> > Hi,
> >
> > is there a way on MS Windows, without using TWAPI to get the monitor/screen a Tk window is displayed on?
> [...]

It is a known bug. I believe there are fixes for it coming in 8.6.6.


Harald Oehlmann

unread,
Jul 13, 2016, 1:44:42 PM7/13/16
to
I did not recognized any bug fix here.

Mostly, one is using the second monitor to extend the screen.
Then, you may recognize that you are on a second screen, if the X/Y Pos
is outside of the physical but inside of the virtual screen (all within
winfo).

Hope this helps,
Harald

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

MartinLemburg@Siemens-PLM

unread,
Jul 13, 2016, 2:43:47 PM7/13/16
to
Hi Harald,

I would have thought of this two, but why asking for the screen width returns the display size no matter on which monitor the Tk window is?

% winfo screenwidth .
1920

If the desktop extending second monitor really wouldn't change the screen in Tk, than I'd expect a value twice as high.

Best regards,

Martin

Unknown

unread,
Jul 14, 2016, 12:42:59 PM7/14/16
to
Brad Lanam <brad....@gmail.com> Wrote in message:
Sorry, no. I started to tackle this issue:

https://core.tcl.tk/tk/tktview?name=c95d4691

But I simply gave up. Too many deep connections with legacy X11
things, and I could not manage to have a clear view of what is
obsolete and can be removed and what cannot.

See discussion on Tcl Core list, especially the last posts of this
tread:


http://code.activestate.com/lists/tcl-core/16069/

More advice welcome, best thing to have would be a TIP.

Regards,
François


----Android NewsGroup Reader----
http://usenet.sinaapp.com/

Harald Oehlmann

unread,
Jul 14, 2016, 2:16:17 PM7/14/16
to
Pleas look to the usage of vrootwidth etc. An example is in the dynhelp
code of bwidgets:

https://core.tcl.tk/bwidget/artifact/fe5b9d560cf3f3de

See function:
DynamicHelp::_show_help
which cares to place the dynamic help totally on the screen where the
item is.

MartinLemburg@Siemens-PLM

unread,
Jul 15, 2016, 5:48:46 AM7/15/16
to
Hi Harald,

thanks for your source code example!

I tried on my multi monitor system (2x 1920x1080, left with taskbar on the left vertical edge):
1. wish window on the first monitor, right side:
% winfo vrootx .
0
% winfo vrooty .
0
% winfo vrootwidth .
1920
% winfo vrootheight .
1080
% winfo rootx .
1029
% winfo rooty .
36
2. wish window on the second monitor, left side:
% winfo vrootx .
0
% winfo vrooty .
0
% winfo vrootwidth .
1920
% winfo vrootheight .
1080
% winfo rootx .
1925
% winfo rooty .
36

I'm not that firm with X-Server definitions, so what is the virtual root and what the root window?

The root seems to be the client area, right? The position of the root window makes me think of the client area. But why the root window cannot be queried for its width/height?
And the virtual root is?
How the screen is related to the root or virtual root window? Or is the screen only related to the window?

The far Tk is platform independent, in this area it seems to be a bit different.

MartinLemburg@Siemens-PLM

unread,
Jul 15, 2016, 5:59:24 AM7/15/16
to
Hi Harald,

the provided source code of DynamicHelp::show_help ensures that the window is completely on the screen. But the used width/height does not take Windows taskbar in account.
If a Tk window is positioned on the screen, than it may happen, that its position is outside the "work area" of the desktop.

BTW the position of a Tk window shows, that my second monitor only extends the desktop on the first monitor.
But the virtual root window is always in (0, 0)? And the screen width/height is always 1920x1080, even if I have only one "screen":

% winfo x .; # . on the left side of second monitor
1920
% winfo screen
:0.0
% winfo x .; # . on the left side of the first monitor aligned to the taskbar
128
% winfo screen
:0.0

I really have difficulties understanding the meaning of virtual root, root, screen.

Cheers,

Martin

Harald Oehlmann

unread,
Jul 15, 2016, 8:26:40 AM7/15/16
to
Am 15.07.2016 um 11:59 schrieb MartinLemburg@Siemens-PLM:
>>>>>>> is there a way on MS Windows, without using TWAPI to get the monitor/screen a Tk window is displayed on?
>> Pleas look to the usage of vrootwidth etc. An example is in the dynhelp
>> code of bwidgets:
>>
>> https://core.tcl.tk/bwidget/artifact/fe5b9d560cf3f3de
>>
>> See function:
>> DynamicHelp::_show_help
>> which cares to place the dynamic help totally on the screen where the
>> item is.
> BTW the position of a Tk window shows, that my second monitor only extends the desktop on the first monitor.

It is not Tk. It is your windows settings.
If you have two physical monitors (prim/sec), you can position them
within windows on a virtual screen over all of your physical monitors.

See the multi screen settings of your computer.

> But the virtual root window is always in (0, 0)?

No.
(0,0) on the virtual screen is the upper-left corner of your primary
physical screen.
If your second monitor is configured to be left of the primary monitor,
the vrootx gets negative.
If your second screens upper edge is above the primary screen, vrooty
gets negative.
Otherwise, it is 0,0

> And the screen width/height is always 1920x1080, even if I have only
one "screen":

This is the size of your primary screen. It is independent on any
secondary screen.

> % winfo x .; # . on the left side of second monitor
> 1920
> % winfo screen
> :0.0
> % winfo x .; # . on the left side of the first monitor aligned to the taskbar
> 128
> % winfo screen
> :0.0

Get away from the notion of "screen" if you use windows in virtual
screen mode. It is always ":0.0", for all monitors. Windows works with
one big virtual pane, where the monitors show you parts of it. There are
invisible parts and you can configure (in windows) that there is space
between the monitors.

Use coordinates, best returned by "wm geometry .".
0 new messages