Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- int main (int argc, char *argv[]) {
- Display *display = XOpenDisplay(NULL);
- Window win, root, parent, *children;
- int revert = RevertToParent;
- int screen = DefaultScreen(display);
- unsigned int nchild;
- XGetInputFocus(display, &win, &revert);
- if (win != RootWindow(display, screen)) {
- parent = win;
- do {
- win = parent;
- XQueryTree(display, win, &root, &parent, &children, &nchild);
- XFree(children);
- } while(parent != RootWindow(display, screen));
- }
- /*
- Display *display;
- Window win;
- char *name;
- int revert;
- display = XOpenDisplay(NULL);
- XGetInputFocus(display, &win, &revert);
- */
- //char *name;
- Atom nameAtom = XInternAtom(display, "_NET_WM_NAME", true);
- Atom utf8Atom = XInternAtom(display, "UTF8_STRING", true);
- Atom type;
- int format;
- unsigned long nitems, after;
- unsigned char *data = 0;
- int status = XGetWindowProperty(display, win, nameAtom, 0, 65536,
- false, /*AnyPropertyType*/ utf8Atom, &type, &format,
- &nitems, &after, &data);
- std::cout << "Returned status: " << status << std::endl;
- //std::cout << "Wtf: " << type << " " << nitems << " " << after << std::cout;
- if (data) {
- std::cout << "Active window name: " << data << std::endl;
- XFree(data);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement