Restoring text input to the default state

Before calling SDL_StartTextInput() SDL2 is in a default state in which characters typed at the keyboard are received in SDL_TEXTINPUT events but no Input Method Editor (or On Screen Keyboard) is displayed.

Calling SDL_StartTextInput() followed by SDL_StopTextInput() does not restore that default state, thereafter no SDL_TEXTINPUT events are received at all. How can the default state be restored without restarting the program?

Seems like the bug is that SDL is sending SDL_TEXTINPUT events before SDL_StartTextInput() has been called. It makes sense that calling SDL_StopTextInput() would make it stop sending SDL_TEXTINPUT events.

The docs for SDL_StartTextInput() make it sound like your app isn’t supposed to get SDL_TEXTINPUT events until after you’ve called SDL_StartTextInput():

This function will start accepting Unicode text input events in the focused
SDL window, and start emitting SDL_TextInputEvent (SDL_TEXTINPUT) and
SDL_TextEditingEvent (SDL_TEXTEDITING) events. Please use this function in
pair with SDL_StopTextInput().

edit: the docs for SDL_StopTextInput() confirm that no longer receiving SDL_TEXTINPUT events after calling it is the intended behavior:

Stop receiving any text input events.

You can see for yourself in SDL_keyboard.h

It’s far from being a ‘bug’, it’s a key behavior that my app (and I’m sure many others) rely on; I’m certain it’s by design. It’s unfortunate that it doesn’t seem to be documented.

If there isn’t a way to restore that state without restarting the program there should be!

The documented behavior is that you’re supposed to get SDL_TEXTINPUT events after you call SDL_StartTextInput() and stop getting them after you call SDL_StopTextInput()

Why would you call SDL_StopTextInput() if you don’t want SDL_TEXTINPUT events to stop coming?

it’s a key behavior that my app (and I’m sure many others) rely on

It’s undocumented behavior, but people using it anyway is probably why it persists.

It’s been documented informally, anyway. For example here Sam says of SDL_StartTextInput() and SDL_StopTextInput(): “If you just want American and Western European language support on desktop systems, you can ignore those functions. They’re for more advanced international input with IMEs and mobile devices.”.

So it’s clear that SDL_TEXTINPUT events are supposed to occur before SDL_StartTextInput() is called.