summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Haller <patrick@haller.ws>2011-03-15 20:07:31 +0800
committerPatrick Haller <patrick@haller.ws>2011-03-15 20:07:31 +0800
commite6080067a6cc7cceb39503799fff4416017aa410 (patch)
tree3e221d15c020e50a5ebe8ae9d55a0f36be943660
parent940b2ed7498beeffc59d072e8d46f4018d72e443 (diff)
added x-window-list
-rw-r--r--Makefile4
-rw-r--r--x-window-list.c22
2 files changed, 16 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index c93f35f..ff1b5d8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
PREFIX = /usr/local/
SRC = x-session.c
-X11SRC = x-move-resize.c x-alt-tab.c x-focus-manager.c x-placement-manager.c x-undecorate.c
+X11SRC = x-move-resize.c x-alt-tab.c x-focus-manager.c x-placement-manager.c x-undecorate.c x-window-list.c
CC = gcc
-CFLAGS = -O2 -Wall -std=c99 -pedantic
+CFLAGS = -O2 -Wall -std=c99 -pedantic
X11LIB = -lX11 -L/usr/X11/lib
BIN = ${SRC:.c=}
diff --git a/x-window-list.c b/x-window-list.c
index 84c2bd2..a9c1381 100644
--- a/x-window-list.c
+++ b/x-window-list.c
@@ -1,17 +1,23 @@
#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <stdio.h>
// http://tronche.com/gui/x/xlib/
+// first window listed is top-most, last is bottom-most in window-stacking
int main(void) {
Display *dpy;
- Window w;
- Window *root_return;
- Window *parent_return;
- Window **children_return;
- unsigned int *nchildren_return;
+ Window root;
+ Window parent;
+ Window *wins;
+ XClassHint hint;
+ unsigned int nwins;
if(!(dpy = XOpenDisplay(NULL)))
return 1;
- XQueryTree(display, DefaultRootWindow(dpy), root_return, parent_return, children_return, nchildren_return);
-
- for (int i=0; i < nchildren_return; i++) {
+ XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &wins, &nwins);
+ for (int i=nwins-1; i >= 0; i--) {
+ XGetClassHint(dpy, wins[i], &hint);
+ fprintf(stderr, "0x%-10x %s\n", (unsigned int)wins[i], hint.res_name);
+ }
+}