event problem
Carsten Haitzler
raster at rasterman.com
Sun Oct 29 14:00:57 UTC 2017
On Sun, 29 Oct 2017 00:29:21 +0800 "石仔" <406643764 at qq.com> said:
> hi all.
> This is my ~/.xinitrc :
> exec xterm
>
> I start x with 'startx' command, and then run 'testx'. This is source :
> /* gcc testx.c -o testx -lX11 */
> 1 #include <stdio.h>
> 2 #include <X11/Xlib.h>
> 3 int main(int argc, char *argv[])
> 4 {
> 5
> 6 Display *display=XOpenDisplay(NULL);
> 7 Window root, parent, *child=NULL, root_win=RootWindow(display,
> DefaultScreen(display)); 8 unsigned int n;
> 9 XWindowAttributes attr;
> 10 if(XQueryTree(display, root_win, &root, &parent, &child, &n))
> 11 for(size_t i=0; i<n; i++)
> 12 if(XGetWindowAttributes(display, child[i], &attr)
> 13 && attr.map_state == IsViewable
> 14 && XSelectInput(display, child[i], ButtonPressMask))
> 15 printf("set %x\n", child[i]);
> 16 XEvent event;
> 17 while(1)
> 18 {
> 19 XNextEvent(display, &event);
> 20 if(event.type == ButtonPress)
> 21 printf("type=%d, w=%x\n", event.type, event.xbutton.window);
> 22 }
> 23 }
>
> I can not get ButtonPress when i press button. But I can get EnterNotify if i
> replace ButtonPressMask with EnterWindowMask. why ?
Because another client (xterm itself) is listening for button presses. presses
(and releases) only go to the first client to request them on a window because
of implicit grabs. You can try intercept them via parent windows (XGrabButton
+ XAllowEvent fun) which is how window managers do click to focus. Only 1
client can select for button press/release events on a window.
--
------------- Codito, ergo sum - "I code, therefore I am" --------------
Carsten Haitzler - raster at rasterman.com
More information about the xorg-devel
mailing list