1
在程序中我需要弄清楚當前焦點窗口的WM_CLASS
屬性。只要聚焦的窗口不是gtk應用程序,此工作正常使用XGetInputFocus()
和XGetClassHint()
。X11:窗口屬性不能用於gtk-windows
我寫了下面的小例子程序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
失敗
失敗
失敗
name:的xterm,類有效:xterm
名稱:xterm中,等級:的XTerm
名稱:默認隨時,等級:Okular中
名稱:默認隨時,等級:Okular中
失敗
失敗
名稱:xterm中,等級:的XTerm
名:的xterm,類有效:xterm
名稱:xterm中,等級:的XTerm
failed
談到如果GTK應用程序集中。我測試了emacs,gimp,chromium和ardor。
這是爲什麼?如何獲得gtk-windows的WM_CLASS
?
明白了。謝謝。 – user2178129 2013-03-18 05:51:01