title: SDL_PollEvent causes screen to wake up after xset dpms force off
body: <p>I have a program that turns the screen on and off with <code>xset dpms force on/off</code> and also calls <code>SDL_PollEvent(&amp;e)</code> in a loop. After turning the display off with <code>xset</code>, any call to <code>SDL_PollEvent</code> causes the screen to wake up, even without any input. I can comment out the <code>SDL_PollEvent</code> call and it doesn't happen. Is there something I need to do with an event or something to prevent the screen from turning on? Updated with minimal code to reproduce the problem:</p>
  
  <pre><code>#include &lt;GL/glew.h&gt;
  #include &lt;SDL2/SDL.h&gt;
  #include &lt;atomic&gt;
  #include &lt;iostream&gt;
  #include &lt;thread&gt;
  using namespace std;
  atomic&lt;bool&gt; SCREEN_ON(true);
  atomic&lt;bool&gt; RUNNING(true);
  atomic&lt;bool&gt; SERVER_CONNECTED(false);
  
  std::string exec(const char *cmd) {
    char buffer[128];
    std::string result = "";
    std::shared_ptr&lt;FILE&gt; pipe(popen(cmd, "r"), pclose);
    if (!pipe)
      throw std::runtime_error("popen() failed!");
    while (!feof(pipe.get())) {
      if (fgets(buffer, 128, pipe.get()) != NULL)
        result += buffer;
    }
    return result;
  }
  double get_time() {
      static const Uint64 freq = SDL_GetPerformanceFrequency();
      static const Uint64 begin_time = SDL_GetPerformanceCounter();
      Uint64 current = SDL_GetPerformanceCounter();
      Uint64 elapsed = current - begin_time;
      return (double)elapsed / (double)freq;
  }
  
  void handle_input() {
    SDL_Event e;
    while (SDL_PollEvent(&amp;e)){}
  }
  
  void monitor_thread() {  
      while (RUNNING) {
          double time = get_time();
          if (time &lt; 15)
              SERVER_CONNECTED = false;
          else if (time &lt; 35)
              SERVER_CONNECTED = true;
          else
              SERVER_CONNECTED = false;
  
          cout &lt;&lt; "server status: " &lt;&lt; SERVER_CONNECTED &lt;&lt; endl;
          cout &lt;&lt; "screen_on status: " &lt;&lt; SCREEN_ON &lt;&lt; endl;
  
          handle_input();
          SDL_Delay(1000);
  
          if (SCREEN_ON &amp;&amp; (!SERVER_CONNECTED)) {
              cout &lt;&lt; "TURNING SCREEN OFF\n";
              SCREEN_ON = false;
              exec("sleep 1 &amp;&amp; xset -display :0.0 dpms force off");
          }
          if ((!SCREEN_ON) &amp;&amp; SERVER_CONNECTED) {
              cout &lt;&lt; "TURNING SCREEN ON\n";
              SCREEN_ON = true;
              exec("sleep 1 &amp;&amp; xset -display :0.0 dpms force on");
          }
      }
  }
  
  int main(int argc, char *argv[]) {
    Uint32 initflags = SDL_INIT_TIMER | SDL_INIT_VIDEO;
    SDL_Init(initflags);
    Uint32 window_flags =
        SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_GRABBED;
    SDL_Window *window =
        SDL_CreateWindow("title", 25, 25, 800, 600, window_flags);
    SDL_SetRelativeMouseMode(SDL_TRUE);
    SDL_EnableScreenSaver();
    SDL_GLContext gl_context = SDL_GL_CreateContext(window);
    glewInit();
    thread update_thread(monitor_thread);
    glClearColor(1, 1, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    while (RUNNING) {
      if (!SCREEN_ON) {
        cout &lt;&lt; "zzz...\n";
        SDL_Delay(2000);
        continue;
      } 
      glClear(GL_COLOR_BUFFER_BIT);
      SDL_Delay(16);
      SDL_GL_SwapWindow(window);
    }
    return 0;
  }
  </code></pre>
  
  <p><s>The screen will turn itself back on very shortly after <code>exec("sleep 1 &amp;&amp; xset -display :0.0 dpms force off");</code>, before the next call to turn it back on.</s></p>
  
  <p>Nevermind, SDL_PollEvent can only be called in the main thread.</p>