diff --git a/openless-all/app/src-tauri/src/coordinator/ime_insertion.rs b/openless-all/app/src-tauri/src/coordinator/ime_insertion.rs index d676e802..e563d1bf 100644 --- a/openless-all/app/src-tauri/src/coordinator/ime_insertion.rs +++ b/openless-all/app/src-tauri/src/coordinator/ime_insertion.rs @@ -515,6 +515,9 @@ pub(crate) fn show_capsule_window_no_activate( } } } + // 走到这里 hwnd 必为 Some:上面循环要么在 Win32 分支 break(hwnd 已赋值), + // 要么提前 return false。此 else 仅是 HANDLE_RETRY_ATTEMPTS == 0(循环体一次都不跑) + // 时的防御性兜底,当前常量为 5 时不可达,保留以防后续把次数改 0。 let Some(hwnd) = hwnd else { return false; }; diff --git a/openless-all/app/src-tauri/src/lib.rs b/openless-all/app/src-tauri/src/lib.rs index 1fcc34bd..96c467ea 100644 --- a/openless-all/app/src-tauri/src/lib.rs +++ b/openless-all/app/src-tauri/src/lib.rs @@ -1228,8 +1228,9 @@ fn clamp_to_monitor( area_bottom: i32, ) -> (i32, i32) { // 右/下边界 = area 右下角减去窗口自身尺寸,确保整窗可见。 - let max_x = (area_right - w).max(area_left); - let max_y = (area_bottom - h).max(area_top); + // 用 saturating_sub 防 area_right/area_bottom 为极小(含 i32::MIN 近邻)时减法溢出。 + let max_x = area_right.saturating_sub(w).max(area_left); + let max_y = area_bottom.saturating_sub(h).max(area_top); let clamped_x = x.clamp(area_left, max_x); let clamped_y = y.clamp(area_top, max_y); (clamped_x, clamped_y) @@ -1969,6 +1970,15 @@ mod tests { assert!(y + 126 <= 1040); } + #[test] + fn clamp_to_monitor_pulls_back_when_right_edge_overflows_inside_area() { + // 左上角 x=1800 本在 area 内,但 x+w=2064 越过右边界 1920 → + // 应被左移到「右边界 - 窗口宽」,整窗右缘恰好贴住 area_right。 + let (x, _y) = clamp_to_monitor(1800, 900, 264, 126, 0, 0, 1920, 1040); + assert_eq!(x, 1920 - 264); + assert!(x + 264 <= 1920); + } + #[test] fn clamp_to_monitor_pushes_into_negative_origin_left_monitor() { // 副屏在主屏左侧(负 X 原点),落点算到了副屏左外侧 → 夹回 area_left。