mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-15 01:21:30 +03:00
fix left over capture barrier
This commit is contained in:
@@ -132,31 +132,35 @@ pub struct InputCapture {
|
|||||||
impl InputCapture {
|
impl InputCapture {
|
||||||
/// create a new client with the given id
|
/// create a new client with the given id
|
||||||
pub async fn create(&mut self, id: CaptureHandle, pos: Position) -> Result<(), CaptureError> {
|
pub async fn create(&mut self, id: CaptureHandle, pos: Position) -> Result<(), CaptureError> {
|
||||||
|
assert!(!self.id_map.contains_key(&id));
|
||||||
|
|
||||||
|
self.id_map.insert(id, pos);
|
||||||
|
|
||||||
if let Some(v) = self.position_map.get_mut(&pos) {
|
if let Some(v) = self.position_map.get_mut(&pos) {
|
||||||
v.push(id);
|
v.push(id);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
self.position_map.insert(pos, vec![id]);
|
self.position_map.insert(pos, vec![id]);
|
||||||
self.id_map.insert(id, pos);
|
|
||||||
self.capture.create(pos).await
|
self.capture.create(pos).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// destroy the client with the given id, if it exists
|
/// destroy the client with the given id, if it exists
|
||||||
pub async fn destroy(&mut self, id: CaptureHandle) -> Result<(), CaptureError> {
|
pub async fn destroy(&mut self, id: CaptureHandle) -> Result<(), CaptureError> {
|
||||||
if let Some(pos) = self.id_map.remove(&id) {
|
let pos = self
|
||||||
let destroy = if let Some(v) = self.position_map.get_mut(&pos) {
|
.id_map
|
||||||
v.retain(|&i| i != id);
|
.remove(&id)
|
||||||
// we were the last id registered at this position
|
.expect("no position for this handle");
|
||||||
v.is_empty()
|
|
||||||
} else {
|
log::debug!("destroying capture {id} @ {pos}");
|
||||||
// nothing to destroy
|
let remaining = self.position_map.get_mut(&pos).expect("id vector");
|
||||||
false
|
remaining.retain(|&i| i != id);
|
||||||
};
|
|
||||||
if destroy {
|
log::debug!("remaining ids @ {pos}: {remaining:?}");
|
||||||
self.position_map.remove(&pos);
|
if remaining.is_empty() {
|
||||||
self.capture.destroy(pos).await?;
|
log::debug!("destroying capture @ {pos} - no remaining ids");
|
||||||
}
|
self.position_map.remove(&pos);
|
||||||
|
self.capture.destroy(pos).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user