Skip to content

Commit

Permalink
fix bug with SDL text input that occurs when multiple responders occu…
Browse files Browse the repository at this point in the history
…r on the screen. (Tested with 2 responders.)
  • Loading branch information
JeffProgrammer committed Dec 12, 2016
1 parent f6b8ef1 commit 3ecbb4b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Engine/source/windowManager/sdl/sdlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,19 @@ void PlatformWindowSDL::_triggerKeyNotify(const SDL_Event& evt)
{
keyEvent.trigger(getWindowId(), torqueModifiers, inputAction, torqueKey);
//Con::printf("Key %d : %d", tKey.sym, inputAction);

if (inputAction == IA_MAKE && SDL_IsTextInputActive())
{
// We have to check if we already have a first responder active.
// We don't want to type the character if it actually creates another responder!
if (mWindowInputGenerator->lastKeyWasGlobalActionMap())
{
// Turn off Text input, and the next frame turn it back on. This tells SDL
// to not generate a text event for this global action map key.
SDL_StopTextInput();
mOwningManager->updateSDLTextInputState(PlatformWindowManagerSDL::KeyboardInputState::TEXT_INPUT);
}
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion Engine/source/windowManager/windowInputGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ WindowInputGenerator::WindowInputGenerator( PlatformWindow *window ) :
mLastCursorPos(0,0),
mClampToWindow(true),
mFocused(false),
mPixelsPerMickey(1.0f)
mPixelsPerMickey(1.0f),
mLastPressWasGlobalActionMap(false)
{
AssertFatal(mWindow, "NULL PlatformWindow on WindowInputGenerator creation");

Expand Down Expand Up @@ -82,6 +83,9 @@ WindowInputGenerator::~WindowInputGenerator()
//-----------------------------------------------------------------------------
void WindowInputGenerator::generateInputEvent( InputEventInfo &inputEvent )
{
// Reset last press being global
mLastPressWasGlobalActionMap = false;

if (!mInputController)// || !mFocused)
return;

Expand All @@ -102,7 +106,10 @@ void WindowInputGenerator::generateInputEvent( InputEventInfo &inputEvent )

// Give the ActionMap first shot.
if (ActionMap::handleEventGlobal(&inputEvent))
{
mLastPressWasGlobalActionMap = true;
return;
}

if (mInputController->processInputEvent(inputEvent))
return;
Expand Down
10 changes: 10 additions & 0 deletions Engine/source/windowManager/windowInputGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class WindowInputGenerator
/// (one unit of mouse movement is a mickey) to units in the GUI.
F32 mPixelsPerMickey;

/// This tells us if the last key we pressed was used from the global action map.
bool mLastPressWasGlobalActionMap;

// Event Handlers
void handleMouseButton(WindowId did, U32 modifier, U32 action, U16 button);
void handleMouseWheel (WindowId did, U32 modifier, S32 wheelDeltaX, S32 wheelDeltaY);
Expand Down Expand Up @@ -83,6 +86,13 @@ class WindowInputGenerator
/// event even if it maps to a character input event.
bool wantAsKeyboardEvent( U32 modifiers, U32 key );

/// Tells us if the last key was used within the global action map.
/// @return true if the key was a global action map key, false otherwise.
/// @note Useful and currently used to tell if we just opened the console
/// by using the console key. Currently this is used to fix a bug in SDL
/// but it is not limited to that use.
bool lastKeyWasGlobalActionMap() const { return mLastPressWasGlobalActionMap; }

void addAcceleratorKey( void *hnd, const String &cmd, U32 keycode, U32 modifier)
{
AccKeyMap acc;
Expand Down

0 comments on commit 3ecbb4b

Please sign in to comment.