Testing the pointer for being already grabbed without calling XGrabPointer()?

Peter Hutterer peter.hutterer at who-t.net
Thu Jan 13 22:45:22 PST 2011


On Fri, Jan 14, 2011 at 02:44:11AM +0100, Piotr Dąbrowski wrote:
> > Hello,
> >
> >
> > Is there a way of testing the pointer for being already grabbed?
> >
> > I know I can call XGrabPointer(), check the result and then
> > XUngrabPointer() if necessary.
> > But this generates EnterNotify and LeaveNotify events which I don't want.
> >
> > Are there any other solutions?
> >
> >
> >
> > Regards,
> > Piotr Dąbrowski
> 
> 
> I have solved it this way:
> 
> bool checkPointerGrab( Display *display )
> {
>     int status = XGrabPointer(
>         display,
>         DefaultRootWindow( display ),
>         True,
>         ButtonReleaseMask | ButtonMotionMask | ButtonPressMask,
>         GrabModeAsync,
>         GrabModeAsync,
>         None,
>         None,
>         1
>     );
>     if( status == AlreadyGrabbed )
>       return true;
>     if( status == GrabSuccess )
>     {
>         XUngrabPointer( display, CurrentTime );
>         XFlush( display );
>     }
>     return false;
> }
> 
> Note value of 1 for the XGrabPointer()'s time parameter. XGrabPointer
> checks for the active grab first. If there is no other grab, then it
> fails at the time parameter being lesser than the server's current
> time.
> There is a very odd chance that this call will actually succeed,
> because server's time wraps around every ~49.7 days
> (http://tronche.com/gui/x/xlib/input/pointer-grabbing.html). In this
> case code ungrabs the pointer.
> 
> Now my question is: should I trust this behavior of X.org? Will it
> always check the active grab first?

unless it's explicitly mentioned in the protocol spec you can't always rely
on it, even though it's unlikely to change.

what problem are you trying to solve?
 
Cheers,
  Peter



More information about the xorg mailing list