SFML community forums

Help => Window => Topic started by: Celtic Minstrel on September 03, 2017, 03:44:12 am

Title: Working with multiple monitors
Post by: Celtic Minstrel on September 03, 2017, 03:44:12 am
Is there any way to distinguish between the main monitor and secondary monitors? I have a fullscreen mode which calls getDesktopMode() to determine the size of the screen and resizes the window to fit it; however, it always uses only the size of the main monitor. I'd like it to take the size of whichever monitor the window currently resides on (based on the window's origin). Can this be done in SFML?
Title: Re: Working with multiple monitors
Post by: eXpl0it3r on September 03, 2017, 09:05:20 am
Unfortunately not yet.
Title: Re: Working with multiple monitors
Post by: Celtic Minstrel on September 09, 2017, 04:58:55 am
I see. I guess I'll have to either wait or use OS-specific routines for it. I don't suppose there's any plans to implement this?
Title: Re: Working with multiple monitors
Post by: Hapax on September 10, 2017, 02:31:06 pm
I don't suppose there's any plans to implement this?
There are (https://github.com/SFML/SFML/issues/188). ;)
Title: Re: Working with multiple monitors
Post by: rherzog on May 21, 2022, 09:42:33 am
I stumbled over the same issue recently that I want to have 2 fullscreen windows on two external displays.
However, SFML only chooses to use the same primary display as the fullscreen window.
At least for MS Windows I found a simple solution:


//...switching to fullscreen on current most overlapping display for SFML window1
RECT rect;
HMONITOR hMonitor;
MONITORINFO mi;
hMonitor = MonitorFromWindow(sfml_window1.getSystemHandle(), MONITOR_DEFAULTTONEAREST);
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor, &mi);
rect = mi.rcMonitor;
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
sfml_window1.create(sf::VideoMode(width, height), "Window1", sf::Style::None);
sfml_window1.setPosition(sf::Vector2i(rect.left, rect.top));
sfml_window1.setVerticalSyncEnabled(true);

The same can be done simultaneously with other SFML windows on different screens and they will go fullscreen on the current most overlapping display. You might need to include <winuser.h>.