[Xcb] xcb_change_window_attributes vs. XSelectInput

Philip Rushik prushik at gmail.com
Thu Mar 6 11:02:16 PST 2014


I am trying to write a simple program that will receive mouse motion events
from all windows. I found the following Xlib code and I have tested it and
it works perfectly. So I did some research and tried to write an equivalent
function in XCB. The Xlib code gets me events from all windows and
everything works as usual (original windows still get the events as well).
However, the XCB code finds all the children correctly, but only gets
events from the JWM desktop and none of the other children despite finding
them correctly. In addition, while the XCB code is running, the JWM desktop
no longer receives those events (clicking does not activate the menu).

I can't figure out how the two are different, XSelectInput must be doing
something more that I don't understand. Can anybody provide some insight?

XLib Code:

void snoop_all_windows(Window root, unsigned long type)
{
  static int level = 0;
  Window parent, *children, *child2;
  unsigned int nchildren;
  int stat, i,j,k;

  level++;

  stat = XQueryTree(display, root, &root, &parent, &children, &nchildren);
  if (stat == 0)
   {
     fprintf(stderr, "Can't query window tree...\n");
     return;
   }

  if (nchildren == 0)
    return;

  XSelectInput(display, root, type);

  for(i=0; i < nchildren; i++)
   {
     XSelectInput(display, children[i], type);
     snoop_all_windows(children[i], type);
   }

  XFree((char *)children);
}



XCB Code:

static void select_children(xcb_window_t root, uint32_t mask)
{
    xcb_query_tree_cookie_t cookie = xcb_query_tree(conn,root);

    xcb_query_tree_reply_t *reply = xcb_query_tree_reply(conn,cookie,NULL);

    xcb_window_t *children = xcb_query_tree_children(reply);

    value[0]=XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_BUTTON_PRESS;
    xcb_change_window_attributes(conn,root,XCB_CW_EVENT_MASK, value);

    int i;
    for (i = 0; i < xcb_query_tree_children_length(reply); i++)
    {
        value[0]=XCB_EVENT_MASK_POINTER_MOTION |
XCB_EVENT_MASK_BUTTON_PRESS;
        xcb_change_window_attributes(conn,children[i],XCB_CW_EVENT_MASK,
value);

        printf("child window = 0x%08x\n", children[i]);
        select_children(children[i],0);
    }
    free(reply);

    return;
}


For reference, XSelectInput source:
http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/SelInput.c

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20140307/9f9c3076/attachment.html>


More information about the Xcb mailing list