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

Conversation

valaphee
Copy link
Contributor

@valaphee valaphee commented Feb 18, 2024

While trying out gamepad device events for X11, I noticed some issues:

  • deviceId is useless, as it always is either the value of the virtual keyboard or virtual pointing device, even though the real deviceId is known and supplied via sourceid, which is only used for raw keyboard events.

This PRs goal is to address both issues.

  • Tested on all platforms changed
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

@kchibisov
Copy link
Member

Wayland, I noticed some issues:

I'm not sure you can get access to HID on wayland and open thing yourself, most just ship udev rules, but that's just wrong, there's a protocol in works for things like that, but that's about it.

On X11, I guess you pass xid and user needs special access for thing to work as well?

src/platform_impl/linux/x11/event_processor.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/x11/event_processor.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/x11/event_processor.rs Outdated Show resolved Hide resolved
@@ -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.

@@ -1448,15 +1448,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) {
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.

@valaphee
Copy link
Contributor Author

valaphee commented Feb 19, 2024

Wayland, I noticed some issues:

I'm not sure you can get access to HID on wayland and open thing yourself, most just ship udev rules, but that's just wrong, there's a protocol in works for things like that, but that's about it.

On X11, I guess you pass xid and user needs special access for thing to work as well?

Gilrs is using udev for both Wayland and X11 (and parsing the raw hid reports, like I do on Windows). But theoretically it could easily be done through XI2 https://www.x.org/releases/current/doc/man/man4/joystick.4.xhtml for X11.

@valaphee
Copy link
Contributor Author

valaphee commented Feb 21, 2024

Switched raw mouse input it back to using raw_values, as otherwise it would be useless, and #3500 should not occur in games, where its normally used, at least when they don't utilize multiple screens on X11.

P.S. after some testing with Bevy, it seems that it doesn't occur at all there

@valaphee valaphee marked this pull request as ready for review February 27, 2024 20:27
@valaphee valaphee changed the title X11: small tweaks for input handling X11: use sourceid instead of deviceid for input events Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

4 participants