//------------------------------------------------------ // xwintool // // simple tool for manipulating X-windows // // written by: David Lawrence 5/14/2014 //------------------------------------------------------ #include #include #include #include #include #include using namespace std; #include #define _DBG__ cout<<__FILE__<<":"<<__LINE__< WINDOWS_TO_FIND; void Usage(void); void ParseCommandLineArguments(int narg, char *argv[]); void FindWindows(Display *d, Window w, map > &windows); string GetWindowName(Display *d, Window w); //----------------- // main //----------------- int main(int narg, char *argv[]) { ParseCommandLineArguments(narg, argv); Display *display = XOpenDisplay(0); if(display==NULL){ cout << "Unable to open X display!" << endl; exit(-1); } Window winRoot = XDefaultRootWindow(display); map > windows; FindWindows(display, winRoot, windows); vector windows_killed; for(unsigned int i=0; i &wins = windows[name]; cout << name << ": "; if(wins.size() == 0){ cout << "No windows found" << endl; }else{ for(unsigned int j=0; j0){ cout << "windows killed: "; for(unsigned int i=0; i > &windows) { static int depth = 0; // Get window name string name = GetWindowName(d, w); if(depth == 0) name = "root"; // Add this window to the map windows[name].push_back(w); // Get List of children Window root_return, parent_return; Window *children_return; unsigned int nchildren=0; XQueryTree(d, w, &root_return, &parent_return, &children_return, &nchildren); // Optionally print window name if(SHOW_TREE)cout << string(depth*2, ' ') << name << " (children: " << nchildren << ")" << endl; // Loop over children for(unsigned int i=0; i 0) XFree(children_return); } //----------------- // GetWindowName //----------------- string GetWindowName(Display *d, Window w) { string name = ""; Atom nameAtom = XInternAtom(d,"_NET_WM_NAME",false); Atom utf8Atom = XInternAtom(d,"UTF8_STRING",false); Atom type; int format; unsigned long nitems, after; unsigned char *data = 0; int status = XGetWindowProperty(d, w, nameAtom, 0, 65536, false, utf8Atom, &type, &format, &nitems, &after, &data); if(status == Success) { if (data) { name = string((char*)data); XFree(data); } } return name; }