diff options
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) { | |||
| 4400 | #undef main | 4400 | #undef main |
| 4401 | #endif | 4401 | #endif |
| 4402 | 4402 | ||
| 4403 | static void SetHighDPIAttributes() { | ||
| 4404 | // Create a temporary QApplication. | ||
| 4405 | int temp_argc = 0; | ||
| 4406 | char** temp_argv = nullptr; | ||
| 4407 | QApplication temp{temp_argc, temp_argv}; | ||
| 4408 | |||
| 4409 | // Get the current screen geometry. | ||
| 4410 | const QScreen* primary_screen = QGuiApplication::primaryScreen(); | ||
| 4411 | if (primary_screen == nullptr) { | ||
| 4412 | return; | ||
| 4413 | } | ||
| 4414 | |||
| 4415 | const QRect screen_rect = primary_screen->geometry(); | ||
| 4416 | const int real_width = screen_rect.width(); | ||
| 4417 | const int real_height = screen_rect.height(); | ||
| 4418 | const float real_ratio = primary_screen->logicalDotsPerInch() / 96.0f; | ||
| 4419 | |||
| 4420 | // Recommended minimum width and height for proper window fit. | ||
| 4421 | // Any screen with a lower resolution than this will still have a scale of 1. | ||
| 4422 | constexpr float minimum_width = 1350.0f; | ||
| 4423 | constexpr float minimum_height = 900.0f; | ||
| 4424 | |||
| 4425 | const float width_ratio = std::max(1.0f, real_width / minimum_width); | ||
| 4426 | const float height_ratio = std::max(1.0f, real_height / minimum_height); | ||
| 4427 | |||
| 4428 | // Get the lower of the 2 ratios and truncate, this is the maximum integer scale. | ||
| 4429 | const float max_ratio = std::trunc(std::min(width_ratio, height_ratio)); | ||
| 4430 | |||
| 4431 | QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | ||
| 4432 | QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); | ||
| 4433 | |||
| 4434 | if (max_ratio > real_ratio) { | ||
| 4435 | QApplication::setHighDpiScaleFactorRoundingPolicy( | ||
| 4436 | Qt::HighDpiScaleFactorRoundingPolicy::Round); | ||
| 4437 | } else { | ||
| 4438 | QApplication::setHighDpiScaleFactorRoundingPolicy( | ||
| 4439 | Qt::HighDpiScaleFactorRoundingPolicy::Floor); | ||
| 4440 | } | ||
| 4441 | } | ||
| 4442 | |||
| 4403 | int main(int argc, char* argv[]) { | 4443 | int main(int argc, char* argv[]) { |
| 4404 | std::unique_ptr<Config> config = std::make_unique<Config>(); | 4444 | std::unique_ptr<Config> config = std::make_unique<Config>(); |
| 4405 | bool has_broken_vulkan = false; | 4445 | bool has_broken_vulkan = false; |
| @@ -4455,6 +4495,8 @@ int main(int argc, char* argv[]) { | |||
| 4455 | } | 4495 | } |
| 4456 | #endif | 4496 | #endif |
| 4457 | 4497 | ||
| 4498 | SetHighDPIAttributes(); | ||
| 4499 | |||
| 4458 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) | 4500 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 4459 | // Disables the "?" button on all dialogs. Disabled by default on Qt6. | 4501 | // Disables the "?" button on all dialogs. Disabled by default on Qt6. |
| 4460 | QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); | 4502 | QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); |
| @@ -4462,6 +4504,7 @@ int main(int argc, char* argv[]) { | |||
| 4462 | 4504 | ||
| 4463 | // Enables the core to make the qt created contexts current on std::threads | 4505 | // Enables the core to make the qt created contexts current on std::threads |
| 4464 | QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity); | 4506 | QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity); |
| 4507 | |||
| 4465 | QApplication app(argc, argv); | 4508 | QApplication app(argc, argv); |
| 4466 | 4509 | ||
| 4467 | #ifdef _WIN32 | 4510 | #ifdef _WIN32 |