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
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.
Added a new parameter to `osk.py` to populate the input box with an existing value.
This makes it easier to replace the `dialog`'s `--inputbox` widget, which accepts an existing value as the last argument.
Removed the prefix from the input prompt, let it be handled by the caller.
Currently, the WiFi configuration from RetroPie menu needs a keyboard for configuring a connection.
Added a `python` script to display on-screen keyboard which can be operated with `joy2key` and the gamepad, which allows entering the WiFi network/key/password without a keyboard.
The script accepts keyboard input, so it's suited for both keyboard and joystick input. It's using the `urwid` library (https://urwid.org).
The WiFi scriptmodule was modified to use the new OSK script instead of the `dialog` based inputboxes.
Additional modifications to the WiFi module:
- added a confirmation step before removing the WiFi config and stopping the WiFi
- added an info message during the WiFi scanning (instead of having a black screen)
- removed the check for the pass length, it's done by the new OSK script
- reformatted a bit the 'country' warning
NOTE: I've tested the new OSK script with smaller displays, but anything less than 40 cols will not be displayed fully. The OSK keyboard will scroll horizontally (when there's no more space on screen), but this is non-intuitive and might confuse users. _If_ we need to accomodate an even smaller screen size, then the OSK display area should be probably changed to accomodate that (i.e. less letters on a 'keyboard' row).
* 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.
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.
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