fix(wm): simplify stack-all command

Implements the equivalent of
https://github.com/LGUG2Z/komorebi/commit/18ee6678962bc31a39ce59fd4a1f6a9ee752ac5c

This commit makes the `stack-all` command simpler, by simply making a
`VecDeque` with all the tiled windows of the workspace, then it creates
a new container with that `VecDeque` and changes the workspace
containers to be just this new container which has all the windows in
it.

Then and only then do we focus and show the previously focused window
and hide all the rest.

This way we don't have a bunch of `FocusChange`/`Cloak`/`Uncloak` events
coming up which might conflict with each other when the user has
transparency and animations enabled.

With this commit, there will only be one focus event for the focused
window and one cloak event for each of the other windows.
This commit is contained in:
LGUG2Z committed 2025-11-02 11:03:16 -08:00
1 parent 34db2e2c90
commit 4c0f34d7ef
1 file changed
+23 -12
+23 -12
View File
@@ -50,6 +50,7 @@ use objc2_core_foundation::CFRunLoop;
use parking_lot::Mutex;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::hash_map::Entry;
use std::io::ErrorKind;
use std::net::Shutdown;
@@ -2279,29 +2280,39 @@ impl WindowManager {
#[tracing::instrument(skip(self))]
pub fn stack_all(&mut self) -> eyre::Result<()> {
self.unstack_all(false)?;
tracing::info!("stacking all windows on workspace");
let workspace = self.focused_workspace_mut()?;
let window_hiding_position = workspace.globals.window_hiding_position;
let mut focused_window_id = None;
let mut focused_hwnd = None;
if let Some(container) = workspace.focused_container()
&& let Some(window) = container.focused_window()
{
focused_window_id = Some(window.id);
focused_hwnd = Some(window.id);
}
workspace.focus_container(workspace.containers().len().saturating_sub(1));
while workspace.focused_container_idx() > 0 {
workspace.move_window_to_container(0)?;
workspace.focus_container(workspace.containers().len().saturating_sub(1));
}
let workspace_hwnds =
workspace
.containers()
.iter()
.fold(VecDeque::new(), |mut hwnds, c| {
hwnds.extend(c.windows().clone());
hwnds
});
if let Some(window_id) = focused_window_id {
workspace.focus_container_by_window(window_id)?;
}
let mut container = Container::default();
*container.windows_mut() = workspace_hwnds;
*workspace.containers_mut() = VecDeque::from([container]);
workspace.focus_container(0);
if let Some(hwnd) = focused_hwnd
&& let Some(c) = workspace.focused_container_mut()
&& let Some(w_idx_to_focus) = c.idx_for_window(hwnd)
{
c.focus_window(w_idx_to_focus);
c.load_focused_window(window_hiding_position)?;
}
self.update_focused_workspace(self.mouse_follows_focus, true)
}