[prev in list] [next in list] [prev in thread] [next in thread]
List: freedesktop-xorg-devel
Subject: Re: event problem
From: Carsten Haitzler <raster () rasterman ! com>
Date: 2017-10-29 14:00:57
Message-ID: 20171029230057.8bd21ab78f00598119b9fa45 () rasterman ! com
[Download RAW message or body]
On Sun, 29 Oct 2017 00:29:21 +0800 "石仔" <406643764@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@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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic