/** 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; }
public void setShellBounds(Rectangle rec) { if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell bounds on " + this + " to " + rec); XToolkit.awtLock(); try { updateSizeHints(rec.x, rec.y, rec.width, rec.height); XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height); XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y); } finally { XToolkit.awtUnlock(); } }
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(); } }
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(); } }
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(); } }
void flush() { XToolkit.awtLock(); try { XlibWrapper.XFlush(XToolkit.getDisplay()); } 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(); } }
public static long xGetInputFocus() { XToolkit.awtLock(); try { return XlibWrapper.XGetInputFocus(XToolkit.getDisplay()); } 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(); } }
static long getScreenOfWindow(long window) { XToolkit.awtLock(); try { return XlibWrapper.getScreenOfWindow(XToolkit.getDisplay(), window); } finally { XToolkit.awtUnlock(); } }
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); } }
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; }
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(); } }
/* * 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; }
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(); } }
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); } }
public void synthesizeFocusInOut(boolean doFocus) { XFocusChangeEvent xev = new XFocusChangeEvent(); XToolkit.awtLock(); try { xev.set_type(doFocus ? FocusIn : FocusOut); xev.set_window(getFocusProxy().getWindow()); xev.set_mode(NotifyNormal); XlibWrapper.XSendEvent( XToolkit.getDisplay(), getFocusProxy().getWindow(), false, NoEventMask, xev.pData); } finally { XToolkit.awtUnlock(); xev.dispose(); } }
void postInit(XCreateWindowParams params) { super.postInit(params); if (embedder != null) { // install X11 event dispatcher embedder.setClient(this); // reparent to XEmbed server embedder.install(); } else if (getParentWindowHandle() != 0) { XToolkit.awtLock(); try { XlibWrapper.XReparentWindow( XToolkit.getDisplay(), getWindow(), getParentWindowHandle(), 0, 0); } finally { XToolkit.awtUnlock(); } } }
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 Rectangle getBoundsPrivate() { int x = 0, y = 0; int w = 0, h = 0; XWindowAttributes attr = new XWindowAttributes(); XToolkit.awtLock(); try { XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), getWindow(), attr.pData); x = attr.get_x(); y = attr.get_y(); w = attr.get_width(); h = attr.get_height(); } finally { XToolkit.awtUnlock(); } attr.dispose(); return new Rectangle(x, y, w, h); }
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(); } }
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); } }
final void dumpWindow(String id, long window) { XWindowAttributes pattr = new XWindowAttributes(); try { XToolkit.awtLock(); try { int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), window, pattr.pData); } finally { XToolkit.awtUnlock(); } System.err.println( ">>>> " + id + ": " + pattr.get_x() + ", " + pattr.get_y() + ", " + pattr.get_width() + ", " + pattr.get_height()); } finally { pattr.dispose(); } }
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(); } }
private Point queryXLocation() { return XlibUtil.translateCoordinates( getContentWindow(), XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()), new Point(0, 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(); } }