Created
September 6, 2010 14:11
Obtaining window pointers using Sun's X11 toolkit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala -nocompdaemon -savecompiled $0 $@ | |
!# | |
// See also: | |
// http://www.docjar.com/html/api/sun/awt/X11/XlibUtil.java.html | |
// Overall the toolkit doesn't provide enough methods to do what I intended, | |
// alternatives are to use JNA or wmctrl. | |
val nativeC = getClass.getClassLoader.loadClass ("sun.awt.X11.Native") | |
//for (method <- nativeC.getDeclaredMethods) {println (method)} | |
val getWindowM = nativeC.getDeclaredMethod ("getWindow", java.lang.Long.TYPE, java.lang.Integer.TYPE) | |
getWindowM.setAccessible (true) | |
val drw = sun.awt.X11.XToolkit.getDefaultRootWindow | |
val xq = new sun.awt.X11.XQueryTree (drw) | |
try { | |
println ("xq.execute: " + xq.execute) // should be 1 | |
println ("xq.get_parent: " + xq.get_parent) | |
println ("xq.get_nchildren: " + xq.get_nchildren) | |
if (xq.get_nchildren > 0) { | |
for (i <- 0 until xq.get_nchildren) { | |
//println (Native.getWindow (xq.get_children, i)) | |
val windowPtr = getWindowM.invoke (null, | |
xq.get_children.asInstanceOf[java.lang.Long], i.asInstanceOf[java.lang.Integer]) | |
println ("windowPtr: " + windowPtr) | |
} | |
} | |
} finally {xq.dispose} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment