You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking Issue: Gamepad support and device events overhaul #944
D - averageLikely as difficult as most tasks hereDS - appkitAffects the AppKit/macOS backendDS - uikitAffects the UIKit backend (iOS, tvOS, watchOS, visionOS)DS - waylandAffects the Wayland backend, or generally free Unix platformsDS - webAffects the Web backend (WebAssembly/WASM)DS - x11Affects the X11 backend, or generally free Unix platformsH - good first issueIdeal for new contributorsH - help wantedSomeone please save usP - highVital to haveS - apiDesign and usabilityS - enhancementWouldn't this be the coolest?S - metaProject governance
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.
At a high level, there are two steps to implementing this:
Fix the compilation errors introduced by the device event API changes.
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 pagearch 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.
@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.
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.
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)
@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.
Reacted by Chrs Msln, Bartłomiej Maryńczak, Guilherme Werner and Osspial
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.
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).
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.
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.
D - averageLikely as difficult as most tasks hereDS - appkitAffects the AppKit/macOS backendDS - uikitAffects the UIKit backend (iOS, tvOS, watchOS, visionOS)DS - waylandAffects the Wayland backend, or generally free Unix platformsDS - webAffects the Web backend (WebAssembly/WASM)DS - x11Affects the X11 backend, or generally free Unix platformsH - good first issueIdeal for new contributorsH - help wantedSomeone please save usP - highVital to haveS - apiDesign and usabilityS - enhancementWouldn't this be the coolest?S - metaProject governance
Activity
Osspial commentedon Jun 20, 2019
Mentoring Instructions
At a high level, there are two steps to implementing this:
Completing the first step will involve stubbing out the
GamepadHandlefunctions, 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, andGamepadHandles, since it's possible (and fairly easy to do) on Windows. I'd be surprised ifGamepadHandlewasn'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.HidIdThe 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.
francesca64 commentedon Jun 20, 2019
I imagine cross-platform rumble is also desired? I don't remember if that was discussed before.
Osspial commentedon Jun 20, 2019
@francesca64 Yep! That's been implemented on Windows, and is exposed here.
francesca64 commentedon Jun 20, 2019
@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
WriteOutputReportis 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.
14 remaining items
FuriouZz commentedon Jan 19, 2020
Hello there! I started to work on the device api changes for wasm32 target.
goddessfreya commentedon Jan 19, 2020
@ryanisaacg
elliegoldstein commentedon Jan 21, 2020
@FuriouZz You can use
wasm-packto test theweb-sysfeature, or you can usecargo webto compile with thestdwebfeature.FuriouZz commentedon Jan 22, 2020
@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
FuriouZz commentedon Apr 24, 2020
Any progress about this issue?
francesca64 commentedon Dec 12, 2020
@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.
FuriouZz commentedon Jan 13, 2021
@francesca64 I can have a look 😊
MarnixKuijs commentedon Jan 17, 2021
I'm also going to take a look and see if I can help
jlowry commentedon May 22, 2021
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?
maroider commentedon May 22, 2021
Is there a particular platform you were considering contributing to?
We're currently trying to update the very old
gamepad-device-eventsbranch, asmasterhas received a lot of work sincegamepad-device-eventsbranched off (see #1856).jlowry commentedon May 23, 2021
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.
francesca64 commentedon May 24, 2021
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.
xgalaxy commentedon Jun 8, 2021
Has anyone discussed supporting SDL2 controller remapping? I know GLFW also supports it.
See: https://github.com/gabomdq/SDL_GameControllerDB
francesca64 commentedon Jun 8, 2021
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.