[Workaround] RPI2 keystrokes leaking into X11 terminal

Applies to : Raspberry Pi 2 and SDL 2.0.4
OS : Raspbian Jessie and Ubuntu MATE for RPI

Problem : when started from a terminal under X-Window, SDL2 programs leak keyboard input into the X11 terminal.
Consequence : Undesired shell commands may be executed and have a potentially dangerous outcome.
Workarounds:

  • start SDL2 programs from a pure tty (not under X11).
  • or capture stdin into your SDL2 application (under X11).

[HOWTO]??Capturing stdin into your SDL2 program:
You can read this code from Rock Dodger CE (https://bitbucket.org/josephpaul0/rockdodger-ce/src/78f0ebe476e4d742942c2aca09c9561013bfc178/src/rockdodger-ce.c?at=master&fileviewer=file-view-default#rockdodger-ce.c-1610) as an example.
Then use it into you main() function like this:

Code:
struct termios saved;
init_RPI_termios(&saved);
gameloop(); // calls capture_RPI_stdin();
restore_RPI_termios(&saved);