public boolean grabInput(){
  if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
    grabLog.fine("Grab input on {0}",this);
  }
  XToolkit.awtLock();
  try {
    if (XAwtState.getGrabWindow() == this && XAwtState.isManualGrab()) {
      grabLog.fine("    Already Grabbed");
      return true;
    }
    XBaseWindow prevGrabWindow=XAwtState.getGrabWindow();
    final int eventMask=(int)(XConstants.ButtonPressMask | XConstants.ButtonReleaseMask | XConstants.EnterWindowMask| XConstants.LeaveWindowMask| XConstants.PointerMotionMask| XConstants.ButtonMotionMask);
    final int ownerEvents=1;
    if (!XToolkit.getSunAwtDisableGrab()) {
      int ptrGrab=XlibWrapper.XGrabPointer(XToolkit.getDisplay(),getContentWindow(),ownerEvents,eventMask,XConstants.GrabModeAsync,XConstants.GrabModeAsync,XConstants.None,(XWM.isMotif() ? XToolkit.arrowCursor : XConstants.None),XConstants.CurrentTime);
      if (ptrGrab != XConstants.GrabSuccess) {
        XlibWrapper.XUngrabPointer(XToolkit.getDisplay(),XConstants.CurrentTime);
        XAwtState.setGrabWindow(null);
        grabLog.fine("    Grab Failure - mouse");
        return false;
      }
      int keyGrab=XlibWrapper.XGrabKeyboard(XToolkit.getDisplay(),getContentWindow(),ownerEvents,XConstants.GrabModeAsync,XConstants.GrabModeAsync,XConstants.CurrentTime);
      if (keyGrab != XConstants.GrabSuccess) {
        XlibWrapper.XUngrabPointer(XToolkit.getDisplay(),XConstants.CurrentTime);
        XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(),XConstants.CurrentTime);
        XAwtState.setGrabWindow(null);
        grabLog.fine("    Grab Failure - keyboard");
        return false;
      }
    }
    if (prevGrabWindow != null) {
      prevGrabWindow.ungrabInputImpl();
    }
    XAwtState.setGrabWindow(this);
    grabLog.fine("    Grab - success");
    return true;
  }
  finally {
    XToolkit.awtUnlock();
  }
}

public boolean grabInput ( ) { if ( grabLog . isLoggable ( PlatformLogger . Level . FINE ) ) { grabLog . fine ( "Grab input on {0}" , this ) ; } XToolkit . awtLock ( ) ; try { if ( XAwtState . getGrabWindow ( ) == this && XAwtState . isManualGrab ( ) ) { grabLog . fine ( "    Already Grabbed" ) ; return true ; } XBaseWindow prevGrabWindow = XAwtState . getGrabWindow ( ) ; final int eventMask = ( int ) ( XConstants . ButtonPressMask | XConstants . ButtonReleaseMask | XConstants . EnterWindowMask | XConstants . LeaveWindowMask | XConstants . PointerMotionMask | XConstants . ButtonMotionMask ) ; final int ownerEvents = 1 ; if ( ! XToolkit . getSunAwtDisableGrab ( ) ) { int ptrGrab = XlibWrapper . XGrabPointer ( XToolkit . getDisplay ( ) , getContentWindow ( ) , ownerEvents , eventMask , XConstants . GrabModeAsync , XConstants . GrabModeAsync , XConstants . None , ( XWM . isMotif ( ) ? XToolkit . arrowCursor : XConstants . None ) , XConstants . CurrentTime ) ; if ( ptrGrab != XConstants . GrabSuccess ) { XlibWrapper . XUngrabPointer ( XToolkit . getDisplay ( ) , XConstants . CurrentTime ) ; XAwtState . setGrabWindow ( null ) ; grabLog . fine ( "    Grab Failure - mouse" ) ; return false ; } int keyGrab = XlibWrapper . XGrabKeyboard ( XToolkit . getDisplay ( ) , getContentWindow ( ) , ownerEvents , XConstants . GrabModeAsync , XConstants . GrabModeAsync , XConstants . CurrentTime ) ; if ( keyGrab != XConstants . GrabSuccess ) { XlibWrapper . XUngrabPointer ( XToolkit . getDisplay ( ) , XConstants . CurrentTime ) ; XlibWrapper . XUngrabKeyboard ( XToolkit . getDisplay ( ) , XConstants . CurrentTime ) ; XAwtState . setGrabWindow ( null ) ; grabLog . fine ( "    Grab Failure - keyboard" ) ; return false ; } } if ( prevGrabWindow != null ) { prevGrabWindow . ungrabInputImpl ( ) ; } XAwtState . setGrabWindow ( this ) ; grabLog . fine ( "    Grab - success" ) ; return true ; } finally { XToolkit . awtUnlock ( ) ; } }
we should always grab both keyboard and pointer to control event flow on popups . this also simplifies synthetic grab implementation . the active grab overrides activated automatic grab .
