w3c / gamepad

Gamepad
https://w3c.github.io/gamepad/
Other
141 stars 48 forks source link

Add device orientation support #211

Open jdarpinian opened 1 month ago

jdarpinian commented 1 month ago

It would be nice to have gyro support. Flick Stick controls are becoming more popular and they can't be implemented on the web today. https://en.wikipedia.org/wiki/Flick_Stick

nondebug commented 1 month ago

Gamepad Extensions defines a GamepadPose interface, but as far as I'm aware it was never implemented in any browser engine. It was proposed as a way to expose motion inputs for WebXR API but WebXR maintainers ultimately decided to create their own interface.

I think we should not add GamepadPose to Gamepad API as it is today. Currently, Gamepad API doesn't prompt the user before exposing access to gamepads. Instead, the API returns no information about gamepads until a gamepad user gesture is received. This works well enough for legacy gamepads which typically don't generate any inputs unless the user is physically interacting with the device, but modern gamepads include sensors that continuously generate inputs until the device is disconnected. I think users would not expect a website to have continuous access to gamepad motion inputs just because they pressed a button on a gamepad, so some additional user consent step is needed.

Other web platform APIs already expose access to motion sensors, we should try to leverage these APIs instead of building new gamepad-specific interfaces:

Chromium implements a motion sensors site permission (chrome://settings/content/sensors), perhaps we can gate gamepad motion inputs on that permission.

jdarpinian commented 1 month ago

I see the gyro/accelerometer inputs as roughly equivalent to the control sticks from a user expectations point of view. They do not generate events or count as user gestures, but once the gamepad is connected to a page their values are monitored and continuously sent to the webpage even if the user is not actively moving them, until page reload. For example, if the gamepad is resting upside down on its control sticks they might report some off-center values, and if the gamepad is jostled those values might change even if the user is not actively using the gamepad. I don't think this is surprising to users for the control sticks and I don't think it would be surprising to users for the gyro/accelerometer either.