Skip to content

Commit 66e21e4

Browse files
gentle focus on Windows?
1 parent 08b64ee commit 66e21e4

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

apps/desktop/src-tauri/src/target_select_overlay.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,30 @@ pub async fn focus_window(window_id: WindowId) -> Result<(), String> {
180180
#[cfg(target_os = "windows")]
181181
{
182182
use windows::Win32::UI::WindowsAndMessaging::{
183-
SW_RESTORE, SetForegroundWindow, ShowWindow,
183+
GetWindowPlacement, IsIconic, SW_RESTORE, SetForegroundWindow, SetWindowPlacement,
184+
ShowWindow, WINDOWPLACEMENT,
184185
};
185186

186187
let hwnd = window.raw_handle().inner();
187188

188189
unsafe {
189-
ShowWindow(hwnd, SW_RESTORE);
190+
// Only restore if the window is actually minimized
191+
if IsIconic(hwnd).as_bool() {
192+
// Get current window placement to preserve size/position
193+
let mut wp = WINDOWPLACEMENT::default();
194+
wp.length = std::mem::size_of::<WINDOWPLACEMENT>() as u32;
195+
196+
if GetWindowPlacement(hwnd, &mut wp).as_bool() {
197+
// Restore using the previous placement to avoid resizing
198+
wp.showCmd = SW_RESTORE;
199+
SetWindowPlacement(hwnd, &wp);
200+
} else {
201+
// Fallback to simple restore if placement fails
202+
ShowWindow(hwnd, SW_RESTORE);
203+
}
204+
}
205+
206+
// Always try to bring to foreground
190207
SetForegroundWindow(hwnd);
191208
}
192209
}

0 commit comments

Comments
 (0)