From da7a09658a6f220bd576d6d2f94a20eb2a04f0c0 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 29 Apr 2025 12:27:02 +0200 Subject: [PATCH] fix: Support fractional refresh rates in video modes on macOS (#4191) We were rounding the refresh rate before converting it to millihertz. --- src/changelog/unreleased.md | 1 + src/platform_impl/macos/monitor.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 272561000..cb53b417f 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -59,3 +59,4 @@ changelog entry. - On Wayland, ensure that external event loop is woken-up when using pump_events and integrating via `FD`. - On Wayland, apply fractional scaling to custom cursors. - On macOS, fixed `run_app_on_demand` returning without closing open windows. +- On macOS, fixed `VideoMode::refresh_rate_millihertz` for fractional refresh rates. diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index bf7ee708e..dab09039d 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -281,12 +281,12 @@ impl MonitorHandle { }; modes.into_iter().map(move |mode| { - let cg_refresh_rate_hertz = ffi::CGDisplayModeGetRefreshRate(mode).round() as i64; + let cg_refresh_rate_hertz = ffi::CGDisplayModeGetRefreshRate(mode); // CGDisplayModeGetRefreshRate returns 0.0 for any display that // isn't a CRT - let refresh_rate_millihertz = if cg_refresh_rate_hertz > 0 { - (cg_refresh_rate_hertz * 1000) as u32 + let refresh_rate_millihertz = if cg_refresh_rate_hertz > 0.0 { + (cg_refresh_rate_hertz * 1000.0).round() as u32 } else { refresh_rate_millihertz };