From 2e3dfb711f7818ca9f9fbdd4dbca792bb32df83d Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 1 Feb 2014 13:30:59 +0800 Subject: ordering is now stable, added ability to raise a window --- x-window-list.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/x-window-list.c b/x-window-list.c index 507e09c..f1408f2 100644 --- a/x-window-list.c +++ b/x-window-list.c @@ -12,13 +12,24 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */ #include #include #include +#include // http://tronche.com/gui/x/xlib/ // first window listed is top-most, last is bottom-most in window-stacking -int main(void) { + +static int cmp(Window **a, Window **b) { + if ( **a > **b ) + return 1; + return -1; +} + +int main(int argc, char **argv) { Display *dpy; - Window root, parent, *wins, *w; - unsigned int nwins; + Window root, parent, *wins, *w, *winlist[256]; + unsigned int nwins, count = 0, dwin = 0; + + if (argc > 1) + dwin = atoi(argv[1]); if ((dpy = XOpenDisplay(NULL)) == NULL) return 1; @@ -26,14 +37,29 @@ int main(void) { XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &wins, &nwins); for (w = wins + nwins - 1; w >= wins; w--) { + XWindowAttributes attr; + + XGetWindowAttributes(dpy, *w, &attr); + if (attr.map_state != IsViewable) + continue; + + winlist[count] = w; + count++; + } + qsort(winlist, count, sizeof(Window *), (__compar_fn_t)cmp); + + for (int i=0; i 1 && i == dwin) { + XRaiseWindow(dpy, *w); + XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); + XSync(dpy, DefaultRootWindow(dpy)); + } } } -- cgit v1.2.3