Browse Source

emscripten: Let SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT accept "#none"

This is used to say "don't even try to listen for keypresses," for apps that
are managing this outside of SDL.

Fixes #10292.
Sam Lantinga 3 months ago
parent
commit
923123a527
2 changed files with 3 additions and 3 deletions
  1. 1 1
      include/SDL3/SDL_hints.h
  2. 2 2
      src/video/emscripten/SDL_emscriptenevents.c

+ 1 - 1
include/SDL3/SDL_hints.h

@@ -730,7 +730,7 @@ extern "C" {
  * - "#document": the javascript document object
  * - "#screen": the javascript window.screen object
  * - "#canvas": the WebGL canvas element
- * - "": Don't bind anything at all
+ * - "#none": Don't bind anything at all
  * - any other string without a leading # sign applies to the element on the
  *   page with that ID.
  *

+ 2 - 2
src/video/emscripten/SDL_emscriptenevents.c

@@ -1029,11 +1029,11 @@ void Emscripten_RegisterEventHandlers(SDL_WindowData *data)
 
     // Keyboard events are awkward
     keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
-    if (!keyElement) {
+    if (!keyElement || !*keyElement) {
         keyElement = EMSCRIPTEN_EVENT_TARGET_WINDOW;
     }
 
-    if (*keyElement) {
+    if (SDL_strcmp(keyElement, "#none") != 0) {
         emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
         emscripten_set_keyup_callback(keyElement, data, 0, Emscripten_HandleKey);
         emscripten_set_keypress_callback(keyElement, data, 0, Emscripten_HandleKeyPress);