jgeumlek / MoltenGamepad

Flexible Linux input device translator, geared for gamepads
MIT License
280 stars 42 forks source link

Release all inputs when switching profiles #98

Open TiZ-HugLife opened 3 years ago

TiZ-HugLife commented 3 years ago

Hi there. I'm not sure you're around anymore, I imagine you've moved on to greener pastures. That's okay! But I wanted to go ahead and open this issue anyways just to track the problem in case you come back and have availability to fix it.

So, imagine this. You made yourself a nice menu with rofi (or yad or zenity) but you want to control it with your gamepad. Okay, that should be easy enough; create a profile that maps directional inputs to arrow keys, primary to enter, and secondary to escape. Then just load it whenever you open the menu, and unload it (rather, use the reset profile and then apply whatever profiles were previously in use) and boom, you're controlling a menu with the gamepad.

It works pretty well, but there is a critical snag.

You press A. MG sends out a press event for enter on the virtual keyboard. The menu closes and returns its result. As part of the menu closing, it resets the active profiles. And computers are fast, so it does all of that before you release A. As a result of the release event never happening, enter remains pressed, which can trigger key repeat events. And that can wreak havoc in various ways. If, for example, I want to play a Doom PWAD by double-clicking it in my file manager, and I have a menu to pick which gameplay mods to load... well, after I pick it, the enter button remains pressed, focus falls back onto the file manager before GZDoom opens, and now it's suddenly receiving continuous enter events and it is now repeatedly opening the PWAD.

In order to get around this, I am sleeping for 0.5 seconds before doing the profile reset, but ideally, MG should just handle this more gracefully. An easy brute-force solution would be to just reset all events to neutral whenever a profile gets loaded. Maybe not elegant, but it's still better than what is happening now. I don't know if anyone is relying on the current behavior. I feel like, hypothetically, you could get chords this way, but I don't feel like anyone else is doing the kind of hacking and scripting that I am.

If you come back and manage to fix this, it'd be highly appreciated.