diff --git a/Core/Core.cpp b/Core/Core.cpp index 93c6eaf8d850..8d8ca89cd9e4 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -150,7 +150,12 @@ static bool IsWindowSmall(int pixelWidth, int pixelHeight) { // TODO: Feels like this belongs elsewhere. bool UpdateScreenScale(int width, int height) { bool smallWindow; -#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) +#if defined(USING_QT_UI) + g_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI); + float g_logical_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_LOGICAL_DPI); + g_dpi_scale_x = g_logical_dpi / g_dpi; + g_dpi_scale_y = g_logical_dpi / g_dpi; +#elif PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) g_dpi = (float)System_GetPropertyInt(SYSPROP_DISPLAY_DPI); g_dpi_scale_x = 96.0f / g_dpi; g_dpi_scale_y = 96.0f / g_dpi; diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 3c9641c1bd3f..83043c150e51 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -159,11 +159,24 @@ int System_GetPropertyInt(SystemProperty prop) { #else return DEVICE_TYPE_DESKTOP; #endif + case SYSPROP_DISPLAY_COUNT: + return QApplication::screens().size(); default: return -1; } } +int System_GetPropertyFloat(SystemProperty prop) { + switch (prop) { + case SYSPROP_DISPLAY_LOGICAL_DPI: + return QApplication::primaryScreen()->logicalDotsPerInch(); + case SYSPROP_DISPLAY_DPI: + return QApplication::primaryScreen()->physicalDotsPerInch(); + default: + return System_GetPropertyInt(prop); + } +} + bool System_GetPropertyBool(SystemProperty prop) { switch (prop) { case SYSPROP_HAS_BACK_BUTTON: @@ -229,16 +242,6 @@ void LaunchBrowser(const char *url) QDesktopServices::openUrl(QUrl(url)); } -float CalculateDPIScale() -{ - // Sane default rather than check DPI -#if defined(USING_GLES2) - return 1.2f; -#else - return 1.0f; -#endif -} - static int mainInternal(QApplication &a) { #ifdef MOBILE_DEVICE emugl = new MainUI(); @@ -628,19 +631,21 @@ int main(int argc, char *argv[]) QGLFormat::setDefaultFormat(format); QApplication a(argc, argv); - QSize res = QApplication::desktop()->screenGeometry().size(); + QScreen* screen = a.primaryScreen(); + QSizeF res = screen->physicalSize(); if (res.width() < res.height()) res.transpose(); pixel_xres = res.width(); pixel_yres = res.height(); - g_dpi_scale_x = CalculateDPIScale(); - g_dpi_scale_y = CalculateDPIScale(); + + g_dpi_scale_x = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX(); + g_dpi_scale_y = screen->logicalDotsPerInchY() / screen->physicalDotsPerInchY(); g_dpi_scale_real_x = g_dpi_scale_x; g_dpi_scale_real_y = g_dpi_scale_y; dp_xres = (int)(pixel_xres * g_dpi_scale_x); dp_yres = (int)(pixel_yres * g_dpi_scale_y); - refreshRate = (int)(a.primaryScreen()->refreshRate() * 1000); + refreshRate = (int)(screen->refreshRate() * 1000); std::string savegame_dir = "."; std::string external_dir = "."; @@ -669,4 +674,3 @@ int main(int argc, char *argv[]) glslang::FinalizeProcess(); return ret; } - diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index 4b4a6aaaf7c4..8b59c683eada 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent, bool fullscreen) : { QDesktopWidget *desktop = QApplication::desktop(); int screenNum = QProcessEnvironment::systemEnvironment().value("SDL_VIDEO_FULLSCREEN_HEAD", "0").toInt(); - + // Move window to the center of selected screen QRect rect = desktop->screenGeometry(screenNum); move((rect.width()-frameGeometry().width()) / 4, (rect.height()-frameGeometry().height()) / 4); @@ -295,19 +295,22 @@ void MainWindow::consoleAct() void MainWindow::raiseTopMost() { setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); - raise(); + raise(); activateWindow(); } void MainWindow::SetFullScreen(bool fullscreen) { if (fullscreen) { +#if !PPSSPP_PLATFORM(MAC) menuBar()->hide(); - + emugl->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + // TODO: Shouldn't this be physicalSize()? emugl->resizeGL(emugl->size().width(), emugl->size().height()); // TODO: Won't showFullScreen do this for us? setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); +#endif showFullScreen(); InitPadLayout(dp_xres, dp_yres); @@ -315,8 +318,10 @@ void MainWindow::SetFullScreen(bool fullscreen) { if (GetUIState() == UISTATE_INGAME && !g_Config.bShowTouchControls) QApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); } else { +#if !PPSSPP_PLATFORM(MAC) menuBar()->show(); updateMenus(); +#endif showNormal(); SetWindowScale(-1); @@ -346,7 +351,7 @@ void MainWindow::forumAct() QDesktopServices::openUrl(QUrl("https://forums.ppsspp.org/")); } -void MainWindow::gitAct() +void MainWindow::gitAct() { QDesktopServices::openUrl(QUrl("https://github.com/hrydgard/ppsspp/")); } @@ -394,9 +399,14 @@ void MainWindow::SetWindowScale(int zoom) { g_Config.iWindowWidth = width; g_Config.iWindowHeight = height; +#if !PPSSPP_PLATFORM(MAC) emugl->setFixedSize(g_Config.iWindowWidth, g_Config.iWindowHeight); + // TODO: Shouldn't this be scaled size? emugl->resizeGL(g_Config.iWindowWidth, g_Config.iWindowHeight); setFixedSize(sizeHint()); +#else + resize(g_Config.iWindowWidth, g_Config.iWindowHeight); +#endif } void MainWindow::SetGameTitle(QString text) @@ -585,7 +595,7 @@ void MainWindow::createMenus() } } langMenu->addActions(langGroup->actions()); - + // Help MenuTree* helpMenu = new MenuTree(this, menuBar(), QT_TR_NOOP("&Help")); helpMenu->add(new MenuAction(this, SLOT(websiteAct()), QT_TR_NOOP("Official &website"), QKeySequence::HelpContents)); diff --git a/ext/native/base/NativeApp.h b/ext/native/base/NativeApp.h index da2fba06bac5..188bcbaa52be 100644 --- a/ext/native/base/NativeApp.h +++ b/ext/native/base/NativeApp.h @@ -149,6 +149,7 @@ enum SystemProperty { SYSPROP_DISPLAY_XRES, SYSPROP_DISPLAY_YRES, SYSPROP_DISPLAY_REFRESH_RATE, // returns 1000*the refresh rate in Hz as it can be non-integer + SYSPROP_DISPLAY_LOGICAL_DPI, SYSPROP_DISPLAY_DPI, SYSPROP_DISPLAY_COUNT, SYSPROP_MOGA_VERSION, @@ -173,6 +174,7 @@ enum SystemProperty { std::string System_GetProperty(SystemProperty prop); int System_GetPropertyInt(SystemProperty prop); +int System_GetPropertyFloat(SystemProperty prop); bool System_GetPropertyBool(SystemProperty prop); std::vector __cameraGetDeviceList();