Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

fix(windows): synchronize webview zoom and window sizing to avoid island clipping

unknownb9b92170a4db
diff --git a/windows/src-tauri/src/island.rs b/windows/src-tauri/src/island.rs
index 4793c79b..b7cf9213 100644
--- a/windows/src-tauri/src/island.rs
+++ b/windows/src-tauri/src/island.rs
@@ -280,6 +280,58 @@ mod display_tests {
}
}
+/// Calculates the zoom correction factor so that 1 CSS pixel equals 1 window logical pixel.
+/// If WebView2's devicePixelRatio differs from the window's scale factor (e.g. system text
+/// scaling or multi-monitor DPI mismatch), adjusting the webview zoom ensures the island
+/// canvas (PANEL_W / EXPANDED_W) fits within the window without clipping.
+pub fn calculate_zoom_correction(current_zoom: f64, scale: f64, dpr: f64) -> Option<f64> {
+ if dpr <= 0.0 || !dpr.is_finite() || scale <= 0.0 || !scale.is_finite() {
+ return None;
+ }
+ if (dpr - scale).abs() / scale < 0.02 {
+ return None;
+ }
+ let new_zoom = (current_zoom * (scale / dpr)).clamp(0.25, 4.0);
+ Some(new_zoom)
+}
+
+#[cfg(test)]
+mod zoom_tests {
+ use super::*;
+
+ #[test]
+ fn zoom_correction_is_none_when_dpr_matches_window_scale() {
+ assert_eq!(calculate_zoom_correction(1.0, 1.0, 1.0), None);
+ assert_eq!(calculate_zoom_correction(1.0, 1.25, 1.25), None);
+ // Within 2% threshold
+ assert_eq!(calculate_zoom_correction(1.0, 1.0, 1.01), None);
+ }
+
+ #[test]
+ fn zoom_correction_adjusts_for_dpi_mismatch() {
+ // Issue #346: 100% scale display (scale 1.0) but WebView2 dpr = 1.25
+ let zoom = calculate_zoom_correction(1.0, 1.0, 1.25);
+ assert_eq!(zoom, Some(0.8));
+
+ // 125% display with 125% text scale (dpr 1.5625 vs scale 1.25)
+ let zoom = calculate_zoom_correction(1.0, 1.25, 1.5625);
+ assert_eq!(zoom, Some(0.8));
+
+ // 150% display with 100% webview dpr
+ let zoom = calculate_zoom_correction(1.0, 1.5, 1.0);
+ assert_eq!(zoom, Some(1.5));
+ }
+
+ #[test]
+ fn zoom_correction_handles_invalid_inputs() {
+ assert_eq!(calculate_zoom_correction(1.0, 0.0, 1.0), None);
+ assert_eq!(calculate_zoom_correction(1.0, 1.0, -1.0), None);
+ assert_eq!(calculate_zoom_correction(1.0, f64::NAN, 1.0), None);
+ assert_eq!(calculate_zoom_correction(1.0, 1.0, f64::INFINITY), None);
+ }
+}
+
+
pub fn screen_info(app: &AppHandle, pref: &str) -> ScreenInfo {
match target_monitor(app, pref) {
Some(m) => {
@@ -327,6 +379,19 @@ pub fn apply_geometry(app: &AppHandle, pref: &str, collapsed: bool) {
// Moving across displays can rescale the window: re-assert the physical size.
let _ = win.set_size(PhysicalSize::new(pw, ph));
let _ = win.set_always_on_top(true);
+
+ // On Windows, moving across displays or waking from the strip can clamp or lag
+ // the resize. If the physical inner size differs from what was requested, retry once.
+ if let Ok(got) = win.inner_size() {
+ if got.width != pw || got.height != ph {
+ crate::log::line(format!(
+ "window size mismatch: wanted {pw}x{ph}, got {}x{} (scale {scale}, monitor {}x{})",
+ got.width, got.height, ms.width, ms.height
+ ));
+ let _ = win.set_size(PhysicalSize::new(pw, ph));
+ let _ = win.set_position(PhysicalPosition::new(x, y));
+ }
+ }
}
/// Position, size and scale of the monitor the island lives on. Any change here
diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rs
index 870af4b6..7acbe20b 100644
--- a/windows/src-tauri/src/lib.rs
+++ b/windows/src-tauri/src/lib.rs
@@ -179,6 +179,26 @@ fn reposition(app: AppHandle, shared: State<Shared>) {
island::apply_geometry(&app, &pref, collapsed);
}
+/// The panel is laid out in CSS px against the window's own scale. If the webview
+/// reports a different devicePixelRatio (it ends up bigger than the window and gets
+/// cut), correct its zoom so one CSS px is one logical px again.
+#[tauri::command]
+fn fit_zoom(app: AppHandle, dpr: f64) -> bool {
+ let Some(win) = island::window(&app) else { return false };
+ let scale = win.scale_factor().unwrap_or(1.0);
+ static ZOOM: std::sync::Mutex<f64> = std::sync::Mutex::new(1.0);
+ let mut zoom = ZOOM.lock().unwrap();
+ if let Some(new_zoom) = island::calculate_zoom_correction(*zoom, scale, dpr) {
+ *zoom = new_zoom;
+ log::line(format!("webview dpr {dpr} != window scale {scale} — setting zoom {new_zoom:.3}"));
+ let _ = win.set_zoom(new_zoom);
+ true
+ } else {
+ false
+ }
+}
+
+
/// The displays the island can be pinned to, for Settings.
#[tauri::command]
fn list_monitors(app: AppHandle) -> Vec<island::MonitorChoice> {
@@ -675,6 +695,7 @@ pub fn run() {
set_island_rect,
focus_window,
reposition,
+ fit_zoom,
list_monitors,
open_url,
open_in_vscode,
diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.ts
index e40b3935..d9c4fed3 100644
--- a/windows/src/core/bridge.ts
+++ b/windows/src/core/bridge.ts
@@ -53,6 +53,7 @@ export const Bridge = {
focusWindow: (focused: boolean) => call<void>("focus_window", { focused }),
reposition: () => call<void>("reposition"),
+ fitZoom: (dpr: number) => call<boolean>("fit_zoom", { dpr }),
/** Displays the island can be pinned to: `key` is what `settings.screen` stores. */
listMonitors: () => call<{ key: string; label: string }[]>("list_monitors"),
diff --git a/windows/src/island/island.ts b/windows/src/island/island.ts
index 2ef6fb90..bca15aaf 100644
--- a/windows/src/island/island.ts
+++ b/windows/src/island/island.ts
@@ -681,7 +681,8 @@ export class Island {
this.greetingCanvas.style.left = `${(w - EXPANDED_W) / 2}px`;
this.uploadCanvas.el.style.left = `${(w - EXPANDED_W) / 2}px`;
- const rect = { x: (PANEL_W - w) / 2, y: 0, w, h: hh };
+ const viewportW = window.innerWidth > 0 ? window.innerWidth : PANEL_W;
+ const rect = { x: (viewportW - w) / 2, y: 0, w, h: hh };
const p = this.pushedRect;
if (Math.abs(p.x - rect.x) > 0.5 || Math.abs(p.w - rect.w) > 0.5 || Math.abs(p.h - rect.h) > 0.5) {
this.pushedRect = rect;
@@ -693,7 +694,8 @@ export class Island {
private islandRect(): { x: number; y: number; w: number; h: number } {
const w = this.width.value;
const hh = this.height.value;
- return { x: (PANEL_W - w) / 2, y: 0, w, h: hh };
+ const viewportW = window.innerWidth > 0 ? window.innerWidth : PANEL_W;
+ return { x: (viewportW - w) / 2, y: 0, w, h: hh };
}
// ── Window collapse (hidden → tiny wake strip, zero polling) ────────────────
diff --git a/windows/src/main.ts b/windows/src/main.ts
index 349e1cda..537c1008 100644
--- a/windows/src/main.ts
+++ b/windows/src/main.ts
@@ -24,6 +24,18 @@ async function main() {
void Sound.preload();
+ // Before the island exists: its canvases size their bitmaps from the pixel
+ // ratio once, so the zoom correction has to land first. If zoom was adjusted,
+ // wait until the ratio updates (or up to 500ms) so nothing is sized against
+ // the stale value.
+ const dprBefore = window.devicePixelRatio || 1;
+ const zoomChanged = await Bridge.fitZoom(dprBefore);
+ if (zoomChanged) {
+ for (let i = 0; i < 20 && window.devicePixelRatio === dprBefore; i++) {
+ await new Promise((r) => setTimeout(r, 25));
+ }
+ }
+
const island = new Island(root);
const boot = await Bridge.boot();
@@ -78,7 +90,31 @@ async function main() {
}
});
- await onEvent<null>("screen-changed", () => void Bridge.reposition());
+ const checkZoom = async () => {
+ const dpr = window.devicePixelRatio || 1;
+ await Bridge.fitZoom(dpr);
+ };
+
+ await onEvent<null>("screen-changed", async () => {
+ await checkZoom();
+ void Bridge.reposition();
+ });
+
+ const mediaQuery = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
+ mediaQuery.addEventListener?.("change", () => void checkZoom());
+
+ window.addEventListener(
+ "wheel",
+ (e) => {
+ if (e.ctrlKey) e.preventDefault();
+ },
+ { passive: false }
+ );
+ window.addEventListener("keydown", (e) => {
+ if (e.ctrlKey && (e.key === "+" || e.key === "-" || e.key === "=" || e.key === "0")) {
+ e.preventDefault();
+ }
+ });
// Settings → Reload sounds: read the sounds folder again, and let them hear it.
await onEvent<null>("sounds-changed", () => {