Qt: Fall back to screen for refresh rate

Wayland, always a pain in the arse.
This commit is contained in:
Stenzek 2024-05-24 23:24:05 +10:00
parent a7f2ad37de
commit 1adc29aeb0
No known key found for this signature in database
1 changed files with 11 additions and 1 deletions

View File

@ -370,7 +370,17 @@ std::optional<WindowInfo> GetWindowInfoForWidget(QWidget* widget)
wi.surface_scale = static_cast<float>(dpr);
// Query refresh rate, we need it for sync.
wi.surface_refresh_rate = WindowInfo::QueryRefreshRateForWindow(wi).value_or(0.0f);
std::optional<float> 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<float>(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;