@@ -203,7 +203,15 @@ void main_loop_iteration(void* user_data)
203203 case SDL_KEYDOWN:
204204 [[fallthrough]];
205205 case SDL_KEYUP:
206- if (auto window = glue.get_window (e.key .windowID )) {
206+ // utki::logcat("SDL_KEYDOWN/UP event, windowID = ", e.key.windowID, '\n');
207+ #if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
208+ // In Emscripten all key events are always sent to window with ID 0 (invalid id).
209+ // Since we have only one window in Emscripten, we can ignore the window ID.
210+ if (auto window = glue.get_window ())
211+ #else
212+ if (auto window = glue.get_window (e.key .windowID ))
213+ #endif
214+ {
207215 auto & win = *window;
208216
209217 auto key = sdl_scancode_to_ruis_key (e.key .keysym .scancode );
@@ -229,7 +237,23 @@ void main_loop_iteration(void* user_data)
229237 }
230238 break ;
231239 case SDL_TEXTINPUT:
232- if (auto window = glue.get_window (e.text .windowID )) {
240+ // utki::logcat("SDL_TEXTINPUT event, windowID = ", e.key.windowID, '\n');
241+ #if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
242+ // In Emscripten all key events are always sent to window with ID 0 (invalid id).
243+ // Since we have only one window in Emscripten, we can ignore the window ID.
244+ if (auto window = glue.get_window ())
245+ #else
246+ if (auto window = glue.get_window (e.text .windowID ))
247+ #endif
248+ {
249+ // this assert is needed to prevent gcc compiler complaining about unused application_glue::get_window() function in non-Emscripten builds
250+ utki::assert (
251+ [&]() {
252+ return glue.get_window () != nullptr ;
253+ },
254+ SL
255+ );
256+
233257 auto & win = *window;
234258
235259 struct sdl_input_string_provider : public ruis ::gui::input_string_provider {
0 commit comments