Add X11 opt-in function for device events

Previously on X11, by default all global events were broadcasted to
every winit application. This unnecessarily drains battery due to
excessive CPU usage when moving the mouse.

To resolve this, device events are now ignored by default and users must
manually opt into it using
`EventLoopWindowTarget::set_filter_device_events`.

Fixes (#1634) on Linux.
This commit is contained in:
Christian Duerr 2022-06-07 23:17:45 +02:00 committed by GitHub
parent c7f7181388
commit f10a984ba3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 108 additions and 32 deletions

View file

@ -49,7 +49,7 @@ impl<T: 'static> EventProcessor<T> {
let mut devices = self.devices.borrow_mut();
if let Some(info) = DeviceInfo::get(&wt.xconn, device) {
for info in info.iter() {
devices.insert(DeviceId(info.deviceid), Device::new(self, info));
devices.insert(DeviceId(info.deviceid), Device::new(info));
}
}
}
@ -907,6 +907,8 @@ impl<T: 'static> EventProcessor<T> {
if self.active_window != Some(xev.event) {
self.active_window = Some(xev.event);
wt.update_device_event_filter(true);
let window_id = mkwid(xev.event);
let position = PhysicalPosition::new(xev.event_x, xev.event_y);
@ -956,6 +958,7 @@ impl<T: 'static> EventProcessor<T> {
if !self.window_exists(xev.event) {
return;
}
wt.ime
.borrow_mut()
.unfocus(xev.event)
@ -964,6 +967,8 @@ impl<T: 'static> EventProcessor<T> {
if self.active_window.take() == Some(xev.event) {
let window_id = mkwid(xev.event);
wt.update_device_event_filter(false);
// Issue key release events for all pressed keys
Self::handle_pressed_keys(
wt,