Search code examples
javascriptgoogle-chromeubuntuperipheralsgamepad-api

SpaceMouse Compact not working with js Gamepad api in Chrome on Ubuntu


As the title suggests I have a problem with using SpaceMouse in Chrome on Ubuntu. On Windows 10 it works fine. I've tried installing 3DxWare 10 and spacenavd but it still does not work. It is worth mentioning that the mouse works with Gazebo perfectly fine so it must be a problem with Chrome. Is there some flag in Chrome or additional software to make the SpaceMouse compatible with Gamepad api in javascript?


Solution

  • Short answer: If your SpaceMouse isn't working with Gamepad API on Chrome for Linux, try relabsd.

    Long answer: SpaceMouse is close enough to a gamepad that it sometimes works but sometimes doesn't. It would be nice if it worked, but getting it to work reliably in Gamepad API across all platforms is non-trivial and that kind of effort is better spent supporting real gamepads.

    For this specific issue, the problem is how the device describes its inputs. Each input has a flag indicating whether the input is absolute (with a defined minimum and maximum value) or relative (meaning each input must be compared with the previous value). Absolute inputs are used for things like joysticks and touchscreen touch points while relative inputs are used for things like optical mice and trackpad movements.

    Some SpaceMouse devices describe their axis inputs as relative, some as absolute. When it's an absolute axis, Chrome can fetch the bounds information and use it to normalize the axis to the range [-1,+1] as required by the Gamepad API. When it's a relative axis, bounds information is not available and the axis can't be normalized reliably.

    SpaceMouse axes always behave like absolute axes, it's a bug when they're defined as relative. There's a third-party tool for mapping SpaceMouse relative axes to absolute axes, I haven't tested it but from the description it sounds like it does what you need:

    https://github.com/nsensfel/relabsd

    Some SpaceMouse devices (like SpaceMouse Wireless) report absolute axes and work with Gamepad API.