title: How do I intercept mouse buttons without blocking in xlib c
body: <p>I'm trying to intercept mouse buttons using xlib c (specificly 4 and 5). I want to this without blocking and prefrebly without external libraries except from xlib.</p>
  <p>I've looked at <a href="https://stackoverflow.com/questions/14561267/how-to-read-mouse-click-event-from-x-server">this question</a>'s answer and it works but blocks input (I can't click on any other windows).</p>
  <p>This is my attempt but it pauses at <code>XNextEvent</code> forever without giving any output</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;X11/Xlib.h&gt;
  
  static Display *display;
  
  int main(void) {
  
      display = XOpenDisplay(NULL);
      XSelectInput(display, DefaultRootWindow(display), ButtonReleaseMask);
      
      XEvent event;
      while (True) {
          XNextEvent(display, &amp;event);
          printf(&quot;Something happened: %s\n&quot;, event.type);
      }
  
      return 0;
  }
  </code></pre>