Commit graph

6 commits

Author SHA1 Message Date
cmitu
d417e06978 joy2key: use 'uinput' for emitting keyboard events
Recent Linux kernels (6.2+) have the ability to disable the 'TIOCSTI' ioctl, thus rendering unusable the method of sending keyboard events to the controlling terminal via `fcntl.ioctl` [1]. Not all distributions have left it enabled currently, but Ubuntu 24.04 has it enabled, affecting the `runcommand` ability to generate keyboard events for a joystick.

Use the `python-uinput` module to create a virtual keyboard and send the proper events through it, without relying on the 'curses' or 'fcntl' modules. Now, since the new module doesn't know about Termios codes, which were used previously, I've added a translation table to accomodate scripts using those capability codes. The `python-uinput` uses the Linux event codes [2].

The new method needs the `uinput` Linux kernel module to be loaded beforehand - so add the module to be automatically loaded. The user also needs to be part of the 'input' group, otherwise they won't be able to use the `uinput` interface -  RetroPie doesn't automate that, but assumes the installation user belongs to that group.

We also don't need the `termios`/`fnctl` calls, so the terminal handling part has been removed, simpplifying a bit the code.

OTHER changes:
 - the device path (/dev/jsX) is now ignored. It hasn't been working since the switch to SDL2 for input processing, but was still parsed for compatibility with the old version.
 - when invoking with the debug (--debug|-d) parameter, the script now runs in the foreground, instead of forking and running in the background. It's easier when running it to diagnose issues; running with debugging enabled should not be used for regular usage.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=83efeeeb3d04b22aaed1df99bc70a48fe9d22c4d
[2] https://github.com/tuomasjjrasanen/python-uinput/blob/master/src/ev.py
2024-10-12 06:52:59 +01:00
cmitu
2277b39b62 joy2key: fix generic mappings definition
Besides the mappings parsed from RetroArch's auto-configuration profiles, there's a generic mapping used for gamepads that don't have a profile saved.
Unfortunately this never worked, since the initialization of the mapping - in the `add_mappings` function - had the buttons and hats parameters switched. This changeset fixes this, creating a correct mapping.

The issue was reported in https://retropie.org.uk/forum/topic/35063/, `joy2key_sdl` would crash with a Python3 error since the (wrong) generic mapping would produce the incorrect data type and values for the `filter_active_events` method.
2024-01-31 17:34:24 +00:00
cmitu
9fa622cf6c joy2key: fix crash on older pythons/py-sdl2 and init update
* Added a local fix for a crash when using older Python and Py-SDL2 versions.
 Upstream bug: https://github.com/marcusva/py-sdl2/issues/75.
 Upstream fixed the issue, but older distros (Ubuntu 18.04 based) don't have an updated `python3-sdl2` package.

* It seems that initializing the video is not really required for the joystick subsystem to work.
 On newer SDL versions (tested with 2.0.16), initialization will fail with video added if the video cannot be initialized.
 This prevents starting `joy2key_sdl.py` if ES is already started or trying to run it headless (i.e. no KMS/X available).
 While this is not a use case we're covering, it's better to remove the video initialization if it's not needed.
2021-11-30 08:15:11 +00:00
cmitu
99fb97f5ae joy2key: fix spurious initialization events
For certain joysticks (axis), SDL will generate spurious axis movement events during initialization.
It seems that for axis where `absmin` and `absmax` are asymmetrical (ex. 0-255 instead of -255 - 255), SDL generates extra events which are not user generated. This can causes issues - i.e. automatically trigger the `runcommand` menu without user interaction, unintended scrolling, etc.

As a workaround, discard any axis movement events _immediately_ after the device is added.
NOTE: this will discard any potential valid axis events from another (already connected) device if they are present, forcing the user to probably re-center the joystick they were using.
2021-11-01 14:09:28 +00:00
cmitu
4341e2fa68 joy2key: remove events for a gamepad on disconnect 2021-11-01 07:18:57 +00:00
Jools Wills
50ed2e781e joy2key - split out into standalone module and rework helper code
Move much of the helpers.sh start/stop logic and default parameters to a joy2key wrapper script.

Switch runcommand.sh to use new wrapper script

Add tab button to "y" key for use in edit dialogs

Remove runcommand $md_inst on update. If old joy2key is present in runcommand install, trigger joy2key module install.

Remove system.sh python3-sdl2 dependency check - moved to joy2key_depends
2021-08-04 00:03:32 +01:00
Renamed from scriptmodules/supplementary/runcommand/joy2key_sdl.py (Browse further)