We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5308

Summary: [patch] udev fallback path is not detecting some "key" devices
Product: SDL Reporter: Luca Weiss <luca+bugzilla>
Component: eventsAssignee: Ozkan Sezer <sezeroz>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: HG 2.1Keywords: target-2.0.16
Hardware: ARM   
OS: Linux   
Attachments: patch file
updated patch for 2.0.14

Description Luca Weiss 2020-10-06 15:22:34 UTC
Created attachment 4476 [details]
patch file

The udev code labels devices that are found by this code with
ID_INPUT_KEY which in turn gets used by SDL to label the devices as
SDL_UDEV_DEVICE_KEYBOARD.
    
This was missing for the code path when udev is not running and as such
devices such as the power button of a phone was not detected as keyboard
input and no devices were emitted.

---

I've also noticed that the commit/revision(?) https://hg.libsdl.org/SDL/rev/2b2cfda26085 tries to do that somewhat but it only looks at the first 32 bits instead of also at the rest of the bits. This results in the behavior that e.g. the power button driver axp20x-pek of the Allwinner A64 platform doesn't get labelled as keyboard which results in no events being emitted to applications using sdl.

Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 116 (KEY_POWER)

In the normal code path where udev properties get used this works because udev correctly labels the device as ID_INPUT_KEY which sdl then uses for SDL_UDEV_DEVICE_KEYBOARD, but it didn't work for the fallback codepath for when udev isn't running (e.g. in initramfs where only busybox mdev is used)

**Also note** that the code is pretty much copied from systemd/udev code, I'm not sure about the licensing side of things - but also I don't think the code can be written much different but please know that.
Comment 1 Ozkan Sezer 2020-11-12 04:20:39 UTC
Is this still an issue with current hg?
Comment 2 Luca Weiss 2020-11-12 16:47:07 UTC
Tested on revision e57fffe5bf89
The guess_device_class function still returns 0 for this input device so this 
is still an issue.
Comment 3 Ozkan Sezer 2020-11-13 08:37:53 UTC
The patch doesn't apply to current hg.
Comment 4 Ozkan Sezer 2020-12-10 08:59:37 UTC
Is there an updated / rebased patch?
Comment 5 Ozkan Sezer 2020-12-12 10:51:36 UTC
Created attachment 4575 [details]
updated patch for 2.0.14

Rebased the original patch to current hg: Compile-tested only.
Luca Weiss: Is it functional?  Sam, Ryan: Please review.
Comment 6 Luca Weiss 2020-12-27 12:10:35 UTC
@Ozkan Sezer: Works fine, thanks for rebasing! (It's quite annoying to get the test setup working which is why my replies have been slow here.)
Comment 7 Ozkan Sezer 2020-12-27 13:14:55 UTC
(In reply to Luca Weiss from comment #6)
> @Ozkan Sezer: Works fine, thanks for rebasing! (It's quite annoying to get
> the test setup working which is why my replies have been slow here.)

OK then.

Ryan and/or Sam:  Is this OK to apply?
Comment 8 Sam Lantinga 2020-12-27 21:10:05 UTC
Yes, this is fine to apply. Thanks!
Comment 9 Ozkan Sezer 2020-12-27 21:55:44 UTC
(In reply to Sam Lantinga from comment #8)
> Yes, this is fine to apply. Thanks!

Patch applied as https://hg.libsdl.org/SDL/rev/416199662658
Closing as fixed.