1
Window / Re: Working with multiple monitors
« 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>.
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>.