Skip to content

Commit 7e2015c

Browse files
committed
fixed incorrect monitor selection
1 parent 95f57ec commit 7e2015c

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

DoomRunner.pro

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ DISTFILES += \
8686

8787
win32:RC_ICONS += Resources/DoomRunner.ico
8888

89-
unix: LIBS += -lX11 -lXrandr
90-
9189
# Default rules for deployment.
9290
qnx: target.path = /tmp/$${TARGET}/bin
9391
else: unix:!android: target.path = /opt/$${TARGET}/bin

Sources/MainWindow.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,8 @@ void MainWindow::restoreLaunchOptions( const LaunchOptions & opts )
19641964
ui->allowCheatsChkBox->setChecked( opts.allowCheats );
19651965

19661966
// video
1967-
ui->monitorCmbBox->setCurrentIndex( opts.monitorIdx );
1967+
if (opts.monitorIdx < ui->monitorCmbBox->count())
1968+
ui->monitorCmbBox->setCurrentIndex( opts.monitorIdx );
19681969
if (opts.resolutionX > 0)
19691970
ui->resolutionXLine->setText( QString::number( opts.resolutionX ) );
19701971
if (opts.resolutionY > 0)
@@ -2165,7 +2166,15 @@ QString MainWindow::generateLaunchCommand( const QString & baseDir )
21652166
cmdStream << " +sv_cheats 1";
21662167

21672168
if (ui->monitorCmbBox->currentIndex() > 0) // the first item is a placeholder for leaving it default
2168-
cmdStream << " +vid_adapter " << ui->monitorCmbBox->currentIndex(); // and ZDoom indexes monitors from 1
2169+
{
2170+
// terrible hack, but it's not my fault
2171+
int vid_adapter;
2172+
if (selectedEngineIdx >= 0 && getFileNameFromPath( engineModel[ selectedEngineIdx ].path ).startsWith("zdoom"))
2173+
vid_adapter = ui->monitorCmbBox->currentIndex(); // in ZDoom monitors are indexed from 1
2174+
else
2175+
vid_adapter = ui->monitorCmbBox->currentIndex() - 1; // but in newer derivatives from 0
2176+
cmdStream << " +vid_adapter " << vid_adapter;
2177+
}
21692178
if (!ui->resolutionXLine->text().isEmpty())
21702179
cmdStream << " -width " << ui->resolutionXLine->text();
21712180
if (!ui->resolutionYLine->text().isEmpty())

Sources/OSUtils.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@
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

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

Comments
 (0)