dlundqvist / xone

Linux kernel driver for Xbox One and Xbox Series X|S accessories
https://discord.gg/FDQxwWk
GNU General Public License v2.0
84 stars 10 forks source link

Report Share button as a BTN_, instead of KEY_RECORD #20 #3

Open Beanow opened 1 year ago

Beanow commented 1 year ago

Porting over from https://github.com/medusalix/xone/pull/20

On kernel 6.5.5, can confirm that evtest is updated accordingly and under Firefox https://luser.github.io/gamepadtest/ will report the share button as a working 11th button. Though it doesn't seem to work under Edge (flatpak) or Rocket League (proton 8.0).

evtest                                                                                                                                                                                      1 ✘  13s  
No device specified, trying to scan all of /dev/input/event*
Not running as root, no devices may be available.
Available devices:
...
/dev/input/event258:    Microsoft Xbox Controller
...
Select the device event number [0-258]: 258

Input driver version is 1.0.1
Input device ID: bus 0x6 vendor 0x45e product 0xb12 version 0x511
Input device name: "Microsoft Xbox Controller"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 304 (BTN_SOUTH)
    Event code 305 (BTN_EAST)
    Event code 307 (BTN_NORTH)
    Event code 308 (BTN_WEST)
    Event code 310 (BTN_TL)
    Event code 311 (BTN_TR)
    Event code 314 (BTN_SELECT)
    Event code 315 (BTN_START)
    Event code 316 (BTN_MODE)
    Event code 317 (BTN_THUMBL)
    Event code 318 (BTN_THUMBR)
    Event code 714 (BTN_TRIGGER_HAPPY11)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value    412
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 1 (ABS_Y)
      Value    245
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 2 (ABS_Z)
      Value      0
      Min        0
      Max     1023
    Event code 3 (ABS_RX)
      Value    177
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 4 (ABS_RY)
      Value   -397
      Min   -32768
      Max    32767
      Fuzz      16
      Flat     128
    Event code 5 (ABS_RZ)
      Value      0
      Min        0
      Max     1023
    Event code 16 (ABS_HAT0X)
      Value      0
      Min       -1
      Max        1
    Event code 17 (ABS_HAT0Y)
      Value      0
      Min       -1
      Max        1
  Event type 21 (EV_FF)
    Event code 80 (FF_RUMBLE)
    Event code 81 (FF_PERIODIC)
    Event code 88 (FF_SQUARE)
    Event code 89 (FF_TRIANGLE)
    Event code 90 (FF_SINE)
    Event code 96 (FF_GAIN)
...
Event: time 1696689585.729637, type 1 (EV_KEY), code 714 (BTN_TRIGGER_HAPPY11), value 1
Event: time 1696689585.729637, -------------- SYN_REPORT ------------
Event: time 1696689585.817695, type 1 (EV_KEY), code 714 (BTN_TRIGGER_HAPPY11), value 0
Event: time 1696689585.817695, -------------- SYN_REPORT ------------
dlundqvist commented 1 year ago

Sorry for the late response. I think this is the correct thing to do, my only questions what button to use. I tried looking around in different input and joystick drivers but could not see any other uses of HAPPY11. Is it up to our discretion to choose one?

Beanow commented 1 year ago

I'm not completely sure either. Maybe @mbenkmann had a rationale for this number specifically.

But my understanding is that... 14 years ago https://github.com/torvalds/linux/commit/cf2f765f1896064e34c6f0f2ef896ff058dd5c06 the BTN_TRIGGER_HAPPY* range was added since the existing BTN_* range was too short to cover controllers with more buttons.

Looking at a recent addition of trigger happy to xpad.c which adds back paddles like these: image

They seem to be using BTN_* and BTN_TRIGGER_HAPPY* freely mixed though. So rather than starting at HAPPY11 because it happens to be the 11th button. You also see HAPPY1 - 4 in case the D-pad is mapped to buttons rather than an axis. And the new HAPPY5 - 8 for the paddles.

I think if we're looking to avoid conflicts with what xpad is defining anywhere above HAPPY9 appears unclaimed.

(Nb: Android seems to have the RECORD binding, and xpadneo maps to F12 to try and trigger steam's screenshots )

There's discussion in xpadneo btw including feedback from the SDL side: https://github.com/atar-axis/xpadneo/issues/428#issuecomment-1590221701 There wasn't a conclusion on the SHARE button specifically, but looking through it there certainly seems more to it than just pick one :laughing:

Beanow commented 1 year ago

Actually, while the thread said KEY_RECORD probably wasn't the best idea to go into the kernel. It is in the kernel for xpad.c and so SDL added support too. https://github.com/libsdl-org/SDL/commit/db1d4d3d76f5e21b2547463710b513fe0ebd7fad#diff-7d94ff2175e20395f77eafb0287c2f5efa984bc6adfba9a1becd6cd2a8314187R2110

The maintainer there at least seems to have gone from RECORD to HAPPY1 to F12, with more plans to look for better solutions.