title: SDL2 window does not work when out of focus
body: <p>I wanted to create a rectangle constantly running across the window. Turns out the rectangle moves only when i feed the window with any input (floating the cursor around it or pressing keys). Is there a way to make it run non-stop? </p>
  
  <p>Code for the running rectangle:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;SDL_image.h&gt;
  #include &lt;SDL.h&gt;
  
  
  const int SCREEN_WIDTH = 640;
  const int SCREEN_HEIGHT = 480;
  SDL_Window *gWindow = nullptr;
  SDL_Renderer *gRenderer = nullptr;
  
  bool init()
  {
      bool in = true;
      if (SDL_Init(SDL_INIT_VIDEO)&lt;0)
      {
          printf("SDL_ did not init, %s", SDL_GetError());
          in = false;
      }
      else
      {
          if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
          {
              printf("linear texture filtering boned.\n");
              in = false;
          }
          else
          {
              gWindow = SDL_CreateWindow("CELLULA_CHARLIE", 1000, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_ALWAYS_ON_TOP);
              if (gWindow == nullptr)
              {
                  printf("gwindow did not load, %s", SDL_GetError());
                  in = false;
              }
              else
              {
                  gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
                  if (gRenderer == nullptr)
                  {
                      printf("main renderer failed loading, %s", SDL_GetError());
                      in = false;
                  }
                  else
                  {
                      SDL_SetRenderDrawColor(gRenderer, 255, 255, 255, 255);
                      int imgFlags = IMG_INIT_PNG;
                      if (!(IMG_Init(imgFlags)&amp;imgFlags))
                      {
                          printf("Img did not init,  %s", IMG_GetError());
                          in = false;
                      }
                  }
              }
          }
      }
      return in;
  }
  
  
  void close()
  {
      SDL_DestroyRenderer(gRenderer);
      SDL_DestroyWindow(gWindow);
      //gMap = nullptr;
      gWindow = nullptr;
      gRenderer = nullptr;
      IMG_Quit();
      SDL_Quit();
  }
  
  int main(int argc, char*args[])
  {
      int i = 0;
      SDL_Rect rectangle;
      rectangle.h = rectangle.w = 32;
      rectangle.x = rectangle.y = 0;
  
      if (!init())
      {
          printf("init failed\n");
      }
      else
      {
  
          bool quit = false;
          SDL_Event e;
          while (!quit)
          {
              while (SDL_PollEvent(&amp;e) != 0)
              {
                  if (e.type == SDL_QUIT)
                  {
                      quit = true;
                  }
  
                  SDL_SetRenderDrawColor(gRenderer, 255, 255, 255, 255);
                  SDL_RenderClear(gRenderer);
  
  
                  rectangle.x = i * 32;
                  rectangle.y = rectangle.x;
                  i++;
                  if (rectangle.x&gt;500)
                  {
                      i = 0;
                  }
                  SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 255);
                  SDL_RenderFillRect(gRenderer, &amp;rectangle);
  
                  SDL_RenderPresent(gRenderer);
              }
  
          }
      }
  
      //the end//
      close();
      return 0;
  }
  </code></pre>