代码拉取完成,页面将自动刷新
//============================================================================
// 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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。