seat: store pressed keys in a vector
This commit is contained in:
parent
2cef936b12
commit
8d43eebc3d
4 changed files with 45 additions and 5 deletions
|
|
@ -56,7 +56,7 @@ use {
|
||||||
utils::{
|
utils::{
|
||||||
asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap,
|
asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap,
|
||||||
errorfmt::ErrorFmt, linkedlist::LinkedNode, numcell::NumCell, rc_eq::rc_eq,
|
errorfmt::ErrorFmt, linkedlist::LinkedNode, numcell::NumCell, rc_eq::rc_eq,
|
||||||
smallmap::SmallMap, transform_ext::TransformExt,
|
smallmap::SmallMap, transform_ext::TransformExt, vecset::VecSet,
|
||||||
},
|
},
|
||||||
wire::{
|
wire::{
|
||||||
wl_seat::*, ExtIdleNotificationV1Id, WlDataDeviceId, WlKeyboardId, WlPointerId,
|
wl_seat::*, ExtIdleNotificationV1Id, WlDataDeviceId, WlKeyboardId, WlPointerId,
|
||||||
|
|
@ -65,7 +65,7 @@ use {
|
||||||
},
|
},
|
||||||
xkbcommon::{XkbKeymap, XkbState},
|
xkbcommon::{XkbKeymap, XkbState},
|
||||||
},
|
},
|
||||||
ahash::{AHashMap, AHashSet},
|
ahash::AHashMap,
|
||||||
jay_config::keyboard::mods::Modifiers,
|
jay_config::keyboard::mods::Modifiers,
|
||||||
smallvec::SmallVec,
|
smallvec::SmallVec,
|
||||||
std::{
|
std::{
|
||||||
|
|
@ -128,7 +128,7 @@ pub struct WlSeatGlobal {
|
||||||
pointer_stack_modified: Cell<bool>,
|
pointer_stack_modified: Cell<bool>,
|
||||||
found_tree: RefCell<Vec<FoundNode>>,
|
found_tree: RefCell<Vec<FoundNode>>,
|
||||||
keyboard_node: CloneCell<Rc<dyn Node>>,
|
keyboard_node: CloneCell<Rc<dyn Node>>,
|
||||||
pressed_keys: RefCell<AHashSet<u32>>,
|
pressed_keys: RefCell<VecSet<u32>>,
|
||||||
bindings: RefCell<AHashMap<ClientId, AHashMap<WlSeatId, Rc<WlSeat>>>>,
|
bindings: RefCell<AHashMap<ClientId, AHashMap<WlSeatId, Rc<WlSeat>>>>,
|
||||||
x_data_devices: SmallMap<XIpcDeviceId, Rc<XIpcDevice>, 1>,
|
x_data_devices: SmallMap<XIpcDeviceId, Rc<XIpcDevice>, 1>,
|
||||||
data_devices: RefCell<AHashMap<ClientId, AHashMap<WlDataDeviceId, Rc<WlDataDevice>>>>,
|
data_devices: RefCell<AHashMap<ClientId, AHashMap<WlDataDeviceId, Rc<WlDataDevice>>>>,
|
||||||
|
|
|
||||||
|
|
@ -742,10 +742,10 @@ impl WlSeatGlobal {
|
||||||
// Focus callbacks
|
// Focus callbacks
|
||||||
impl WlSeatGlobal {
|
impl WlSeatGlobal {
|
||||||
pub fn focus_surface(&self, surface: &WlSurface) {
|
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();
|
let serial = surface.client.next_serial();
|
||||||
self.surface_kb_event(Version::ALL, surface, |k| {
|
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 {
|
let ModifierState {
|
||||||
mods_depressed,
|
mods_depressed,
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ pub mod trim;
|
||||||
pub mod unlink_on_drop;
|
pub mod unlink_on_drop;
|
||||||
pub mod vec_ext;
|
pub mod vec_ext;
|
||||||
pub mod vecdeque_ext;
|
pub mod vecdeque_ext;
|
||||||
|
pub mod vecset;
|
||||||
pub mod vecstorage;
|
pub mod vecstorage;
|
||||||
pub mod windows;
|
pub mod windows;
|
||||||
pub mod xrd;
|
pub mod xrd;
|
||||||
|
|
|
||||||
39
src/utils/vecset.rs
Normal file
39
src/utils/vecset.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
pub struct VecSet<T> {
|
||||||
|
vec: Vec<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Default for VecSet<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { vec: vec![] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Deref for VecSet<T> {
|
||||||
|
type Target = [T];
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.vec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: PartialEq> VecSet<T> {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue