1010
1111#include < QStandardPaths>
1212#include < QApplication>
13+ #include < QGuiApplication>
14+ #include < QScreen>
15+
1316#include < QDebug>
1417
1518#ifdef _WIN32
16- #include < windows.h>
19+ // #include <windows.h>
1720#else
18- #include < X11/Xlib.h>
19- #include < X11/extensions/Xrandr.h>
21+ // #include <X11/Xlib.h>
22+ // #include <X11/extensions/Xrandr.h>
23+ // #include <SDL2/SDL.h>
24+ // #include <SDL2/SDL_vulkan.h>
2025#endif // _WIN32
2126
2227
2328// ======================================================================================================================
2429
2530#ifdef _WIN32
26- static BOOL CALLBACK enumMonitorCallback ( HMONITOR hMonitor, HDC /* hdc*/ , LPRECT /* lprcClip*/ , LPARAM userData )
27- {
31+ // static BOOL CALLBACK enumMonitorCallback( HMONITOR hMonitor, HDC /*hdc*/, LPRECT /*lprcClip*/, LPARAM userData )
32+ /* {
2833 QVector< MonitorInfo > * monitors = (QVector< MonitorInfo > *)userData;
2934
3035 MONITORINFOEXA theirInfo;
@@ -40,22 +45,34 @@ static BOOL CALLBACK enumMonitorCallback( HMONITOR hMonitor, HDC /*hdc*/, LPRECT
4045 }
4146
4247 return TRUE;
43- };
48+ };*/
4449#endif // _WIN32
4550
4651QVector< MonitorInfo > listMonitors ()
4752{
4853 QVector< MonitorInfo > monitors;
4954
50- // We can't use Qt for that because Qt reorders the monitors so that the primary one is always first,
51- // but we need them in the original order given by system.
55+ // in the end this work well for both platforms, just ZDoom indexes the monitors from 1 while GZDoom from 0
56+ QList<QScreen *> screens = QGuiApplication::screens ();
57+ for (int monitorIdx = 0 ; monitorIdx < screens.count (); monitorIdx++)
58+ {
59+ MonitorInfo myInfo;
60+ myInfo.name = screens[ monitorIdx ]->name ();
61+ myInfo.width = screens[ monitorIdx ]->size ().width ();
62+ myInfo.height = screens[ monitorIdx ]->size ().height ();
63+ myInfo.isPrimary = monitorIdx == 0 ;
64+ monitors.push_back ( myInfo );
65+ }
5266
5367#ifdef _WIN32
5468
69+ /* WinAPI
5570 EnumDisplayMonitors( nullptr, nullptr, (MONITORENUMPROC)enumMonitorCallback, (LONG_PTR)&monitors );
71+ */
5672
5773#else
5874
75+ /* libXrandr
5976 Display * display = XOpenDisplay( nullptr );
6077 if (!display)
6178 {
@@ -104,6 +121,26 @@ QVector< MonitorInfo > listMonitors()
104121
105122 XFree( xMonitors );
106123 XCloseDisplay( display );
124+ */
125+
126+ /* SDL2
127+ SDL_Init( SDL_INIT_VIDEO );
128+
129+ int monitorCnt = SDL_GetNumVideoDisplays();
130+ for (int monitorIdx = 0; monitorIdx < monitorCnt; monitorIdx++)
131+ {
132+ MonitorInfo myInfo;
133+ SDL_DisplayMode mode;
134+ SDL_GetCurrentDisplayMode( monitorIdx, &mode );
135+ myInfo.name = SDL_GetDisplayName( monitorIdx );
136+ myInfo.width = mode.w;
137+ myInfo.height = mode.h;
138+ myInfo.isPrimary = monitorIdx == 0;
139+ monitors.push_back( myInfo );
140+ }
141+
142+ SDL_Quit();
143+ */
107144
108145#endif // _WIN32
109146
0 commit comments