wayland: implement pointer-gestures-unstable-v1
This commit is contained in:
parent
afc360ea85
commit
ee24971c6d
24 changed files with 1589 additions and 18 deletions
|
|
@ -1,10 +1,11 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientId},
|
||||
object::{Object, ObjectId},
|
||||
object::{Object, ObjectId, Version},
|
||||
utils::copyhashmap::{CopyHashMap, Locked},
|
||||
},
|
||||
std::rc::Rc,
|
||||
ahash::AHashMap,
|
||||
std::{cell::RefCell, collections::hash_map::Entry, rc::Rc},
|
||||
};
|
||||
|
||||
pub struct Bindings<P> {
|
||||
|
|
@ -37,3 +38,50 @@ impl<P: Object> Bindings<P> {
|
|||
self.bindings.lock()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PerClientBindings<P> {
|
||||
bindings: RefCell<AHashMap<ClientId, AHashMap<ObjectId, Rc<P>>>>,
|
||||
}
|
||||
|
||||
impl<P> Default for PerClientBindings<P> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bindings: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Object> PerClientBindings<P> {
|
||||
pub fn add(&self, client: &Client, obj: &Rc<P>) {
|
||||
let prev = self
|
||||
.bindings
|
||||
.borrow_mut()
|
||||
.entry(client.id)
|
||||
.or_default()
|
||||
.insert(obj.id(), obj.clone());
|
||||
assert!(prev.is_none());
|
||||
}
|
||||
|
||||
pub fn remove(&self, client: &Client, obj: &P) {
|
||||
if let Entry::Occupied(mut oe) = self.bindings.borrow_mut().entry(client.id) {
|
||||
oe.get_mut().remove(&obj.id());
|
||||
if oe.get().is_empty() {
|
||||
oe.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
self.bindings.borrow_mut().clear();
|
||||
}
|
||||
|
||||
pub fn for_each(&self, client: ClientId, version: Version, mut f: impl FnMut(&P)) {
|
||||
if let Some(bindings) = self.bindings.borrow().get(&client) {
|
||||
for obj in bindings.values() {
|
||||
if obj.version() >= version {
|
||||
f(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue