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<CosmicMapped> for FocusTarget`, so the blanket
impl of `indexmap::Equivalent` won't work, but implementing seems fine.
This commit is contained in:
Ian Douglas Scott 2025-10-30 13:31:13 -07:00 committed by Ian Douglas Scott
parent 505e36dcda
commit f230a23bd0

View file

@ -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<CosmicSurface> for FocusTarget {
}
}
impl indexmap::Equivalent<FocusTarget> for CosmicMapped {
fn equivalent(&self, key: &FocusTarget) -> bool {
key == self
}
}
impl indexmap::Equivalent<FocusTarget> for CosmicSurface {
fn equivalent(&self, key: &FocusTarget) -> bool {
key == self
}
}
impl From<CosmicMapped> for FocusTarget {
fn from(value: CosmicMapped) -> Self {
Self::Window(value)
@ -119,9 +131,9 @@ impl FocusStackMut<'_> {
pub fn remove<T>(&mut self, target: &T)
where
FocusTarget: PartialEq<T>,
T: Hash + indexmap::Equivalent<FocusTarget>,
{
self.0.retain(|w| w != target);
self.0.shift_remove(target);
}
pub fn last(&self) -> Option<&FocusTarget> {