-
Notifications
You must be signed in to change notification settings - Fork 924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
X11: use sourceid instead of deviceid for input events #3501
Open
valaphee
wants to merge
6
commits into
rust-windowing:master
Choose a base branch
from
valaphee:xi-raw-mm-and-ids
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+24
−13
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c56dd12
Use sourceid instead of deviceid, replace raw_values with valuators.v…
valaphee f39971e
Revert to using raw_values, add comments to why prefering sourceid ov…
valaphee 311f84c
Rustfmt
valaphee da6aa68
Do zero check first in rmm event
valaphee f258abf
Also filter out normal mouse events when value is 0
valaphee 6e84547
Use single comment, and state that it requires XI2.1
valaphee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -979,12 +979,15 @@ impl EventProcessor { | |||||
F: FnMut(&RootELW, Event<T>), | ||||||
{ | ||||||
let wt = Self::window_target(&self.target); | ||||||
let window_id = mkwid(event.event as xproto::Window); | ||||||
let device_id = mkdid(event.deviceid as xinput::DeviceId); | ||||||
|
||||||
// Set the timestamp. | ||||||
wt.xconn.set_timestamp(event.time as xproto::Timestamp); | ||||||
|
||||||
let window_id = mkwid(event.event as xproto::Window); | ||||||
// Use sourceid instead of deviceid, as deviceid is typically the device's class id. | ||||||
// Note that this requires XInput 2.1. | ||||||
let device_id = mkdid(event.sourceid as xinput::DeviceId); | ||||||
|
||||||
// Deliver multi-touch events instead of emulated mouse events. | ||||||
if (event.flags & xinput2::XIPointerEmulated) != 0 { | ||||||
return; | ||||||
|
@@ -1053,9 +1056,9 @@ impl EventProcessor { | |||||
// Set the timestamp. | ||||||
wt.xconn.set_timestamp(event.time as xproto::Timestamp); | ||||||
|
||||||
let device_id = mkdid(event.deviceid as xinput::DeviceId); | ||||||
let window = event.event as xproto::Window; | ||||||
let window_id = mkwid(window); | ||||||
let device_id = mkdid(event.sourceid as xinput::DeviceId); | ||||||
let new_cursor_pos = (event.event_x, event.event_y); | ||||||
|
||||||
let cursor_moved = self.with_window(window, |window| { | ||||||
|
@@ -1096,6 +1099,9 @@ impl EventProcessor { | |||||
} | ||||||
|
||||||
let x = unsafe { *value }; | ||||||
if x == 0.0 { | ||||||
continue; | ||||||
} | ||||||
|
||||||
let event = if let Some(&mut (_, ref mut info)) = physical_device | ||||||
.scroll_axes | ||||||
|
@@ -1121,7 +1127,7 @@ impl EventProcessor { | |||||
WindowEvent::AxisMotion { | ||||||
device_id, | ||||||
axis: i as u32, | ||||||
value: unsafe { *value }, | ||||||
value: x, | ||||||
} | ||||||
}; | ||||||
|
||||||
|
@@ -1146,7 +1152,7 @@ impl EventProcessor { | |||||
|
||||||
let window = event.event as xproto::Window; | ||||||
let window_id = mkwid(window); | ||||||
let device_id = mkdid(event.deviceid as xinput::DeviceId); | ||||||
let device_id = mkdid(event.sourceid as xinput::DeviceId); | ||||||
|
||||||
if let Some(all_info) = DeviceInfo::get(&wt.xconn, super::ALL_DEVICES.into()) { | ||||||
let mut devices = self.devices.borrow_mut(); | ||||||
|
@@ -1202,7 +1208,7 @@ impl EventProcessor { | |||||
let event = Event::WindowEvent { | ||||||
window_id: mkwid(window), | ||||||
event: WindowEvent::CursorLeft { | ||||||
device_id: mkdid(event.deviceid as xinput::DeviceId), | ||||||
device_id: mkdid(event.sourceid as xinput::DeviceId), | ||||||
}, | ||||||
}; | ||||||
callback(&self.target, event); | ||||||
|
@@ -1265,7 +1271,7 @@ impl EventProcessor { | |||||
let pointer_id = self | ||||||
.devices | ||||||
.borrow() | ||||||
.get(&DeviceId(xev.deviceid as xinput::DeviceId)) | ||||||
.get(&DeviceId(xev.sourceid as xinput::DeviceId)) | ||||||
.map(|device| device.attachment) | ||||||
.unwrap_or(2); | ||||||
|
||||||
|
@@ -1366,7 +1372,7 @@ impl EventProcessor { | |||||
let event = Event::WindowEvent { | ||||||
window_id, | ||||||
event: WindowEvent::Touch(Touch { | ||||||
device_id: mkdid(xev.deviceid as xinput::DeviceId), | ||||||
device_id: mkdid(xev.sourceid as xinput::DeviceId), | ||||||
phase, | ||||||
location, | ||||||
force: None, // TODO | ||||||
|
@@ -1392,7 +1398,7 @@ impl EventProcessor { | |||||
|
||||||
if xev.flags & xinput2::XIPointerEmulated == 0 { | ||||||
let event = Event::DeviceEvent { | ||||||
device_id: mkdid(xev.deviceid as xinput::DeviceId), | ||||||
device_id: mkdid(xev.sourceid as xinput::DeviceId), | ||||||
event: DeviceEvent::Button { | ||||||
state, | ||||||
button: xev.detail as u32, | ||||||
|
@@ -1411,7 +1417,7 @@ impl EventProcessor { | |||||
// Set the timestamp. | ||||||
wt.xconn.set_timestamp(xev.time as xproto::Timestamp); | ||||||
|
||||||
let did = mkdid(xev.deviceid as xinput::DeviceId); | ||||||
let device_id = mkdid(xev.sourceid as xinput::DeviceId); | ||||||
|
||||||
let mask = | ||||||
unsafe { slice::from_raw_parts(xev.valuators.mask, xev.valuators.mask_len as usize) }; | ||||||
|
@@ -1422,7 +1428,11 @@ impl EventProcessor { | |||||
if !xinput2::XIMaskIsSet(mask, i) { | ||||||
continue; | ||||||
} | ||||||
|
||||||
let x = unsafe { *value }; | ||||||
if x == 0.0 { | ||||||
continue; | ||||||
} | ||||||
|
||||||
// We assume that every XInput2 device with analog axes is a pointing device emitting | ||||||
// relative coordinates. | ||||||
|
@@ -1435,7 +1445,7 @@ impl EventProcessor { | |||||
} | ||||||
|
||||||
let event = Event::DeviceEvent { | ||||||
device_id: did, | ||||||
device_id, | ||||||
event: DeviceEvent::Motion { | ||||||
axis: i as u32, | ||||||
value: x, | ||||||
|
@@ -1448,15 +1458,15 @@ impl EventProcessor { | |||||
|
||||||
if mouse_delta != (0.0, 0.0) { | ||||||
let event = Event::DeviceEvent { | ||||||
device_id: did, | ||||||
device_id, | ||||||
event: DeviceEvent::MouseMotion { delta: mouse_delta }, | ||||||
}; | ||||||
callback(&self.target, event); | ||||||
} | ||||||
|
||||||
if scroll_delta != (0.0, 0.0) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Ditto. |
||||||
let event = Event::DeviceEvent { | ||||||
device_id: did, | ||||||
device_id, | ||||||
event: DeviceEvent::MouseWheel { | ||||||
delta: MouseScrollDelta::LineDelta(scroll_delta.0, scroll_delta.1), | ||||||
}, | ||||||
|
@@ -1479,6 +1489,7 @@ impl EventProcessor { | |||||
wt.xconn.set_timestamp(xev.time as xproto::Timestamp); | ||||||
|
||||||
let device_id = mkdid(xev.sourceid as xinput::DeviceId); | ||||||
|
||||||
let keycode = xev.detail as u32; | ||||||
if keycode < KEYCODE_OFFSET as u32 { | ||||||
return; | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the issue might be that floating point comparisons like this are imprecise. So this should filter out any "garbage" values.