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。
添加回答
舉報