Processing of joystick events is performed in a response to a zero-timeout timer. Previously only one event was handled when the timer fired. The 10 ms timeout of the select call checking if there are events to process prevented 100% CPU usage of a constantly firing timer.
The problem with such an approach is that joystick events are visibly slow to process and show up in the buttons and axis readout. In some cases they are even lost. It is not clear why this happens, my guess would be that each update of the button or axis state in the UI triggers a redraw, which then waits for VSync, preventing the timer from running.
This commit changes the event processing logic to run until there are no events left to consume. This requires zeroing of the select call timeout, as otherwise a joystick emitting events every 9 ms would be able completely block the UI.
To prevent 100% CPU usage, 10 ms sleep calls are issued when the event queue is empty. This has similar effect as the previous 10 ms select timeout.
Changes in the joystick calibration dialog are minimal, as I don't have use for it. The behavior there shouldn't be degraded, but that's it.
BUG: 426230 FIXED-IN: 5.27
The previous behavior of joystick event processing can be seen at https://cdn.discordapp.com/attachments/745210855725203516/1067207157923201096/2023-01-23_23-01-29.mp4 In this video jstest is running in the terminal, printing joystick events as they arrive. The readout of same axis in the system settings heavily lags behind.
Comparison of position graph when the joystick is manipulated to produce circles.