浏览代码

Added workaround for weird SDL behavior that causes SDL to report text
input as active when app starts until first actual text input

Ivan Savenko 1 年之前
父节点
当前提交
611249d11d
共有 3 个文件被更改,包括 10 次插入1 次删除
  1. 7 0
      client/eventsSDL/InputSourceText.cpp
  2. 2 0
      client/eventsSDL/InputSourceText.h
  3. 1 1
      client/gui/CGuiHandler.cpp

+ 7 - 0
client/eventsSDL/InputSourceText.cpp

@@ -21,6 +21,13 @@
 
 #include <SDL_events.h>
 
+InputSourceText::InputSourceText()
+{
+	// For whatever reason, in SDL text input is considered to be active by default at least on desktop platforms
+	// Apparently fixed in SDL3, but until then we need a workaround
+	SDL_StopTextInput();
+}
+
 void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text)
 {
 	GH.events().dispatchTextInput(text.text);

+ 2 - 0
client/eventsSDL/InputSourceText.h

@@ -21,6 +21,8 @@ struct SDL_TextInputEvent;
 class InputSourceText
 {
 public:
+	InputSourceText();
+
 	void handleEventTextInput(const SDL_TextInputEvent & current);
 	void handleEventTextEditing(const SDL_TextEditingEvent & current);
 

+ 1 - 1
client/gui/CGuiHandler.cpp

@@ -72,11 +72,11 @@ void CGuiHandler::init()
 {
 	inGuiThread = true;
 
-	inputHandlerInstance = std::make_unique<InputHandler>();
 	eventDispatcherInstance = std::make_unique<EventDispatcher>();
 	windowHandlerInstance = std::make_unique<WindowHandler>();
 	screenHandlerInstance = std::make_unique<ScreenHandler>();
 	renderHandlerInstance = std::make_unique<RenderHandler>();
+	inputHandlerInstance = std::make_unique<InputHandler>(); // Must be after windowHandlerInstance
 	shortcutsHandlerInstance = std::make_unique<ShortcutHandler>();
 	framerateManagerInstance = std::make_unique<FramerateManager>(settings["video"]["targetfps"].Integer());
 }