Skip to content

Commit f230a23

Browse files
committed
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.
1 parent 505e36d commit f230a23

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/shell/focus/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use smithay::{
1717
shell::wlr_layer::{KeyboardInteractivity, Layer},
1818
},
1919
};
20-
use std::{borrow::Cow, mem, sync::Mutex};
20+
use std::{borrow::Cow, hash::Hash, mem, sync::Mutex};
2121

2222
use tracing::{debug, trace};
2323

@@ -47,6 +47,18 @@ impl PartialEq<CosmicSurface> for FocusTarget {
4747
}
4848
}
4949

50+
impl indexmap::Equivalent<FocusTarget> for CosmicMapped {
51+
fn equivalent(&self, key: &FocusTarget) -> bool {
52+
key == self
53+
}
54+
}
55+
56+
impl indexmap::Equivalent<FocusTarget> for CosmicSurface {
57+
fn equivalent(&self, key: &FocusTarget) -> bool {
58+
key == self
59+
}
60+
}
61+
5062
impl From<CosmicMapped> for FocusTarget {
5163
fn from(value: CosmicMapped) -> Self {
5264
Self::Window(value)
@@ -119,9 +131,9 @@ impl FocusStackMut<'_> {
119131

120132
pub fn remove<T>(&mut self, target: &T)
121133
where
122-
FocusTarget: PartialEq<T>,
134+
T: Hash + indexmap::Equivalent<FocusTarget>,
123135
{
124-
self.0.retain(|w| w != target);
136+
self.0.shift_remove(target);
125137
}
126138

127139
pub fn last(&self) -> Option<&FocusTarget> {

0 commit comments

Comments
 (0)