[comp.windows.x] XGrabPointer and ButtonPress

mac@trantor.harris-atd.com (Mike McDonald) (02/10/89)

  I'm trying to write a menu using Xlib but I'm having problems 
with the XGrabPointer stuff. Here's the basic of my code:

main()
{
  ...
  XSelectInput(display, root, ButtonPressMask);
  while (!done)
    { XNextEvent(display, &event);
      switch (event.type) {
        case ButtonPress: show_menu(menu, &event);
                          break;
        ...
      }
    }
}

show_menu(menu, event)
{
  XChangeActivePointerGrab(display, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, None, CurrentTime);
  map_menu(menu);
  while (!done) {
    { XNextEvent(display, &menu_event);
      switch (menu_event.type) {
        /* process menu events */
      }
    }
}

  The XChangeActivePointerGrab gets the following XError:

X Protocol error:  BadAccess, attempt to access private resource denied
  Major opcode of failed request:  30 (X_ChangeActivePointerGrab)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x600006
  Serial number of failed request:  87
  Current serial number in output stream:  88

  I've tried to do an XUngrabPointer and then a XGrabPointer but that tells me the
pointer is already grabbed. I've also tried using event->time instead of 
CurrentTime with no luck. I'm running Xr11.3 on a Sun3/50 under SunOS3.5. I haven't 
gotten the patches from Expo yet if that matters.

  Can anybody tell me what stupid thing I'm doing wrong.

  Mike McDonald

  mac@trantor.harris-atd.com
  postmaster@trantor.harris-atd.com
  (407) 727-5060

  Advanced Technology Dept.
  Harris Corp.
  M.S. 3A-1912
  P.O. Box 37
  Melbourne, Florida
             32902

klee@daisy.UUCP (Ken Lee) (02/11/89)

In article <1481@trantor.harris-atd.com> mac@trantor.harris-atd.com (Mike McDonald) writes:
>X Protocol error:  BadAccess, attempt to access private resource denied

The protocol error indicates that another client has already grabbed the
pointer.  Is that possible?  Does the window manager have it?  We do the
same sort of thing, with an XGrabPointer after the ButtonPress event, and
it works fine for us.

Ken Lee
-- 
klee@daisy.uucp
Daisy Systems Corp., Interactive Graphics Tools Dept.

mac@trantor.harris-atd.com (Mike McDonald) (02/14/89)

In article <2664@daisy.UUCP> klee@daisy.UUCP (Ken Lee) writes:
>In article <1481@trantor.harris-atd.com> mac@trantor.harris-atd.com (Mike McDonald) writes:
>>X Protocol error:  BadAccess, attempt to access private resource denied
>
>The protocol error indicates that another client has already grabbed the
>pointer.  Is that possible?  Does the window manager have it?  We do the
>same sort of thing, with an XGrabPointer after the ButtonPress event, and
>it works fine for us.
>
>Ken Lee
>-- 
>klee@daisy.uucp
>Daisy Systems Corp., Interactive Graphics Tools Dept.


  I was explicitly not running a window manager to avoid that problem. I have
two xterms running and that's it.


  Mike McDonald

  mac@trantor.harris-atd.com
  postmaster@trantor.harris-atd.com
  (407) 727-5060

  Advanced Technology Dept.
  Harris Corp.
  M.S. 3A-1912
  P.O. Box 37
  Melbourne, Florida
             32902

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (02/15/89)

You're getting a BadAccess on ChangeActivePointerGrab because your
application is using two connections in conflict.  On one connection
you select for ButtonPress on the root window.  When the button gets
pressed, a grab is activated.  Subsequently you try to ChangeActivePointerGrab
on the *other* connection.  This is a no-no.  A "client" is defined by
a connection, not by an address space.

mac@TRANTOR.HARRIS-ATD.COM (Mike McDonald) (02/15/89)

    Date: Wed, 15 Feb 89 08:32:34 EST
    From: rws@expo.lcs.mit.edu (Bob Scheifler)

    You're getting a BadAccess on ChangeActivePointerGrab because your
    application is using two connections in conflict.  On one connection
    you select for ButtonPress on the root window.  When the button gets
    pressed, a grab is activated.  Subsequently you try to ChangeActivePointerGrab
    on the *other* connection.  This is a no-no.  A "client" is defined by
    a connection, not by an address space.

  And I imagine that there is no way to find an already existing
connection using Xlib. What I was trying to do was implement a SunWindows
compatible library. Most of the users around here have Suns and won't
consider switching to X unless I find an easy way for them to convert
their existing code. I'll have to rethink my approach now.

  Thanks for your time.

  Mike McDonald

P.S. I think you should be able to grab the mouse even if another
connection has it grabbed. Example usage: The system is going down so I
pop up a notifier on your screen. I want the user to have to acknowledge
the notifier immediately so I can either stop the shutdown or continue
without having to listen to the user belly ache later about the system
being down while he has so much important news to read.