Skip to content

Commit ebb9fbe

Browse files
committed
Qt/macOS: enable HiDPI ( retina display ) support
1 parent 78e36ec commit ebb9fbe

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

Core/Core.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
150150
// TODO: Feels like this belongs elsewhere.
151151
bool UpdateScreenScale(int width, int height) {
152152
bool smallWindow;
153-
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
153+
#if defined(USING_QT_UI)
154+
g_dpi = (float)System_GetPropertyInt(SYSPROP_DISPLAY_DPI);
155+
float g_logical_dpi = (float)System_GetPropertyInt(SYSPROP_DISPLAY_LOGICAL_DPI);
156+
g_dpi_scale_x = g_logical_dpi / g_dpi;
157+
g_dpi_scale_y = g_logical_dpi / g_dpi;
158+
#elif PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
154159
g_dpi = (float)System_GetPropertyInt(SYSPROP_DISPLAY_DPI);
155160
g_dpi_scale_x = 96.0f / g_dpi;
156161
g_dpi_scale_y = 96.0f / g_dpi;

Qt/QtMain.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ int System_GetPropertyInt(SystemProperty prop) {
159159
#else
160160
return DEVICE_TYPE_DESKTOP;
161161
#endif
162+
case SYSPROP_DISPLAY_LOGICAL_DPI:
163+
return (int)QApplication::primaryScreen()->logicalDotsPerInch();
164+
case SYSPROP_DISPLAY_DPI:
165+
return (int)QApplication::primaryScreen()->physicalDotsPerInch();
166+
case SYSPROP_DISPLAY_COUNT:
167+
return QApplication::screens().size();
162168
default:
163169
return -1;
164170
}
@@ -229,16 +235,6 @@ void LaunchBrowser(const char *url)
229235
QDesktopServices::openUrl(QUrl(url));
230236
}
231237

232-
float CalculateDPIScale()
233-
{
234-
// Sane default rather than check DPI
235-
#if defined(USING_GLES2)
236-
return 1.2f;
237-
#else
238-
return 1.0f;
239-
#endif
240-
}
241-
242238
static int mainInternal(QApplication &a) {
243239
#ifdef MOBILE_DEVICE
244240
emugl = new MainUI();
@@ -628,19 +624,21 @@ int main(int argc, char *argv[])
628624
QGLFormat::setDefaultFormat(format);
629625

630626
QApplication a(argc, argv);
631-
QSize res = QApplication::desktop()->screenGeometry().size();
627+
QScreen* screen = a.primaryScreen();
628+
QSizeF res = screen->physicalSize();
632629
if (res.width() < res.height())
633630
res.transpose();
634631
pixel_xres = res.width();
635632
pixel_yres = res.height();
636-
g_dpi_scale_x = CalculateDPIScale();
637-
g_dpi_scale_y = CalculateDPIScale();
633+
634+
g_dpi_scale_x = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX();
635+
g_dpi_scale_y = screen->logicalDotsPerInchY() / screen->physicalDotsPerInchY();
638636
g_dpi_scale_real_x = g_dpi_scale_x;
639637
g_dpi_scale_real_y = g_dpi_scale_y;
640638
dp_xres = (int)(pixel_xres * g_dpi_scale_x);
641639
dp_yres = (int)(pixel_yres * g_dpi_scale_y);
642640

643-
refreshRate = (int)(a.primaryScreen()->refreshRate() * 1000);
641+
refreshRate = (int)(screen->refreshRate() * 1000);
644642

645643
std::string savegame_dir = ".";
646644
std::string external_dir = ".";
@@ -669,4 +667,3 @@ int main(int argc, char *argv[])
669667
glslang::FinalizeProcess();
670668
return ret;
671669
}
672-

Qt/mainwindow.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent, bool fullscreen) :
2424
{
2525
QDesktopWidget *desktop = QApplication::desktop();
2626
int screenNum = QProcessEnvironment::systemEnvironment().value("SDL_VIDEO_FULLSCREEN_HEAD", "0").toInt();
27-
27+
2828
// Move window to the center of selected screen
2929
QRect rect = desktop->screenGeometry(screenNum);
3030
move((rect.width()-frameGeometry().width()) / 4, (rect.height()-frameGeometry().height()) / 4);
@@ -293,28 +293,33 @@ void MainWindow::consoleAct()
293293
void MainWindow::raiseTopMost()
294294
{
295295
setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
296-
raise();
296+
raise();
297297
activateWindow();
298298
}
299299

300300
void MainWindow::SetFullScreen(bool fullscreen) {
301301
if (fullscreen) {
302+
#if !PPSSPP_PLATFORM(MAC)
302303
menuBar()->hide();
303-
304+
304305
emugl->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
306+
// TODO: Shouldn't this be physicalSize()?
305307
emugl->resizeGL(emugl->size().width(), emugl->size().height());
306308
// TODO: Won't showFullScreen do this for us?
307309
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
308310
setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
311+
#endif
309312

310313
showFullScreen();
311314
InitPadLayout(dp_xres, dp_yres);
312315

313316
if (GetUIState() == UISTATE_INGAME && !g_Config.bShowTouchControls)
314317
QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
315318
} else {
319+
#if !PPSSPP_PLATFORM(MAC)
316320
menuBar()->show();
317321
updateMenus();
322+
#endif
318323

319324
showNormal();
320325
SetWindowScale(-1);
@@ -344,7 +349,7 @@ void MainWindow::forumAct()
344349
QDesktopServices::openUrl(QUrl("https://forums.ppsspp.org/"));
345350
}
346351

347-
void MainWindow::gitAct()
352+
void MainWindow::gitAct()
348353
{
349354
QDesktopServices::openUrl(QUrl("https://github.com/hrydgard/ppsspp/"));
350355
}
@@ -392,9 +397,14 @@ void MainWindow::SetWindowScale(int zoom) {
392397
g_Config.iWindowWidth = width;
393398
g_Config.iWindowHeight = height;
394399

400+
#if !PPSSPP_PLATFORM(MAC)
395401
emugl->setFixedSize(g_Config.iWindowWidth, g_Config.iWindowHeight);
402+
// TODO: Shouldn't this be scaled size?
396403
emugl->resizeGL(g_Config.iWindowWidth, g_Config.iWindowHeight);
397404
setFixedSize(sizeHint());
405+
#else
406+
resize(g_Config.iWindowWidth, g_Config.iWindowHeight);
407+
#endif
398408
}
399409

400410
void MainWindow::SetGameTitle(QString text)
@@ -583,7 +593,7 @@ void MainWindow::createMenus()
583593
}
584594
}
585595
langMenu->addActions(langGroup->actions());
586-
596+
587597
// Help
588598
MenuTree* helpMenu = new MenuTree(this, menuBar(), QT_TR_NOOP("&Help"));
589599
helpMenu->add(new MenuAction(this, SLOT(websiteAct()), QT_TR_NOOP("Official &website"), QKeySequence::HelpContents));

ext/native/base/NativeApp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ enum SystemProperty {
148148
SYSPROP_DISPLAY_XRES,
149149
SYSPROP_DISPLAY_YRES,
150150
SYSPROP_DISPLAY_REFRESH_RATE, // returns 1000*the refresh rate in Hz as it can be non-integer
151+
SYSPROP_DISPLAY_LOGICAL_DPI,
151152
SYSPROP_DISPLAY_DPI,
152153
SYSPROP_DISPLAY_COUNT,
153154
SYSPROP_MOGA_VERSION,

0 commit comments

Comments
 (0)