title: Sending X11 click event doesn't work with some windows
body: <p>The following snippet of code works most of the time, except in certain windows. For instance, under the latest Ubuntu it does not work for selecting folders in the file explorer. It seems to work just about everywhere else, but this gap is significant. I suspect it has to do with how I am using XQueryPointer, but I've tried nearly every example I can find. If I use the computer's mouse instead, it work's fine.
  FYI: I've already tried the answers to these questions:
  <a href="https://stackoverflow.com/questions/4402216/sending-programtic-mouse-events-to-x">Sending Programmatic events</a>
  <a href="https://stackoverflow.com/questions/2607010/linux-how-to-capture-screen-and-simulate-mouse-movements">Capuring Mouse Input</a>
  but they don't work any different...</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;X11/Xlib.h&gt;
  #include &lt;X11/Xutil.h&gt;
  
  void SendClick(int button, int down) {
      Display *display = XOpenDisplay(NULL);
      XEvent event;
  
      if(display == NULL)
      {
          return;
      }
  
      memset(&amp;event, 0, sizeof(event));
  
      event.xbutton.button = button;
      event.xbutton.same_screen = True;
      event.xbutton.subwindow = DefaultRootWindow (display);
  
      while (event.xbutton.subwindow)
      {
        event.xbutton.window = event.xbutton.subwindow;
        XQueryPointer (display, event.xbutton.window,
               &amp;event.xbutton.root, &amp;event.xbutton.subwindow,
               &amp;event.xbutton.x_root, &amp;event.xbutton.y_root,
               &amp;event.xbutton.x, &amp;event.xbutton.y,
               &amp;event.xbutton.state);
      }
  
      event.type = down ? ButtonPress : ButtonRelease;
  
      XSendEvent(display, PointerWindow, True, down ? ButtonPressMask : ButtonReleaseMask, &amp;event); 
  
      XFlush(display);
  
      XCloseDisplay(display);
  }
  </code></pre>