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

Piotr Dąbrowski ultr at ultr.pl
Thu Jan 13 17:44:11 PST 2011


> 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?



Regards,
Piotr Dąbrowski



More information about the xorg mailing list