From 1adc29aeb0dac26db69c1a45aea95d341cf599f5 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 24 May 2024 23:24:05 +1000 Subject: [PATCH] Qt: Fall back to screen for refresh rate Wayland, always a pain in the arse. --- src/duckstation-qt/qtutils.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/duckstation-qt/qtutils.cpp b/src/duckstation-qt/qtutils.cpp index 339a9fe78..b1a609630 100644 --- a/src/duckstation-qt/qtutils.cpp +++ b/src/duckstation-qt/qtutils.cpp @@ -370,7 +370,17 @@ std::optional GetWindowInfoForWidget(QWidget* widget) wi.surface_scale = static_cast(dpr); // Query refresh rate, we need it for sync. - wi.surface_refresh_rate = WindowInfo::QueryRefreshRateForWindow(wi).value_or(0.0f); + std::optional surface_refresh_rate = WindowInfo::QueryRefreshRateForWindow(wi); + if (!surface_refresh_rate.has_value()) + { + // Fallback to using the screen, getting the rate for Wayland is an utter mess otherwise. + const QScreen* widget_screen = widget->screen(); + if (!widget_screen) + widget_screen = QGuiApplication::primaryScreen(); + surface_refresh_rate = widget_screen ? static_cast(widget_screen->refreshRate()) : 0.0f; + } + + wi.surface_refresh_rate = surface_refresh_rate.value(); INFO_LOG("Surface refresh rate: {} hz", wi.surface_refresh_rate); return wi;