diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index abb61689..f29c7a9b 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -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())?)?; diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 062f4c78..49172a98 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -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(()) }