We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2527

Summary: initializing video alters SDL_TEXTINPUT/EDITING state unnecessarily
Product: SDL Reporter: Adam M. <adam>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.3   
Hardware: x86_64   
OS: Windows 7   
Attachments: proposed patch (v1)

Description Adam M. 2014-05-09 00:03:35 UTC
In my project, the video, event, and input systems are very much separated. There is an option to disable SDL_TEXTINPUT/EDITING events, which uses SDL_EventState to disable them. However, when the video subsystem is initialized at a later point, it silently reenables them. This is annoying and unintuitive. I don't want the video system to have to communicate with the event system about the text editing state.

If I explicitly disable the events, SDL should not be silently reenabling them for an apparently unrelated feature. (It's not like I called SDL_StartTextInput.)

This might be related to #884 and #1482, but it's not a duplicate because those are about window focus behavior. This is about SDL reenabling events that I've told it to disable.

Repro:

#define SDL_MAIN_HANDLED
#include <SDL.h>
#include <stdio.h>

int main()
{
  SDL_InitSubSystem(SDL_INIT_EVENTS);
  printf("Initial SDL_TEXTEDITING and SDL_TEXTINPUT states: %d and %d\n",
         SDL_EventState(SDL_TEXTEDITING, SDL_QUERY), SDL_EventState(SDL_TEXTINPUT, SDL_QUERY));

  SDL_EventState(SDL_TEXTEDITING, SDL_IGNORE);
  SDL_EventState(SDL_TEXTINPUT, SDL_IGNORE);
  printf("States after disabling: %d and %d\n",
         SDL_EventState(SDL_TEXTEDITING, SDL_QUERY), SDL_EventState(SDL_TEXTINPUT, SDL_QUERY));

  SDL_InitSubSystem(SDL_INIT_VIDEO);
  printf("States after initializing video: %d and %d\n",
         SDL_EventState(SDL_TEXTEDITING, SDL_QUERY), SDL_EventState(SDL_TEXTINPUT, SDL_QUERY));

  SDL_Window *pWindow = SDL_CreateWindow("Window", 100, 100, 400, 300, 0);

  while(true)
  {
    SDL_Event e;
    SDL_WaitEvent(&e);
    if(e.type == SDL_TEXTEDITING || e.type == SDL_TEXTINPUT) puts("Got text event!");
    else if(e.type == SDL_QUIT) break;
  }

  SDL_DestroyWindow(pWindow);
  SDL_QuitSubSystem(SDL_INIT_VIDEO);
  SDL_QuitSubSystem(SDL_INIT_EVENTS);
  return 0;
}
Comment 1 Adam M. 2015-06-20 01:42:20 UTC
Created attachment 2193 [details]
proposed patch (v1)

I've attached a proposed (but not fully tested) patch for this problem. I don't think the video subsystem should be messing with the keyboard.
Comment 2 Sam Lantinga 2015-06-20 05:10:34 UTC
Many programs rely on the behavior that once they initialize the video subsystem they will get keyboard events (from windows they create)

There currently isn't any way to signal that you don't want this behavior other than adding a hint.

If you really can't call SDL_StopTextInput() after initializing the video subsystem, then I'll accept a patch that adds a hint to prevent this. Otherwise I'll go ahead and close this bug.
Comment 3 Adam M. 2015-06-20 07:33:37 UTC
It's understandable that it's too much of a breaking change. I'll just have to remember the text input settings before enabling video and reset them afterwards.