1

WM_CLASSプログラムでは、現在フォーカスされているウィンドウのプロパティを把握する必要があります。これは、フォーカスされたウィンドウが gtk アプリケーションでない限り、正常XGetInputFocus()に機能します。XGetClassHint()

私は次の最小限のサンプルプログラムを書きましたwmclass.c:

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

int main(int argc, char** argv) 
{
    Window win;
    Display *d;
    XClassHint *clh;

    int rev;
    int status;

    clh = XAllocClassHint();
    d = XOpenDisplay(0);

    for(;;) {
        XGetInputFocus(d, &win, &rev);
        status = XGetClassHint(d,win,clh);
        if (status) 
            printf("name: %s, class: %s\n", clh->res_name,clh->res_class);
        else 
            printf("failed\n");
        sleep(1);
    }

    XFree(clh);
}

このプログラムは以下を出力します。

名前: xterm、クラス: XTerm
名前: xterm、クラス: XTerm
失敗
失敗
失敗
名前: xterm、クラス: XTerm
名前: xterm、クラス: XTerm
名前: okular、クラス: Okular
名前: okular、クラス: Okular
失敗
失敗
名前: xterm 、クラス: XTerm
名: xterm、クラス: XTerm
名: xterm、クラス: XTerm

failedgtk アプリがフォーカスされている場合に発生します。私は、emacs、gimp、chromium、および ardour をテストしました。

何故ですか?どうすればWM_CLASSgtk-windows を取得できますか?

4

1 に答える 1

1

フォーカスは必ずしも最上位ウィンドウに設定されているわけではありません。特に、Gtk はそのようなウィンドウの子に設定する傾向があります。

ウィンドウ ツリーを上に移動する必要があります。

于 2013-03-17T04:47:38.393 に答える