x11: Add virtual Device{Added, Removed} events

This commit is contained in:
Victor Brekenfeld 2021-12-21 20:11:03 +01:00
parent cc6225ce21
commit 94b3ce8e6f
1 changed files with 21 additions and 0 deletions

View File

@ -610,6 +610,27 @@ impl X11Inner {
where
F: FnMut(X11Event, &mut ()),
{
{
let mut inner = inner.lock().unwrap();
if !inner.windows.is_empty() && !inner.devices {
callback(
Input(InputEvent::DeviceAdded {
device: X11VirtualDevice,
}),
&mut (),
);
inner.devices = true;
} else if inner.windows.is_empty() && inner.devices {
callback(
Input(InputEvent::DeviceRemoved {
device: X11VirtualDevice,
}),
&mut (),
);
inner.devices = false;
}
}
use self::X11Event::Input;
// If X11 is deadlocking somewhere here, make sure you drop your mutex guards.