GarageGames / Torque3D

MIT Licensed Open Source version of Torque 3D from GarageGames
http://torque3d.org
MIT License
3.35k stars 1.2k forks source link

Problem with SDL text input mode switching. #2260

Open OTHGMars opened 6 years ago

OTHGMars commented 6 years ago

When closing a gui that requested keyboard translations via GlobalActionMap keybind, keyboard translation doesn't get turned off. Fortunately the console dialog is the perfect test case for this problem. To see the issue, place a breakpoint on line 529 (or uncomment line 530) of windowManager/sdl/sdlWindow.cpp https://github.com/GarageGames/Torque3D/blob/development/Engine/source/windowManager/sdl/sdlWindow.cpp#L526-L532. Execute the program and press a key on the keyboard (any printable character key). You'll notice the breakpoint does not hit (no “Char: “ line in the console). Now open and close the console with the keyboard shortcut. Now press a key on the keyboard and the breakpoint will hit. This is because SDL is still in Text Input mode.

The gui sleeps and calls disableKeyboardTranslation() as a result of the event triggered on https://github.com/GarageGames/Torque3D/blob/development/Engine/source/windowManager/sdl/sdlWindow.cpp#L504, but the change does not get passed to SDL until the end of the current process loop https://github.com/GarageGames/Torque3D/blob/development/Engine/source/windowManager/sdl/sdlWindowMgr.cpp#L361-L375. This line, https://github.com/GarageGames/Torque3D/blob/development/Engine/source/windowManager/sdl/sdlWindow.cpp#L516, is resetting that change and needs to be conditional on if (mEnableKeyboardTranslation) to prevent this problem.

Note: changing SDL_IsTextInputActive() to if(mEnableKeyboardTranslation) here https://github.com/GarageGames/Torque3D/blob/development/Engine/source/windowManager/sdl/sdlWindow.cpp#L507 is not a correct solution. As per the comment, it would result in a text event being generated for the key that should have been eaten by the Global action map.