Skip to content
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
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl EventProcessor {
{
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);
let device_id = mkdid(event.sourceid as xinput::DeviceId);
valaphee marked this conversation as resolved.
Show resolved Hide resolved

// Set the timestamp.
wt.xconn.set_timestamp(event.time as xproto::Timestamp);
Expand Down Expand Up @@ -1053,7 +1053,7 @@ impl EventProcessor {
// Set the timestamp.
wt.xconn.set_timestamp(event.time as xproto::Timestamp);

let device_id = mkdid(event.deviceid as xinput::DeviceId);
let device_id = mkdid(event.sourceid as xinput::DeviceId);
valaphee marked this conversation as resolved.
Show resolved Hide resolved
let window = event.event as xproto::Window;
let window_id = mkwid(window);
let new_cursor_pos = (event.event_x, event.event_y);
Expand Down Expand Up @@ -1146,7 +1146,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();
Expand Down Expand Up @@ -1202,7 +1202,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);
Expand Down Expand Up @@ -1265,7 +1265,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);

Expand Down Expand Up @@ -1366,7 +1366,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
Expand All @@ -1392,7 +1392,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,
Expand All @@ -1411,11 +1411,11 @@ 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) };
let mut value = xev.raw_values;
let mut value = xev.valuators.values;
valaphee marked this conversation as resolved.
Show resolved Hide resolved
let mut mouse_delta = (0.0, 0.0);
let mut scroll_delta = (0.0, 0.0);
for i in 0..xev.valuators.mask_len * 8 {
Expand All @@ -1435,7 +1435,7 @@ impl EventProcessor {
}

let event = Event::DeviceEvent {
device_id: did,
device_id,
event: DeviceEvent::Motion {
axis: i as u32,
value: x,
Expand All @@ -1448,15 +1448,15 @@ impl EventProcessor {

if mouse_delta != (0.0, 0.0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if mouse_delta != (0.0, 0.0) {
if mouse_delta.0.abs() > 0.0001 || mouse_delta.1.abs() > 0.0001 {

Part of the issue might be that floating point comparisons like this are imprecise. So this should filter out any "garbage" values.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if scroll_delta != (0.0, 0.0) {
if scroll_delta.0.abs() > 0.0001 || scroll_delta.1.abs() > 0.0001 {

Ditto.

let event = Event::DeviceEvent {
device_id: did,
device_id,
event: DeviceEvent::MouseWheel {
delta: MouseScrollDelta::LineDelta(scroll_delta.0, scroll_delta.1),
},
Expand Down