Path: utzoo!attcan!uunet!ncrlnk!ncr-sd!hp-sdd!hplabs!sm.unisys.com!oberon!bloom-beacon!mit-eddie!uw-beaver!cornell!mailrus!ncar!boulder!stan!garya From: garya@stan.com (Gary Aitken) Newsgroups: comp.windows.x Subject: Unwanted Enter/Leave events during XGrabPointer Keywords: XGrabPointer Message-ID: <278@stan.com> Date: 17 Nov 88 00:40:05 GMT Organization: Solbourne Computer Inc., Longmont, Co. Lines: 96 Consider the following: EnterWindowMask, LeaveWindowMask, ButtonPressMask, and ButtonReleaseMask are selected for input on a window. The pointer is subsequently grabbed while in the window; and the pointer is restricted to the window during the grab; and grab events are restricted to ButtonPressMask and ButtonReleaseMask. While the pointer is grabbed, the window is moved such that the cursor would be outside the window if it were not constrained. Then each time the window is moved, a LeaveNotify followed by an EnterNotify are generated for the window. My reading of the event mask passed to XGrabPointer says the Enter/Leave events should be discarded; is there something I am missing here? The following code will illustrate the problem. To run: Start it up. After you have the windows displayed, type a carriage return. Move Pointer into small box. You should see an EnterNotify event. Press a button and keep it pressed while the window moves. You should see a ButtonPress, followed by a series of LeaveNotify/EnterNotify events Release the button. If the small window is still visible, you should see a ButtonRelease event. ---------------------------- Cut Here -------------------------------- # include # include main (argc,argv) int argc ; char **argv ; { static char dspnam[] = "unix:0.0" ; Display *dpy ; Window root,w,w1 ; XEvent ev ; char str[10] ; int i ; if (dpy = XOpenDisplay(dspnam)) { XSynchronize(dpy,1) ; root = XRootWindowOfScreen(XScreenOfDisplay(dpy,0)) ; w = XCreateSimpleWindow(dpy,root,0,0,100,12,1,1,0) ; w1 = XCreateSimpleWindow(dpy,w,0,0,10,10,1,1,0) ; XMapWindow(dpy,w1) ; XMapWindow(dpy,w) ; gets(str) ; XSelectInput(dpy,w1, EnterWindowMask|LeaveWindowMask|ButtonPressMask|ButtonReleaseMask) ; while (1) { XNextEvent(dpy,&ev) ; switch (ev.type) { case (EnterNotify) : case (LeaveNotify) : printf("type:%d win:0x:%x\n",ev.type,ev.xcrossing.window) ; break ; case (ButtonPress) : case (ButtonRelease) : printf("type:%d win:0x:%x\n",ev.type,ev.xbutton.window) ; break ; } if (ev.type == ButtonPress) { XGrabPointer(dpy,w1,False,ButtonPressMask|ButtonReleaseMask, GrabModeAsync,GrabModeSync,w1,None,CurrentTime) ; i = 1 ; while (1) { XMoveWindow(dpy,w1,i,0) ; XSync(dpy,0) ; i += 3 ; while (XPending(dpy)) { XNextEvent(dpy,&ev) ; switch (ev.type) { case (EnterNotify) : case (LeaveNotify) : printf("type:%d win:0x:%x\n",ev.type,ev.xcrossing.window) ; break ; case (ButtonPress) : case (ButtonRelease) : printf("type:%d win:0x:%x\n",ev.type,ev.xbutton.window) ; break ; } if (ev.type == ButtonRelease) { XUngrabPointer(dpy,CurrentTime) ; goto quit ; } } } } } quit : ; } }