Skip to content

Tracking Issue: Gamepad support and device events overhaul #944

Open

Description

@Osspial

This issue tracks the implementation of gamepad support and the device events API changes begun in #804. PRs working on this should be made against the gamepad-device-events branch, and we'll merge that branch onto master once it's implemented on all platforms.

  • Public API finalized
  • Implemented on all platforms
    • Windows
    • macOS
    • iOS
    • Linux X11
    • Linux Wayland
    • WASM
  • Updated feature matrix, if new features were added or implemented.

Activity

  1. added
    S - enhancement
    H - help wanted
    DS - appkit
    DS - win32
    DS - x11
    DS - wayland
    S - api
    DS - uikit
    D - average
    P - high
    H - good first issue
    on Jun 20, 2019
  2. Osspial commented on Jun 20, 2019

    @Osspial
    ContributorAuthor

    Mentoring Instructions

    At a high level, there are two steps to implementing this:

    1. Fix the compilation errors introduced by the device event API changes.
    2. Implement gamepad support on your platform of choice.

    Completing the first step will involve stubbing out the GamepadHandle functions, and I wouldn't worry about trying to implement them at that stage. These API changes are for the most part aesthetic changes, so fixing them shouldn't involve much fiddling around with the actual platform-specific code. I'd recommend using this step to become more familiar with how the backend works at a high level, and using that to assist with properly implementing gamepad support.

    The second step is a bit more tricky, since it involves directly messing with the platform-specific APIs. MacOS and iOS can probably share a significant amount of code for this, since it looks like they use the same APIs for controller input. Similarly, Wayland and X11 can probably both use the evdev API (official page arch linux on Gamepads), but I'm not 100% certain on that. @vberger can confirm or deny that, and give more detailed mentoring instructions on Wayland if he deems necessary.

    Enumerating Devices

    I've added APIs for enumerating attached MouseIds, KeyboardIds, HidIds, and GamepadHandles, since it's possible (and fairly easy to do) on Windows. I'd be surprised if GamepadHandle wasn't enumerable everywhere, but please bring it up in this thread if it turns out to be impossible to enumerate the other listed types on your platform.

    HidId

    The HID device API was added mainly because it was easy to do on Windows, but even there it isn't much more than a stub implementation. If you're confused on how to implement this, feel free to just stub it out - we probably need to do some additional API work to make it functional, and I expect there will be a larger discussion on what the API should look like/whether it's necessary.

  3. francesca64 commented on Jun 20, 2019

    @francesca64
    Member

    I imagine cross-platform rumble is also desired? I don't remember if that was discussed before.

  4. Osspial commented on Jun 20, 2019

    @Osspial
    ContributorAuthor

    @francesca64 Yep! That's been implemented on Windows, and is exposed here.

  5. francesca64 commented on Jun 20, 2019

    @francesca64
    Member

    @Osspial right, but it's only implemented for XInput. The comment I left in for RAWINPUT isn't very helpful, and I learned more after that but never documented my findings.

    So, the reality is that XInput is probably the only API that directly exposes rumble to you. Otherwise, you have to go through the platform's low-level HID API and send some device-specific values to the device. The data you send to the device is going to be the same on every platform, so it's not as scary as it sounds.

    Chromium's source code is probably the best resource for both finding this info and for finding a reasonable range of devices to support. For instance, here's what you'd generate for the DS4 controller: https://chromium.googlesource.com/chromium/src/+/lkgr/device/gamepad/dualshock4_controller_base.cc#47 - and then WriteOutputReport is implemented on Windows, macOS, and Linux.

    From looking at the file list, there actually aren't a ton of devices (I doubt Chromium has sub-par device support, but it could still be a good idea to compare to Firefox, SDL, etc. to be sure). It's still an undertaking to implement, but it seems feasible.

    There's also other device-specific functionality out there, like the LEDs on DS4. Unsurprisingly, that doesn't fit neatly into winit's existing API patterns... but the workload is big enough already, so that's something that can be eventually implemented by whomever ends up needing it.

  6. 14 remaining items

  7. FuriouZz commented on Jan 19, 2020

    @FuriouZz

    Hello there! I started to work on the device api changes for wasm32 target.

    • Well, I need help to understand how to test too. You do not seem to use wasm-pack.
    • It seems that the compilation with the stdweb features does not work =/. Same on the master branch.
    92 |     let v = js! { return performance.now(); };
       |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
       |
       = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
    
  8. goddessfreya commented on Jan 19, 2020

    @goddessfreya
    Contributor

    @ryanisaacg

  9. elliegoldstein commented on Jan 21, 2020

    @elliegoldstein
    Contributor

    @FuriouZz You can use wasm-pack to test the web-sys feature, or you can use cargo web to compile with the stdweb feature.

  10. FuriouZz commented on Jan 22, 2020

    @FuriouZz

    @ryanisaacg Maybe I am doing wrong, it does not seem to wort =/. I just created a pull request, if you want to look my changes #1414

  11. FuriouZz commented on Apr 24, 2020

    @FuriouZz

    Any progress about this issue?

  12. francesca64 commented on Dec 12, 2020

    @francesca64
    Member

    @FuriouZz there's not really anyone around to champion this issue anymore. It's only implemented in 2 backends, and I imagine there's also concern that the needs of the remaining platforms could violate some of the assumptions in the currently planned API design.

    I made the original implementation of this for Windows over 2 years ago, so um... at this point, I think we should just release this feature in an incomplete form. It's not useful to anyone if we don't release it, and the missing implementations would encourage people to make contributions that fill in the gaps.

    However, I don't have the bandwidth to champion this issue myself. If anyone wants to, getting this to a releasable state doesn't seem too difficult, though there's some cross-platform stubbing and API conformance stuff that needs to be done. The incompleteness would also need to be well-documented.

  13. FuriouZz commented on Jan 13, 2021

    @FuriouZz

    @francesca64 I can have a look 😊

  14. MarnixKuijs commented on Jan 17, 2021

    @MarnixKuijs
    Contributor

    I'm also going to take a look and see if I can help

  15. jlowry commented on May 22, 2021

    @jlowry

    Whats the status with this? Does it need more work still? How complex is the work left to be done? I'm asking because I'm considering contributing but would like to understand it before committing to any undertaking.

    -- update --
    So I've just taken a look at https://gitlab.com/gilrs-project/gilrs and I'm wondering if gamepad support in winit is even nesecary now?

  16. maroider commented on May 22, 2021

    @maroider
    Member

    I'm asking because I'm considering contributing

    Is there a particular platform you were considering contributing to?

    We're currently trying to update the very old gamepad-device-events branch, as master has received a lot of work since gamepad-device-events branched off (see #1856).

  17. jlowry commented on May 23, 2021

    @jlowry

    Is there a particular platform you were considering contributing to?

    I have access to win10 21H1 , macOs 11.3 on intel and Ubuntu 21.04 and iOs 14.4. I'm not especially interested in supporting any legacy or old versions. I have two wired xbox 360 pads I can test with.

  18. francesca64 commented on May 24, 2021

    @francesca64
    Member

    So I've just taken a look at https://gitlab.com/gilrs-project/gilrs and I'm wondering if gamepad support in winit is even nesecary now?

    Motivation discussed here: #695 (comment)

    tl;dr it's necessary for robust gamepad support on Windows + having gamepad support on Wayland at all, among other things.

  19. xgalaxy commented on Jun 8, 2021

    @xgalaxy

    Has anyone discussed supporting SDL2 controller remapping? I know GLFW also supports it.
    See: https://github.com/gabomdq/SDL_GameControllerDB

  20. francesca64 commented on Jun 8, 2021

    @francesca64
    Member

    Has anyone discussed supporting SDL2 controller remapping?

    Thanks for bringing this up! It's definitely something we should at least be compatible with. Without it, anything besides xinput is a pain for users.

    Parsing/etc. should live in a different crate. In an ideal world, we wouldn't depend on that crate, and users would have an ergonomic way to translate winit events themselves. I'm fine with us integrating it with winit if it turns out we don't live in that world, though.

  21. unpinned this issue on Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    D - averageDS - appkitDS - uikitDS - waylandDS - webDS - x11H - good first issueH - help wantedP - highS - apiS - enhancementS - meta

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions