简体   繁体   English

JNA-Ubuntu-XGetInputFocus

[英]JNA - Ubuntu - XGetInputFocus

OS: Ubuntu 16.04 操作系统:Ubuntu 16.04
JNA: 4.2.X JNA:4.2.X
JDK: 1.8.0u111 JDK:1.8.0u111

I'm trying to get the currently focused window programmaticaly on a JavaFX application. 我正在尝试以编程方式在JavaFX应用程序上获取当前关注的窗口。

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 : 我使用旧版本的JNA(4.1.X)进行了测试,并且错误更改为:

Unrecognized calling convention: 1

Debug log with -Djna.debug_load=true 使用-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. 您的XLib定义使用StdCallLibrary ,仅在32位Windows系统上才有意义。 It should simply be Library , or derive from the JNA contrib-defined version. 它应该只是Library ,或者是从JNA contrib定义的版本派生的。

You're basically asking for a calling convention that does not exist. 您基本上是在要求不存在的调用约定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM