From f230a23bd0358ec15b03c63fa7c5c0072cedead1 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 30 Oct 2025 13:31:13 -0700 Subject: [PATCH] focus-stack: Use `IndexSet::shift_remove()` for `remove` This seems like the correct way to use an `IndexSet`. It shouldn't be possible to have multiple entries that match, since it's a "set". We can't define `Borrow for FocusTarget`, so the blanket impl of `indexmap::Equivalent` won't work, but implementing seems fine. --- src/shell/focus/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/shell/focus/mod.rs b/src/shell/focus/mod.rs index 916b2493..6b8830d5 100644 --- a/src/shell/focus/mod.rs +++ b/src/shell/focus/mod.rs @@ -17,7 +17,7 @@ use smithay::{ shell::wlr_layer::{KeyboardInteractivity, Layer}, }, }; -use std::{borrow::Cow, mem, sync::Mutex}; +use std::{borrow::Cow, hash::Hash, mem, sync::Mutex}; use tracing::{debug, trace}; @@ -47,6 +47,18 @@ impl PartialEq for FocusTarget { } } +impl indexmap::Equivalent for CosmicMapped { + fn equivalent(&self, key: &FocusTarget) -> bool { + key == self + } +} + +impl indexmap::Equivalent for CosmicSurface { + fn equivalent(&self, key: &FocusTarget) -> bool { + key == self + } +} + impl From for FocusTarget { fn from(value: CosmicMapped) -> Self { Self::Window(value) @@ -119,9 +131,9 @@ impl FocusStackMut<'_> { pub fn remove(&mut self, target: &T) where - FocusTarget: PartialEq, + T: Hash + indexmap::Equivalent, { - self.0.retain(|w| w != target); + self.0.shift_remove(target); } pub fn last(&self) -> Option<&FocusTarget> {