From 4c13906865240401415ba59b33952a94b5fe131a Mon Sep 17 00:00:00 2001 From: Areloch Date: Mon, 21 Sep 2015 00:14:16 -0500 Subject: [PATCH 1/2] Corrects input issues when typing into text fields and it bleeding through to player inputs. --- Engine/source/windowManager/sdl/sdlWindow.cpp | 15 +++++++++------ Engine/source/windowManager/sdl/sdlWindow.h | 3 +++ .../source/windowManager/windowInputGenerator.cpp | 5 +++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Engine/source/windowManager/sdl/sdlWindow.cpp b/Engine/source/windowManager/sdl/sdlWindow.cpp index 60c3c4065..63ffa2549 100644 --- a/Engine/source/windowManager/sdl/sdlWindow.cpp +++ b/Engine/source/windowManager/sdl/sdlWindow.cpp @@ -484,12 +484,6 @@ void PlatformWindowSDL::_triggerKeyNotify(const SDL_Event& evt) keyEvent.trigger(getWindowId(), torqueModifiers, inputAction, torqueKey); //Con::printf("Key %d : %d", tKey.sym, inputAction); } - - // stop SDL_TEXTINPUT event when unwanted - if( inputAction == IA_MAKE && getKeyboardTranslation() && shouldNotTranslate( torqueModifiers, torqueKey ) ) - SDL_StopTextInput(); - else - SDL_StartTextInput(); } void PlatformWindowSDL::_triggerTextNotify(const SDL_Event& evt) @@ -606,3 +600,12 @@ const UTF16 *PlatformWindowSDL::getCurtainWindowClassName() static String str("CurtainWindowClassName"); return str.utf16(); } + +void PlatformWindowSDL::setKeyboardTranslation(const bool enabled) +{ + mEnableKeyboardTranslation = enabled; + if (mEnableKeyboardTranslation) + SDL_StartTextInput(); + else + SDL_StopTextInput(); +} \ No newline at end of file diff --git a/Engine/source/windowManager/sdl/sdlWindow.h b/Engine/source/windowManager/sdl/sdlWindow.h index 75abdee4f..eb73f39bd 100644 --- a/Engine/source/windowManager/sdl/sdlWindow.h +++ b/Engine/source/windowManager/sdl/sdlWindow.h @@ -160,6 +160,9 @@ public: virtual bool isMouseLocked() const { return mMouseLocked; }; virtual bool shouldLockMouse() const { return mShouldLockMouse; }; + /// Set if relevant keypress events should be translated into character input events. + virtual void setKeyboardTranslation(const bool enabled); + virtual WindowId getWindowId(); SDL_Window* getSDLWindow() const { return mWindowHandle; } diff --git a/Engine/source/windowManager/windowInputGenerator.cpp b/Engine/source/windowManager/windowInputGenerator.cpp index ecd75cdcc..fb95c4be8 100644 --- a/Engine/source/windowManager/windowInputGenerator.cpp +++ b/Engine/source/windowManager/windowInputGenerator.cpp @@ -105,6 +105,11 @@ void WindowInputGenerator::generateInputEvent( InputEventInfo &inputEvent ) if( mInputController->processInputEvent( inputEvent ) ) return; + if (mWindow->getKeyboardTranslation()) + { + return; + } + // If we get here we failed to process it with anything prior... so let // the ActionMap handle it. ActionMap::handleEvent(&inputEvent); From 9f7513dc0b4c1aec2b29985acfe37aab24db8cc1 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 27 Sep 2015 15:43:47 -0500 Subject: [PATCH 2/2] Further fixes to work around certain accelerators being missed, and additional command bleed-through. --- .../windowManager/windowInputGenerator.cpp | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Engine/source/windowManager/windowInputGenerator.cpp b/Engine/source/windowManager/windowInputGenerator.cpp index fb95c4be8..608aadb8a 100644 --- a/Engine/source/windowManager/windowInputGenerator.cpp +++ b/Engine/source/windowManager/windowInputGenerator.cpp @@ -82,33 +82,33 @@ WindowInputGenerator::~WindowInputGenerator() //----------------------------------------------------------------------------- void WindowInputGenerator::generateInputEvent( InputEventInfo &inputEvent ) { - if( !mInputController || !mFocused ) + if (!mInputController || !mFocused) return; - if (inputEvent.action == SI_MAKE && inputEvent.deviceType == KeyboardDeviceType) - { - for( int i = 0; i < mAcceleratorMap.size(); ++i ) - { - const AccKeyMap &acc = mAcceleratorMap[i]; - if( acc.modifier & inputEvent.modifier && acc.keyCode == inputEvent.objInst ) - { - Con::evaluatef(acc.cmd); - return; - } - } - } + if (inputEvent.action == SI_MAKE && inputEvent.deviceType == KeyboardDeviceType) + { + for (int i = 0; i < mAcceleratorMap.size(); ++i) + { + const AccKeyMap &acc = mAcceleratorMap[i]; + if (!mWindow->getKeyboardTranslation() && + (acc.modifier & inputEvent.modifier || (acc.modifier == 0 && inputEvent.modifier == 0)) + && acc.keyCode == inputEvent.objInst) + { + Con::evaluatef(acc.cmd); + return; + } + } + } // Give the ActionMap first shot. if (ActionMap::handleEventGlobal(&inputEvent)) return; - if( mInputController->processInputEvent( inputEvent ) ) + if (mInputController->processInputEvent(inputEvent)) return; if (mWindow->getKeyboardTranslation()) - { return; - } // If we get here we failed to process it with anything prior... so let // the ActionMap handle it.