diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-01-26 03:16:04 +0100 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-01-26 03:16:04 +0100 |
commit | 6a1b089a501aca93cd275d853ef8f34a62b904c5 (patch) | |
tree | 2f8039744199b8fe17e54fbd6535aa5b66c484ab /src | |
parent | Merge pull request #9681 from Morph1984/nice-one-qt6 (diff) | |
download | yuzu-6a1b089a501aca93cd275d853ef8f34a62b904c5.tar yuzu-6a1b089a501aca93cd275d853ef8f34a62b904c5.tar.gz yuzu-6a1b089a501aca93cd275d853ef8f34a62b904c5.tar.bz2 yuzu-6a1b089a501aca93cd275d853ef8f34a62b904c5.tar.lz yuzu-6a1b089a501aca93cd275d853ef8f34a62b904c5.tar.xz yuzu-6a1b089a501aca93cd275d853ef8f34a62b904c5.tar.zst yuzu-6a1b089a501aca93cd275d853ef8f34a62b904c5.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/yuzu/main.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 62aaf41bf..82e4adfe0 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -4400,6 +4400,46 @@ void GMainWindow::changeEvent(QEvent* event) { #undef main #endif +static void SetHighDPIAttributes() { + // Create a temporary QApplication. + int temp_argc = 0; + char** temp_argv = nullptr; + QApplication temp{temp_argc, temp_argv}; + + // Get the current screen geometry. + const QScreen* primary_screen = QGuiApplication::primaryScreen(); + if (primary_screen == nullptr) { + return; + } + + const QRect screen_rect = primary_screen->geometry(); + const int real_width = screen_rect.width(); + const int real_height = screen_rect.height(); + const float real_ratio = primary_screen->logicalDotsPerInch() / 96.0f; + + // Recommended minimum width and height for proper window fit. + // Any screen with a lower resolution than this will still have a scale of 1. + constexpr float minimum_width = 1350.0f; + constexpr float minimum_height = 900.0f; + + const float width_ratio = std::max(1.0f, real_width / minimum_width); + const float height_ratio = std::max(1.0f, real_height / minimum_height); + + // Get the lower of the 2 ratios and truncate, this is the maximum integer scale. + const float max_ratio = std::trunc(std::min(width_ratio, height_ratio)); + + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + + if (max_ratio > real_ratio) { + QApplication::setHighDpiScaleFactorRoundingPolicy( + Qt::HighDpiScaleFactorRoundingPolicy::Round); + } else { + QApplication::setHighDpiScaleFactorRoundingPolicy( + Qt::HighDpiScaleFactorRoundingPolicy::Floor); + } +} + int main(int argc, char* argv[]) { std::unique_ptr<Config> config = std::make_unique<Config>(); bool has_broken_vulkan = false; @@ -4455,6 +4495,8 @@ int main(int argc, char* argv[]) { } #endif + SetHighDPIAttributes(); + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Disables the "?" button on all dialogs. Disabled by default on Qt6. QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); @@ -4462,6 +4504,7 @@ int main(int argc, char* argv[]) { // Enables the core to make the qt created contexts current on std::threads QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity); + QApplication app(argc, argv); #ifdef _WIN32 |