From 6fce630be537bbeeb50ad38287843a5d12f60d08 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 21 Apr 2024 12:35:21 -0700 Subject: [PATCH] fix(wm): restore stackback on monocle off This commit ensures that if a container stack has a stackbar, when toggling off monocle mode, the stackbar will be restored as expected. This requires an additional retile which it would be nice to avoid in the future. --- komorebi/src/container.rs | 12 ++++++++++++ komorebi/src/window_manager.rs | 17 ++++++++++++++--- komorebi/src/workspace.rs | 6 ++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/komorebi/src/container.rs b/komorebi/src/container.rs index 4c1cc589..206136bb 100644 --- a/komorebi/src/container.rs +++ b/komorebi/src/container.rs @@ -9,6 +9,7 @@ use serde::Serialize; use crate::ring::Ring; use crate::stackbar::Stackbar; use crate::window::Window; +use crate::WindowsApi; use crate::STACKBAR_MODE; use komorebi_core::StackbarMode; @@ -170,4 +171,15 @@ impl Container { } }; } + + pub fn renew_stackbar(&mut self) { + match &self.stackbar { + None => {} + Some(stackbar) => { + if !WindowsApi::is_window(stackbar.hwnd()) { + self.stackbar = Stackbar::create().ok() + } + } + } + } } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 652d6bcf..72e25665 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1694,14 +1694,25 @@ impl WindowManager { pub fn toggle_monocle(&mut self) -> Result<()> { self.handle_unmanaged_window_behaviour()?; - let workspace = self.focused_workspace_mut()?; - + let workspace = self.focused_workspace()?; match workspace.monocle_container() { None => self.monocle_on()?, Some(_) => self.monocle_off()?, } - self.update_focused_workspace(true, true) + self.update_focused_workspace(true, true)?; + + // TODO: fix this ugly hack to restore stackbar after monocle is toggled off + let workspace = self.focused_workspace()?; + if workspace.monocle_container().is_none() { + if let Some(container) = workspace.focused_container() { + if container.stackbar().is_some() { + self.retile_all(true)?; + }; + } + }; + + Ok(()) } #[tracing::instrument(skip(self))] diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 0a7ab254..dec96f62 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -299,8 +299,10 @@ impl Workspace { let containers = self.containers_mut(); for (i, container) in containers.iter_mut().enumerate() { + container.renew_stackbar(); + let container_windows = container.windows().clone(); - let container_topbar = container.stackbar().clone(); + let container_stackbar = container.stackbar().clone(); if let (Some(window), Some(layout)) = (container.focused_window_mut(), layouts.get(i)) @@ -326,7 +328,7 @@ impl Workspace { rect.add_padding(width); } - if let Some(stackbar) = container_topbar { + if let Some(stackbar) = container_stackbar { if stackbar .set_position( &stackbar.get_position_from_container_layout(layout),