diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index 0cfb87a7..031f70e1 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -56,7 +56,7 @@ use { utils::{ asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, linkedlist::LinkedNode, numcell::NumCell, rc_eq::rc_eq, - smallmap::SmallMap, transform_ext::TransformExt, + smallmap::SmallMap, transform_ext::TransformExt, vecset::VecSet, }, wire::{ wl_seat::*, ExtIdleNotificationV1Id, WlDataDeviceId, WlKeyboardId, WlPointerId, @@ -65,7 +65,7 @@ use { }, xkbcommon::{XkbKeymap, XkbState}, }, - ahash::{AHashMap, AHashSet}, + ahash::AHashMap, jay_config::keyboard::mods::Modifiers, smallvec::SmallVec, std::{ @@ -128,7 +128,7 @@ pub struct WlSeatGlobal { pointer_stack_modified: Cell, found_tree: RefCell>, keyboard_node: CloneCell>, - pressed_keys: RefCell>, + pressed_keys: RefCell>, bindings: RefCell>>>, x_data_devices: SmallMap, 1>, data_devices: RefCell>>>, diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index aab12a45..3a975ff0 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -742,10 +742,10 @@ impl WlSeatGlobal { // Focus callbacks impl WlSeatGlobal { pub fn focus_surface(&self, surface: &WlSurface) { - let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect(); + let pressed_keys = &*self.pressed_keys.borrow(); let serial = surface.client.next_serial(); self.surface_kb_event(Version::ALL, surface, |k| { - k.send_enter(serial, surface.id, &pressed_keys) + k.send_enter(serial, surface.id, pressed_keys) }); let ModifierState { mods_depressed, diff --git a/src/utils.rs b/src/utils.rs index 44c9a5ce..0ab8c1d3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -50,6 +50,7 @@ pub mod trim; pub mod unlink_on_drop; pub mod vec_ext; pub mod vecdeque_ext; +pub mod vecset; pub mod vecstorage; pub mod windows; pub mod xrd; diff --git a/src/utils/vecset.rs b/src/utils/vecset.rs new file mode 100644 index 00000000..6eec7272 --- /dev/null +++ b/src/utils/vecset.rs @@ -0,0 +1,39 @@ +use std::ops::Deref; + +pub struct VecSet { + vec: Vec, +} + +impl Default for VecSet { + fn default() -> Self { + Self { vec: vec![] } + } +} + +impl Deref for VecSet { + type Target = [T]; + + fn deref(&self) -> &Self::Target { + &self.vec + } +} + +impl VecSet { + pub fn insert(&mut self, val: T) -> bool { + if self.vec.contains(&val) { + return false; + } + self.vec.push(val); + true + } + + pub fn remove(&mut self, val: &T) -> bool { + for i in 0..self.vec.len() { + if self.vec[i] == *val { + self.vec.swap_remove(i); + return true; + } + } + false + } +}