diff --git a/komorebi/src/container.rs b/komorebi/src/container.rs index bbcac493..4c1cc589 100644 --- a/komorebi/src/container.rs +++ b/komorebi/src/container.rs @@ -156,4 +156,18 @@ impl Container { tracing::info!("focusing window"); self.windows.focus(idx); } + + pub fn set_stackbar_mode(&mut self, mode: StackbarMode) { + self.stackbar = match mode { + StackbarMode::Always => Stackbar::create().ok(), + StackbarMode::Never => None, + StackbarMode::OnStack => { + if self.windows().len() > 1 && self.stackbar().is_none() { + Stackbar::create().ok() + } else { + None + } + } + }; + } } diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 146a8c06..2e6f7d37 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1280,6 +1280,14 @@ impl WindowManager { SocketMessage::StackbarMode(mode) => { let mut stackbar_mode = STACKBAR_MODE.lock(); *stackbar_mode = mode; + + for m in self.monitors_mut() { + for w in m.workspaces_mut() { + for c in w.containers_mut() { + c.set_stackbar_mode(mode); + } + } + } } SocketMessage::StackbarFocusedTextColour(r, g, b) => { let rgb = Rgb::new(r, g, b); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index d16422ea..2f0a5bb9 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -188,12 +188,14 @@ impl WindowManager { self.has_pending_raise_op = false; } WindowManagerEvent::Destroy(_, window) | WindowManagerEvent::Unmanage(window) => { - self.focused_workspace_mut()?.remove_window(window.hwnd)?; - self.update_focused_workspace(false, false)?; + if self.focused_workspace()?.contains_window(window.hwnd) { + self.focused_workspace_mut()?.remove_window(window.hwnd)?; + self.update_focused_workspace(false, false)?; - let mut already_moved_window_handles = self.already_moved_window_handles.lock(); + let mut already_moved_window_handles = self.already_moved_window_handles.lock(); - already_moved_window_handles.remove(&window.hwnd); + already_moved_window_handles.remove(&window.hwnd); + } } WindowManagerEvent::Minimize(_, window) => { let mut hide = false; diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 57442ac6..7e8c3ab1 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -518,10 +518,12 @@ impl StaticConfig { if let Some(height) = &stackbar.height { STACKBAR_TAB_HEIGHT.store(*height, Ordering::SeqCst); } + if let Some(mode) = &stackbar.mode { let mut stackbar_mode = STACKBAR_MODE.lock(); *stackbar_mode = *mode; } + if let Some(tabs) = &stackbar.tabs { if let Some(background) = &tabs.background { STACKBAR_TAB_BACKGROUND_COLOUR.store((*background).into(), Ordering::SeqCst); @@ -725,6 +727,16 @@ impl StaticConfig { value.apply_globals()?; + let stackbar_mode = STACKBAR_MODE.lock().clone(); + + for m in wm.monitors_mut() { + for w in m.workspaces_mut() { + for c in w.containers_mut() { + c.set_stackbar_mode(stackbar_mode); + } + } + } + if let Some(monitors) = value.monitors { for (i, monitor) in monitors.iter().enumerate() { if let Some(m) = wm.monitors_mut().get_mut(i) { diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index adc1bd22..aa223ad4 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -359,7 +359,7 @@ impl WindowsApi { flags |= SetWindowPosition::NO_Z_ORDER; } - let shadow_rect = Self::shadow_rect(hwnd)?; + let shadow_rect = Self::shadow_rect(hwnd).unwrap_or_default(); let rect = Rect { left: layout.left + shadow_rect.left, top: layout.top + shadow_rect.top, diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index d69ab4af..eb2384de 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -327,17 +327,17 @@ impl Workspace { } if let Some(stackbar) = container_topbar { - stackbar.set_position( + if let Ok(_) = stackbar.set_position( &stackbar.get_position_from_container_layout(layout), false, - )?; + ) { + stackbar.update(&container_windows, focused_hwnd)?; + let tab_height = STACKBAR_TAB_HEIGHT.load(Ordering::SeqCst); + let total_height = tab_height + container_padding; - stackbar.update(&container_windows, focused_hwnd)?; - let tab_height = STACKBAR_TAB_HEIGHT.load(Ordering::SeqCst); - let total_height = tab_height + container_padding; - - rect.top += total_height; - rect.bottom -= total_height; + rect.top += total_height; + rect.bottom -= total_height; + } } window.set_position(&rect, false)?;