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
match WindowsApi::set_foreground_window(self.hwnd()) {
Ok(_) => {}
Err(error) => {
tracing::error!(
"could not set as foreground window, but continuing execution of focus(): {}",
error
);
}
};
let mut foregrounded = false;
while !foregrounded {
match WindowsApi::set_foreground_window(self.hwnd()) {
Ok(_) => {
foregrounded = true;
}
Err(error) => {
tracing::error!(
"could not set as foreground window, but continuing execution of focus(): {}",
error
);
}
};
}
// Center cursor in Window
if mouse_follows_focus {