Merge pull request #1416 from Areloch/SDL_Inputs_Fixup

SDL Textbox bleedthrough inputs fix
This commit is contained in:
Areloch 2015-09-27 16:41:48 -05:00
commit 7da2d6d9d2
3 changed files with 31 additions and 20 deletions

View file

@ -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();
}

View file

@ -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; }

View file

@ -82,27 +82,32 @@ 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