fix(wm): retry foreground calls on focus change

For the past few weeks since upgrading the windows-rs crate I've seen
sporadic failures when calling SetForegroundWindow which require a full
restart to get the wm working as expected again. Adding in a retry loop
here seems to help when the issue comes up for me on Windows 11.
This commit is contained in:
LGUG2Z
2022-10-07 06:57:35 -07:00
parent f8ada73739
commit 577fa0a97f

View File

@@ -257,15 +257,20 @@ impl Window {
}; };
// Raise Window to foreground // Raise Window to foreground
match WindowsApi::set_foreground_window(self.hwnd()) { let mut foregrounded = false;
Ok(_) => {} while !foregrounded {
Err(error) => { match WindowsApi::set_foreground_window(self.hwnd()) {
tracing::error!( Ok(_) => {
"could not set as foreground window, but continuing execution of focus(): {}", foregrounded = true;
error }
); Err(error) => {
} tracing::error!(
}; "could not set as foreground window, but continuing execution of focus(): {}",
error
);
}
};
}
// Center cursor in Window // Center cursor in Window
if mouse_follows_focus { if mouse_follows_focus {