Пример #1
0
 /** Xinerama-aware version of XlibWrapper.RootWindow method. */
 public static long getRootWindow(int screenNumber) {
   XToolkit.awtLock();
   try {
     X11GraphicsEnvironment x11ge =
         (X11GraphicsEnvironment) GraphicsEnvironment.getLocalGraphicsEnvironment();
     if (x11ge.runningXinerama()) {
       // all the Xinerama windows share the same root window
       return XlibWrapper.RootWindow(XToolkit.getDisplay(), 0);
     } else {
       return XlibWrapper.RootWindow(XToolkit.getDisplay(), screenNumber);
     }
   } finally {
     XToolkit.awtUnlock();
   }
 }
Пример #2
0
  /** Returns the supported cursor size */
  static Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {

    // Fix for bug 4212593 The Toolkit.createCustomCursor does not
    //                     check absence of the image of cursor
    // We use XQueryBestCursor which accepts unsigned ints to obtain
    // the largest cursor size that could be dislpayed
    // Dimension d = new Dimension(Math.abs(preferredWidth), Math.abs(preferredHeight));
    Dimension d;

    XToolkit.awtLock();
    try {
      long display = XToolkit.getDisplay();
      long root_window = XlibWrapper.RootWindow(display, XlibWrapper.DefaultScreen(display));

      XlibWrapper.XQueryBestCursor(
          display,
          root_window,
          Math.abs(preferredWidth),
          Math.abs(preferredHeight),
          XlibWrapper.larg1,
          XlibWrapper.larg2);
      d =
          new Dimension(
              XlibWrapper.unsafe.getInt(XlibWrapper.larg1),
              XlibWrapper.unsafe.getInt(XlibWrapper.larg2));
    } finally {
      XToolkit.awtUnlock();
    }
    return d;
  }
Пример #3
0
  protected void createCursor(
      byte[] xorMask,
      byte[] andMask,
      int width,
      int height,
      int fcolor,
      int bcolor,
      int xHotSpot,
      int yHotSpot) {
    XToolkit.awtLock();
    try {
      long display = XToolkit.getDisplay();
      long root_window = XlibWrapper.RootWindow(display, XlibWrapper.DefaultScreen(display));

      long colormap = XToolkit.getDefaultXColormap();
      XColor fore_color = new XColor();

      fore_color.set_flags((byte) (XlibWrapper.DoRed | XlibWrapper.DoGreen | XlibWrapper.DoBlue));
      fore_color.set_red((short) (((fcolor >> 16) & 0x000000ff) << 8));
      fore_color.set_green((short) (((fcolor >> 8) & 0x000000ff) << 8));
      fore_color.set_blue((short) (((fcolor >> 0) & 0x000000ff) << 8));

      XlibWrapper.XAllocColor(display, colormap, fore_color.pData);

      XColor back_color = new XColor();
      back_color.set_flags((byte) (XlibWrapper.DoRed | XlibWrapper.DoGreen | XlibWrapper.DoBlue));

      back_color.set_red((short) (((bcolor >> 16) & 0x000000ff) << 8));
      back_color.set_green((short) (((bcolor >> 8) & 0x000000ff) << 8));
      back_color.set_blue((short) (((bcolor >> 0) & 0x000000ff) << 8));

      XlibWrapper.XAllocColor(display, colormap, back_color.pData);

      long nativeXorMask = Native.toData(xorMask);
      long source =
          XlibWrapper.XCreateBitmapFromData(display, root_window, nativeXorMask, width, height);

      long nativeAndMask = Native.toData(andMask);
      long mask =
          XlibWrapper.XCreateBitmapFromData(display, root_window, nativeAndMask, width, height);

      long cursor =
          XlibWrapper.XCreatePixmapCursor(
              display, source, mask, fore_color.pData, back_color.pData, xHotSpot, yHotSpot);

      XlibWrapper.unsafe.freeMemory(nativeXorMask);
      XlibWrapper.unsafe.freeMemory(nativeAndMask);
      XlibWrapper.XFreePixmap(display, source);
      XlibWrapper.XFreePixmap(display, mask);
      back_color.dispose();
      fore_color.dispose();

      XGlobalCursorManager.setPData(this, cursor);
    } finally {
      XToolkit.awtUnlock();
    }
  }
Пример #4
0
  /** Checks if the given window is a root window for the given screen */
  static boolean isRoot(long rootCandidate, long screenNumber) {
    long root;

    XToolkit.awtLock();
    try {
      root = XlibWrapper.RootWindow(XToolkit.getDisplay(), screenNumber);
    } finally {
      XToolkit.awtUnlock();
    }

    return root == rootCandidate;
  }
Пример #5
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);
   }
 }
Пример #6
0
  public void handleReparentNotifyEvent(XEvent xev) {
    XReparentEvent xe = xev.get_xreparent();
    if (insLog.isLoggable(Level.FINE)) insLog.fine(xe.toString());
    reparent_serial = xe.get_serial();
    XToolkit.awtLock();
    try {
      long root = XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber());

      if (isEmbedded()) {
        setReparented(true);
        insets_corrected = true;
        return;
      }
      Component t = (Component) target;
      if (getDecorations() == winAttr.AWT_DECOR_NONE) {
        setReparented(true);
        insets_corrected = true;
        reshape(dimensions, SET_SIZE, false);
      } else if (xe.get_parent() == root) {
        configure_seen = false;
        insets_corrected = false;

        /*
         * We can be repareted to root for two reasons:
         *   . setVisible(false)
         *   . WM exited
         */
        if (isVisible()) {
            /* WM exited */
          /* Work around 4775545 */
          XWM.getWM().unshadeKludge(this);
          insLog.fine("- WM exited");
        } else {
          insLog.fine(" - reparent due to hide");
        }
      } else {
          /* reparented to WM frame, figure out our insets */
        setReparented(true);
        insets_corrected = false;

        // Check if we have insets provided by the WM
        Insets correctWM = getWMSetInsets(null);
        if (correctWM != null) {
          if (insLog.isLoggable(Level.FINER)) {
            insLog.log(
                Level.FINER, "wm-provided insets {0}", new Object[] {String.valueOf(correctWM)});
          }
          // If these insets are equal to our current insets - no actions are necessary
          Insets dimInsets = dimensions.getInsets();
          if (correctWM.equals(dimInsets)) {
            insLog.finer("Insets are the same as estimated - no additional reshapes necessary");
            no_reparent_artifacts = true;
            insets_corrected = true;
            applyGuessedInsets();
            return;
          }
        } else {
          correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent());

          if (correctWM != null) {
            if (insLog.isLoggable(Level.FINER)) {
              insLog.log(Level.FINER, "correctWM {0}", new Object[] {String.valueOf(correctWM)});
            }
          } else {
            insLog.log(
                Level.FINER, "correctWM insets are not available, waiting for configureNotify");
          }
        }

        if (correctWM != null) {
          handleCorrectInsets(correctWM);
        }
      }
    } finally {
      XToolkit.awtUnlock();
    }
  }
Пример #7
0
 private Point queryXLocation() {
   return XlibUtil.translateCoordinates(
       getContentWindow(),
       XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()),
       new Point(0, 0));
 }
  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);
  }