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:
parent
505e36dcda
commit
f230a23bd0
1 changed files with 15 additions and 3 deletions
|
|
@ -17,7 +17,7 @@ use smithay::{
|
||||||
shell::wlr_layer::{KeyboardInteractivity, Layer},
|
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};
|
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 {
|
impl From<CosmicMapped> for FocusTarget {
|
||||||
fn from(value: CosmicMapped) -> Self {
|
fn from(value: CosmicMapped) -> Self {
|
||||||
Self::Window(value)
|
Self::Window(value)
|
||||||
|
|
@ -119,9 +131,9 @@ impl FocusStackMut<'_> {
|
||||||
|
|
||||||
pub fn remove<T>(&mut self, target: &T)
|
pub fn remove<T>(&mut self, target: &T)
|
||||||
where
|
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> {
|
pub fn last(&self) -> Option<&FocusTarget> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue