From 83db8d8939ce21fcb53c24b97a8e7848ba84e65d Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Mon, 1 Apr 2024 12:18:05 -0700 Subject: [PATCH] NativeWindow: call setTextInputEnabled(false) right away when window is created (closes openfl/openfl#2697) We seem to have been assuming that it was false by default, but in SDL 2, it is true by default (planned to be false in SDL 3, apparently). It can cause weird behavior like IME popups appearing when holding down keys (something commonly done by users playing games, so we don't want that!). We want setTextInputEnabled(true) to happen only when an OpenFL TextField (or anything else that accepts text input) receives focus, and then cleared again when focus is lost. This does not disable regular keyboard input. It is specifically related to what SDL considers text input, which is different, even if it uses the keyboard. --- src/lime/_internal/backend/native/NativeWindow.hx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lime/_internal/backend/native/NativeWindow.hx b/src/lime/_internal/backend/native/NativeWindow.hx index 0f9295035..7d9ca2ed8 100644 --- a/src/lime/_internal/backend/native/NativeWindow.hx +++ b/src/lime/_internal/backend/native/NativeWindow.hx @@ -173,6 +173,13 @@ class NativeWindow setFrameRate(Reflect.hasField(attributes, "frameRate") ? attributes.frameRate : 60); #end + + // SDL 2 enables text input events by default, but we want them only + // when requested. otherwise, we might get weird behavior like IME + // candidate windows appearing unexpectedly when holding down a key. + // See, for example: openfl/openfl#2697 + // it appears that SDL 3 may behave differently, if we ever upgrade. + setTextInputEnabled(false); } public function alert(message:String, title:String):Void