Advertisement
Kalashnikov

Untitled

Aug 3rd, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <X11/Xlib.h>
  4. #include <X11/Xutil.h>
  5.  
  6. int main (int argc, char *argv[]) {
  7.     Display *display = XOpenDisplay(NULL);
  8.     Window win, root, parent, *children;
  9.     int revert = RevertToParent;
  10.     int screen = DefaultScreen(display);
  11.     unsigned int nchild;
  12.     XGetInputFocus(display, &win, &revert);
  13.  
  14.     if (win != RootWindow(display, screen)) {
  15.         parent = win;
  16.         do {
  17.             win = parent;
  18.             XQueryTree(display, win, &root, &parent, &children, &nchild);
  19.             XFree(children);
  20.         } while(parent != RootWindow(display, screen));
  21.     }
  22.  
  23. /*
  24.     Display *display;
  25.     Window win;
  26.     char *name;
  27.     int revert;
  28.  
  29.     display = XOpenDisplay(NULL);
  30.     XGetInputFocus(display, &win, &revert);
  31. */
  32.  
  33.     //char *name;
  34.  
  35.     Atom nameAtom = XInternAtom(display, "_NET_WM_NAME", true);
  36.     Atom utf8Atom = XInternAtom(display, "UTF8_STRING", true);
  37.     Atom type;
  38.     int format;
  39.     unsigned long nitems, after;
  40.     unsigned char *data = 0;
  41.  
  42.     int status = XGetWindowProperty(display, win, nameAtom, 0, 65536,
  43.                                     false, /*AnyPropertyType*/ utf8Atom, &type, &format,
  44.                                     &nitems, &after, &data);
  45.  
  46.     std::cout << "Returned status: " << status << std::endl;
  47.     //std::cout << "Wtf: " << type << " " << nitems << " " << after << std::cout;
  48.     if (data) {
  49.         std::cout << "Active window name: " << data << std::endl;
  50.         XFree(data);
  51.     }
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement