From 94b3ce8e6f90d620ae81b7fca3fa77c6fc224c50 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Tue, 21 Dec 2021 20:11:03 +0100 Subject: [PATCH] x11: Add virtual Device{Added, Removed} events --- src/backend/x11/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/backend/x11/mod.rs b/src/backend/x11/mod.rs index 1a9bf6a..a32d48f 100644 --- a/src/backend/x11/mod.rs +++ b/src/backend/x11/mod.rs @@ -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.