title: SDL2 input focus
body: <p>I'm currently trying to build and run an UnrealEngine4 demo app, which uses SDL2, on a Linux armv7 embedded system with X server running but no window manager.</p>
  
  <p>What I'm seeing is that the app is not responsive to keyboard events, although mouse works fine. </p>
  
  <p>Digging further it turns out the problem is that UE4 ignores the keyboard event if the SDL_Event.key.windowID does not match the ID of the app's SDL_Window. I verified this by calling SDL_GetKeyboardFocus() and it turns out the window ID for the keyboard focus is 0 whereas the app's window's ID is 5.</p>
  
  <p>Digging a bit further inside SDL2 it looks like the keyboard focus is set to a particular SDL window after a focusIn event is received from the X server. (see X11_DispatchEvent() in SDL_x11events.c).</p>
  
  <p>It looks like if you're running X11 without a window manager however this focusIn event is never generated by the X-server as already answered here:</p>
  
  <p><a href="https://stackoverflow.com/questions/18234136/focusin-focusout-not-generated">FocusIn/FocusOut not generated</a></p>
  
  <p>After hacking X11_RaiseWindow() in SDL_x11windows.c by adding:</p>
  
  <p>X11_XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
  SDL_SetKeyboardFocus(data->window);</p>
  
  <p>was able to finally get the keyboard events processed.</p>
  
  <p>Does the above assessment sound correct ? If so is there a clean solution to this ? I'm still digging around but any suggestion would be greatly appreciated.</p>
  
  <p>Thanks</p>