On Sun, 29 Oct 2017 00:29:21 +0800 "石仔" <406643...@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
> 2 #include
> 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, , , , ))
> 11 for(size_t i=0; i 12 if(XGetWindowAttributes(display, child[i], )
> 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, );
> 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 - ras...@rasterman.com
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel