亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

XGetInputFocus 的正確 JNA 映射是什么

XGetInputFocus 的正確 JNA 映射是什么

慕娘9325324 2022-05-12 18:46:37
我正在嘗試XGetInputFocus通過 JNA 映射 X11。原始方法簽名是XGetInputFocus(Display *display, Window *focus_return, int *revert_to_return)我假設可以使用已經定義的 JNA 平臺類型將其映射到 Java 中的以下內容。void XGetInputFocus(Display display, Window focus_return, IntByReference revert_to_return);這與文檔中描述的建議相關。我現在使用以下代碼調用它final X11 XLIB = X11.INSTANCE;Window current = new Window();Display display = XLIB.XOpenDisplay(null);if (display != null) {   IntByReference revert_to_return = new IntByReference();   XLIB.XGetInputFocus(display, current, revert_to_return);}但是,它會使JVM崩潰# Problematic frame:# C  [libX11.so.6+0x285b7]  XGetInputFocus+0x57我錯過了什么?
查看完整描述

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。


查看完整回答
反對 回復 2022-05-12
  • 1 回答
  • 0 關注
  • 259 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號