Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [4.9.23] Windows7, MultiMonitor, Display is created on the wrong screen

This thread is locked; no one can reply to it. rss feed Print
 1   2 
[4.9.23] Windows7, MultiMonitor, Display is created on the wrong screen
Dennis
Member #1,090
July 2003
avatar

EDIT: DO NOT BOTHER READING THIS THREAD. THE ISSUE IS ALREADY FIXED IN THE LATEST SVN REVISION.

{"name":"602361","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/b\/1bf7917daae0f76487527aec963c23d7.png","w":686,"h":287,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/b\/1bf7917daae0f76487527aec963c23d7"}602361

I run a two screen system with Windows 7. The screens are arranged as seen in the image above. Pressing "identify" in the hardware configuration gives the numbers seen in the upper left corners.

However, the second screen is configured as the "primary screen" and all applications open their windows on that screen, except for the ones using Allegro. They always open the display (via al_create_display) on the wrong (1 but not primary) screen.

Thomas Fjellstrom
Member #476
June 2000
avatar

The code should be letting windows do the positioning (As long as you aren't trying to force it yourself), but I didn't write that code so I don't know for sure.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Elias
Member #358
May 2000

Looks like a bug to me. And rather annoying as well, I hate it when in X11 programs think they are smarter than the window manager. And the same seems to happen here under Windows. If nobody shows up who knows how to fix it right now, can you enter it to the bug tracker? Then it won't be forgotten to fix it.

--
"Either help out or stop whining" - Evert

Dennis
Member #1,090
July 2003
avatar

Done.

append (found some more information while debugging it)
It seems as though windows is treating the entire area as one virtual screen space into which it positions the monitors.

The origin (0,0) of the virtual screen space seems to be mapped to the upper left corner of the primary display.

That way, my secondary displays(first adapter but not primary display) upper left corner ends up being at (-1280, 0).

To fix that, the system initialization code (I couldn't find it yet) would have to set the default display adapter for new displays (currently 0) to the adapter which reports (0,0) as the upper left corner in "win_get_monitor_info".

screenshot to illustrate the issue (ignore the green comments in the code, that was just a lazy fix (which works to open the window on the primary display but doesn't center the new window)):
{"name":"602362","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/a\/2a822c6d71b8c6f5bbbdccdaffb31bbc.png","w":1310,"h":844,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/a\/2a822c6d71b8c6f5bbbdccdaffb31bbc"}602362

append 2:
Ok, I've created a patch which seems to fix the issue on my system (see attachment). http://www.allegro.cc/files/attachment/602363 (is a unified diff file)

wonsungi
Member #11,799
March 2010
avatar

I was able to reproduce Dennis' bug, and I confirm his patch works on my system.

On a related note, how can you force an Allegro program to open in the active monitor? For example, if the folder containing the Allegro exe is on monitor 2, the Allegro program opens on monitor 2; if on monitor 1, the Allegro program also opens on monitor 1.

Picasa Photo viewer works like this. It is very handy to select which monitor a full screen application will open in by first moving the containing folder to that monitor.

Thomas Fjellstrom
Member #476
June 2000
avatar

edit: nevermind. I misread.

I don't think theres a way to get the "active" monitor. If allegro isn't already doing that it may be a bug.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Arthur Kalliokoski
Second in Command
February 2005
avatar

I don't think theres a way to get the "active" monitor.

Active monitor? You mean the monitor that's displaying the program that has current focus?

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

Active monitor? You mean the monitor that's displaying the program that has current focus?

That or the one with the mouse. Either way, I don't know if allegro has a way to give you that info at the moment.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Evert
Member #794
November 2000
avatar

So what happens if we don't specify any display at all and just let the OS pick what it thinks is the best display for the window to pop-up? Does that do what's expected?

And yes... that will possibly not be compatible with the solution to the problem that the OP posted in this thread.
For what it's worth, I don't think the OS X port lets you decide to pop up on the "current" display either, but I hardly ever do multi-display stuff with that (not having a second display doesn't help there).

Arthur Kalliokoski
Second in Command
February 2005
avatar

I think a nice touch would be that if an Allegro program is started from a console, then the graphical window would open on the other monitor. It's a pain switching back and forth to view the windows in their entirety if they have any size to them.

They all watch too much MSNBC... they get ideas.

Dennis
Member #1,090
July 2003
avatar

Just posting to tell that this issue is fixed. The patch has already been applied to the SVN and Trent fixed it up further so it's still possible to override the default display adapter manually.

If the display adapter is set to -1 (or not at all) now, Windows will always open the window centered on the primary display (regardless of it's display adapter index number).

Chris Katko
Member #1,881
January 2002
avatar

How long would this take to apply to a pre-compiled version of Allegro 5? I use the pre-compiled version and just realized this affects me now (I just got a second monitor).

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Trent Gamblin
Member #261
April 2000
avatar

The patch Dennis posted is kind of... incomplete and wrong. What actually got committed to svn is different. So you'd be better of just starting from SVN IMO. It's no buggier than the latest release (If anything, it's better).

Michał Cichoń
Member #11,736
March 2010

For me the reason of such behavior (see first Denis post) lie in the implementation of monitor enumeration.

Brief look at the implementation...

Ok, there is a problem. Simple example: three attached monitors 1, 2 and 3. Second is turned off.

al_get_num_video_adapters() returns 2. al_get_monitor_info(0) return info for 1. al_get_monitor_info(1) return info for 2. al_get_monitor_info(2) return info for 3.

I will run some tests on multi-monitor machine to make sure what results using EnumDisplayDevices() I got.

Edit:
Implementation assume that one adapter can handle one monitor, which is not true.

Edit2:
Maybe we could use EnumDisplayMonitors() instead of EnumDisplayDevices(). In result we got information about region of activity and primary flag.

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Trent Gamblin
Member #261
April 2000
avatar

Do you have a use case right now where it's broken? Cause if it ain't broke...

Michał Cichoń
Member #11,736
March 2010

A little investigation.

I did trough following steps:
- switch with dual-display, report
- switch to 'show only on first', report
- switch to 'show only on second', report
- switch to extended, report

Four session has been found.

Conclusions:
- for dual-display EnumDisplayDevices() return more than one monitor
- for dual-display EnumDisplayDevices() will return adapter without monitor
- inactive monitors may be attached to many devices (I guess this is because internal state is not updated until monitor is being activated)
- active monitor is attached to only one device
- primary monitor is not the first one (but may be)
- EnumDisplayMonitors() give what we want, without bothering about details
- GetSystemMetrics() give correct result - number of active monitors (it is simpler than using EnumDisplayDevices())

I propose to switch the implementation into pair GetSystemMetrics()/EnumDisplayMonitors(). Also al_get_primary_adapter() should be added, because adapter with zero index doesn't have to be primary one.



  --- SESSION ---



-- GetSystemMetrics --

Monitors:   1                                   


-- EnumDisplayDevices --

Monitors:   1                                    Attached to desktop

Monitors:   5                                    All


-- EnumDisplayDevices --

Device:     \\.\DISPLAY1                         NVIDIA GeForce 8600M GT  
  Rect:     (0, 0), (1920, 1080)
  State:    Attached to Desktop, Primary Device
  Monitor:  \\.\DISPLAY1\Monitor0                Generic PnP Monitor
    State:  Active, Attached

  Monitor:  \\.\DISPLAY1\Monitor1                Generic PnP Monitor
    State:  Active, Attached

Device:     \\.\DISPLAY2                         NVIDIA GeForce 8600M GT  
  State:    <empty>

Device:     \\.\DISPLAYV1                        RDPDD Chained DD
  State:    Mirroring Driver

Device:     \\.\DISPLAYV2                        RDP Encoder Mirror Driver
  State:    Mirroring Driver, TS Compatible

Device:     \\.\DISPLAYV3                        RDP Reflector Display Driver
  State:    Mirroring Driver, TS Compatible


-- EnumDisplayMonitors --

Monitor:    \\.\DISPLAY1                        
  Rect:     (0, 0), (1920, 1080)
  State:    Primary



  --- SESSION ---



-- GetSystemMetrics --

Monitors:   1                                   


-- EnumDisplayDevices --

Monitors:   1                                    Attached to desktop

Monitors:   5                                    All


-- EnumDisplayDevices --

Device:     \\.\DISPLAY1                         NVIDIA GeForce 8600M GT  
  Rect:     (0, 0), (1920, 1200)
  State:    Attached to Desktop, Primary Device
  Monitor:  \\.\DISPLAY1\Monitor0                Generic PnP Monitor
    State:  Active, Attached

Device:     \\.\DISPLAY2                         NVIDIA GeForce 8600M GT  
  State:    <empty>
  Monitor:  \\.\DISPLAY2\Monitor0                Generic PnP Monitor
    State:  Attached

Device:     \\.\DISPLAYV1                        RDPDD Chained DD
  State:    Mirroring Driver

Device:     \\.\DISPLAYV2                        RDP Encoder Mirror Driver
  State:    Mirroring Driver, TS Compatible

Device:     \\.\DISPLAYV3                        RDP Reflector Display Driver
  State:    Mirroring Driver, TS Compatible


-- EnumDisplayMonitors --

Monitor:    \\.\DISPLAY1                        
  Rect:     (0, 0), (1920, 1200)
  State:    Primary



  --- SESSION ---



-- GetSystemMetrics --

Monitors:   1                                   


-- EnumDisplayDevices --

Monitors:   1                                    Attached to desktop

Monitors:   5                                    All


-- EnumDisplayDevices --

Device:     \\.\DISPLAY1                         NVIDIA GeForce 8600M GT  
  Rect:     (0, 0), (1920, 1080)
  State:    Attached to Desktop, Primary Device
  Monitor:  \\.\DISPLAY1\Monitor0                Generic PnP Monitor
    State:  Active, Attached

  Monitor:  \\.\DISPLAY1\Monitor1                Generic PnP Monitor
    State:  Attached

Device:     \\.\DISPLAY2                         NVIDIA GeForce 8600M GT  
  State:    <empty>
  Monitor:  \\.\DISPLAY2\Monitor0                Generic PnP Monitor
    State:  Attached

Device:     \\.\DISPLAYV1                        RDPDD Chained DD
  State:    Mirroring Driver

Device:     \\.\DISPLAYV2                        RDP Encoder Mirror Driver
  State:    Mirroring Driver, TS Compatible

Device:     \\.\DISPLAYV3                        RDP Reflector Display Driver
  State:    Mirroring Driver, TS Compatible


-- EnumDisplayMonitors --

Monitor:    \\.\DISPLAY1                        
  Rect:     (0, 0), (1920, 1080)
  State:    Primary



  --- SESSION ---



-- GetSystemMetrics --

Monitors:   2                                   


-- EnumDisplayDevices --

Monitors:   2                                    Attached to desktop

Monitors:   5                                    All


-- EnumDisplayDevices --

Device:     \\.\DISPLAY1                         NVIDIA GeForce 8600M GT  
  Rect:     (-1920, 0), (0, 1200)
  State:    Attached to Desktop
  Monitor:  \\.\DISPLAY1\Monitor0                Generic PnP Monitor
    State:  Active, Attached

Device:     \\.\DISPLAY2                         NVIDIA GeForce 8600M GT  
  Rect:     (0, 0), (1920, 1080)
  State:    Attached to Desktop, Primary Device
  Monitor:  \\.\DISPLAY2\Monitor0                Generic PnP Monitor
    State:  Active, Attached

Device:     \\.\DISPLAYV1                        RDPDD Chained DD
  State:    Mirroring Driver

Device:     \\.\DISPLAYV2                        RDP Encoder Mirror Driver
  State:    Mirroring Driver, TS Compatible

Device:     \\.\DISPLAYV3                        RDP Reflector Display Driver
  State:    Mirroring Driver, TS Compatible


-- EnumDisplayMonitors --

Monitor:    \\.\DISPLAY1                        
  Rect:     (-1920, 0), (0, 1200)
  State:    <empty>

Monitor:    \\.\DISPLAY2                        
  Rect:     (0, 0), (1920, 1080)
  State:    Primary

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Trent Gamblin
Member #261
April 2000
avatar

Conclusions:
- for dual-display EnumDisplayDevices() return more than one monitor
- for dual-display EnumDisplayDevices() will return adapter without monitor
- inactive monitors may be attached to many devices (I guess this is because internal state is not updated until monitor is being activated)
- active monitor is attached to only one device
- primary monitor is not the first one (but may be)
- EnumDisplayMonitors() give what we want, without bothering about details
- GetSystemMetrics() give correct result - number of active monitors (it is simpler than using EnumDisplayDevices())

I propose to switch the implementation into pair GetSystemMetrics()/EnumDisplayMonitors(). Also al_get_primary_adapter() should be added, because adapter with zero index doesn't have to be primary one.

Ok. Can you open a bug on Sourceforge? And since you already have some code, attach it there? Unless you plan on fixing it yourself. Also I think the new function is a good idea too.

EDIT:

What about the initial value for the current adapter? I assume that can be found without installing a display driver, on all platforms, rather than using 0?

Michał Cichoń
Member #11,736
March 2010

I can prepare a patch, which address those issues.

Primary adapter can be detected without initializing display driver. This is simple result of monitor enumeration. That's true for Windows. Mac OS should handle this easily and Linux... Who knows, there is X11 under the hood.

I will put xxx_get_primary_adapter in system driver vtable.

Committing changes is an another issue, due to feature freeze. I will probably release a patch and unofficial build with it.

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Evert
Member #794
November 2000
avatar

Mac OS should handle this easily

You mean the first element returned by [NSScreen screens]? Currently, I think, the default is the return value of [NSScreen mainScreen], which gives you the one that "the user currently interacts with".
Is it clear (and is there consensus) on what the correct behaviour is?

Thomas Fjellstrom
Member #476
June 2000
avatar

Primary for OSX would be which ever monitor the dock and menu are both on.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Evert
Member #794
November 2000
avatar

Primary for OSX would be which ever monitor the dock and menu are both on.

Ok, that's the first entry that's returned by [NSScreen screens] (which makes sense, for "primary" to be "the first"). In other words, it's always the first screen reported.
But going back to using [NSScreen mainScreen], I guess it's been discussed in a previous thread here, but what should the initially default screen be? Should it be "the first display", or should it be "the currently active display"? On OS X right now it's the latter, which I think makes sense, but does that make sense to everyone and is it consistent across platforms (in particular, Windows)? Or do users expect different default behaviour on different platforms?

Thomas Fjellstrom
Member #476
June 2000
avatar

I think you probably want an app to launch on the "currently active" screen. At least I generally do. If I start an app while on my secondary screen, I tend to want it to pop up there since thats where I have my focus.

But I think the only way to start an app on a secondary screen on osx is with some kind of icon or bundle on the desktop.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Evert
Member #794
November 2000
avatar

But I think the only way to start an app on a secondary screen on osx is with some kind of icon or bundle on the desktop.

I don't think so. Finder or commandline should do as well.

Thomas Fjellstrom
Member #476
June 2000
avatar

Evert said:

I don't think so. Finder or commandline should do as well.

Ah, ok. I suppose that'd work too. Wasn't thinking.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Elias
Member #358
May 2000

In X11 an app by default is started on the same monitor i start it from. I.e. if I type "./my_game" into a console and that console is on the right monitor, that's where the window is created. That is, that's how it worked under Ubuntu 10.04 with NVidia's TwinView - only setup I tried multiple monitors on.

--
"Either help out or stop whining" - Evert

 1   2 


Go to: