summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-07 18:47:38 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-07 18:47:38 +0200
commit81b09f0e5cd153bdca77782c3438cd28ffefeace (patch)
tree17333eaee4ed8195d0470e317a69e7005a7be9e2
downloadtterm-81b09f0e5cd153bdca77782c3438cd28ffefeace.tar.gz
First commit
-rw-r--r--Makefile8
-rw-r--r--tterm.c62
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
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 <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);
+}