OS: Ubuntu 16.04
JNA: 4.2.X
JDK: 1.8.0u111
I'm trying to get the currently focused window programmaticaly on a JavaFX application.
if (Platform.isLinux()) {
final X11 x11 = X11.INSTANCE;
final XLib xlib = XLib.INSTANCE;
X11.Display display = x11.XOpenDisplay(null);
X11.Window window = new X11.Window();
Pointer pointer = Pointer.NULL;
xlib.XGetInputFocus(display, window, pointer); // << ERROR
X11.XTextProperty name = new X11.XTextProperty();
x11.XGetWMName(display, window, name);
System.out.println(name.toString());
}
public interface XLib extends StdCallLibrary {
XLib INSTANCE = (XLib) Native.loadLibrary("/usr/lib/x86_64-linux-gnu/libX11.so", XLib.class);
int XGetInputFocus(X11.Display display, X11.Window focus_return, Pointer revert_to_return);
}
But it doesn't work and throws this exception :
java.lang.IllegalArgumentException: Unrecognized calling convention: 63
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:390)
at com.sun.jna.Function.invoke(Function.java:323)
at com.sun.jna.Library$Handler.invoke(Library.java:236)
at com.sun.proxy.$Proxy1.XGetInputFocus(Unknown Source)
at application.Main.start(Main.java:33)
Is this line correct ?
XLib INSTANCE = (XLib) Native.loadLibrary("/usr/lib/x86_64-linux-gnu/libX11.so", XLib.class);
I tested with an older version of JNA (4.1.X) and the error changed for :
Unrecognized calling convention: 1
Debug log with -Djna.debug_load=true
Looking in classpath from sun.misc.Launcher$AppClassLoader@73d16e93 for /com/sun/jna/linux-x86-64/libjnidispatch.so
Found library resource at jar:file:/home/puglic/eclipse/jna-4.2.2.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so
Looking for library 'X11'
Adding paths from jna.library.path: null
Trying libX11.so
Found library 'X11' at libX11.so
Looking for library 'X11'
Adding paths from jna.library.path: null
Trying libX11.so
Found library 'X11' at libX11.so
java.lang.IllegalArgumentException: Unrecognized calling convention: 63
Your XLib
definition uses StdCallLibrary
, which only makes sense on 32-bit windows systems. It should simply be Library
, or derive from the JNA contrib-defined version.
You're basically asking for a calling convention that does not exist.