[英]X11: Window properties not working for gtk-windows
在程序中,我需要找出当前焦点所在窗口的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
名称:秋葵,类:秋葵
名称:秋葵,类:秋葵
失败
失败
名称:xterm,类:XTerm
名称:xterm,类:XTerm
名称:xterm,类:XTerm
如果专注于gtk应用,则failed
。 我测试了emacs,gimp,铬和ardour。
这是为什么? 如何获得gtk-Windows的WM_CLASS
?
焦点不一定设置为顶层窗口。 特别是,Gtk倾向于将其设置为此类窗口的子级。
您需要向上移动窗口树。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.