Detecting wx window locations on a system with multiple monitors

840 views
Skip to first unread message

cappy2112

unread,
Aug 24, 2010, 7:30:17 PM8/24/10
to wxPython-users
On a Windows XP system ...

Does anyone know of a way to
1. Detect when a system has multiple monitors?
2. Detect when wx windows are displayed on the "other" monitor(s) ?


I've written a program which allows the user to create many stand
alone windows (TLW?).

When I run the program I usually drag those windows to my secondary
monitor. I'm trying to implement a way to restore these windows on
the other monitor.

The program needs to be able to detect this first.

Robin Dunn

unread,
Aug 24, 2010, 10:03:57 PM8/24/10
to wxpytho...@googlegroups.com


See wx.Display.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Andrea Gavana

unread,
Aug 25, 2010, 2:16:59 AM8/25/10
to wxpytho...@googlegroups.com

See also my PerspectiveControls library to save/restore TLW positions,
size, etc...:

http://xoomer.virgilio.it/infinity77/main/PersistentControls.html


Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever.
http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <==

Ray Pasco

unread,
Aug 25, 2010, 12:01:57 PM8/25/10
to Wxpython Users
You didn't mention which physical hardware configuration you have. There are 2 possibilities:

1. The "Extended Desktop" in which the right half of the single double-wide MSW Desktop is displayed on a second physical monitor. This is simply treated as a single extra-wide display. If your primary monitor's horizontal screen size is, for example, 1280, then any wx.Window's horz position over 1280 has to be on the second monitor.

2. There are multiple physical display adapters/cards on your PC's motherboard which display on separate physical monitors.

I am assuming that you are using configuration #2.  I can't locate a "Place-this control-on-this-video-adapter-screen" function in wxDisplay or wx.Display.  If you already can do this why can't you save the display number associated with the control for later use ?

Please share this technique with all of us.

Ray

cappy2112

unread,
Aug 25, 2010, 12:46:11 PM8/25/10
to wxPython-users


>> 2. There are multiple physical display adapters/cardson your PC's motherboard which display on separate physical monitors.
This is the one I'm using

> I am assuming that you are using configuration #2.  I can't locate a "Place-this control-on-this-video-adapter-screen" function in wxDisplay or wx.Display.  If you already can do >>this why can't you save the display number associated with the control for later use ?
This is an attribute I'm not familiar with.



Robin Dunn

unread,
Aug 25, 2010, 12:54:06 PM8/25/10
to wxpytho...@googlegroups.com
On 8/25/10 9:01 AM, Ray Pasco wrote:
> You didn't mention which physical hardware configuration you have.
> There are 2 possibilities:
>
> 1. The "Extended Desktop" in which the right half of the single
> double-wide MSW Desktop is displayed on a second physical monitor. This
> is simply treated as a single extra-wide display. If your primary
> monitor's horizontal screen size is, for example, 1280, then any
> wx.Window's horz position over 1280 has to be on the second monitor.
>
> 2. There are *multiple physical display adapters/cards* on your PC's

> motherboard which display on separate physical monitors.

In almost all cases I know of the OS still maps multiple video cards to
the extended desktop metaphor.

>
> I am assuming that you are using configuration #2. I can't locate a

> "*Place-this control-on-this-video-adapter-screen*" function in


> wxDisplay or wx.Display. If you already can do this why can't you save
> the display number associated with the control for later use ?
>

> *Please share this technique with all of us.*

wx.Display gives you all the information you need. You can get the
number of displays and the geometry and client area of each of them.
You can also get the display number that a particular window is
positioned on. To place a window on a specific display you simply get
that display's geometry and position the window within that rectangle.

>>> import wx
>>> for idx in range(wx.Display.GetCount()):
... d = wx.Display(idx)
... print d.IsPrimary(), d.GetGeometry()
...
True (0, 0, 1920, 1200)
False (-1600, 0, 1600, 1200)
>>>

As you can see from the above, I have a 1920x1200 display located at the
virtual (0,0) that is my primary display (where the OSX Dock and menubar
are located) and a 1600x1200 display positioned on the left of the
primary (indicated by the negative x position).

Ray Pasco

unread,
Aug 25, 2010, 8:41:19 PM8/25/10
to Wxpython Users
Thanks.  "Extended Desktop" is an official Microsoft term for XP. 

Many video cards have 2 blocks of display memory in which the second block can be configured by hardware control registers as a duplicated output of the primary screen and on the 2nd physical video jack on the same video adapter card. This is done for duplicate-monitor group presentations. Alternately, the video adapter can output a single double-wide screen duplicated on both video jacks typically to produce a double-wide screen split across 2 separate monitors for development workstation use.

MS XP allows the second display of the Extended Desktop (TM) to have a different geometry than the other(s) on the same video adapter.

So, are you saying that all OS's (that you know) map all the different-geometry adapters screens into a single, possibly huge "virtual" screen ?  Or, at least, does WX do this virtualization work to make the separate physical adapter screens that the OS reports to WX and combine it into a single huge virtual screen ?

I think you know now why I am confused.  It was confusing just to ask these questions.

And, on top of this screen coordinate virtualization process, your WX/OSX system reports a negative (!) primary-screen offset. How does it know that this monitor is located on the left side of the primary monitor ???  I.e., what is the meaning/purpose of negative offset values ?

Ray

Robin Dunn

unread,
Aug 25, 2010, 9:05:57 PM8/25/10
to wxpytho...@googlegroups.com
On 8/25/10 5:41 PM, Ray Pasco wrote:
> So, are you saying that all OS's (that you know) map all the
> different-geometry adapters screens into a single, possibly huge
> "virtual" screen ? Or, at least, does WX do this virtualization work to
> make the separate physical adapter screens that the OS reports to WX and
> combine it into a single huge virtual screen ?

Yes, although it can of course be more complicated than that... For
probably 98% of the use cases however it boils down to one of two scenarios:

* One (possibly virtual) desktop, spread across N screens where N >= 1
* One (possibly virtual) desktop that is mirrored between two sets of N
screens.

We don't have to worry about display mirroring, because as far as the
applications are concerned there is only one desktop. So all we really
need to be concerned with is that the valid screen real estate may be
split into more than one screen. If it matters to your app you may want
to do things like ensure that the position and size of your frame that
was saved the last time it was run are still a valid position and size,
and adjust it if not. Or if you want to explicitly take advantage of
multiple screens you may just move your frames to each screen
programatically.

BTW, the other 2% of situations that come to mind are things like
applications that take advantage of the client/server nature of
X-Windows and open the display of some other machine or X-server (IOW,
an independent desktop) and explicitly put windows there.

>
> I think you know now why I am confused. It was confusing just to ask
> these questions.
>
> And, on top of this screen coordinate virtualization process, your

> WX/OSX system reports a _negative_ (!) primary-screen offset. How does
> it know that this monitor is _located on the left side_ of the primary


> monitor ??? I.e., what is the meaning/purpose of negative offset values ?
>


My primary display is the first one listed, and its upper-left
coordinate is (0,0) (position a in the diagram). Since I've told the OS
that my secondary monitor is positioned to the left of my primary then
its upper-left point is (-1600, 0) (position b in the diagram). If I
had told the OS that it was positioned above my primary then it would be
(0, -1200). This way when the mouse is on the left edge of my primary
screen, and I move it 1 pixel to the left, it then appears to be on the
right edge of the secondary screen and will be located at point (-1, y).


+---------------+----------------------+
|b |a |
| | |
| | |
| | |
| | |
+---------------+----------------------+

WinCrazy

unread,
Aug 26, 2010, 11:18:59 AM8/26/10
to wxPython-users
Thanks, Robin. I suspected that negative coordinates was non-MSW.
That's a nice OS feature, though. cappy2112 said he was developing on
XP. I haven't looked, but I would guess that all >=NT MSW platforms
use the same positive-only coordinate system.

Ray
Reply all
Reply to author
Forward
0 new messages