mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-18 15:33:56 +01:00
fix(workspaces): let set_foreground_window fail
When hiding/restoring windows as part of workspace switching, calls to SetForegroundWindow fail, and if they fail, other hidden windows get lost forever in hidden mode when the error is returned up the call chain using the ? operator. This commit separates out the focus() calls from the loops restoring windows when switching workspaces, and also ensures that calls to SetForegroundWindow will log an error, but ultimately continue to the end of the focus() function call.
This commit is contained in:
@@ -124,7 +124,15 @@ impl Window {
|
||||
WindowsApi::attach_thread_input(current_thread_id, window_thread_id, true)?;
|
||||
|
||||
// Raise Window to foreground
|
||||
WindowsApi::set_foreground_window(self.hwnd())?;
|
||||
match WindowsApi::set_foreground_window(self.hwnd()) {
|
||||
Ok(_) => {}
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
"could not set as foreground window, but continuing execution of focus(): {}",
|
||||
error
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Center cursor in Window
|
||||
WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(self.hwnd())?)?;
|
||||
|
||||
@@ -58,16 +58,22 @@ impl Workspace {
|
||||
|
||||
pub fn restore(&mut self) -> Result<()> {
|
||||
let idx = self.focused_container_idx();
|
||||
let mut to_focus = None;
|
||||
for (i, container) in self.containers_mut().iter_mut().enumerate() {
|
||||
if let Some(window) = container.visible_window_mut() {
|
||||
window.restore();
|
||||
|
||||
if idx == i {
|
||||
window.focus()?;
|
||||
to_focus = Option::from(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do this here to make sure that an error doesn't stop the restoration of other windows
|
||||
if let Some(window) = to_focus {
|
||||
window.focus()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user