Use evdev for gamepads on Linux/FreeBSD
Categories
(Core :: DOM: Device Interfaces, enhancement)
Tracking
()
People
(Reporter: val, Assigned: evilpies)
References
(Blocks 2 open bugs)
Details
Attachments
(1 file, 3 obsolete files)
Currently, Firefox uses Linux's legacy joystick API (https://www.kernel.org/doc/html/latest/input/joydev/joystick-api.html) which
- is limited to 2 axes
- does not support analog triggers
- does not have well-defined driver-agnostic meaningful mappings
- does not support rumble, LED, etc.
- is not implemented on FreeBSD :)
- discouraged by Linux kernel docs: "Newer clients are encouraged to switch to the generic event (evdev) interface"
I just wrote a patch that switches this to evdev.
It should resolve bug 1643358, maybe bug 1650152, bug 1523355, and is a prerequisite for rumble/LED/etc. support (I see in bug 680289 someone tried to use evdev only for these extras, keeping legacy joystick for the core input, which is… uh, very silly.)
Reporter | ||
Comment 1•4 years ago
|
||
Switch from the legacy Linux joystick API to the generic evdev API.
- BTN_GAMEPAD semantic buttons are interpreted directly,
since all kernel drivers are supposed to use them correctly:
https://www.kernel.org/doc/html/latest/input/gamepad.html - BTN_JOYSTICK legacy style numbered buttons use the model specific remappers
- using evdev is a prerequisite for adding rumble (haptic feedback) and other extras
- the Linux gamepad module is enabled on FreeBSD, because
FreeBSD provides evdev, and libudev-devd provides enough of libudev
(evdev headers are provided by the devel/evdev-proto package)
Reporter | ||
Updated•4 years ago
|
Can be enabled on DragonFly
as well as it has prerequisites:
https://github.com/DragonFlyBSD/DragonFlyBSD/commits/master/sys/dev/misc/evdev
https://github.com/DragonFlyBSD/DeltaPorts/tree/master/ports/devel/libudev-devd
https://sting.dragonflybsd.org/dports/logs/devel___libudev-devd.log
Comment on attachment 9191539 [details]
Bug 1680982 - Use evdev instead of the Linux legacy joystick API for gamepads
Clang in C++ mode seems to trip on -Wmissing-braces
(via -Wall
) despite https://github.com/llvm/llvm-project/commit/fa52e00c85ce
$ c++ --version
FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe)
Target: x86_64-unknown-freebsd13.0
Thread model: posix
InstalledDir: /usr/bin
$ echo "ac_add_options --enable-warnings-as-errors" >>.mozconfig
$ ./mach build
[...]
In file included from Unified_cpp_dom_gamepad0.cpp:137:
dom/gamepad/linux/LinuxGamepad.cpp:363:33: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
struct input_event event = {0};
^
{}
1 error generated.
$ clang a.c -Wall
$ clang -xc++ a.c -Wall
a.c:13:31: warning: suggest braces around initialization of subobject [-Wmissing-braces]
struct input_event event = {0};
^
{}
1 warning generated.
$ cat a.c
struct input_event {
struct {
long tv_sec;
long tv_usec;
} time;
unsigned short type;
unsigned short code;
int value;
};
int main()
{
struct input_event event = {0};
(void)event;
return 0;
}
Updated•4 years ago
|
Comment 4•3 years ago
|
||
The bug has a release status flag that shows some version of Firefox is affected, thus it will be considered confirmed.
Comment 5•2 years ago
|
||
Sorry if this is bad form, but is there any update on this? This is an issue I've run into with testing custom gamepads in Firefox, and it'd be great if it could be fixed.
Comment 6•2 years ago
|
||
The patch seems to compile on latest trunk. Can you verify it fixes the issue / works as expected? I don't have any such device.
Thanks.
Updated•2 years ago
|
Reporter | ||
Comment 7•2 years ago
|
||
I no longer have my device either, hah.. I'm glad this finally got some attention though :) Yeah, retesting would be very appreciated.
Comment 8•2 years ago
|
||
I tested it, and there were a couple issues - "extra" buttons would just trigger index 0, instead of being appended on the end, and also the axis handling was a little bit off. Also GamepadRemapper is in a weird spot on Linux, it's basically entirely unnecessary but I figured I'd leave it in just in case there's some weird driver that marks a device as a gamepad but doesn't have proper BTN_GAMEPAD mappings for it. In any case, I've got a patch (based on the previous one) that I think mostly gets it in working order (at least with my Switch Pro Controller, which has an extra button that now goes in index 17). I've done a lot of evdev stuff, but never contributed to Firefox, so I'm confident on about half of it. (I'm figuring out phabricator, I'll post the revision here soon (or should it be a new bug?))
Comment 9•2 years ago
|
||
Great, Thanks. Please use this bug, no need to create new one. Feel free to ask if you have any issues with the path processing.
Comment 10•2 years ago
|
||
Ok, not sure how to get a fancy x-phabricator-request
but here's the differential is D180004
Comment 11•2 years ago
|
||
Based off of D98868
Comment 12•2 years ago
|
||
Comment 13•2 years ago
|
||
Well I guess I figured it out, aha
Updated•2 years ago
|
Updated•2 years ago
|
Reporter | ||
Comment 14•2 years ago
|
||
in case there's some weird driver that marks a device as a gamepad but doesn't have proper BTN_GAMEPAD mappings for it
That's more useful for us on FreeBSD, as we don't have any mappings in the kernel for basic "DInput" gamepads, they all end up with only BTN_JOYSTICK nonsense, we only have PS4 and XInput/XBox drivers that support BTN_GAMEPAD.
And yeah I've also tried to use it for the extra above-16 buttons as well – I guess incorrectly :)
Comment 15•2 years ago
|
||
Huh, wrt to the build failures - is that due to declarations being removed from GamepadRemapping.h
between 3 years ago and now? Should I just re-add AxisNegativeAsButton
et al to the header file?
Comment 16•2 years ago
|
||
(In reply to Noa [:coolreader18] from comment #15)
Huh, wrt to the build failures - is that due to declarations being removed from
GamepadRemapping.h
between 3 years ago and now? Should I just re-addAxisNegativeAsButton
et al to the header file?
I think so.
Updated•2 years ago
|
Comment 17•2 years ago
|
||
@stransky I put you as a reviewer cause you had been one for the other patch, let me know if it should be someone else
Comment hidden (obsolete) |
Updated•1 year ago
|
Updated•1 year ago
|
Assignee | ||
Comment 20•1 year ago
|
||
This patch works great with my Playstation 4 (Dualshock 4) controller on Linux 5.15.0. It would be great if someone could test some other controllers, in particular Xbox 360/One.
Comment 22•1 year ago
|
||
(In reply to Tom S [:evilpie] from comment #20)
This patch works great with my Playstation 4 (Dualshock 4) controller on Linux 5.15.0. It would be great if someone could test some other controllers, in particular Xbox 360/One.
I have only Ps4 one too but I think it's a good start.
Thanks!
Assignee | ||
Comment 23•1 year ago
|
||
I just tested this with a third-party Xbox 360 controller. There are some issues, but overall a lot more actually works.
- For some reason West/North (labeled X and Y) are swapped
- L/R triggers don't register, because they get treated as an axis (ABS_RZ and ABS_Z)
- L/R bumpers seems to be the L/R triggers?
Everything else seems to work. An improvement to missing D-pad and Right Stick support currently. The swapped buttons are annoying though.
Comment 25•1 year ago
|
||
(In reply to Tom S [:evilpie] from comment #24)
See phab comment about unsigned long.
okay, leave it as is then.
Comment 26•1 year ago
|
||
Comment 27•1 year ago
|
||
bugherder |
Comment 28•1 year ago
|
||
Oh, yay! Apologies I didn't respond to the needinfo, I'm not very familiar with this workflow so couldn't tell what was left outstanding from the code review, but I'm really glad Firefox has functional gamepad support on Linux now!
Updated•1 year ago
|
Description
•