diff options
| author | Patrick <devnull@mailinator.com> | 2015-10-13 14:25:21 +0800 |
|---|---|---|
| committer | Patrick <devnull@mailinator.com> | 2015-10-13 14:25:21 +0800 |
| commit | 4e34b4e73ac51147c098a5cc6bdc7c0cf7724e15 (patch) | |
| tree | 287089ce967eb7214769f8be72a214ec0bf6e64e | |
| parent | 5ed15bde7bc262fac96cb50a676495fedb691d04 (diff) | |
tidy
| -rw-r--r-- | x-alt-tab.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/x-alt-tab.c b/x-alt-tab.c index 1073678..c83f9d2 100644 --- a/x-alt-tab.c +++ b/x-alt-tab.c @@ -11,28 +11,26 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */ #include <X11/Xlib.h> #include <X11/Xutil.h> -void alt_tab(int argc, Display *dpy, Window *wins, unsigned int nwins) { +void alt_tab(unsigned int direction, Display *dpy, Window *wins, unsigned int nwins) { XWindowAttributes attr; Window *viewables[nwins], *w = 0; - unsigned int count, vc = 0; + unsigned int vc = 0; // make list of viewable windows - for (count = 0; count < nwins; count++) { - w = wins + count; + for (w = wins; w - wins < nwins; w++) { XGetWindowAttributes(dpy, *w, &attr); if (attr.map_state == IsViewable) { - viewables[vc] = w; - vc++; + viewables[vc++] = w; } } viewables[vc] = NULL; - // promote the last to top, or demote top to last and raise 2nd - if (argc > 1) { - w = viewables[vc - 2]; - XLowerWindow(dpy, *(viewables[vc - 1])); - } else { + // promote the bottom to top, or demote top to bottom and raise 2nd + if (direction) { w = viewables[0]; + } else { + XLowerWindow(dpy, *(viewables[vc - 1])); + w = viewables[vc - 2]; } XRaiseWindow(dpy, *w); @@ -43,7 +41,7 @@ void alt_tab(int argc, Display *dpy, Window *wins, unsigned int nwins) { int main(int argc, char **argv) { Display *dpy; - unsigned int nwins = 0; + unsigned int nwins, direction = 0; Window root, parent, *wins = 0; if ( (dpy = XOpenDisplay(NULL)) == NULL) @@ -54,6 +52,7 @@ int main(int argc, char **argv) if (nwins == 1) return 0; - alt_tab(argc, dpy, wins, nwins); + direction = argc % 2; + alt_tab(direction, dpy, wins, nwins); return 0; } |
