private void removeDnDGrab(long time) {
    assert XToolkit.isAWTLockHeldByCurrentThread();

    XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), time);
    XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), time);

    /* Restore the root event mask if it was changed. */
    if ((rootEventMask | ROOT_EVENT_MASK) != rootEventMask && dragRootWindow != 0) {

      XlibWrapper.XSelectInput(XToolkit.getDisplay(), dragRootWindow, rootEventMask);
    }

    rootEventMask = 0;
    dragRootWindow = 0;
  }
예제 #2
0
 public void xSetVisible(boolean visible) {
   if (log.isLoggable(Level.FINE)) log.fine("Setting visible on " + this + " to " + visible);
   XToolkit.awtLock();
   try {
     this.visible = visible;
     if (visible) {
       XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow());
     } else {
       XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
     }
     XlibWrapper.XFlush(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #3
0
  Rectangle getClientBounds() {
    XToolkit.awtLock();
    try {
      XWindowAttributes wattr = new XWindowAttributes();
      try {
        XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
        int status =
            XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), xembed.handle, wattr.pData);

        XToolkit.RESTORE_XERROR_HANDLER();

        if (status == 0
            || (XToolkit.saved_error != null
                && XToolkit.saved_error.get_error_code() != XConstants.Success)) {
          return null;
        }

        return new Rectangle(wattr.get_x(), wattr.get_y(), wattr.get_width(), wattr.get_height());
      } finally {
        wattr.dispose();
      }
    } finally {
      XToolkit.awtUnlock();
    }
  }
예제 #4
0
 /** Helper function to set W */
 public final void setWMHints(XWMHints hints) {
   XToolkit.awtLock();
   try {
     XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #5
0
 void flush() {
   XToolkit.awtLock();
   try {
     XlibWrapper.XFlush(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #6
0
 static long getScreenOfWindow(long window) {
   XToolkit.awtLock();
   try {
     return XlibWrapper.getScreenOfWindow(XToolkit.getDisplay(), window);
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #7
0
 long getScreenNumber() {
   XToolkit.awtLock();
   try {
     return XlibWrapper.XScreenNumberOfScreen(getScreen());
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #8
0
 public void toFront() {
   XToolkit.awtLock();
   try {
     XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #9
0
 public static long xGetInputFocus() {
   XToolkit.awtLock();
   try {
     return XlibWrapper.XGetInputFocus(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #10
0
 boolean processXEmbedInfo() {
   long xembed_info_data = Native.allocateLongArray(2);
   try {
     if (!XEmbedInfo.getAtomData(handle, xembed_info_data, 2)) {
       // No more XEMBED_INFO? This is not XEmbed client!
       // Unfortunately this is the initial state of the most clients
       // FIXME: add 5-state processing
       // childDestroyed();
       xembedLog.finer("Unable to get XEMBED_INFO atom data");
       return false;
     }
     version = Native.getCard32(xembed_info_data, 0);
     flags = Native.getCard32(xembed_info_data, 1);
     boolean new_mapped = (flags & XEMBED_MAPPED) != 0;
     boolean currently_mapped = XlibUtil.getWindowMapState(handle) != XConstants.IsUnmapped;
     if (new_mapped != currently_mapped) {
       if (xembedLog.isLoggable(PlatformLogger.FINER))
         xembedLog.fine(
             "Mapping state of the client has changed, old state: "
                 + currently_mapped
                 + ", new state: "
                 + new_mapped);
       if (new_mapped) {
         XToolkit.awtLock();
         try {
           XlibWrapper.XMapWindow(XToolkit.getDisplay(), handle);
         } finally {
           XToolkit.awtUnlock();
         }
       } else {
         XToolkit.awtLock();
         try {
           XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), handle);
         } finally {
           XToolkit.awtUnlock();
         }
       }
     } else {
       xembedLog.finer("Mapping state didn't change, mapped: " + currently_mapped);
     }
     return true;
   } finally {
     XlibWrapper.unsafe.freeMemory(xembed_info_data);
   }
 }
예제 #11
0
 public Dimension getMinimumSize() {
   if (isXEmbedActive()) {
     XToolkit.awtLock();
     try {
       long p_hints = XlibWrapper.XAllocSizeHints();
       XSizeHints hints = new XSizeHints(p_hints);
       XlibWrapper.XGetWMNormalHints(
           XToolkit.getDisplay(), xembed.handle, p_hints, XlibWrapper.larg1);
       Dimension res = new Dimension(hints.get_min_width(), hints.get_min_height());
       XlibWrapper.XFree(p_hints);
       return res;
     } finally {
       XToolkit.awtUnlock();
     }
   } else {
     return super.getMinimumSize();
   }
 }
예제 #12
0
 public XWMHints getWMHints() {
   if (wmHints == null) {
     wmHints = new XWMHints(XlibWrapper.XAllocWMHints());
     //              XlibWrapper.XGetWMHints(XToolkit.getDisplay(),
     //                                      getWindow(),
     //                                      wmHints.pData);
   }
   return wmHints;
 }
예제 #13
0
 public void xRequestFocus() {
   XToolkit.awtLock();
   try {
     if (focusLog.isLoggable(Level.FINER))
       focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
     XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #14
0
 /*
  * Call this method under AWTLock.
  * The lock should be acquired untill all operations with XSizeHints are completed.
  */
 public XSizeHints getHints() {
   if (hints == null) {
     long p_hints = XlibWrapper.XAllocSizeHints();
     hints = new XSizeHints(p_hints);
     //              XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), getWindow(), p_hints,
     // XlibWrapper.larg1);
     // TODO: Shouldn't we listen for WM updates on this property?
   }
   return hints;
 }
예제 #15
0
 static void ungrabInput() {
   XToolkit.awtLock();
   try {
     XBaseWindow grabWindow = XAwtState.getGrabWindow();
     if (grabLog.isLoggable(Level.FINE)) {
       grabLog.log(Level.FINE, "UnGrab input on {0}", new Object[] {String.valueOf(grabWindow)});
     }
     if (grabWindow != null) {
       grabWindow.ungrabInputImpl();
       XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), CurrentTime);
       XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), CurrentTime);
       XAwtState.setGrabWindow(null);
       // we need to call XFlush() here to force ungrab
       // see 6384219 for details
       XlibWrapper.XFlush(XToolkit.getDisplay());
     }
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #16
0
 void detachChild() {
   if (xembedLog.isLoggable(PlatformLogger.FINE))
     xembedLog.fine("Detaching child " + Long.toHexString(xembed.handle));
   /**
    * XEmbed specification: "The embedder can unmap the client and reparent the client window to
    * the root window. If the client receives an ReparentNotify event, it should check the parent
    * field of the XReparentEvent structure. If this is the root window of the window's screen,
    * then the protocol is finished and there is no further interaction. If it is a window other
    * than the root window, then the protocol continues with the new parent acting as the embedder
    * window."
    */
   XToolkit.awtLock();
   try {
     XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), xembed.handle);
     XlibWrapper.XReparentWindow(
         XToolkit.getDisplay(), xembed.handle, XToolkit.getDefaultRootWindow(), 0, 0);
   } finally {
     XToolkit.awtUnlock();
   }
   endDispatching();
   xembed.handle = 0;
 }
예제 #17
0
  void destroy() {
    XToolkit.awtLock();
    try {
      if (hints != null) {
        XlibWrapper.XFree(hints.pData);
        hints = null;
      }
      XToolkit.removeFromWinMap(getWindow(), this);
      XlibWrapper.XDestroyWindow(XToolkit.getDisplay(), getWindow());
      if (XPropertyCache.isCachingSupported()) {
        XPropertyCache.clearCache(window);
      }
      window = -1;
      if (!isDisposed()) {
        setDisposed(true);
      }

      XAwtState
          .getGrabWindow(); // Magic - getGrabWindow clear state if grabbing window is disposed of.
    } finally {
      XToolkit.awtUnlock();
    }
  }
  private void updateTargetWindow(XMotionEvent xmotion) {
    assert XToolkit.isAWTLockHeldByCurrentThread();

    int x = xmotion.get_x_root();
    int y = xmotion.get_y_root();
    long time = xmotion.get_time();
    long subwindow = xmotion.get_subwindow();

    /*
     * If this event had occurred before the pointer was grabbed,
     * query the server for the current root subwindow.
     */
    if (xmotion.get_window() != xmotion.get_root()) {
      XlibWrapper.XQueryPointer(
          XToolkit.getDisplay(),
          xmotion.get_root(),
          XlibWrapper.larg1, // root
          XlibWrapper.larg2, // subwindow
          XlibWrapper.larg3, // x_root
          XlibWrapper.larg4, // y_root
          XlibWrapper.larg5, // x
          XlibWrapper.larg6, // y
          XlibWrapper.larg7); // modifiers
      subwindow = Native.getLong(XlibWrapper.larg2);
    }

    if (targetRootSubwindow != subwindow) {
      if (dragProtocol != null) {
        dragProtocol.sendLeaveMessage(time);

        /*
         * Neither Motif DnD nor XDnD provide a mean for the target
         * to notify the source that the pointer exits the drop site
         * that occupies the whole top level.
         * We detect this situation and post dragExit.
         */
        if (targetAction != DnDConstants.ACTION_NONE) {
          dragExit(x, y);
        }
      }

      /* Update the global state. */
      doUpdateTargetWindow(subwindow, time);

      if (dragProtocol != null) {
        dragProtocol.sendEnterMessage(sourceFormats, sourceAction, sourceActions, time);
      }
    }
  }
예제 #19
0
 Point toLocal(int x, int y) {
   long root;
   XToolkit.awtLock();
   try {
     root = XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber());
   } finally {
     XToolkit.awtUnlock();
   }
   Point p = toOtherWindow(root, getContentWindow(), x, y);
   if (p != null) {
     return p;
   } else {
     return new Point(x, y);
   }
 }
  protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) {
    assert XToolkit.isAWTLockHeldByCurrentThread();

    if (c == null) {
      return;
    }

    long xcursor = XGlobalCursorManager.getCursor(c);

    if (xcursor == 0) {
      return;
    }

    XlibWrapper.XChangeActivePointerGrab(
        XToolkit.getDisplay(), GRAB_EVENT_MASK, xcursor, XConstants.CurrentTime);
  }
예제 #21
0
  void initDispatching() {
    if (xembedLog.isLoggable(PlatformLogger.FINE))
      xembedLog.fine("Init embedding for " + Long.toHexString(xembed.handle));
    XToolkit.awtLock();
    try {
      XToolkit.addEventDispatcher(xembed.handle, xembed);
      XlibWrapper.XSelectInput(
          XToolkit.getDisplay(),
          xembed.handle,
          XConstants.StructureNotifyMask | XConstants.PropertyChangeMask);

      XDropTargetRegistry.getRegistry().registerXEmbedClient(getWindow(), xembed.handle);
    } finally {
      XToolkit.awtUnlock();
    }
    xembed.processXEmbedInfo();

    notifyChildEmbedded();
  }
예제 #22
0
 public void xSetBounds(int x, int y, int width, int height) {
   if (getWindow() == 0) {
     insLog.warning("Attempt to resize uncreated window");
     throw new IllegalStateException("Attempt to resize uncreated window");
   }
   insLog.fine(
       "Setting bounds on " + this + " to (" + x + ", " + y + "), " + width + "x" + height);
   if (width <= 0) {
     width = 1;
   }
   if (height <= 0) {
     height = 1;
   }
   XToolkit.awtLock();
   try {
     XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getWindow(), x, y, width, height);
   } finally {
     XToolkit.awtUnlock();
   }
 }
예제 #23
0
 void forwardKeyEvent(KeyEvent e) {
   xembedLog.fine("Try to forward key event");
   byte[] bdata = getBData(e);
   long data = Native.toData(bdata);
   if (data == 0) {
     return;
   }
   try {
     XKeyEvent ke = new XKeyEvent(data);
     ke.set_window(xembed.handle);
     if (xembedLog.isLoggable(PlatformLogger.FINE))
       xembedLog.fine("Forwarding native key event: " + ke);
     XToolkit.awtLock();
     try {
       XlibWrapper.XSendEvent(
           XToolkit.getDisplay(), xembed.handle, false, XConstants.NoEventMask, data);
     } finally {
       XToolkit.awtUnlock();
     }
   } finally {
     XlibWrapper.unsafe.freeMemory(data);
   }
 }
  protected void startDrag(Transferable transferable, long[] formats, Map formatMap) {
    Component component = getTrigger().getComponent();
    Component c = null;
    XWindowPeer wpeer = null;

    for (c = component;
        c != null && !(c instanceof Window);
        c = AWTAccessor.getComponentAccessor().getParent(c)) ;

    if (c instanceof Window) {
      wpeer = (XWindowPeer) c.getPeer();
    }

    if (wpeer == null) {
      throw new InvalidDnDOperationException("Cannot find top-level for the drag source component");
    }

    long xcursor = 0;
    long rootWindow = 0;
    long dragWindow = 0;
    long timeStamp = 0;

    /* Retrieve the X cursor for the drag operation. */
    {
      Cursor cursor = getCursor();
      if (cursor != null) {
        xcursor = XGlobalCursorManager.getCursor(cursor);
      }
    }

    XToolkit.awtLock();
    try {
      if (proxyModeSourceWindow != 0) {
        throw new InvalidDnDOperationException("Proxy drag in progress");
      }
      if (dndInProgress) {
        throw new InvalidDnDOperationException("Drag in progress");
      }

      /* Determine the root window for the drag operation. */
      {
        long screen = XlibWrapper.XScreenNumberOfScreen(wpeer.getScreen());
        rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen);
      }

      dragWindow = XWindow.getXAWTRootWindow().getWindow();

      timeStamp = XToolkit.getCurrentServerTime();

      int dropActions = getDragSourceContext().getSourceActions();

      Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
      while (dragProtocols.hasNext()) {
        XDragSourceProtocol dragProtocol = (XDragSourceProtocol) dragProtocols.next();
        try {
          dragProtocol.initializeDrag(
              dropActions, transferable,
              formatMap, formats);
        } catch (XException xe) {
          throw (InvalidDnDOperationException) new InvalidDnDOperationException().initCause(xe);
        }
      }

      /* Install X grabs. */
      {
        int status;
        XWindowAttributes wattr = new XWindowAttributes();
        try {
          status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), rootWindow, wattr.pData);

          if (status == 0) {
            throw new InvalidDnDOperationException("XGetWindowAttributes failed");
          }

          rootEventMask = wattr.get_your_event_mask();

          XlibWrapper.XSelectInput(
              XToolkit.getDisplay(), rootWindow, rootEventMask | ROOT_EVENT_MASK);
        } finally {
          wattr.dispose();
        }

        XBaseWindow.ungrabInput();

        status =
            XlibWrapper.XGrabPointer(
                XToolkit.getDisplay(),
                rootWindow,
                0,
                GRAB_EVENT_MASK,
                XConstants.GrabModeAsync,
                XConstants.GrabModeAsync,
                XConstants.None,
                xcursor,
                timeStamp);

        if (status != XConstants.GrabSuccess) {
          cleanup(timeStamp);
          throwGrabFailureException("Cannot grab pointer", status);
          return;
        }

        status =
            XlibWrapper.XGrabKeyboard(
                XToolkit.getDisplay(),
                rootWindow,
                0,
                XConstants.GrabModeAsync,
                XConstants.GrabModeAsync,
                timeStamp);

        if (status != XConstants.GrabSuccess) {
          cleanup(timeStamp);
          throwGrabFailureException("Cannot grab keyboard", status);
          return;
        }
      }

      /* Update the global state. */
      dndInProgress = true;
      dragInProgress = true;
      dragRootWindow = rootWindow;
      sourceActions = dropActions;
      sourceFormats = formats;
    } finally {
      XToolkit.awtUnlock();
    }

    /* This implementation doesn't use native context */
    setNativeContext(0);

    SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
  }
예제 #25
0
  /**
   * Creates window with parameters specified by <code>params</code>
   *
   * @see #init
   */
  private final void create(XCreateWindowParams params) {
    XToolkit.awtLock();
    try {
      XSetWindowAttributes xattr = new XSetWindowAttributes();
      try {
        checkParams(params);

        long value_mask = ((Long) params.get(VALUE_MASK)).longValue();

        Long eventMask = (Long) params.get(EVENT_MASK);
        xattr.set_event_mask(eventMask.longValue());
        value_mask |= XlibWrapper.CWEventMask;

        Long border_pixel = (Long) params.get(BORDER_PIXEL);
        if (border_pixel != null) {
          xattr.set_border_pixel(border_pixel.longValue());
          value_mask |= XlibWrapper.CWBorderPixel;
        }

        Long colormap = (Long) params.get(COLORMAP);
        if (colormap != null) {
          xattr.set_colormap(colormap.longValue());
          value_mask |= XlibWrapper.CWColormap;
        }
        Long background_pixmap = (Long) params.get(BACKGROUND_PIXMAP);
        if (background_pixmap != null) {
          xattr.set_background_pixmap(background_pixmap.longValue());
          value_mask |= XlibWrapper.CWBackPixmap;
        }

        Long parentWindow = (Long) params.get(PARENT_WINDOW);
        Rectangle bounds = (Rectangle) params.get(BOUNDS);
        Integer depth = (Integer) params.get(DEPTH);
        Integer visual_class = (Integer) params.get(VISUAL_CLASS);
        Long visual = (Long) params.get(VISUAL);
        Boolean overrideRedirect = (Boolean) params.get(OVERRIDE_REDIRECT);
        if (overrideRedirect != null) {
          xattr.set_override_redirect(overrideRedirect.booleanValue());
          value_mask |= XlibWrapper.CWOverrideRedirect;
        }

        Boolean saveUnder = (Boolean) params.get(SAVE_UNDER);
        if (saveUnder != null) {
          xattr.set_save_under(saveUnder.booleanValue());
          value_mask |= XlibWrapper.CWSaveUnder;
        }

        Integer backingStore = (Integer) params.get(BACKING_STORE);
        if (backingStore != null) {
          xattr.set_backing_store(backingStore.intValue());
          value_mask |= XlibWrapper.CWBackingStore;
        }

        Integer bitGravity = (Integer) params.get(BIT_GRAVITY);
        if (bitGravity != null) {
          xattr.set_bit_gravity(bitGravity.intValue());
          value_mask |= XlibWrapper.CWBitGravity;
        }

        if (log.isLoggable(Level.FINE)) {
          log.fine("Creating window for " + this + " with the following attributes: \n" + params);
        }
        window =
            XlibWrapper.XCreateWindow(
                XToolkit.getDisplay(),
                parentWindow.longValue(),
                bounds.x,
                bounds.y, // location
                bounds.width,
                bounds.height, // size
                0, // border
                depth.intValue(), // depth
                visual_class.intValue(), // class
                visual.longValue(), // visual
                value_mask, // value mask
                xattr.pData); // attributes

        if (window == 0) {
          throw new IllegalStateException(
              "Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details");
        }
        XToolkit.addToWinMap(window, this);
      } finally {
        xattr.dispose();
      }
    } finally {
      XToolkit.awtUnlock();
    }
  }
  /**
   * The caller must own awtLock.
   *
   * @returns true if the even was processed and shouldn't be passed along.
   */
  private boolean doProcessEvent(XEvent ev) {
    assert XToolkit.isAWTLockHeldByCurrentThread();

    if (processProxyModeEvent(ev)) {
      return true;
    }

    if (!dndInProgress) {
      return false;
    }

    switch (ev.get_type()) {
      case XConstants.ClientMessage:
        {
          XClientMessageEvent xclient = ev.get_xclient();
          return processClientMessage(xclient);
        }
      case XConstants.DestroyNotify:
        {
          XDestroyWindowEvent xde = ev.get_xdestroywindow();

          /* Target crashed during drop processing - cleanup. */
          if (!dragInProgress
              && dragProtocol != null
              && xde.get_window() == dragProtocol.getTargetWindow()) {
            cleanup(XConstants.CurrentTime);
            return true;
          }
          /* Pass along */
          return false;
        }
    }

    if (!dragInProgress) {
      return false;
    }

    /* Process drag-only messages. */
    switch (ev.get_type()) {
      case XConstants.KeyRelease:
      case XConstants.KeyPress:
        {
          XKeyEvent xkey = ev.get_xkey();
          long keysym = XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), xkey.get_keycode(), 0);
          switch ((int) keysym) {
            case (int) XKeySymConstants.XK_Escape:
              {
                if (ev.get_type() == (int) XConstants.KeyRelease) {
                  cleanup(xkey.get_time());
                }
                break;
              }
            case (int) XKeySymConstants.XK_Control_R:
            case (int) XKeySymConstants.XK_Control_L:
            case (int) XKeySymConstants.XK_Shift_R:
            case (int) XKeySymConstants.XK_Shift_L:
              {
                XlibWrapper.XQueryPointer(
                    XToolkit.getDisplay(),
                    xkey.get_root(),
                    XlibWrapper.larg1, // root
                    XlibWrapper.larg2, // subwindow
                    XlibWrapper.larg3, // x_root
                    XlibWrapper.larg4, // y_root
                    XlibWrapper.larg5, // x
                    XlibWrapper.larg6, // y
                    XlibWrapper.larg7); // modifiers
                XMotionEvent xmotion = new XMotionEvent();
                try {
                  xmotion.set_type(XConstants.MotionNotify);
                  xmotion.set_serial(xkey.get_serial());
                  xmotion.set_send_event(xkey.get_send_event());
                  xmotion.set_display(xkey.get_display());
                  xmotion.set_window(xkey.get_window());
                  xmotion.set_root(xkey.get_root());
                  xmotion.set_subwindow(xkey.get_subwindow());
                  xmotion.set_time(xkey.get_time());
                  xmotion.set_x(xkey.get_x());
                  xmotion.set_y(xkey.get_y());
                  xmotion.set_x_root(xkey.get_x_root());
                  xmotion.set_y_root(xkey.get_y_root());
                  xmotion.set_state((int) Native.getLong(XlibWrapper.larg7));
                  // we do not use this field, so it's unset for now
                  // xmotion.set_is_hint(???);
                  xmotion.set_same_screen(xkey.get_same_screen());

                  // It's safe to use key event as motion event since we use only their common
                  // fields.
                  processMouseMove(xmotion);
                } finally {
                  xmotion.dispose();
                }
                break;
              }
          }
          return true;
        }
      case XConstants.ButtonPress:
        return true;
      case XConstants.MotionNotify:
        processMouseMove(ev.get_xmotion());
        return true;
      case XConstants.ButtonRelease:
        {
          XButtonEvent xbutton = ev.get_xbutton();
          /*
           * Ignore the buttons above 20 due to the bit limit for
           * InputEvent.BUTTON_DOWN_MASK.
           * One more bit is reserved for FIRST_HIGH_BIT.
           */
          if (xbutton.get_button() > SunToolkit.MAX_BUTTONS_SUPPORTED) {
            return true;
          }

          /*
           * On some X servers it could happen that ButtonRelease coordinates
           * differ from the latest MotionNotify coordinates, so we need to
           * process it as a mouse motion.
           */
          XMotionEvent xmotion = new XMotionEvent();
          try {
            xmotion.set_type(XConstants.MotionNotify);
            xmotion.set_serial(xbutton.get_serial());
            xmotion.set_send_event(xbutton.get_send_event());
            xmotion.set_display(xbutton.get_display());
            xmotion.set_window(xbutton.get_window());
            xmotion.set_root(xbutton.get_root());
            xmotion.set_subwindow(xbutton.get_subwindow());
            xmotion.set_time(xbutton.get_time());
            xmotion.set_x(xbutton.get_x());
            xmotion.set_y(xbutton.get_y());
            xmotion.set_x_root(xbutton.get_x_root());
            xmotion.set_y_root(xbutton.get_y_root());
            xmotion.set_state(xbutton.get_state());
            // we do not use this field, so it's unset for now
            // xmotion.set_is_hint(???);
            xmotion.set_same_screen(xbutton.get_same_screen());

            // It's safe to use key event as motion event since we use only their common fields.
            processMouseMove(xmotion);
          } finally {
            xmotion.dispose();
          }
          if (xbutton.get_button() == XConstants.buttons[0]
              || xbutton.get_button() == XConstants.buttons[1]) {
            // drag is initiated with Button1 or Button2 pressed and
            // ended on release of either of these buttons (as the same
            // behavior was with our old Motif DnD-based implementation)
            removeDnDGrab(xbutton.get_time());
            dragInProgress = false;
            if (dragProtocol != null && targetAction != DnDConstants.ACTION_NONE) {
              /*
               * ACTION_NONE indicates that either the drop target rejects the
               * drop or it haven't responded yet. The latter could happen in
               * case of fast drag, slow target-server connection or slow
               * drag notifications processing on the target side.
               */
              processDrop(xbutton);
            } else {
              cleanup(xbutton.get_time());
            }
          }
          return true;
        }
    }

    return false;
  }
예제 #27
0
  /**
   * 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.
   */
  public boolean grabInput() {
    if (grabLog.isLoggable(Level.FINE)) {
      grabLog.log(Level.FINE, "Grab input on {0}", new Object[] {String.valueOf(this)});
    }

    XToolkit.awtLock();
    try {
      if (XAwtState.getGrabWindow() == this && XAwtState.isManualGrab()) {
        grabLog.fine("    Already Grabbed");
        return true;
      }
      // 6273031: PIT. Choice drop down does not close once it is right clicked to show a popup menu
      // remember previous window having grab and if it's not null ungrab it.
      XBaseWindow prevGrabWindow = XAwtState.getGrabWindow();
      final int eventMask =
          (int)
              (ButtonPressMask
                  | ButtonReleaseMask
                  | EnterWindowMask
                  | LeaveWindowMask
                  | PointerMotionMask
                  | ButtonMotionMask);
      final int ownerEvents = 1;

      int ptrGrab =
          XlibWrapper.XGrabPointer(
              XToolkit.getDisplay(),
              getContentWindow(),
              ownerEvents,
              eventMask,
              GrabModeAsync,
              GrabModeAsync,
              None,
              (XWM.isMotif() ? XToolkit.arrowCursor : None),
              CurrentTime);
      // Check grab results to be consistent with X server grab
      if (ptrGrab != GrabSuccess) {
        XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), CurrentTime);
        XAwtState.setGrabWindow(null);
        grabLog.fine("    Grab Failure - mouse");
        return false;
      }

      int keyGrab =
          XlibWrapper.XGrabKeyboard(
              XToolkit.getDisplay(),
              getContentWindow(),
              ownerEvents,
              GrabModeAsync,
              GrabModeAsync,
              CurrentTime);
      if (keyGrab != GrabSuccess) {
        XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), CurrentTime);
        XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), 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();
    }
  }
예제 #28
0
 public void setSizeHints(long flags, int x, int y, int width, int height) {
   if (insLog.isLoggable(Level.FINER))
     insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(flags));
   XToolkit.awtLock();
   try {
     XSizeHints hints = getHints();
     // Note: if PPosition is not set in flags this means that
     // we want to reset PPosition in hints.  This is necessary
     // for locationByPlatform functionality
     if ((flags & XlibWrapper.PPosition) != 0) {
       hints.set_x(x);
       hints.set_y(y);
     }
     if ((flags & XlibWrapper.PSize) != 0) {
       hints.set_width(width);
       hints.set_height(height);
     } else if ((hints.get_flags() & XlibWrapper.PSize) != 0) {
       flags |= XlibWrapper.PSize;
     }
     if ((flags & XlibWrapper.PMinSize) != 0) {
       hints.set_min_width(width);
       hints.set_min_height(height);
     } else if ((hints.get_flags() & XlibWrapper.PMinSize) != 0) {
       flags |= XlibWrapper.PMinSize;
       // Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
       // We don't need to reset minimum size if it's already set
     }
     if ((flags & XlibWrapper.PMaxSize) != 0) {
       if (maxBounds != null) {
         if (maxBounds.width != Integer.MAX_VALUE) {
           hints.set_max_width(maxBounds.width);
         } else {
           hints.set_max_width(XToolkit.getDefaultScreenWidth());
         }
         if (maxBounds.height != Integer.MAX_VALUE) {
           hints.set_max_height(maxBounds.height);
         } else {
           hints.set_max_height(XToolkit.getDefaultScreenHeight());
         }
       } else {
         hints.set_max_width(width);
         hints.set_max_height(height);
       }
     } else if ((hints.get_flags() & XlibWrapper.PMaxSize) != 0) {
       flags |= XlibWrapper.PMaxSize;
       if (maxBounds != null) {
         if (maxBounds.width != Integer.MAX_VALUE) {
           hints.set_max_width(maxBounds.width);
         } else {
           hints.set_max_width(XToolkit.getDefaultScreenWidth());
         }
         if (maxBounds.height != Integer.MAX_VALUE) {
           hints.set_max_height(maxBounds.height);
         } else {
           hints.set_max_height(XToolkit.getDefaultScreenHeight());
         }
       } else {
         // Leave intact
       }
     }
     flags |= XlibWrapper.PWinGravity;
     hints.set_flags(flags);
     hints.set_win_gravity((int) XlibWrapper.NorthWestGravity);
     if (insLog.isLoggable(Level.FINER))
       insLog.finer(
           "Setting hints, resulted flags "
               + XlibWrapper.hintsToString(flags)
               + ", values "
               + hints);
     XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), getWindow(), hints.pData);
   } finally {
     XToolkit.awtUnlock();
   }
 }