summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar liamwhite2023-02-06 23:20:49 -0500
committerGravatar GitHub2023-02-06 23:20:49 -0500
commit1f3e8d633a6886aabc6631f2474dea644557458c (patch)
tree383436051ba66d167b4a335d9cc4b6d0b10a69df /src
parentMerge pull request #9644 from SaiKai/volume_quicksetting (diff)
parentmain: Convert to device independent coordinates for scaling (diff)
downloadyuzu-1f3e8d633a6886aabc6631f2474dea644557458c.tar.gz
yuzu-1f3e8d633a6886aabc6631f2474dea644557458c.tar.xz
yuzu-1f3e8d633a6886aabc6631f2474dea644557458c.zip
Merge pull request #4949 from Morph1984/hidpi-temp-fix
main: Enable High DPI fixes for Qt >= 5.14
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/applets/qt_software_keyboard.cpp2
-rw-r--r--src/yuzu/main.cpp69
-rw-r--r--src/yuzu/util/overlay_dialog.cpp2
3 files changed, 65 insertions, 8 deletions
diff --git a/src/yuzu/applets/qt_software_keyboard.cpp b/src/yuzu/applets/qt_software_keyboard.cpp
index 734b0ea40..4ae49506d 100644
--- a/src/yuzu/applets/qt_software_keyboard.cpp
+++ b/src/yuzu/applets/qt_software_keyboard.cpp
@@ -575,7 +575,7 @@ void QtSoftwareKeyboardDialog::MoveAndResizeWindow(QPoint pos, QSize size) {
575 QDialog::resize(size); 575 QDialog::resize(size);
576 576
577 // High DPI 577 // High DPI
578 const float dpi_scale = qApp->screenAt(pos)->logicalDotsPerInch() / 96.0f; 578 const float dpi_scale = screen()->logicalDotsPerInch() / 96.0f;
579 579
580 RescaleKeyboardElements(size.width(), size.height(), dpi_scale); 580 RescaleKeyboardElements(size.width(), size.height(), dpi_scale);
581} 581}
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index f5e6e0f58..f28268e9b 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -680,8 +680,10 @@ void GMainWindow::SoftwareKeyboardShowNormal() {
680 const auto y = layout.screen.top; 680 const auto y = layout.screen.top;
681 const auto w = layout.screen.GetWidth(); 681 const auto w = layout.screen.GetWidth();
682 const auto h = layout.screen.GetHeight(); 682 const auto h = layout.screen.GetHeight();
683 const auto scale_ratio = devicePixelRatioF();
683 684
684 software_keyboard->ShowNormalKeyboard(render_window->mapToGlobal(QPoint(x, y)), QSize(w, h)); 685 software_keyboard->ShowNormalKeyboard(render_window->mapToGlobal(QPoint(x, y) / scale_ratio),
686 QSize(w, h) / scale_ratio);
685} 687}
686 688
687void GMainWindow::SoftwareKeyboardShowTextCheck( 689void GMainWindow::SoftwareKeyboardShowTextCheck(
@@ -714,9 +716,11 @@ void GMainWindow::SoftwareKeyboardShowInline(
714 (1.0f - appear_parameters.key_top_scale_y)))); 716 (1.0f - appear_parameters.key_top_scale_y))));
715 const auto w = static_cast<int>(layout.screen.GetWidth() * appear_parameters.key_top_scale_x); 717 const auto w = static_cast<int>(layout.screen.GetWidth() * appear_parameters.key_top_scale_x);
716 const auto h = static_cast<int>(layout.screen.GetHeight() * appear_parameters.key_top_scale_y); 718 const auto h = static_cast<int>(layout.screen.GetHeight() * appear_parameters.key_top_scale_y);
719 const auto scale_ratio = devicePixelRatioF();
717 720
718 software_keyboard->ShowInlineKeyboard(std::move(appear_parameters), 721 software_keyboard->ShowInlineKeyboard(std::move(appear_parameters),
719 render_window->mapToGlobal(QPoint(x, y)), QSize(w, h)); 722 render_window->mapToGlobal(QPoint(x, y) / scale_ratio),
723 QSize(w, h) / scale_ratio);
720} 724}
721 725
722void GMainWindow::SoftwareKeyboardHideInline() { 726void GMainWindow::SoftwareKeyboardHideInline() {
@@ -796,10 +800,11 @@ void GMainWindow::WebBrowserOpenWebPage(const std::string& main_url,
796 } 800 }
797 801
798 const auto& layout = render_window->GetFramebufferLayout(); 802 const auto& layout = render_window->GetFramebufferLayout();
799 web_browser_view.resize(layout.screen.GetWidth(), layout.screen.GetHeight()); 803 const auto scale_ratio = devicePixelRatioF();
800 web_browser_view.move(layout.screen.left, layout.screen.top + menuBar()->height()); 804 web_browser_view.resize(layout.screen.GetWidth() / scale_ratio,
801 web_browser_view.setZoomFactor(static_cast<qreal>(layout.screen.GetWidth()) / 805 layout.screen.GetHeight() / scale_ratio);
802 static_cast<qreal>(Layout::ScreenUndocked::Width)); 806 web_browser_view.move(layout.screen.left / scale_ratio,
807 (layout.screen.top / scale_ratio) + menuBar()->height());
803 808
804 web_browser_view.setFocus(); 809 web_browser_view.setFocus();
805 web_browser_view.show(); 810 web_browser_view.show();
@@ -4448,6 +4453,55 @@ void GMainWindow::changeEvent(QEvent* event) {
4448#undef main 4453#undef main
4449#endif 4454#endif
4450 4455
4456static void SetHighDPIAttributes() {
4457#ifdef _WIN32
4458 // For Windows, we want to avoid scaling artifacts on fractional scaling ratios.
4459 // This is done by setting the optimal scaling policy for the primary screen.
4460
4461 // Create a temporary QApplication.
4462 int temp_argc = 0;
4463 char** temp_argv = nullptr;
4464 QApplication temp{temp_argc, temp_argv};
4465
4466 // Get the current screen geometry.
4467 const QScreen* primary_screen = QGuiApplication::primaryScreen();
4468 if (primary_screen == nullptr) {
4469 return;
4470 }
4471
4472 const QRect screen_rect = primary_screen->geometry();
4473 const int real_width = screen_rect.width();
4474 const int real_height = screen_rect.height();
4475 const float real_ratio = primary_screen->logicalDotsPerInch() / 96.0f;
4476
4477 // Recommended minimum width and height for proper window fit.
4478 // Any screen with a lower resolution than this will still have a scale of 1.
4479 constexpr float minimum_width = 1350.0f;
4480 constexpr float minimum_height = 900.0f;
4481
4482 const float width_ratio = std::max(1.0f, real_width / minimum_width);
4483 const float height_ratio = std::max(1.0f, real_height / minimum_height);
4484
4485 // Get the lower of the 2 ratios and truncate, this is the maximum integer scale.
4486 const float max_ratio = std::trunc(std::min(width_ratio, height_ratio));
4487
4488 if (max_ratio > real_ratio) {
4489 QApplication::setHighDpiScaleFactorRoundingPolicy(
4490 Qt::HighDpiScaleFactorRoundingPolicy::Round);
4491 } else {
4492 QApplication::setHighDpiScaleFactorRoundingPolicy(
4493 Qt::HighDpiScaleFactorRoundingPolicy::Floor);
4494 }
4495#else
4496 // Other OSes should be better than Windows at fractional scaling.
4497 QApplication::setHighDpiScaleFactorRoundingPolicy(
4498 Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
4499#endif
4500
4501 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
4502 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
4503}
4504
4451int main(int argc, char* argv[]) { 4505int main(int argc, char* argv[]) {
4452 std::unique_ptr<Config> config = std::make_unique<Config>(); 4506 std::unique_ptr<Config> config = std::make_unique<Config>();
4453 bool has_broken_vulkan = false; 4507 bool has_broken_vulkan = false;
@@ -4503,6 +4557,8 @@ int main(int argc, char* argv[]) {
4503 } 4557 }
4504#endif 4558#endif
4505 4559
4560 SetHighDPIAttributes();
4561
4506#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 4562#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
4507 // Disables the "?" button on all dialogs. Disabled by default on Qt6. 4563 // Disables the "?" button on all dialogs. Disabled by default on Qt6.
4508 QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); 4564 QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
@@ -4510,6 +4566,7 @@ int main(int argc, char* argv[]) {
4510 4566
4511 // Enables the core to make the qt created contexts current on std::threads 4567 // Enables the core to make the qt created contexts current on std::threads
4512 QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity); 4568 QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
4569
4513 QApplication app(argc, argv); 4570 QApplication app(argc, argv);
4514 4571
4515#ifdef _WIN32 4572#ifdef _WIN32
diff --git a/src/yuzu/util/overlay_dialog.cpp b/src/yuzu/util/overlay_dialog.cpp
index 796f5bf41..ee35a3e15 100644
--- a/src/yuzu/util/overlay_dialog.cpp
+++ b/src/yuzu/util/overlay_dialog.cpp
@@ -163,7 +163,7 @@ void OverlayDialog::MoveAndResizeWindow() {
163 const auto height = static_cast<float>(parentWidget()->height()); 163 const auto height = static_cast<float>(parentWidget()->height());
164 164
165 // High DPI 165 // High DPI
166 const float dpi_scale = parentWidget()->windowHandle()->screen()->logicalDotsPerInch() / 96.0f; 166 const float dpi_scale = screen()->logicalDotsPerInch() / 96.0f;
167 167
168 const auto title_text_font_size = BASE_TITLE_FONT_SIZE * (height / BASE_HEIGHT) / dpi_scale; 168 const auto title_text_font_size = BASE_TITLE_FONT_SIZE * (height / BASE_HEIGHT) / dpi_scale;
169 const auto body_text_font_size = 169 const auto body_text_font_size =