1 回答

TA贡献1801条经验 获得超8个赞
在原生 X11 函数中
XGetInputFocus(Display *display, Window *focus_return, int *revert_to_return)
该参数Window *focus_return用于返回一个Window. JNA 实现Window起来非常像不可变类型,因为在 C 语言中它是由typedef XID Window;. 因此Window*,C 中的类型需要映射到WindowByReferenceJNA 中。(这与C 中需要映射到JNA中
的原因基本相同。)int*IntByReference
那么扩展X11界面可以是这样的:
public interface X11Extended extends X11 {
X11Extended INSTANCE = (X11Extended) Native.loadLibrary("X11", X11Extended.class);
void XGetInputFocus(Display display, WindowByReference focus_return, IntByReference revert_to_return);
}
并且您的代码应该相应地修改:
X11Extended xlib = X11Extended.INSTANCE;
WindowByReference current_ref = new WindowByReference();
Display display = xlib.XOpenDisplay(null);
if (display != null) {
IntByReference revert_to_return = new IntByReference();
xlib.XGetInputFocus(display, current_ref, revert_to_return);
Window current = current_ref.getValue();
System.out.println(current);
}
现在程序不再崩溃了。对我来说,它打印出来0x3c00605。
添加回答
举报