/** * Translate coordinates from one window into another. Optimized for XAWT - uses cached data when * possible. Preferable over pure XTranslateCoordinates. * * @return coordinates relative to dst, or null if error happened */ static Point toOtherWindow(long src, long dst, int x, int y) { Point rpt = new Point(0, 0); // Check if both windows belong to XAWT - then no X calls are necessary XBaseWindow srcPeer = XToolkit.windowToXWindow(src); XBaseWindow dstPeer = XToolkit.windowToXWindow(dst); if (srcPeer != null && dstPeer != null) { // (x, y) is relative to src rpt.x = x + srcPeer.getAbsoluteX() - dstPeer.getAbsoluteX(); rpt.y = y + srcPeer.getAbsoluteY() - dstPeer.getAbsoluteY(); } else if (dstPeer != null && XlibUtil.isRoot(src, dstPeer.getScreenNumber())) { // from root into peer rpt.x = x - dstPeer.getAbsoluteX(); rpt.y = y - dstPeer.getAbsoluteY(); } else if (srcPeer != null && XlibUtil.isRoot(dst, srcPeer.getScreenNumber())) { // from peer into root rpt.x = x + srcPeer.getAbsoluteX(); rpt.y = y + srcPeer.getAbsoluteY(); } else { rpt = XlibUtil.translateCoordinates(src, dst, new Point(x, y)); } return rpt; }
/** Returns the client window under the specified root subwindow. */ private static long findClientWindow(long window) { if (XlibUtil.isTrueToplevelWindow(window)) { return window; } Set<Long> children = XlibUtil.getChildWindows(window); for (Long child : children) { long win = findClientWindow(child); if (win != 0) { return win; } } return 0; }
final void dumpParent() { long parent = XlibUtil.getParentWindow(getShell()); if (parent != 0) { dumpWindow("Parent", parent); } else { System.err.println(">>> NO PARENT"); } }
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 void handleConfigureNotifyEvent(XEvent xev) { assert (SunToolkit.isAWTLockHeldByCurrentThread()); XConfigureEvent xe = xev.get_xconfigure(); if (insLog.isLoggable(Level.FINE)) { insLog.log(Level.FINE, "Configure notify {0}", new Object[] {String.valueOf(xe)}); } // XXX: should really only consider synthetic events, but if (isReparented()) { configure_seen = true; } if (!isMaximized() && (xe.get_serial() == reparent_serial || xe.get_window() != getShell()) && !no_reparent_artifacts) { insLog.fine("- reparent artifact, skipping"); return; } no_reparent_artifacts = false; /** * When there is a WM we receive some CN before being visible and after. We should skip all CN * which are before being visible, because we assume the gravity is in action while it is not * yet. * * <p>When there is no WM we receive CN only _before_ being visible. We should process these * CNs. */ if (!isVisible() && XWM.getWMID() != XWM.NO_WM) { insLog.fine(" - not visible, skipping"); return; } /* * Some window managers configure before we are reparented and * the send event flag is set! ugh... (Enlighetenment for one, * possibly MWM as well). If we haven't been reparented yet * this is just the WM shuffling us into position. Ignore * it!!!! or we wind up in a bogus location. */ int runningWM = XWM.getWMID(); if (insLog.isLoggable(Level.FINE)) { insLog.log( Level.FINE, "reparented={0}, visible={1}, WM={2}, decorations={3}", new Object[] {isReparented(), isVisible(), runningWM, getDecorations()}); } if (!isReparented() && isVisible() && runningWM != XWM.NO_WM && !XWM.isNonReparentingWM() && getDecorations() != winAttr.AWT_DECOR_NONE) { insLog.fine("- visible but not reparented, skipping"); return; } // Last chance to correct insets if (!insets_corrected && getDecorations() != winAttr.AWT_DECOR_NONE) { long parent = XlibUtil.getParentWindow(window); Insets correctWM = (parent != -1) ? XWM.getWM().getInsets(this, window, parent) : null; if (insLog.isLoggable(Level.FINER)) { if (correctWM != null) { insLog.finer("Configure notify - insets : " + correctWM); } else { insLog.finer("Configure notify - insets are still not available"); } } if (correctWM != null) { handleCorrectInsets(correctWM); } else { // Only one attempt to correct insets is made (to lower risk) // if insets are still not available we simply set the flag insets_corrected = true; } } updateChildrenSizes(); // Bounds of the window Rectangle targetBounds = new Rectangle( ComponentAccessor.getX((Component) target), ComponentAccessor.getY((Component) target), ComponentAccessor.getWidth((Component) target), ComponentAccessor.getHeight((Component) target)); Point newLocation = targetBounds.getLocation(); if (xe.get_send_event() || runningWM == XWM.NO_WM || XWM.isNonReparentingWM()) { // Location, Client size + insets newLocation = new Point(xe.get_x() - currentInsets.left, xe.get_y() - currentInsets.top); } else { // CDE/MWM/Metacity/Sawfish bug: if shell is resized using // top or left border, we don't receive synthetic // ConfigureNotify, only the one from X with zero // coordinates. This is the workaround to get real // location, 6261336 switch (XWM.getWMID()) { case XWM.CDE_WM: case XWM.MOTIF_WM: case XWM.METACITY_WM: case XWM.SAWFISH_WM: { Point xlocation = queryXLocation(); if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "New X location: {0}", new Object[] {String.valueOf(xlocation)}); } if (xlocation != null) { newLocation = xlocation; } break; } default: break; } } WindowDimensions newDimensions = new WindowDimensions( newLocation, new Dimension(xe.get_width(), xe.get_height()), copy(currentInsets), true); if (insLog.isLoggable(Level.FINER)) { insLog.log( Level.FINER, "Insets are {0}, new dimensions {1}", new Object[] {String.valueOf(currentInsets), String.valueOf(newDimensions)}); } checkIfOnNewScreen(newDimensions.getBounds()); Point oldLocation = getLocation(); dimensions = newDimensions; if (!newLocation.equals(oldLocation)) { handleMoved(newDimensions); } reconfigureContentWindow(newDimensions); updateChildrenSizes(); }
private Point queryXLocation() { return XlibUtil.translateCoordinates( getContentWindow(), XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()), new Point(0, 0)); }
public int getAbsoluteY() { Point absoluteLoc = XlibUtil.translateCoordinates( getWindow(), XToolkit.getDefaultRootWindow(), new Point(0, 0)); return absoluteLoc != null ? absoluteLoc.y : 0; }