[comp.windows.x] XUngrabPointer isn't

jkm@hp-ptp.HP.COM (Jocelyn_Montgomery) (08/25/89)

I am writing an application in which I want to grab the pointer, do something,
then ungrab the pointer.  All goes well with the grab but when I try to 
ungrab the pointer, it won't.  I am getting a GrabInvalidTime value returned
from XUngrabPointer, but I am giving it CurrentTime for both the grab and
ungrab.  I am running on an HP 9000/360 with 6.5 
Any help is greatly appreciated!

Here is the code:

	char buf[20];
	int returnval;
	char *display_name = NULL;
	Cursor cursor;
	XEvent event;
	
	/* get display pointer */
	display = XOpenDisplay (display_name);
	
	/* create question mark cursor */
	cursor = XCreateFontCursor(display, 92);
	
	/* change cursor to question mark */
	if ((returnval = XGrabPointer(display, XtWindow(questionMarkPB), True, 
				      ButtonPressMask|ButtonReleaseMask| 
				      OwnerGrabButtonMask, GrabModeAsync, 
				      GrabModeAsync, None, cursor, CurrentTime)) != 0)
	   printf("grab error = %s\n", XGetErrorText(display, returnval, buf, sizeof (buf)));

	XMaskEvent(display,ButtonPressMask, &event);
	/* do something */
	returnval = XUngrabPointer(display,CurrentTime);
	printf("ungrab return = %d\n", returnval);	
	sleep(3); /* these are here so I don't hang my program when
		     it doesn't ungrab */
	exit(0);
}

The printf returns:  ungrab return = 2.

Thanks,

Jocelyn Montgomery
Hewlett Packard
jocelyn@hp-ptp.HP.COM

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (08/26/89)

	returnval = XUngrabPointer(display,CurrentTime);

Look at the documentation again, XUngrabPointer doesn't return a value.
Also, as your program is written, the XUngrabPointer won't be executed
because it's an asynchronous request, which gets buffered internally by
Xlib, and your program never causes the buffer output to be flushed.
Both of these errors are among the tops in "common mistakes" people make
when programming to Xlib.