加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Untitled Document 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
布衣行者 提交于 2020-04-05 15:35 . first commit
//============================================================================
// Name : testEnv.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "stdio.h"
#include "string.h"
#include "Xatom.h"
#include "Xlib.h"
using namespace std;
#ifndef False
#define False 0
#endif
char *get_wnd_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;
}
/*
* track xtree and fine the main wnd with brower name
*/
Window ** QueryChildrenList(Display *dsp,Window *proot ,unsigned int *num)
{
Window root_r;
Window parent_r;
Window **pchildren = 0;
Status status = XQueryTree(dsp,*proot,&root_r,&parent_r , pchildren, num);
if(status != 0)
return pchildren;
return 0;
}
Window *DeepScanTree_name(Display *dsp,Window *proot,char * name)
{
unsigned int num = 0;
Window **pList = QueryChildrenList(dsp,proot,&num);
if(0 == pList)
return 0;
for(int i = 0;i < num;i++)
{
Window *pwnd = pList[i];
//request wnd n and compare name
char *pname = get_wnd_name(dsp,*pwnd);
if(NULL != strstr(pname,name))
return pwnd;
Window *tmpL = DeepScanTree_name(dsp, pwnd,name);
if(tmpL != 0)
return tmpL;
}
return 0;
}
Window * find_main_wnd(char *browser)
{
puts(browser);
/*
* 1.open defaut Display
* 2.Request root desktop
* 3.track window tree for special window with name 'browser'
*/
Display * dsp = XOpenDisplay(0);
Window rw = XDefaultRootWindow(dsp);
// DefaultRootWindow(0);
/**
* 1.Reqeust child list at first from root
* 2.scan all the child and find windown name
*/
return DeepScanTree_name(dsp,&rw,browser);
}
int main() {
find_main_wnd("fox");
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化