mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 07:08:48 +01:00
fix(wm): prune duplicate windows on ws
Got into a weird state after turning on my monitor where the same window_id appeared in two separate containers on the workspace, so this commit ensures that we always prune duplicate windows before updating the workspace layout.
This commit is contained in:
1 parent
dddd79d39d
commit
10aabdac2c
1 file changed
+51
@@ -18,6 +18,7 @@ use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
use std::num::NonZeroUsize;
|
||||
@@ -287,6 +288,55 @@ impl Workspace {
|
||||
insertion_idx
|
||||
}
|
||||
|
||||
pub fn prune_duplicate_windows(&mut self) -> eyre::Result<()> {
|
||||
let mut tracker = HashMap::new();
|
||||
let mut to_prune_from_containers = vec![];
|
||||
let mut to_prune_from_floating = vec![];
|
||||
|
||||
for container in self.containers() {
|
||||
for window in container.windows() {
|
||||
let entry = tracker.entry(window.id).or_insert(0);
|
||||
*entry += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(container) = &self.monocle_container {
|
||||
for window in container.windows() {
|
||||
let entry = tracker.entry(window.id).or_insert(0);
|
||||
*entry += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (window_id, count) in &tracker {
|
||||
if *count > 1 {
|
||||
to_prune_from_containers.push(*window_id);
|
||||
}
|
||||
}
|
||||
|
||||
for id in to_prune_from_containers {
|
||||
self.remove_window(id)?;
|
||||
tracker.remove(&id);
|
||||
}
|
||||
|
||||
for window in self.floating_windows() {
|
||||
let entry = tracker.entry(window.id).or_insert(0);
|
||||
*entry += 1;
|
||||
}
|
||||
|
||||
for (window_id, count) in &tracker {
|
||||
if *count > 1 {
|
||||
to_prune_from_floating.push(*window_id);
|
||||
}
|
||||
}
|
||||
|
||||
for id in to_prune_from_floating {
|
||||
self.remove_window(id)?;
|
||||
tracker.remove(&id);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn reap_invalid_windows_for_application(
|
||||
&mut self,
|
||||
@@ -891,6 +941,7 @@ impl Workspace {
|
||||
impl Workspace {
|
||||
pub fn update(&mut self) -> eyre::Result<()> {
|
||||
// make sure we are never holding on to empty containers
|
||||
self.prune_duplicate_windows()?;
|
||||
self.containers_mut().retain(|c| !c.windows().is_empty());
|
||||
|
||||
let container_padding = self
|
||||
|
||||
Reference in new issue
Block a user