long (@NotNull Window frame) { try { // getPeer method was removed in jdk9, but 'peer' field still exists MethodHandles.Lookup lookup = MethodHandles.lookup(); ComponentPeer componentPeer = (ComponentPeer)MethodHandles.privateLookupIn(Component.class, lookup) .findVarHandle(Component.class, "peer", ComponentPeer.class) .get(frame); if (componentPeer == null) { // wait a little for X11-peer to be connected LOG.debug("frame peer is null, wait for connection"); return 0; } // sun.awt.X11.XBaseWindow isn't available at all jdks => use reflection Class<? extends ComponentPeer> componentPeerClass = componentPeer.getClass(); if (!componentPeerClass.getName().equals("sun.awt.X11.XFramePeer")) { LOG.info("frame peer isn't instance of XBaseWindow, class of peer: " + componentPeerClass); return 0; } // System.out.println("Window id (from XBaseWindow): 0x" + Long.toHexString(((XBaseWindow)frame.getPeer()).getWindow())); return (long)MethodHandles.privateLookupIn(componentPeerClass, lookup) .findVirtual(componentPeerClass, "getWindow", MethodType.methodType(Long.TYPE)) .invoke(componentPeer); } catch (Throwable e) { LOG.error(e); return 0; } }