summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--x-alt-tab.c70
-rw-r--r--x-focus-manager.c56
-rw-r--r--x-move-resize.c138
-rw-r--r--x-placement-manager.c78
-rw-r--r--x-session.c7
-rw-r--r--x-undecorate.c15
-rw-r--r--x-window-list.c82
8 files changed, 233 insertions, 224 deletions
diff --git a/Makefile b/Makefile
index 35601d2..6c64bed 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
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 x-window-list.c
-SCRIPTS= scripts/x-banish scripts/x-root-clean scripts/x-launcher
+X11SRC = $(filter-out $(SRC),$(wildcard *.c))
+SCRIPTS= $(wildcard scripts/*)
CC = gcc
CFLAGS = -O2 -Wall -std=c99 -pedantic
@@ -17,8 +17,11 @@ $(BIN): %: %.c
$(X11BIN): %: %.c
$(CC) $(CFLAGS) $(X11LIB) $^ -o $@
-clean:
- rm $(BIN) $(X11BIN)
+clean: dist
+ @rm $(basename $(wildcard *.c)) $(wildcard *.c.orig)
+
+dist:
+ @astyle --style=google *.c
install:
install -m 0755 $(BIN) $(X11BIN) $(SCRIPTS) ${PREFIX}/bin/.
diff --git a/x-alt-tab.c b/x-alt-tab.c
index 66ce6ea..c5acc16 100644
--- a/x-alt-tab.c
+++ b/x-alt-tab.c
@@ -15,45 +15,45 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */
typedef enum RotationEnum { bottom_to_top, top_to_bottom } Rotation;
void x_alt_tab(Rotation r, Display *dpy, Window *wins, unsigned int nwins) {
- Window *viewables[nwins], *w = 0;
- unsigned int vc = 0;
-
- // make list of viewable windows
- XWindowAttributes attr;
- for (w = wins; w - wins < nwins; w++) {
- XGetWindowAttributes(dpy, *w, &attr);
- if (attr.map_state == IsViewable)
- viewables[vc++] = w;
- }
- viewables[vc] = NULL;
-
- // promote the bottom to top, or demote top to bottom and raise 2nd
- if (r == bottom_to_top)
- w = viewables[0];
- else {
- XLowerWindow(dpy, *(viewables[vc - 1]));
- w = viewables[vc - 2];
- }
-
- XRaiseWindow(dpy, *w);
- XSetInputFocus(dpy, *w, RevertToPointerRoot, CurrentTime);
- XSync(dpy, True);
+ Window *viewables[nwins], *w = 0;
+ unsigned int vc = 0;
+
+ // make list of viewable windows
+ XWindowAttributes attr;
+ for (w = wins; w - wins < nwins; w++) {
+ XGetWindowAttributes(dpy, *w, &attr);
+ if (attr.map_state == IsViewable)
+ viewables[vc++] = w;
+ }
+ viewables[vc] = NULL;
+
+ // promote the bottom to top, or demote top to bottom and raise 2nd
+ if (r == bottom_to_top)
+ w = viewables[0];
+ else {
+ XLowerWindow(dpy, *(viewables[vc - 1]));
+ w = viewables[vc - 2];
+ }
+
+ XRaiseWindow(dpy, *w);
+ XSetInputFocus(dpy, *w, RevertToPointerRoot, CurrentTime);
+ XSync(dpy, True);
}
int main(int argc, char **argv) {
- Display *dpy;
- unsigned int nwins = 0;
- Window root, parent, *wins = 0;
+ Display *dpy;
+ unsigned int nwins = 0;
+ Window root, parent, *wins = 0;
- if ( (dpy = XOpenDisplay(NULL)) == NULL)
- return 1;
+ if ( (dpy = XOpenDisplay(NULL)) == NULL)
+ return 1;
- XSync(dpy, True);
- XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &wins, &nwins);
- if (nwins <= 1)
- return 0;
+ XSync(dpy, True);
+ XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &wins, &nwins);
+ if (nwins <= 1)
+ return 0;
- Rotation r = (argc == 1) ? bottom_to_top : top_to_bottom;
- x_alt_tab(r, dpy, wins, nwins);
- return 0;
+ Rotation r = (argc == 1) ? bottom_to_top : top_to_bottom;
+ x_alt_tab(r, dpy, wins, nwins);
+ return 0;
}
diff --git a/x-focus-manager.c b/x-focus-manager.c
index c9abdb8..c1fae73 100644
--- a/x-focus-manager.c
+++ b/x-focus-manager.c
@@ -24,49 +24,49 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */
void reset_focus(Display *d, XEvent *e);
static void (*handler[LASTEvent]) (Display *d, XEvent *) = {
- [UnmapNotify] = reset_focus,
- [DestroyNotify] = reset_focus
+ [UnmapNotify] = reset_focus,
+ [DestroyNotify] = reset_focus
};
/// fun on down
void
reset_focus(Display *d, XEvent *e) {
- XSetInputFocus(d, PointerRoot , RevertToPointerRoot, CurrentTime);
+ XSetInputFocus(d, PointerRoot , RevertToPointerRoot, CurrentTime);
}
void set_atoms(Display *dpy) { // from scrotwm via euclid-wm
- int root = DefaultRootWindow(dpy);
- Atom wm_change_state = XInternAtom(dpy,"_NET_WM_STATE",False);
- Atom wm_supported = XInternAtom(dpy,"_NET_SUPPORTED",False);
- Atom wm_check = XInternAtom(dpy,"_NET_SUPPORTING_WM_CHECK",False);
- Atom wm_name = XInternAtom(dpy,"_NET_WM_NAME",False);
- Atom utf8 = XInternAtom(dpy,"UTF8_STRING",False);
- Atom supported[] = {wm_supported, wm_name, wm_change_state};
- XChangeProperty(dpy,root,wm_check,XA_WINDOW,32,PropModeReplace,(unsigned char *)&root,1);
- XChangeProperty(dpy,root,wm_name,utf8,8,PropModeReplace,(unsigned char *) "LG3D",5);
- XChangeProperty(dpy,root,wm_supported,XA_ATOM,32,PropModeReplace,(unsigned char *) supported,4);
- XSync(dpy,False);
+ int root = DefaultRootWindow(dpy);
+ Atom wm_change_state = XInternAtom(dpy,"_NET_WM_STATE",False);
+ Atom wm_supported = XInternAtom(dpy,"_NET_SUPPORTED",False);
+ Atom wm_check = XInternAtom(dpy,"_NET_SUPPORTING_WM_CHECK",False);
+ Atom wm_name = XInternAtom(dpy,"_NET_WM_NAME",False);
+ Atom utf8 = XInternAtom(dpy,"UTF8_STRING",False);
+ Atom supported[] = {wm_supported, wm_name, wm_change_state};
+ XChangeProperty(dpy,root,wm_check,XA_WINDOW,32,PropModeReplace,(unsigned char *)&root,1);
+ XChangeProperty(dpy,root,wm_name,utf8,8,PropModeReplace,(unsigned char *) "LG3D",5);
+ XChangeProperty(dpy,root,wm_supported,XA_ATOM,32,PropModeReplace,(unsigned char *) supported,4);
+ XSync(dpy,False);
}
int
main(int argc, char **argv) {
- Display *dpy;
- XEvent e;
- XSetWindowAttributes wa;
+ Display *dpy;
+ XEvent e;
+ XSetWindowAttributes wa;
- if(!(dpy = XOpenDisplay(NULL)))
- return 1;
+ if(!(dpy = XOpenDisplay(NULL)))
+ return 1;
- wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
- wa.event_mask = SubstructureNotifyMask|StructureNotifyMask;
- XChangeWindowAttributes(dpy, DefaultRootWindow(dpy) , CWEventMask|CWCursor, &wa);
- set_atoms(dpy);
+ wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
+ wa.event_mask = SubstructureNotifyMask|StructureNotifyMask;
+ XChangeWindowAttributes(dpy, DefaultRootWindow(dpy) , CWEventMask|CWCursor, &wa);
+ set_atoms(dpy);
- for(;;) {
- XNextEvent(dpy, &e);
- if(handler[e.type])
- handler[e.type](dpy, &e);
- }
+ for(;;) {
+ XNextEvent(dpy, &e);
+ if(handler[e.type])
+ handler[e.type](dpy, &e);
+ }
}
diff --git a/x-move-resize.c b/x-move-resize.c
index bb673ac..45bbf9a 100644
--- a/x-move-resize.c
+++ b/x-move-resize.c
@@ -33,87 +33,89 @@ extern void exit(int code);
// fun on down
void configure(Display *d, Window *w, XWindowAttributes *wa) {
- XConfigureEvent ce;
-
- ce.type = ConfigureNotify;
- ce.display = d;
- ce.event = *w;
- ce.window = *w;
- ce.x = wa->x;
- ce.y = wa->y;
- ce.width = wa->width;
- ce.height = wa->height;
- ce.border_width = 0;
- ce.above = None;
- ce.override_redirect = False;
- XSendEvent(d, *w, False, StructureNotifyMask, (XEvent *)&ce);
+ XConfigureEvent ce;
+
+ ce.type = ConfigureNotify;
+ ce.display = d;
+ ce.event = *w;
+ ce.window = *w;
+ ce.x = wa->x;
+ ce.y = wa->y;
+ ce.width = wa->width;
+ ce.height = wa->height;
+ ce.border_width = 0;
+ ce.above = None;
+ ce.override_redirect = False;
+ XSendEvent(d, *w, False, StructureNotifyMask, (XEvent *)&ce);
}
void die(Display *dpy, int return_value) {
- XUngrabPointer(dpy, CurrentTime);
- XFreeCursor (dpy, cursor);
- XSync (dpy, DefaultRootWindow(dpy));
- XCloseDisplay(dpy);
- exit(return_value);
+ XUngrabPointer(dpy, CurrentTime);
+ XFreeCursor (dpy, cursor);
+ XSync (dpy, DefaultRootWindow(dpy));
+ XCloseDisplay(dpy);
+ exit(return_value);
}
void buttonpress(Display *dpy, XEvent *e) {
- XEvent ev = *e;
- Window root = DefaultRootWindow(dpy);
- if (ev.xbutton.subwindow == None)
- return;
- XUngrabPointer(dpy, root);
- XSync(dpy, root);
- if (XGrabPointer (dpy, ev.xbutton.subwindow, False, (PointerMotionMask | ButtonReleaseMask),
- GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess)
- die(dpy, 1);
- XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
- start = ev.xbutton;
+ XEvent ev = *e;
+ Window root = DefaultRootWindow(dpy);
+ if (ev.xbutton.subwindow == None)
+ return;
+ XUngrabPointer(dpy, root);
+ XSync(dpy, root);
+ if (XGrabPointer (dpy, ev.xbutton.subwindow, False, (PointerMotionMask | ButtonReleaseMask),
+ GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess)
+ die(dpy, 1);
+ XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
+ start = ev.xbutton;
}
void motionnotify(Display *dpy, XEvent *e) {
- int xdiff, ydiff;
- XEvent ev = *e;
-
- while (XCheckTypedEvent(dpy, MotionNotify, &ev));
- xdiff = ev.xbutton.x_root - start.x_root;
- ydiff = ev.xbutton.y_root - start.y_root;
- XMoveResizeWindow(dpy, ev.xmotion.window,
- attr.x + (start.button==1 ? xdiff : 0),
- attr.y + (start.button==1 ? ydiff : 0),
- MAX(1, attr.width + (start.button==3 ? xdiff : 0)),
- MAX(1, attr.height + (start.button==3 ? ydiff : 0)));
- if (start.button == 1)
- return;
+ int xdiff, ydiff;
+ XEvent ev = *e;
+
+ while (XCheckTypedEvent(dpy, MotionNotify, &ev));
+ xdiff = ev.xbutton.x_root - start.x_root;
+ ydiff = ev.xbutton.y_root - start.y_root;
+ XMoveResizeWindow(dpy, ev.xmotion.window,
+ attr.x + (start.button==1 ? xdiff : 0),
+ attr.y + (start.button==1 ? ydiff : 0),
+ MAX(1, attr.width + (start.button==3 ? xdiff : 0)),
+ MAX(1, attr.height + (start.button==3 ? ydiff : 0)));
+ if (start.button == 1)
+ return;
}
void buttonrelease(Display *dpy, XEvent *e) {
- die(dpy, 0);
+ die(dpy, 0);
}
int main() {
- Display * dpy;
- Window root;
- XEvent ev;
- void (*handler[LASTEvent]) (Display *d, XEvent *) = {
- [ButtonPress] = buttonpress,
- [ButtonRelease] = buttonrelease,
- [MotionNotify] = motionnotify,
- };
- int cursor_shape = XC_plus;
- start.button = 0; start.x_root = 0; start.y_root = 0;
-
- if(!(dpy = XOpenDisplay(0x0))) return 1;
-
- root = DefaultRootWindow(dpy);
- cursor = XCreateFontCursor(dpy, cursor_shape);
- if (XGrabPointer (dpy, root, False, (ButtonPressMask),
- GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess)
- die(dpy, 1);
-
- for(;;) {
- XNextEvent(dpy, &ev);
- if(handler[ev.type])
- handler[ev.type](dpy, &ev);
- }
+ Display * dpy;
+ Window root;
+ XEvent ev;
+ void (*handler[LASTEvent]) (Display *d, XEvent *) = {
+ [ButtonPress] = buttonpress,
+ [ButtonRelease] = buttonrelease,
+ [MotionNotify] = motionnotify,
+ };
+ int cursor_shape = XC_plus;
+ start.button = 0;
+ start.x_root = 0;
+ start.y_root = 0;
+
+ if(!(dpy = XOpenDisplay(0x0))) return 1;
+
+ root = DefaultRootWindow(dpy);
+ cursor = XCreateFontCursor(dpy, cursor_shape);
+ if (XGrabPointer (dpy, root, False, (ButtonPressMask),
+ GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess)
+ die(dpy, 1);
+
+ for(;;) {
+ XNextEvent(dpy, &ev);
+ if(handler[ev.type])
+ handler[ev.type](dpy, &ev);
+ }
}
diff --git a/x-placement-manager.c b/x-placement-manager.c
index f997709..fdc1269 100644
--- a/x-placement-manager.c
+++ b/x-placement-manager.c
@@ -18,58 +18,58 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */
void place_center(Display *d, XEvent *e);
static void (*handler[LASTEvent]) (Display *d, XEvent *) = {
- [MapRequest] = place_center,
- [ConfigureNotify] = place_center
+ [MapRequest] = place_center,
+ [ConfigureNotify] = place_center
};
/// fun on down
void
place_center(Display *d, XEvent *e) {
- static XWindowAttributes r_wa;
- static XWindowAttributes c_wa;
- Window r = DefaultRootWindow(d);
- Window trans = None;
- XMapRequestEvent *ev = &e->xmaprequest;
- int x, y;
+ static XWindowAttributes r_wa;
+ static XWindowAttributes c_wa;
+ Window r = DefaultRootWindow(d);
+ Window trans = None;
+ XMapRequestEvent *ev = &e->xmaprequest;
+ int x, y;
- if (!XGetWindowAttributes(d, r, &r_wa))
- return;
- if (!XGetWindowAttributes(d, ev->window, &c_wa))
- return;
- if (c_wa.override_redirect)
- return;
- if(XGetTransientForHint(d, ev->window, &trans))
- return;
- x = r_wa.width/2 - c_wa.width/2;
- y = r_wa.height/2 - c_wa.height/2;
- if (x < 0)
- x = 0;
- if (y < 0)
- y = 0;
- XMoveResizeWindow(d, ev->window, x, y,
- c_wa.width > r_wa.width ? r_wa.width : c_wa.width,
- c_wa.height > r_wa.height ? r_wa.height : c_wa.height
- );
+ if (!XGetWindowAttributes(d, r, &r_wa))
+ return;
+ if (!XGetWindowAttributes(d, ev->window, &c_wa))
+ return;
+ if (c_wa.override_redirect)
+ return;
+ if(XGetTransientForHint(d, ev->window, &trans))
+ return;
+ x = r_wa.width/2 - c_wa.width/2;
+ y = r_wa.height/2 - c_wa.height/2;
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+ XMoveResizeWindow(d, ev->window, x, y,
+ c_wa.width > r_wa.width ? r_wa.width : c_wa.width,
+ c_wa.height > r_wa.height ? r_wa.height : c_wa.height
+ );
}
int
main(int argc, char **argv) {
- Display *dpy;
- XEvent e;
- XSetWindowAttributes wa;
+ Display *dpy;
+ XEvent e;
+ XSetWindowAttributes wa;
- if(!(dpy = XOpenDisplay(NULL)))
- return 1;
+ if(!(dpy = XOpenDisplay(NULL)))
+ return 1;
- wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
- wa.event_mask = SubstructureNotifyMask|StructureNotifyMask;
- XChangeWindowAttributes(dpy, DefaultRootWindow(dpy) , CWEventMask|CWCursor, &wa);
+ wa.cursor = XCreateFontCursor(dpy, XC_left_ptr);
+ wa.event_mask = SubstructureNotifyMask|StructureNotifyMask;
+ XChangeWindowAttributes(dpy, DefaultRootWindow(dpy) , CWEventMask|CWCursor, &wa);
- for(;;) {
- XNextEvent(dpy, &e);
- if(handler[e.type])
- handler[e.type](dpy, &e);
- }
+ for(;;) {
+ XNextEvent(dpy, &e);
+ if(handler[e.type])
+ handler[e.type](dpy, &e);
+ }
}
diff --git a/x-session.c b/x-session.c
index 8fcf7bd..e83b926 100644
--- a/x-session.c
+++ b/x-session.c
@@ -12,5 +12,10 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */
#include <unistd.h>
#include <sys/wait.h>
-int main(void) { for (;;) { wait(NULL); sleep(1); } }
+int main(void) {
+ for (;;) {
+ wait(NULL);
+ sleep(1);
+ }
+}
diff --git a/x-undecorate.c b/x-undecorate.c
index 7c3d873..a008cfc 100644
--- a/x-undecorate.c
+++ b/x-undecorate.c
@@ -15,15 +15,14 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */
// mark a window as undecorated
// i.e. remove the borders and titlebar
-int main(int argc, char **argv)
-{
- Display *dpy;
- XSetWindowAttributes c_wa;
+int main(int argc, char **argv) {
+ Display *dpy;
+ XSetWindowAttributes c_wa;
- if ( ! (dpy = XOpenDisplay(0x0) ))
- return -1;
+ if ( ! (dpy = XOpenDisplay(0x0) ))
+ return -1;
- XChangeWindowAttributes(dpy, atoi(argv[1]), CWOverrideRedirect, &c_wa);
- return 0;
+ XChangeWindowAttributes(dpy, atoi(argv[1]), CWOverrideRedirect, &c_wa);
+ return 0;
}
diff --git a/x-window-list.c b/x-window-list.c
index ef53d38..36ece4b 100644
--- a/x-window-list.c
+++ b/x-window-list.c
@@ -16,8 +16,8 @@ If not, see http://creativecommons.org/publicdomain/zero/1.0/ */
#include <stdlib.h>
typedef struct Config {
- _Bool is_switch; // list windows or switch to dst window?
- unsigned int dst;
+ _Bool is_switch; // list windows or switch to dst window?
+ unsigned int dst;
} Config;
/* static int cmp(Window **a, Window **b) {
@@ -27,54 +27,54 @@ typedef struct Config {
} */
void x_window_list(Config cfg, Display *dpy, Window *wins, unsigned int nwins) {
- Window *viewables[nwins], *w;
- unsigned int vc = 0;
+ Window *viewables[nwins], *w;
+ unsigned int vc = 0;
- // get list of viewable windows
- for (w = wins + nwins - 1; w >= wins; w--) {
- XWindowAttributes attr;
+ // get list of viewable windows
+ for (w = wins + nwins - 1; w >= wins; w--) {
+ XWindowAttributes attr;
- XGetWindowAttributes(dpy, *w, &attr);
- if (attr.map_state == IsViewable) {
- viewables[vc++] = w;
- }
- }
- viewables[vc] = NULL;
+ XGetWindowAttributes(dpy, *w, &attr);
+ if (attr.map_state == IsViewable) {
+ viewables[vc++] = w;
+ }
+ }
+ viewables[vc] = NULL;
- // list them out
- for (int i=0; i < vc; i++) {
- XTextProperty name;
- XClassHint hint;
- w = viewables[i];
+ // list them out
+ for (int i=0; i < vc; i++) {
+ XTextProperty name;
+ XClassHint hint;
+ w = viewables[i];
- XGetClassHint(dpy, *w, &hint);
- XGetWMName(dpy, *w, &name);
- printf("%02d 0x%-12x %s - %s\n", i, (unsigned int)*w, hint.res_name, name.value);
- if (cfg.is_switch && i == cfg.dst) {
- XRaiseWindow(dpy, *w);
- XSetInputFocus(dpy, *w, RevertToPointerRoot, CurrentTime);
- }
- }
+ XGetClassHint(dpy, *w, &hint);
+ XGetWMName(dpy, *w, &name);
+ printf("%02d 0x%-12x %s - %s\n", i, (unsigned int)*w, hint.res_name, name.value);
+ if (cfg.is_switch && i == cfg.dst) {
+ XRaiseWindow(dpy, *w);
+ XSetInputFocus(dpy, *w, RevertToPointerRoot, CurrentTime);
+ }
+ }
}
int main(int argc, char **argv) {
- Display *dpy;
- Window root, parent, *wins;
- unsigned int nwins = 0;
- Config c = { .is_switch = 0, .dst = 0 };
+ Display *dpy;
+ Window root, parent, *wins;
+ unsigned int nwins = 0;
+ Config c = { .is_switch = 0, .dst = 0 };
- if (argc > 1) {
- c.is_switch = 1;
- c.dst = atoi(argv[1]);
- }
+ if (argc > 1) {
+ c.is_switch = 1;
+ c.dst = atoi(argv[1]);
+ }
- if ((dpy = XOpenDisplay(NULL)) == NULL)
- return 1;
+ if ((dpy = XOpenDisplay(NULL)) == NULL)
+ return 1;
- XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &wins, &nwins);
- if (nwins == 0)
- return 0;
+ XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &wins, &nwins);
+ if (nwins == 0)
+ return 0;
- x_window_list(c, dpy, wins, nwins);
- return 0;
+ x_window_list(c, dpy, wins, nwins);
+ return 0;
}