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();
   }
 }
Exemple #2
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();
    }
  }
 public void toFront() {
   XToolkit.awtLock();
   try {
     XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
 long getScreenNumber() {
   XToolkit.awtLock();
   try {
     return XlibWrapper.XScreenNumberOfScreen(getScreen());
   } finally {
     XToolkit.awtUnlock();
   }
 }
 /** Helper function to set W */
 public final void setWMHints(XWMHints hints) {
   XToolkit.awtLock();
   try {
     XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
   } finally {
     XToolkit.awtUnlock();
   }
 }
 void flush() {
   XToolkit.awtLock();
   try {
     XlibWrapper.XFlush(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
 public static long xGetInputFocus() {
   XToolkit.awtLock();
   try {
     return XlibWrapper.XGetInputFocus(XToolkit.getDisplay());
   } finally {
     XToolkit.awtUnlock();
   }
 }
 static long getScreenOfWindow(long window) {
   XToolkit.awtLock();
   try {
     return XlibWrapper.getScreenOfWindow(XToolkit.getDisplay(), window);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Exemple #9
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);
   }
 }
Exemple #10
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();
   }
 }
 public XWMHints getWMHints() {
   if (wmHints == null) {
     wmHints = new XWMHints(XlibWrapper.XAllocWMHints());
     //              XlibWrapper.XGetWMHints(XToolkit.getDisplay(),
     //                                      getWindow(),
     //                                      wmHints.pData);
   }
   return wmHints;
 }
 /*
  * 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;
 }
 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();
   }
 }
 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();
   }
 }
Exemple #15
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;
 }
  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();
    }
  }
 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);
   }
 }
Exemple #18
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();
  }
 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();
   }
 }
Exemple #20
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);
   }
 }
  /**
   * 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();
    }
  }
  /**
   * 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();
    }
  }
 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();
   }
 }