Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

fix overlay with text scaling on windows (#2059)

CJ Paise29520d623e2
diff --git a/src-tauri/src/overlay.rs b/src-tauri/src/overlay.rs
index 1157a6b5..292acce3 100644
--- a/src-tauri/src/overlay.rs
+++ b/src-tauri/src/overlay.rs
@@ -40,11 +40,14 @@ tauri_panel! {
// where the card sits — only OVERLAY_TOP_OFFSET / OVERLAY_BOTTOM_OFFSET do. Keep
// these in sync with the CSS card geometry.
//
+// On Windows these sizes are additionally multiplied by the accessibility text
+// scale (see windows_text_scale_factor), which WebView2 applies as a zoom.
+//
// Compact overlay (Minimal / transcribing / processing): the 40h pill animates
// width from 172 (--ov-rest-w) to 216 (--ov-work-w) and expands from center, so
// the window must fit the widest state plus a little slack.
const OVERLAY_WIDTH: f64 = 256.0;
-const OVERLAY_HEIGHT: f64 = 46.0;
+const OVERLAY_HEIGHT: f64 = 50.0;
// Actual is 394x118, just a little extra
const OVERLAY_STREAM_WIDTH: f64 = 400.0;
@@ -286,6 +289,18 @@ fn current_overlay_logical_size(window: &tauri::webview::WebviewWindow) -> Optio
#[cfg(target_os = "windows")]
static WINDOWS_OVERLAY_IS_STREAMING: AtomicBool = AtomicBool::new(false);
+/// Windows accessibility text size (Settings > Accessibility > Text size), a
+/// separate axis from display scaling that WebView2 applies as a document zoom.
+#[cfg(target_os = "windows")]
+fn windows_text_scale_factor() -> f64 {
+ // Absent until the user moves the slider off 100%; stored as a percentage.
+ winreg::RegKey::predef(winreg::enums::HKEY_CURRENT_USER)
+ .open_subkey(r"Software\Microsoft\Accessibility")
+ .and_then(|key| key.get_value::<u32, _>("TextScaleFactor"))
+ .map(|percent| (percent as f64 / 100.0).clamp(1.0, 2.25))
+ .unwrap_or(1.0)
+}
+
/// Overlay rectangle in the destination monitor's physical pixels, so nothing
/// is converted through the window's previous-monitor DPI.
#[cfg(target_os = "windows")]
@@ -293,12 +308,16 @@ fn windows_overlay_bounds(
monitor_position: PhysicalPosition<i32>,
monitor_size: PhysicalSize<u32>,
scale: f64,
+ text_scale: f64,
logical_width: f64,
logical_height: f64,
overlay_position: OverlayPosition,
) -> (i32, i32, i32, i32) {
- let width = (logical_width * scale).round().max(1.0) as i32;
- let height = (logical_height * scale).round().max(1.0) as i32;
+ // Grow the window with the text scale; offsets stay DPI-only since the
+ // card sits flush against the window's screen-edge side.
+ let content_scale = scale * text_scale;
+ let width = (logical_width * content_scale).round().max(1.0) as i32;
+ let height = (logical_height * content_scale).round().max(1.0) as i32;
let x = (monitor_position.x as f64 + (monitor_size.width as f64 - width as f64) / 2.0).round()
as i32;
let y = match overlay_position {
@@ -327,10 +346,12 @@ fn place_windows_overlay(
let monitor = get_monitor_with_cursor(app_handle)
.ok_or_else(|| "failed to determine the monitor containing the cursor".to_string())?;
+ let text_scale = windows_text_scale_factor();
let (x, y, width, height) = windows_overlay_bounds(
*monitor.position(),
*monitor.size(),
monitor.scale_factor(),
+ text_scale,
logical_width,
logical_height,
settings::get_settings(app_handle).overlay_position,
@@ -353,12 +374,13 @@ fn place_windows_overlay(
}
log::debug!(
- "windows overlay bounds: x={} y={} width={} height={} scale={}",
+ "windows overlay bounds: x={} y={} width={} height={} scale={} text_scale={}",
x,
y,
width,
height,
- monitor.scale_factor()
+ monitor.scale_factor(),
+ text_scale
);
Ok(())
}
@@ -797,22 +819,24 @@ mod tests {
monitor_position,
monitor_size,
1.5,
+ 1.0,
OVERLAY_WIDTH,
OVERLAY_HEIGHT,
OverlayPosition::Bottom,
),
- (3648, 2031, 384, 69)
+ (3648, 2025, 384, 75)
);
assert_eq!(
windows_overlay_bounds(
monitor_position,
monitor_size,
1.5,
+ 1.0,
OVERLAY_WIDTH,
OVERLAY_HEIGHT,
OverlayPosition::Top,
),
- (3648, 6, 384, 69)
+ (3648, 6, 384, 75)
);
}
@@ -824,6 +848,7 @@ mod tests {
PhysicalPosition::new(-2560, -200),
PhysicalSize::new(2560, 1440),
1.25,
+ 1.0,
OVERLAY_STREAM_WIDTH,
OVERLAY_STREAM_HEIGHT,
OverlayPosition::Bottom,
@@ -831,4 +856,37 @@ mod tests {
(-1530, 1040, 500, 150)
);
}
+
+ #[cfg(target_os = "windows")]
+ #[test]
+ fn windows_overlay_bounds_grow_with_text_scale_without_moving_the_anchored_edge() {
+ let monitor_position = PhysicalPosition::new(-2560, -200);
+ let monitor_size = PhysicalSize::new(2560, 1440);
+
+ let (x, y, width, height) = windows_overlay_bounds(
+ monitor_position,
+ monitor_size,
+ 1.25,
+ 1.1,
+ OVERLAY_STREAM_WIDTH,
+ OVERLAY_STREAM_HEIGHT,
+ OverlayPosition::Bottom,
+ );
+ // 400x120 logical at 1.25 DPI x 1.1 text, still centered horizontally.
+ assert_eq!((x, y, width, height), (-1555, 1025, 550, 165));
+ // Bottom edge unchanged from the 1.0 case above (1040 + 150).
+ assert_eq!(y + height, 1190);
+
+ let (_, top_y, _, _) = windows_overlay_bounds(
+ monitor_position,
+ monitor_size,
+ 1.25,
+ 1.1,
+ OVERLAY_STREAM_WIDTH,
+ OVERLAY_STREAM_HEIGHT,
+ OverlayPosition::Top,
+ );
+ // Top offset rides the DPI scale alone, so the top edge doesn't move.
+ assert_eq!(top_y, -195);
+ }
}
diff --git a/src/overlay/RecordingOverlay.css b/src/overlay/RecordingOverlay.css
index d369d0c2..eb400687 100644
--- a/src/overlay/RecordingOverlay.css
+++ b/src/overlay/RecordingOverlay.css
@@ -161,6 +161,9 @@
/* Shared base card. Flat: theme surface + hairline border, no shadow or blur. */
.scard {
width: var(--ov-pill-w);
+ /* Never wider than the window: an unaccounted content zoom degrades to a
+ narrower card instead of clipping. 2px = our border (no border-box reset). */
+ max-width: calc(100vw - 2px);
border-radius: 24px;
overflow: hidden;
display: flex;
@@ -235,7 +238,9 @@
min-height: 0;
}
.stext-cap {
- max-height: var(--ov-cap-max-h);
+ /* Vertical counterpart of the .scard clamp: show fewer lines rather than clip.
+ 20px = cap padding (12) + card borders (2) + 6px slack for zoom rounding. */
+ max-height: min(var(--ov-cap-max-h), calc(100vh - var(--ov-base-h) - 20px));
overflow-y: auto;
overscroll-behavior: contain;
display: flex;
@@ -286,6 +291,7 @@
Same structure for pill & panel; the dot stays anchored left in both. */
.sbase {
height: var(--ov-base-h);
+ flex: none; /* the control row never squashes; only the text region gives */
padding: 0 10px;
display: grid;
/* Equal side columns (min 22px to hold the cancel button) keep the center item