Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Picker: enable the asking window before handing it the foreground

gelenmedyadcb13fe565b3
diff --git a/crates/rf-win/src/window.rs b/crates/rf-win/src/window.rs
index 110a3068..7b670e02 100644
--- a/crates/rf-win/src/window.rs
+++ b/crates/rf-win/src/window.rs
@@ -222,8 +222,13 @@ pub fn enable(hwnd: isize) {
/// Gives the foreground back to `owner` (another app's window) while we still hold it: when our
/// window closes, Windows would otherwise activate whatever window comes next.
+///
+/// The owner is enabled first. The asking app disabled it for the dialog and enables it again only once our answer reaches it,
+/// which can be after our window is gone: a disabled owner can't take the foreground, so Windows gave it to another app and the
+/// browser fell behind it (Firefox, whose dialogs run in a helper process that can't take the foreground back itself).
pub fn hand_foreground(owner: isize) {
use windows::Win32::Foundation::HWND;
+ use windows::Win32::UI::Input::KeyboardAndMouse::EnableWindow;
use windows::Win32::UI::WindowsAndMessaging::{AllowSetForegroundWindow, GetWindowThreadProcessId, SetForegroundWindow};
unsafe {
let h = HWND(owner as *mut _);
@@ -232,6 +237,7 @@ pub fn hand_foreground(owner: isize) {
if pid != 0 {
let _ = AllowSetForegroundWindow(pid);
}
+ let _ = EnableWindow(h, true);
let _ = SetForegroundWindow(h);
}
}