XLib窗口名称问题 [英] XLib Window Name Problems
问题描述
从4天,我试图看看XLib如何工作,我终于明白了。
我试图做一个简短的程序,检索打开的窗口的名称。
为此,我创建了两个函数:
since 4 days, I try to see how XLib works, and I have finally understood that. Si I tried to make a short program wich retrieve open window's name. For that, I created 2 functions :
Window *list (Display *disp, unsigned long *len) {
Atom prop = XInternAtom(disp,"_NET_CLIENT_LIST",False), type;
int form;
unsigned long remain;
unsigned char *list;
if (XGetWindowProperty(disp,XDefaultRootWindow(disp),prop,0,1024,False,XA_WINDOW,
&type,&form,len,&remain,&list) != Success) {
return 0;
}
return (Window*)list;
}
所以,这个第一个函数返回所有窗口的窗口对象。
然后,我创建了一个函数来从所有这些窗口中检索名称。
So, this first function return a window object of all the windows. Then, I created a function to retrieve the name from all those windows.
char *name (Display *disp, Window win) {
Atom prop = XInternAtom(disp,"WM_NAME",False), type;
int form;
unsigned long remain, len;
unsigned char *list;
if (XGetWindowProperty(disp,win,prop,0,1024,False,XA_STRING,
&type,&form,&len,&remain,&list) != Success) {
return NULL;
}
return (char*)list;
}
这个函数很好,main.c示例:
And this function works fine, an main.c example:
int main(int argc, char* argv[]){
int i;
unsigned long len;
XKeyEvent esend;
Display *disp = XOpenDisplay(NULL);
Window *list;
char *name;
list = (Window*)list(disp,&len);
for (i=0;i<(int)len;i++) {
name = name(disp,list[i]);
printf("%d : %s \n",i,name);
free(name);
}
}
它返回:
1:Xlib编程手册:键盘和指针事件 - Google Chrome
1 : Xlib Programming Manual: Keyboard and Pointer Events - Google Chrome
2:Debian Web [En fonction] - Oracle VM VirtualBox
2 : Debian Web [En fonction] - Oracle VM VirtualBox
3:XChat:necromoine @ /(+ CSTfnst 10:2)
3 : XChat: necromoine @ / (+CSTfnst 10:2)
4:
5:root @ root-Laptop:〜
5 : root@root-Laptop: ~
6:
并且,数字4和6是空白的(我实际上有两个打开的skype窗口)。
And, the number 4 and 6 are blank (I actually have two opened skype window).
你能帮我。
推荐答案
A WM_NAME
不一定是简单的字符串。它可以是复合文本(不同类型的字符串),实际上是Skype窗口的情况。您需要使用 AnyPropertyType
而不是 XA_STRING
获取属性,然后根据实际类型进行格式化。看看 xprops
的来源,看看是怎么做的。
A WM_NAME
is not necessarily a simple string. It could be a compound text (a different type of string), which is actually the case for Skype windows. You need to use AnyPropertyType
instead of XA_STRING
to get the property, then format according to actual type. Look at the source of xprops
to see how it's done.
这篇关于XLib窗口名称问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!