diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | tterm.c | 62 |
2 files changed, 70 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..00825f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +CFLAGS != pkg-config --cflags x11 +LDFLAGS != pkg-config --libs x11 +CFLAGS += -O2 -pedantic -Wall -Wextra + +tterm: tterm.c + +install: + install tterm /usr/local/bin @@ -0,0 +1,62 @@ +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/param.h> +#include <unistd.h> +#include <X11/Xatom.h> +#include <X11/Xlib.h> + +#define die(...) do{fprintf(stderr,__VA_ARGS__);exit(1);}while(0) + +Atom pidatom; +Display *display; +Window root; + +unsigned char *pidprop = 0; + +Window +findwindow(unsigned int pid, Window w) +{ + Atom type; + int format; + unsigned int i, nchildren; + unsigned long nitems, bytes_after; + Window *children, _root, parent; + + pidprop = 0; + if (XGetWindowProperty(display, w, pidatom, 0, 1, False, XA_CARDINAL, + &type, &format, &nitems, &bytes_after, &pidprop) == Success + && pidprop && pid == *((unsigned long *)pidprop)) + return w; + + if (XQueryTree(display, w, &_root, &parent, &children, &nchildren)) + for (i = 0; i < nchildren; i++) { + w = findwindow(pid, children[i]); + if (w) return w; + } + return 0; +} + +int +main(int argc, char *argv[]) +{ + char *ap; + Window w; + + display = XOpenDisplay(0); + if (display == NULL) + die("could not open display\n"); + + root = XDefaultRootWindow(display); + pidatom = XInternAtom(display, "_NET_WM_PID", 1); + if (pidatom == None) + die("no _NET_WM_PID atom found\n"); + + w = findwindow(2400, root); + if (!w) + die("could not find window\n"); + + //XStoreName(display, w, ap); + XCloseDisplay(display); +} |