mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
X11 - Ignore scroll events that happen outside of Glutin windows
Scroll deltas are calculated in X11 by comparing the current and previous absolute values for the scroll axis when a scroll motion event is received. If the user scrolls whilst the cursor is outside of the window then an incorrect delta is reported when the cursor re-enters the window. Fix this by resetting the last-seen axis values whenever the cursor re-enters the window.
This commit is contained in:
parent
cb08d9b05b
commit
edc95d554d
|
@ -75,7 +75,7 @@ impl XInputEventHandler {
|
||||||
// Button clicks and mouse events are handled via XInput
|
// Button clicks and mouse events are handled via XInput
|
||||||
// events. Key presses are still handled via plain core
|
// events. Key presses are still handled via plain core
|
||||||
// X11 events.
|
// X11 events.
|
||||||
let mut mask: [libc::c_uchar; 1] = [0];
|
let mut mask: [libc::c_uchar; 2] = [0, 0];
|
||||||
let mut input_event_mask = ffi::XIEventMask {
|
let mut input_event_mask = ffi::XIEventMask {
|
||||||
deviceid: ffi::XIAllDevices,
|
deviceid: ffi::XIAllDevices,
|
||||||
mask_len: mask.len() as i32,
|
mask_len: mask.len() as i32,
|
||||||
|
@ -84,7 +84,9 @@ impl XInputEventHandler {
|
||||||
let events = &[
|
let events = &[
|
||||||
ffi::XI_ButtonPress,
|
ffi::XI_ButtonPress,
|
||||||
ffi::XI_ButtonRelease,
|
ffi::XI_ButtonRelease,
|
||||||
ffi::XI_Motion
|
ffi::XI_Motion,
|
||||||
|
ffi::XI_Enter,
|
||||||
|
ffi::XI_Leave
|
||||||
];
|
];
|
||||||
for event in events {
|
for event in events {
|
||||||
ffi::XISetMask(&mut mask, *event);
|
ffi::XISetMask(&mut mask, *event);
|
||||||
|
@ -224,6 +226,16 @@ impl XInputEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
ffi::XI_Enter => {
|
||||||
|
// axis movements whilst the cursor is outside the window
|
||||||
|
// will alter the absolute value of the axes. We only want to
|
||||||
|
// report changes in the axis value whilst the cursor is above
|
||||||
|
// our window however, so clear the previous axis state whenever
|
||||||
|
// the cursor re-enters the window
|
||||||
|
self.current_state.axis_values.clear();
|
||||||
|
None
|
||||||
|
},
|
||||||
|
ffi::XI_Leave => None,
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ use std::{mem, ptr};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::slice::from_raw_parts;
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use Api;
|
use Api;
|
||||||
|
@ -23,7 +22,7 @@ use api::egl::Context as EglContext;
|
||||||
use platform::MonitorID as PlatformMonitorID;
|
use platform::MonitorID as PlatformMonitorID;
|
||||||
|
|
||||||
use super::input::XInputEventHandler;
|
use super::input::XInputEventHandler;
|
||||||
use super::{events, ffi};
|
use super::{ffi};
|
||||||
use super::{MonitorID, XConnection};
|
use super::{MonitorID, XConnection};
|
||||||
|
|
||||||
// XOpenIM doesn't seem to be thread-safe
|
// XOpenIM doesn't seem to be thread-safe
|
||||||
|
|
Loading…
Reference in a new issue