From 81b09f0e5cd153bdca77782c3438cd28ffefeace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 7 Jun 2021 18:47:38 +0200 Subject: First commit --- Makefile | 8 ++++++++ tterm.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 Makefile create mode 100644 tterm.c 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 diff --git a/tterm.c b/tterm.c new file mode 100644 index 0000000..3aceae7 --- /dev/null +++ b/tterm.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +} -- cgit v1.2.3