Getting display information before creating a window

I’m currently (with SDL 2.0.3) using SDL_CreateWindow to create a centered, borderless window with a predetermined resolution to create a “windowed fullscreen” mode. However, this requires one to know the display’s resolution in advance. I know I can get a window’s associated display’s resolution. What would be great is if I could know before creating a window what display it would be on. Is this possible? Or does the OS maybe handle that or something?

I had also thought of creating a window with SDL_WINDOW_FULLSCREEN_DESKTOP for a simple fullscreen window. However, I’d like to have a display number option so users can switch the display that the game window is on. Is there some way to specify a display to create a window on using SDL_CreateWindow?

Is this on Windows ? If so, you can use the standard API to grab display information (including list of monitors and what-not) before you create a window. Its not easy, but it is all there…

I think SDL_GetNumVideoDisplays and SDL_GetDisplayBounds should be usable before creating a window

They are, but is there a way to know which display my window will be created on before I create it?

I can see what displays there are, and their sizes and relative positions. So I can map all the displays out. But I would like to know which of the displays my window will be created on if I just do SDL_CreateWindow.

Also, if I create a window instead using the SDL_WINDOW_FULLSCREEN_DESKTOP flag, can I specify which display it should be created on? The only way to do that that I can guess is to specify a position that has the window’s center somewhere on the display I want it on. Would that work?

SDL does also provide some useful stuff for that too, which could also do what you want - and would be multi-platform.

You can use SDL_GetWindowDisplayIndex to get the index, (or SDL_GetDisplayName for the name), at which point you could iterate through the available displays to find out which one it is.

There doesn’t seem to be a way to force window creation on a specific display - someone queried it here : http://stackoverflow.com/questions/26238552/how-to-create-an-sdl2-window-on-the-current-display

Or rather - there doesn’t seem to be an easy/automatic way - you could do it by calculating the total widths for display - 1 and then horizontally position the window, but is a cumbersome process…

My engine runs on Windows, Linux, OS X, and Android. I’ve found the code for getting number of displays, number of display modes per display, etc. I’ve gone ahead and used that, but the one thing that would be nice is to know before calling SDL_CreateWindow which display the window will be created on.

Yes! Thank you. Last night I tried out the “give it a position on another display at creation time” thing and it does seem to work. It isn’t the prettiest, but it gets the job done!

So now I’ve got a display_number option that starts at -1. If it is greater than -1, I attempt to create the window on that display (after making sure it IS a valid display) using the “give SDL_CreateWindow a position on the display I want” method. If it is -1, the game just creates a window in the normal way, and passes SDL_WINDOWPOS_CENTERED for the x and y position. Then some code checks for things like “is the window fullscreen, using SDL_WINDOW_FULLSCREEN, and larger in either dimension than the largest available dimensions for its current display?” Finally, whatever display the window is now on is saved in display_number.

I?ll quote my previous reply, since it?s not showing up in the forum (yet?):> You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y arguments of SDL_CreateWindow to specify which monitor the window will be created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP flag to easily make a fullscreen-desktop window on a specific monitor.

If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason (even though it?s recommended), you can use SDL_GetDesktopDisplayMode or SDL_GetCurrentDisplayMode to get the resolution of a monitor.

On Jan 2, 2015, at 6:33 PM, MrTAToad wrote:

You can use SDL_GetWindowDisplayIndex to get the index, (or SDL_GetDisplayName for the name), at which point you could iterate through the available displays to find out which one it is.

There doesn’t seem to be a way to force window creation on a specific display - someone queried it here :http://stackoverflow.com/questions/26238552/how-to-create-an-sdl2-window-on-the-current-display

Or rather - there doesn’t seem to be an easy/automatic way - you could do it by calculating the total widths for display - 1 and then horizontally position the window, but is a cumbersome process…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y arguments of SDL_CreateWindow to specify which monitor the window will be created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP flag to easily make a fullscreen-desktop window on a specific monitor.

If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason (even though it?s recommended), you can use SDL_GetDesktopDisplayMode or SDL_GetCurrentDisplayMode to get the resolution of a monitor.On Jan 2, 2015, at 5:28 AM, Dark_Oppressor wrote:

I’m currently (with SDL 2.0.3) using SDL_CreateWindow to create a centered, borderless window with a predetermined resolution to create a “windowed fullscreen” mode. However, this requires one to know the display’s resolution in advance. I know I can get a window’s associated display’s resolution. What would be great is if I could know before creating a window what display it would be on. Is this possible? Or does the OS maybe handle that or something?

I had also thought of creating a window with SDL_WINDOW_FULLSCREEN_DESKTOP for a simple fullscreen window. However, I’d like to have a display number option so users can switch the display that the game window is on. Is there some way to specify a display to create a window on using SDL_CreateWindow?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Alex Szpakowski wrote:

You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y arguments of SDL_CreateWindow to specify which monitor the window will be created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP flag to easily make a fullscreen-desktop window on a specific monitor.

If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason (even though it?s recommended), you can use SDL_GetDesktopDisplayMode or SDL_GetCurrentDisplayMode to get the resolution of a monitor.

Awesome, thanks! That was mentioned briefly in that link above, but I wasn’t sure if it was real! I actually have 3 fullscreen modes that I support. “desktop” which uses SDL_WINDOW_FULLSCREEN_DESKTOP, “standard” which uses SDL_WINDOW_FULLSCREEN (so users can specify some random resolution if they really want to), and “windowed” which creates a borderless window the same size as the display. I MAY have overengineered this… :smiley:

SDL_WINDOW_FULLSCREEN_DESKTOP is a borderless window so your third
fullscreen mode may be redundant.

Best,
AaronOn Fri, Jan 2, 2015 at 8:56 PM, Dark_Oppressor wrote:

Alex Szpakowski wrote:

You can use SDL_WINDOWPOS_CENTERED_DISPLAY(displayindex) for the x and y
arguments of SDL_CreateWindow to specify which monitor the window will be
created in. You can combine that with the SDL_WINDOW_FULLSCREEN_DESKTOP
flag to easily make a fullscreen-desktop window on a specific monitor.

If you don?t want to use SDL_WINDOW_FULLSCREEN_DESKTOP for whatever reason
(even though it?s recommended), you can use SDL_GetDesktopDisplayMode or
SDL_GetCurrentDisplayMode to get the resolution of a monitor.

Awesome, thanks! That was mentioned briefly in that link above, but I
wasn’t sure if it was real! I actually have 3 fullscreen modes that I
support. “desktop” which uses SDL_WINDOW_FULLSCREEN_DESKTOP, "standard"
which uses SDL_WINDOW_FULLSCREEN (so users can specify some random
resolution if they really want to), and “windowed” which creates a
borderless window the same size as the display. I MAY have overengineered
this… [image: Very Happy]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Aaron Melcher wrote:

SDL_WINDOW_FULLSCREEN_DESKTOP is a borderless window so your third fullscreen mode may be redundant.

Best,
Aaron

There is a slight difference, in that they behave differently when I alt+tab out (which is why I originally added another mode!)

2015-01-07 7:37 GMT-03:00, Dark_Oppressor :

There is a slight difference, in that they behave differently when I alt+tab
out (which is why I originally added another mode!)

Oh right, SDL_WINDOW_FULLSCREEN_DESKTOP minimizes when unfocused, but
windowed doesn’t.

Sik wrote:

Oh right, SDL_WINDOW_FULLSCREEN_DESKTOP minimizes when unfocused, but
windowed doesn’t.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Exactly, that’s why I’ve got the three. It might be silly, but they each have a legitimate function, I swear!

You can change that behaviour at runtime with SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, “0”) (or “1” for the default behaviour.) No need to create your own pseudo-fullscreen mode.> On Jan 8, 2015, at 12:46 AM, Dark_Oppressor wrote:

Sik wrote:

Oh right, SDL_WINDOW_FULLSCREEN_DESKTOP minimizes when unfocused, but
windowed doesn’t.


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Exactly, that’s why I’ve got the three. It might be silly, but they each have a legitimate function, I swear!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org