Closed Bug 1680982 Opened 4 years ago Closed 4 months ago

Use evdev for gamepads on Linux/FreeBSD

Categories

(Core :: DOM: Device Interfaces, enhancement)

Desktop
FreeBSD
enhancement

Tracking

()

RESOLVED FIXED
123 Branch
Tracking Status
firefox85 --- wontfix
firefox123 --- fixed

People

(Reporter: val, Assigned: evilpie)

References

(Blocks 1 open bug)

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.)

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)
Blocks: 1643835
See Also: → 1643358, 1523355

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;
}
Attachment #9191539 - Attachment description: Bug 1680982 - Use evdev for gamepads on Linux/FreeBSD → Bug 1680982 - Use evdev instead of the Linux legacy joystick API for gamepads

The bug has a release status flag that shows some version of Firefox is affected, thus it will be considered confirmed.

Status: UNCONFIRMED → NEW
Ever confirmed: true

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.

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.

Assignee: nobody → val
Status: NEW → ASSIGNED

I no longer have my device either, hah.. I'm glad this finally got some attention though :) Yeah, retesting would be very appreciated.

Flags: needinfo?(blueshuk2)

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?))

Flags: needinfo?(blueshuk2)

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.

Ok, not sure how to get a fancy x-phabricator-request but here's the differential is D180004

Attached file Bug 1680982 - Evdev gamepad mapping (obsolete) —

Based off of D98868

Attached file Use evdev for gamepad mapping on Linux (obsolete) —
Attachment #9337540 - Attachment is obsolete: true

Well I guess I figured it out, aha

Attachment #9337540 - Attachment is obsolete: false
Attachment #9337540 - Attachment description: Use evdev for gamepad mapping on Linux → Bug 1680982 - Evdev gamepad mapping

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 :)

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?

(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-add AxisNegativeAsButton et al to the header file?

I think so.

Attachment #9337544 - Attachment is obsolete: true

@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

Hi! Are you still working on this?

Flags: needinfo?(coolreader18)
Attachment #9337540 - Attachment is obsolete: true
Attachment #9191539 - Attachment is obsolete: true

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.

Duplicate of this bug: 1523355
Assignee: val → evilpies

(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!

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.

See phab comment about unsigned long.

Flags: needinfo?(stransky)

(In reply to Tom S [:evilpie] from comment #24)

See phab comment about unsigned long.

okay, leave it as is then.

Flags: needinfo?(stransky)
Pushed by evilpies@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/c0050d05b7ce
Implement Linux/Unix Gamepad support using evdev. r=stransky
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 123 Branch

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!

Flags: needinfo?(coolreader18)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: