Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Handle DPI scale changes for desktop windows
Richie McIlroya2c26a1a8197
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex 971270530..f17290e05 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -5819,7 +5819,15 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {}}}- _ => {}+ WindowEvent::ScaleFactorChanged { scale_factor, .. } => {+ if let Some(webview_window) = app.get_webview_window(label) {+ windows::update_window_rasterization_scale(+ &webview_window,+ *scale_factor,+ );+ }+ }+ _ => {}}}));diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rsindex d8505bf06..2eecff2b2 100644--- a/apps/desktop/src-tauri/src/windows.rs+++ b/apps/desktop/src-tauri/src/windows.rs@@ -2925,6 +2925,34 @@ fn lock_window_text_scale(_window: &WebviewWindow<Wry>) {}}+/// `lock_window_text_scale` disables WebView2's own monitor-scale detection+/// (so the Windows text-size setting can't zoom the UI), which also stops it+/// following per-monitor DPI. The new scale factor must be forwarded here on+/// every `ScaleFactorChanged`, or a window dragged to a monitor with+/// different scaling keeps rasterizing and laying out at the old DPI.+pub fn update_window_rasterization_scale(_window: &WebviewWindow<Wry>, _scale_factor: f64) {+ #[cfg(windows)]+ {+ if let Err(e) = _window.with_webview(move |webview| unsafe {+ use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Controller3;+ use windows_core::Interface;++ let controller = webview.controller();++ let Ok(controller3) = controller.cast::<ICoreWebView2Controller3>() else {+ warn!("Failed to access WebView2 controller scale APIs");+ return;+ };++ if let Err(e) = controller3.SetRasterizationScale(_scale_factor) {+ warn!("Failed to update WebView rasterization scale: {}", e);+ }+ }) {+ warn!("Failed to access platform WebView: {}", e);+ }+ }+}+#[cfg(target_os = "macos")]fn add_traffic_lights(window: &WebviewWindow<Wry>, controls_inset: Option<LogicalPosition<f64>>) {use crate::platform::delegates;