title: X: trigger events at fixed intervals
body: <p>What's the best way of waiting a finite a mount of time for an expose event on X, then waking up and doing a redraw, even if not expose event has been received? The purpose is to have an opengl animation running at sometimes where at others I simply want to redraw if needed. Here is my code as I have it now, check below for pseudo-code of what I'm looking for:</p>
  
  <pre><code>    do {
          XNextEvent(dpy, &amp;event);
          switch(event.type) {
              ...
              case Expose:
                 need_redraw = True;
                 break;
          }
      } while(XPending(dpy)); /* loop to compress events */
  
      if ( need_redraw )
      {
          // do redraw
      } 
  </code></pre>
  
  <p>And this is a pseudo-example of what I would like:</p>
  
  <pre><code>    bool animation_enabled = true;
      XPostTimeoutEventEvery( 0.3 ); // &lt;-- X will send a "Timeout"
                                     // event each 0.3 seconds.
  
      do {
          XNextEvent(dpy, &amp;event);
          switch(event.type) {
              ...
              case Expose:
                 // Redraw if it is required
                 need_redraw = True;
                 break;
              // -- here -- 
              case Timeout:
                 // Otherwise, after 0.3 seconds, redraw anyway if
                 // the animation is running
                 if ( animation_enabled )
                 {
                    need_redraw = True;
                 }
                 break;
  
  
          }
      } while(XPending(dpy)); /* loop to compress events */
  
      if ( need_redraw )
      {
          // do redraw
  
          // potentially change "animation_enabled" value 
      } 
  </code></pre>