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
failed
gtk アプリがフォーカスされている場合に発生します。私は、emacs、gimp、chromium、および ardour をテストしました。
何故ですか?どうすればWM_CLASS
gtk-windows を取得できますか?