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
Thomas Fjellstrom
Member #476
June 2000
avatar

Thats entirely up to the window manager, at least if the user didn't force the position.

--
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

Yes, but if we add a function to return the primary monitor, should it be the one where the WM would run the app?

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

Thomas Fjellstrom
Member #476
June 2000
avatar

Elias said:

Yes, but if we add a function to return the primary monitor, should it be the one where the WM would run the app?

I guess it depends if we mean "primary" or "active". If its primary, it aught to be the actual primary monitor, the one at 0x0.

--
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

I guess it depends if we mean "primary" or "active". If its primary, it aught to be the actual primary monitor, the one at 0x0.

I think we should avoid the use of the name "primary". For one thing, if that's really what the user wants, he/she could just select the first screen (afterall, that's what "primary" means) and be done with it. This is already the current behaviour on OS X (since screen 0 is always the one with the Dock and the menu bar, which starts at 0,0) and, as I understand it, Linux.
What we would need then is a function that tells the user what the "active" or "default" display is where the OS will show a window, which is what [NSScreen mainScreen] returns on OS X.

For the sake of clarity I think we should maybe avoid the use of "primary" to refer to anything other than the first display (for which we don't need a function to tell us what it is, since it's the first one). It seems to me that this is mainly a Windows problem, where the first display is the one that is "on the left" rather than the one containing the taskbar (in other words, different operating systems mean different things by "primary display"). In which case, perhaps we need to have the following:

  • A function to get the "active" (current, default, whatever) screen, which is where the window will appear unless we explicitly tell it to go elsewhere. Not sure how easy it is to get that on X11, but maybe this could just be a "magic" identifier of -1 to say "we don't care".

  • A function to get the screen that has the taskbar (dock) on it. On OS X, this is just the first screen (index 0). No idea on how to get this information on X11 though.

With those two functions, I think we have all we need. I don't think we should force our own ordering on screens (for instance, force "0" to be the display containing the taskbar (dock) on every operating system, since I see that become messy and confusing in the future) beside that: whether screen "0" is "the one on the left" or "the one that contains the taskbar" depends on the platform.

Thomas Fjellstrom
Member #476
June 2000
avatar

Evert said:

What we would need then is a function that tells the user what the "active" or "default" display is where the OS will show a window, which is what [NSScreen mainScreen] returns on OS X.

Except that changes when the user moves their mouse, and I'm not sure X even has such a concept. It probably doesn't. AFAIK Its completely up to X WMs.

Quote:

No idea on how to get this information on X11 though.

Which taskbar? I can have many. Some WMs don't have any.

append:

Quote:

whether screen "0" is "the one on the left" or "the one that contains the taskbar" depends on the platform.

Indeed. X can have "the one that contains the taskbar" on the right or left. It can place secondary screens on either side of 0x0. And it all depends on how the user sets up their config.

--
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

Except that changes when the user moves their mouse,

No. It changes when the user changes the key window. In other words, it's the screen that the currently active window is on. The location of the mouse has nothing to do with it (obviously, OS X doesn't have focus-follows-mouse, which I still find annoying). But in the current context, that's irrelevant: what matters is that it's the screen that the display will appear on if we go with the default.

Quote:

and I'm not sure X even has such a concept. It probably doesn't. AFAIK Its completely up to X WMs.

There is absolutely no way to ask where the window is going to show up if we don't specify anything?
In which case, we probably should go with a generic "-1" to indicate we don't care and "pick the default". We could still add a function that tells you what the "main" display is (the one with the taskbar on Windows, equivalent to the first one on OS X, probably equivalent to the first one on X11).

Quote:

Which taskbar? I can have many. Some WMs don't have any.

Sure. You probably understand what I meant though.

gnolam
Member #2,030
March 2002
avatar

Evert said:

It seems to me that this is mainly a Windows problem, where the first display is the one that is "on the left" rather than the one containing the taskbar

What?

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Thomas Fjellstrom
Member #476
June 2000
avatar

Evert said:

Sure. You probably understand what I meant though.

X doesn't though ;) The closest thing to a primary monitor is the one at 0x0, and the closest thing to a default is the one that contains a window that has focus.

I think in the end thats what the "default" monitor has to be at any given time. The monitor with a window on it that has focus.

--
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

Quote:

What?

See first post.
The complaint is that Allegro identifies the "first" screen as the one on the left rather than the one containing the taskbar. In OS X, the "first" screen would be the one with the dock and the menu bar on it (in other words, the one on the right in the picture) and the second one would be the one on the left.
It seems though (from Dennis' second post) that Windows does, in fact, put the origin of the coordinate system on the screen with the taskbar, as in OS X. It just doesn't report it as the "first" display.
Either way, it's a problem with the Windows port of Allegro, not a general problem.

The closest thing to a primary monitor is the one at 0x0, and the closest thing to a default is the one that contains a window that has focus.

That's exactly what it is on OS X. And, looking at the earlier discussion again, it seems that this is what it is in Windows as well.
So it seems we actually have a platform-neutral way of identifying different displays, it's just that Windows enumerates them in the "wrong" order.

Michał Cichoń
Member #11,736
March 2010

How about such results?

2 adapters found...
Main adapter is 0
Active adapter is 1
Adapter 0: (0, 0) - (1920, 1200)
   Available fullscreen display modes:
   Mode   0:  640 x  480, 60 Hz
   Mode   1:  720 x  480, 60 Hz
   ...
   Mode  25: 1920 x 1200, 60 Hz
Adapter 1: (1920, 0) - (3360, 900)
   Available fullscreen display modes:
   Mode   0: 1440 x  900, 60 Hz
   Mode   1: 1440 x  900, 75 Hz
   ...
   Mode  53: 1280 x 1024, 75 Hz

New functions:

int al_get_main_adapter(void);
int al_get_active_adapter(void);

First one return index of main adapter (one with task bar). Second one return active one. For example if you launch your application on second monitor then it will be considered as active. If active adapter couldn't be determined there is a fall back to main adapter.

During Allegro initialization active adapter is set as default adapter.

Edit:
I attached patch to this post. Please confirm me than Mac implementation is working and Linux version compile without problems. (Linux implementation isn't done, but I created stubs in mmon_interface).

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

Evert
Member #794
November 2000
avatar

First one return index of main adapter (one with task bar).

This would only ever be different from 0 only on Windows, as I understand it?

Quote:

If active adapter couldn't be determined there is a fall back to main adapter.

During Allegro initialization active adapter is set as default adapter.

Yes, although I still think we should allow a "magic value" of -1 when setting the current active adapter for those cases where you can't determine the "active" one and still want the OS to select whatever it thinks the default should be (which may be the case on X11).

EDIT: I can try if the OS X patch compiles later, but I don't have a second monitor to test it with.

Thomas Fjellstrom
Member #476
June 2000
avatar

Evert said:

This would only ever be different from 0 only on Windows, as I understand it?

No, the monitor at 0x0 can be listed at any point in the Xrandr output. I assume if you put a secondary to the left on OSX it might appear first in its output too.

--
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

Michał Cichoń
Member #11,736
March 2010

Evert said:

This would only ever be different from 0 only on Windows, as I understand it?

I don't know how other platforms will behave. I have linux on VM and still, there is only one monitor in there.
We have MacMinis and they have only one video output (unless I didn't spot HDMI yet). So I may try to confirm that on Thursday.

Evert said:

Yes, although I still think we should allow a "magic value" of -1 when setting the current active adapter for those cases where you can't determine the "active" one and still want the OS to select whatever it thinks the default should be (which may be the case on X11).

This will alter display initialization code. I can do that for Windows and this is relatively simple thing to do. Other platforms are... hm... sill mysterious to me. :)

This feature doesn't collide with patch, so may be considered separately.
I think first we should run some test to confirm results are satisfactory. If not we will back to -1 idea.

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

Matthew Leverton
Supreme Loser
January 1999
avatar

Evert said:

It seems to me that this is mainly a Windows problem, where the first display is the one that is "on the left" rather than the one containing the taskbar

I cannot speak for how Allegro works with the Windows API, but Windows treats the primary display as the one marked as "Use this device as the primary monitor." It doesn't matter which is to the left or right or up or down or has the task bar, etc.

Evert
Member #794
November 2000
avatar

I assume if you put a secondary to the left on OSX it might appear first in its output too.

No. That's the point I was making:

Quote:

screens

Returns an array of NSScreen objects representing all of the screens available on the system.
+ (NSArray *)screens
Return Value

An array of the NSScreen objects available on the current system or nil if the screen information could not be obtained from the window system.
Discussion

The screen at index 0 in the returned array corresponds to the primary screen of the user’s system. This is the screen that contains the menu bar and whose origin is at the point (0, 0). In the case of mirroring, the first screen is the largest drawable display; if all screens are the same size, it is the screen with the highest pixel depth. This primary screen may not be the same as the one returned by the mainScreen method, which returns the screen with the active window.

The array should not be cached. Screens can be added, removed, or dynamically reconfigured at any time. When the display configuration is changed, the default notification center sends a NSApplicationDidChangeScreenParametersNotification notification.

Michał Cichoń
Member #11,736
March 2010

I implemented OSX function according to this documentation.

The question is, what about NSApplicationDidChangeScreenParametersNotification? Maybe Allegro should notify user about changing display layout? There is also similar message generated by Windows.

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

Evert
Member #794
November 2000
avatar

Maybe Allegro should notify user about changing display layout?

Maybe. We have an event for when the orientation of the display changes (only on the iOS port, I think).
Querying the status of different adapters after things change should work properly though (since we indeed don't cache the results).

I think that's a separate issue though, and also one that we don't necessarily need to fix for 5.0 (since we can easily add event types afterwards).

EDIT:
I finally had time to look at the patch. On OS X, it's not going to work; [NSScreen mainScreen] returns an NSScreen, not the index in the screens array corresponding to the currently active display, which is what the function should return.
I still think there needs to be a magic "-1" to indicate that "we don't care" and let the OS pick whatever it thinks the default screen should be, rather than explicitly asking for the default and setting that. This to accomodate situations where that information is not readily available.

Michał Cichoń
Member #11,736
March 2010

OK. I added that magic "-1" value to my TODO list.

I will try to fix OSX version tomorrow.

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

 1   2 


Go to: