aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kanakarakis <ivan.kanak@gmail.com>2011-12-16 11:28:31 +0200
committerIvan Kanakarakis <ivan.kanak@gmail.com>2011-12-16 12:55:07 +0200
commit88f62c8e4c1e86bab9bb18f780b28c66ebc45fcc (patch)
treef297c1b781b0c536ba471d3ff409cb44b9c220a9
parentf72668d67b26a9bc2e167f6705552d5f54bbd851 (diff)
sort functions alphabetically
-rw-r--r--monsterwm.c679
1 files changed, 333 insertions, 346 deletions
diff --git a/monsterwm.c b/monsterwm.c
index 07ca69b..1161fe6 100644
--- a/monsterwm.c
+++ b/monsterwm.c
@@ -30,15 +30,8 @@
#define LENGTH(x) (sizeof(x)/sizeof(*x))
-enum { WM_PROTOCOLS, WM_DELETE_WINDOW, ATOM_COUNT };
-
-/* layout modes */
-enum {
- TILE,
- MONOCLE,
- BSTACK,
- GRID,
-};
+enum { WM_PROTOCOLS, WM_DELETE_WINDOW, WM_COUNT };
+enum { TILE, MONOCLE, BSTACK, GRID, };
/* structs */
typedef union {
@@ -78,39 +71,39 @@ typedef struct {
static void add_window(Window w);
static void buttonpressed(XEvent *e);
static void change_desktop(const Arg *arg);
+static void cleanup(void);
static void client_to_desktop(const Arg *arg);
+static void deletewindow(Window w);
static void destroynotify(XEvent *e);
-static void enternotify(XEvent *e);
static void die(const char* errstr, ...);
-static int xerrorstart();
+static void enternotify(XEvent *e);
static unsigned long getcolor(const char* color);
static void grabkeys(void);
static void keypress(XEvent *e);
static void killclient();
+static void last_desktop();
static void maprequest(XEvent *e);
static void move_down();
static void move_up();
-static void rotate_desktop(const Arg *arg);
static void next_win();
static void prev_win();
-static void cleanup(void);
static void quit(const Arg *arg);
static void removeclient(client *c);
static void resize_master(const Arg *arg);
static void resize_stack(const Arg *arg);
+static void rotate_desktop(const Arg *arg);
+static void run(void);
static void save_desktop(int i);
static void select_desktop(int i);
-static void togglepanel();
-static void deletewindow(Window w);
static void setup(void);
static void sigchld();
static void spawn(const Arg *arg);
-static void run(void);
static void swap_master();
-static void last_desktop();
static void switch_mode(const Arg *arg);
static void tile(void);
+static void togglepanel();
static void update_current(void);
+static int xerrorstart();
#include "config.h"
@@ -133,9 +126,9 @@ static unsigned int win_unfocus;
static unsigned int numlockmask = 0; /* dynamic key lock mask */
static Display *dis;
static Window root;
-static client *head = NULL;
+static client *head = NULL;
static client *current = NULL;
-static Atom atoms[ATOM_COUNT];
+static Atom atoms[WM_COUNT];
static desktop desktops[DESKTOPS];
/* events array */
@@ -147,7 +140,6 @@ static void (*events[LASTEvent])(XEvent *e) = {
[DestroyNotify] = destroynotify,
};
-/* -------- Window Management -------- */
void add_window(Window w) {
client *c, *t;
@@ -176,53 +168,207 @@ void add_window(Window w) {
if(FOLLOW_MOUSE) XSelectInput(dis, c->win, EnterWindowMask);
}
-void removeclient(client *c) {
- if(!c->prev) { /* w is head */
- if(!c->next) { /* head is only window on screen */
- free(head);
- head = NULL;
- } else { /* more windows on screen */
- head->next->prev = NULL;
- head = head->next;
- }
- current = head;
- } else { /* w is on stack */
- if(!c->next) { /* w is last window on screen */
- c->prev->next = NULL;
- } else { /* w is somewhere in the middle */
- c->next->prev = c->prev;
- c->prev->next = c->next;
- }
- current = c->prev;
- }
+void buttonpressed(XEvent *e) {
+ client *c;
+ XButtonPressedEvent *ev = &e->xbutton;
+ if(CLICK_TO_FOCUS && ev->window != current->win && ev->button == Button1)
+ for(c=head; c; c=c->next)
+ if(ev->window == c->win) {
+ current = c;
+ update_current();
+ return;
+ }
+}
+
+void change_desktop(const Arg *arg) {
+ if(arg->i == current_desktop) return;
+ previous_desktop = current_desktop;
+
+ /* save current desktop settings and unmap windows */
save_desktop(current_desktop);
+ for(client *c=head; c; c=c->next)
+ XUnmapWindow(dis, c->win);
+
+ /* read new desktop properties, tile and map new windows */
+ select_desktop(arg->i);
tile();
- if(mode == MONOCLE && current)
- XMapWindow(dis, current->win);
+ if(mode == MONOCLE && current) XMapWindow(dis, current->win);
+ else for(client *c=head; c; c=c->next) XMapWindow(dis, c->win);
+
update_current();
}
+void cleanup(void) {
+ Window root_return;
+ Window parent_return;
+ Window *children;
+ unsigned int nchildren;
+
+ XUngrabKey(dis, AnyKey, AnyModifier, root);
+
+ XQueryTree(dis, root, &root_return, &parent_return, &children, &nchildren);
+ for(unsigned int i = 0; i < nchildren; i++)
+ deletewindow(children[i]);
+ if(children) XFree(children);
+
+ XSync(dis, False);
+ XSetInputFocus(dis, PointerRoot, RevertToPointerRoot, CurrentTime);
+}
+
+void client_to_desktop(const Arg *arg) {
+ if(arg->i == current_desktop || !current) return;
+
+ client *c = current;
+ int cd = current_desktop;
+
+ select_desktop(arg->i);
+ add_window(c->win);
+ save_desktop(arg->i);
+
+ select_desktop(cd);
+ XUnmapWindow(dis, c->win);
+ removeclient(c);
+ save_desktop(cd);
+
+ tile();
+ update_current();
+
+ if(FOLLOW_WINDOW) change_desktop(arg);
+}
+
+void deletewindow(Window w) {
+ XEvent ev;
+ ev.type = ClientMessage;
+ ev.xclient.window = w;
+ ev.xclient.message_type = atoms[WM_PROTOCOLS];
+ ev.xclient.format = 32;
+ ev.xclient.data.l[0] = atoms[WM_DELETE_WINDOW];
+ ev.xclient.data.l[1] = CurrentTime;
+ XSendEvent(dis, w, False, NoEventMask, &ev);
+}
+
+void destroynotify(XEvent *e) {
+ client *c;
+ XDestroyWindowEvent *ev = &e->xdestroywindow;
+ int cd = current_desktop;
+ Bool found = False;
+
+ save_desktop(cd);
+ for(int d=0; d<DESKTOPS && !found; select_desktop(d++))
+ for(c=head; c && !found; c=c->next)
+ if((found = ev->window == c->win))
+ removeclient(c);
+ select_desktop(cd);
+}
+
+void die(const char *errstr, ...) {
+ va_list ap;
+ va_start(ap, errstr);
+ vfprintf(stderr, errstr, ap);
+ va_end(ap);
+ exit(EXIT_FAILURE);
+}
+
+void enternotify(XEvent *e) {
+ client *c;
+ XCrossingEvent *ev = &e->xcrossing;
+
+ if(FOLLOW_MOUSE) {
+ if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) return;
+ for(c=head; c; c=c->next)
+ if(ev->window == c->win) {
+ current = c;
+ update_current();
+ return;
+ }
+ }
+}
+
+unsigned long getcolor(const char* color) {
+ Colormap map = DefaultColormap(dis, screen);
+ XColor c;
+
+ if(!XAllocNamedColor(dis, map, color, &c, &c))
+ die("error: cannot allocate color '%s'\n", c);
+ return c.pixel;
+}
+
+void grabkeys(void) {
+ KeyCode code;
+
+ XUngrabKey(dis, AnyKey, AnyModifier, root);
+ for(unsigned int i=0; i<LENGTH(keys); i++) {
+ code = XKeysymToKeycode(dis, keys[i].keysym);
+ XGrabKey(dis, code, keys[i].mod, root, True, GrabModeAsync, GrabModeAsync);
+ XGrabKey(dis, code, keys[i].mod | LockMask, root, True, GrabModeAsync, GrabModeAsync);
+ XGrabKey(dis, code, keys[i].mod | numlockmask, root, True, GrabModeAsync, GrabModeAsync);
+ XGrabKey(dis, code, keys[i].mod | numlockmask | LockMask, root, True, GrabModeAsync, GrabModeAsync);
+ }
+}
+
+void keypress(XEvent *e) {
+ static unsigned int len = sizeof keys / sizeof keys[0];
+ unsigned int i;
+ KeySym keysym;
+ XKeyEvent *ev = &e->xkey;
+
+ keysym = XKeycodeToKeysym(dis, (KeyCode)ev->keycode, 0);
+ for(i = 0; i < len; i++)
+ if(keysym == keys[i].keysym && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) && keys[i].function)
+ keys[i].function(&keys[i].arg);
+}
+
void killclient() {
if(!current) return;
deletewindow(current->win);
removeclient(current);
}
-void next_win() {
- if(!current || (!current->next && !current->prev)) return;
- if(mode == MONOCLE) XUnmapWindow(dis, current->win);
- current = (current->next) ? current->next : head;
- if(mode == MONOCLE) XMapWindow(dis, current->win);
- update_current();
+void last_desktop() {
+ change_desktop(&(Arg){.i = previous_desktop});
}
-void prev_win() {
- if(!current || (!current->next && !current->prev)) return;
- if(mode == MONOCLE) XUnmapWindow(dis, current->win);
- if(current->prev) current = current->prev;
- else while(current->next) current=current->next;
- if(mode == MONOCLE) XMapWindow(dis, current->win);
+void maprequest(XEvent *e) {
+ XMapRequestEvent *ev = &e->xmaprequest;
+ static XWindowAttributes wa;
+ if(XGetWindowAttributes(dis, ev->window, &wa) && wa.override_redirect) return;
+
+ /* window is transient */
+ Window trans;
+ if(XGetTransientForHint(dis, ev->window, &trans) && trans) {
+ add_window(ev->window);
+ XMapWindow(dis, ev->window);
+ XSetInputFocus(dis, ev->window, RevertToParent, CurrentTime);
+ XRaiseWindow(dis, ev->window);
+ return;
+ }
+
+ /* window is normal and has a rule set */
+ XClassHint ch = {0, 0};
+ if(XGetClassHint(dis, ev->window, &ch))
+ for(unsigned int i=0; i<LENGTH(rules); i++) {
+ if(strcmp(ch.res_class, rules[i].class)) continue;
+ int cd = current_desktop;
+ save_desktop(cd);
+ select_desktop(rules[i].desktop);
+ add_window(ev->window);
+ select_desktop(cd);
+ if(cd == rules[i].desktop) {
+ XMapWindow(dis, ev->window);
+ tile();
+ update_current();
+ } else if(rules[i].follow)
+ change_desktop(&(Arg){.i = rules[i].desktop});
+ if(ch.res_class) XFree(ch.res_class);
+ if(ch.res_name) XFree(ch.res_name);
+ return;
+ }
+
+ /* window is normal and has no rule set */
+ add_window(ev->window);
+ XMapWindow(dis, ev->window);
+ tile();
update_current();
}
@@ -248,64 +394,74 @@ void move_up() {
update_current();
}
-void swap_master() {
- if(!current || !head->next || mode == MONOCLE) return;
- Window tmpwin = head->win;
- current = (current == head) ? head->next : current;
- head->win = current->win;
- current->win = tmpwin;
- current = head;
- save_desktop(current_desktop);
- tile();
+void next_win() {
+ if(!current || (!current->next && !current->prev)) return;
+ if(mode == MONOCLE) XUnmapWindow(dis, current->win);
+ current = (current->next) ? current->next : head;
+ if(mode == MONOCLE) XMapWindow(dis, current->win);
update_current();
}
-/* -------- Desktop Management -------- */
-void change_desktop(const Arg *arg) {
- if(arg->i == current_desktop) return;
- previous_desktop = current_desktop;
+void prev_win() {
+ if(!current || (!current->next && !current->prev)) return;
+ if(mode == MONOCLE) XUnmapWindow(dis, current->win);
+ if(current->prev) current = current->prev;
+ else while(current->next) current=current->next;
+ if(mode == MONOCLE) XMapWindow(dis, current->win);
+ update_current();
+}
- /* save current desktop settings and unmap windows */
- save_desktop(current_desktop);
- for(client *c=head; c; c=c->next)
- XUnmapWindow(dis, c->win);
+void quit(const Arg *arg) {
+ retval = arg->i;
+ running = False;
+}
- /* read new desktop properties, tile and map new windows */
- select_desktop(arg->i);
- tile();
- if(mode == MONOCLE && current) XMapWindow(dis, current->win);
- else for(client *c=head; c; c=c->next) XMapWindow(dis, c->win);
+void removeclient(client *c) {
+ if(!c->prev) { /* w is head */
+ if(!c->next) { /* head is only window on screen */
+ free(head);
+ head = NULL;
+ } else { /* more windows on screen */
+ head->next->prev = NULL;
+ head = head->next;
+ }
+ current = head;
+ } else { /* w is on stack */
+ if(!c->next) { /* w is last window on screen */
+ c->prev->next = NULL;
+ } else { /* w is somewhere in the middle */
+ c->next->prev = c->prev;
+ c->prev->next = c->next;
+ }
+ current = c->prev;
+ }
+ save_desktop(current_desktop);
+ tile();
+ if(mode == MONOCLE && current)
+ XMapWindow(dis, current->win);
update_current();
}
-void last_desktop() {
- change_desktop(&(Arg){.i = previous_desktop});
+void resize_master(const Arg *arg) {
+ master_size += arg->i;
+ tile();
+}
+
+void resize_stack(const Arg *arg) {
+ growth += arg->i;
+ tile();
}
void rotate_desktop(const Arg *arg) {
change_desktop(&(Arg){.i = (current_desktop + DESKTOPS + arg->i) % DESKTOPS});
}
-void client_to_desktop(const Arg *arg) {
- if(arg->i == current_desktop || !current) return;
-
- client *c = current;
- int cd = current_desktop;
-
- select_desktop(arg->i);
- add_window(c->win);
- save_desktop(arg->i);
-
- select_desktop(cd);
- XUnmapWindow(dis, c->win);
- removeclient(c);
- save_desktop(cd);
-
- tile();
- update_current();
-
- if(FOLLOW_WINDOW) change_desktop(arg);
+void run(void) {
+ XEvent ev;
+ while(running && !XNextEvent(dis, &ev))
+ if(events[ev.type])
+ events[ev.type](&ev);
}
void save_desktop(int i) {
@@ -328,10 +484,80 @@ void select_desktop(int i) {
current_desktop = i;
}
-void togglepanel() {
- showpanel = !showpanel;
+void setup(void) {
+ sigchld();
+
+ screen = DefaultScreen(dis);
+ root = RootWindow(dis, screen);
+
+ sw = XDisplayWidth(dis, screen) - BORDER_WIDTH;
+ sh = XDisplayHeight(dis, screen) - ((showpanel) ? PANEL_HEIGHT : 0) - BORDER_WIDTH;
+ master_size = ((mode == BSTACK) ? sh : sw) * MASTER_SIZE;
+ for(int i=0; i<DESKTOPS; i++)
+ save_desktop(i);
+ change_desktop(&(Arg){.i = DEFAULT_DESKTOP});
+
+ win_focus = getcolor(FOCUS);
+ win_unfocus = getcolor(UNFOCUS);
+
+ XModifierKeymap *modmap = XGetModifierMapping(dis);
+ for (int k=0; k<8; k++)
+ for (int j=0; j<modmap->max_keypermod; j++)
+ if(modmap->modifiermap[modmap->max_keypermod*k + j] == XKeysymToKeycode(dis, XK_Num_Lock))
+ numlockmask = (1 << k);
+ XFreeModifiermap(modmap);
+
+ /* set up atoms for dialog/notification windows */
+ atoms[WM_PROTOCOLS] = XInternAtom(dis, "WM_PROTOCOLS", False);
+ atoms[WM_DELETE_WINDOW] = XInternAtom(dis, "WM_DELETE_WINDOW", False);
+
+ /* check if another window manager is running */
+ xerrorxlib = XSetErrorHandler(xerrorstart);
+ XSelectInput(dis, DefaultRootWindow(dis), SubstructureNotifyMask|SubstructureRedirectMask);
+ XSync(dis, False);
+ XSetErrorHandler(xerror);
+ XSync(dis, False);
+
+ grabkeys();
+}
+
+void sigchld() {
+ if(signal(SIGCHLD, sigchld) == SIG_ERR)
+ die("error: can't install SIGCHLD handler\n");
+ while(0 < waitpid(-1, NULL, WNOHANG));
+}
+
+void spawn(const Arg *arg) {
+ if(fork() == 0) {
+ if(dis) close(ConnectionNumber(dis));
+ setsid();
+ execvp((char*)arg->com[0], (char**)arg->com);
+ fprintf(stderr, "error: execvp %s", (char *)arg->com[0]);
+ perror(" failed"); /* also prints the err msg */
+ exit(EXIT_SUCCESS);
+ }
+}
+
+void swap_master() {
+ if(!current || !head->next || mode == MONOCLE) return;
+ Window tmpwin = head->win;
+ current = (current == head) ? head->next : current;
+ head->win = current->win;
+ current->win = tmpwin;
+ current = head;
save_desktop(current_desktop);
tile();
+ update_current();
+}
+
+void switch_mode(const Arg *arg) {
+ if(mode == arg->i) return;
+ if(mode == MONOCLE) for(client *c=head; c; c=c->next) XMapWindow(dis, c->win);
+ mode = arg->i;
+ if(mode == TILE || mode == GRID) master_size = sw * MASTER_SIZE;
+ else if(mode == BSTACK) master_size = sh * MASTER_SIZE;
+ tile();
+ update_current();
}
void tile(void) {
@@ -446,6 +672,12 @@ void tile(void) {
free(c);
}
+void togglepanel() {
+ showpanel = !showpanel;
+ save_desktop(current_desktop);
+ tile();
+}
+
void update_current(void) {
client *c;
@@ -470,224 +702,6 @@ void update_current(void) {
XSync(dis, False);
}
-void switch_mode(const Arg *arg) {
- if(mode == arg->i) return;
- if(mode == MONOCLE) for(client *c=head; c; c=c->next) XMapWindow(dis, c->win);
- mode = arg->i;
- if(mode == TILE || mode == GRID) master_size = sw * MASTER_SIZE;
- else if(mode == BSTACK) master_size = sh * MASTER_SIZE;
- tile();
- update_current();
-}
-
-void resize_master(const Arg *arg) {
- master_size += arg->i;
- tile();
-}
-
-void resize_stack(const Arg *arg) {
- growth += arg->i;
- tile();
-}
-
-/* -------- Keyboard Management -------- */
-void grabkeys(void) {
- KeyCode code;
-
- XUngrabKey(dis, AnyKey, AnyModifier, root);
- for(unsigned int i=0; i<LENGTH(keys); i++) {
- code = XKeysymToKeycode(dis, keys[i].keysym);
- XGrabKey(dis, code, keys[i].mod, root, True, GrabModeAsync, GrabModeAsync);
- XGrabKey(dis, code, keys[i].mod | LockMask, root, True, GrabModeAsync, GrabModeAsync);
- XGrabKey(dis, code, keys[i].mod | numlockmask, root, True, GrabModeAsync, GrabModeAsync);
- XGrabKey(dis, code, keys[i].mod | numlockmask | LockMask, root, True, GrabModeAsync, GrabModeAsync);
- }
-}
-
-void keypress(XEvent *e) {
- static unsigned int len = sizeof keys / sizeof keys[0];
- unsigned int i;
- KeySym keysym;
- XKeyEvent *ev = &e->xkey;
-
- keysym = XKeycodeToKeysym(dis, (KeyCode)ev->keycode, 0);
- for(i = 0; i < len; i++)
- if(keysym == keys[i].keysym && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) && keys[i].function)
- keys[i].function(&keys[i].arg);
-}
-
-/* -------- Signal Management -------- */
-void maprequest(XEvent *e) {
- XMapRequestEvent *ev = &e->xmaprequest;
- static XWindowAttributes wa;
- if(XGetWindowAttributes(dis, ev->window, &wa) && wa.override_redirect) return;
-
- /* window is transient */
- Window trans;
- if(XGetTransientForHint(dis, ev->window, &trans) && trans) {
- add_window(ev->window);
- XMapWindow(dis, ev->window);
- XSetInputFocus(dis, ev->window, RevertToParent, CurrentTime);
- XRaiseWindow(dis, ev->window);
- return;
- }
-
- /* window is normal and has a rule set */
- XClassHint ch = {0, 0};
- if(XGetClassHint(dis, ev->window, &ch))
- for(unsigned int i=0; i<LENGTH(rules); i++) {
- if(strcmp(ch.res_class, rules[i].class)) continue;
- int cd = current_desktop;
- save_desktop(cd);
- select_desktop(rules[i].desktop);
- add_window(ev->window);
- select_desktop(cd);
- if(cd == rules[i].desktop) {
- XMapWindow(dis, ev->window);
- tile();
- update_current();
- } else if(rules[i].follow)
- change_desktop(&(Arg){.i = rules[i].desktop});
- if(ch.res_class) XFree(ch.res_class);
- if(ch.res_name) XFree(ch.res_name);
- return;
- }
-
- /* window is normal and has no rule set */
- add_window(ev->window);
- XMapWindow(dis, ev->window);
- tile();
- update_current();
-}
-
-void destroynotify(XEvent *e) {
- client *c;
- XDestroyWindowEvent *ev = &e->xdestroywindow;
- int cd = current_desktop;
- Bool found = False;
-
- save_desktop(cd);
- for(int d=0; d<DESKTOPS && !found; select_desktop(d++))
- for(c=head; c; c=c->next)
- if((found = ev->window == c->win)) {
- removeclient(c);
- break;
- }
- select_desktop(cd);
-}
-
-void enternotify(XEvent *e) {
- client *c;
- XCrossingEvent *ev = &e->xcrossing;
-
- if(FOLLOW_MOUSE) {
- if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) return;
- for(c=head; c; c=c->next)
- if(ev->window == c->win) {
- current = c;
- update_current();
- return;
- }
- }
-}
-
-void buttonpressed(XEvent *e) {
- client *c;
- XButtonPressedEvent *ev = &e->xbutton;
-
- if(CLICK_TO_FOCUS && ev->window != current->win && ev->button == Button1)
- for(c=head; c; c=c->next)
- if(ev->window == c->win) {
- current = c;
- update_current();
- return;
- }
-}
-
-void deletewindow(Window w) {
- XEvent ev;
- ev.type = ClientMessage;
- ev.xclient.window = w;
- ev.xclient.message_type = atoms[WM_PROTOCOLS];
- ev.xclient.format = 32;
- ev.xclient.data.l[0] = atoms[WM_DELETE_WINDOW];
- ev.xclient.data.l[1] = CurrentTime;
- XSendEvent(dis, w, False, NoEventMask, &ev);
-}
-
-unsigned long getcolor(const char* color) {
- Colormap map = DefaultColormap(dis, screen);
- XColor c;
-
- if(!XAllocNamedColor(dis, map, color, &c, &c))
- die("error: cannot allocate color '%s'\n", c);
- return c.pixel;
-}
-
-void quit(const Arg *arg) {
- retval = arg->i;
- running = False;
-}
-
-void cleanup(void) {
- Window root_return;
- Window parent_return;
- Window *children;
- unsigned int nchildren;
-
- XUngrabKey(dis, AnyKey, AnyModifier, root);
-
- XQueryTree(dis, root, &root_return, &parent_return, &children, &nchildren);
- for(unsigned int i = 0; i < nchildren; i++)
- deletewindow(children[i]);
- if(children) XFree(children);
-
- XSync(dis, False);
- XSetInputFocus(dis, PointerRoot, RevertToPointerRoot, CurrentTime);
-}
-
-void setup(void) {
- sigchld();
-
- screen = DefaultScreen(dis);
- root = RootWindow(dis, screen);
-
- sw = XDisplayWidth(dis, screen) - BORDER_WIDTH;
- sh = XDisplayHeight(dis, screen) - ((showpanel) ? PANEL_HEIGHT : 0) - BORDER_WIDTH;
- master_size = ((mode == BSTACK) ? sh : sw) * MASTER_SIZE;
- for(int i=0; i<DESKTOPS; i++)
- save_desktop(i);
- change_desktop(&(Arg){.i = DEFAULT_DESKTOP});
-
- win_focus = getcolor(FOCUS);
- win_unfocus = getcolor(UNFOCUS);
-
- XModifierKeymap *modmap = XGetModifierMapping(dis);
- for (int k=0; k<8; k++)
- for (int j=0; j<modmap->max_keypermod; j++)
- if(modmap->modifiermap[modmap->max_keypermod*k + j] == XKeysymToKeycode(dis, XK_Num_Lock))
- numlockmask = (1 << k);
- XFreeModifiermap(modmap);
-
- /* set up atoms for dialog/notification windows */
- atoms[WM_PROTOCOLS] = XInternAtom(dis, "WM_PROTOCOLS", False);
- atoms[WM_DELETE_WINDOW] = XInternAtom(dis, "WM_DELETE_WINDOW", False);
-
- /* check if another window manager is running */
- xerrorxlib = XSetErrorHandler(xerrorstart);
- XSelectInput(dis, DefaultRootWindow(dis), SubstructureNotifyMask|SubstructureRedirectMask);
- XSync(dis, False);
- XSetErrorHandler(xerror);
- XSync(dis, False);
-
- grabkeys();
-}
-
-int xerrorstart() {
- die("error: another window manager is already running\n");
- return -1;
-}
-
/* There's no way to check accesses to destroyed windows, thus those cases are
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
* default error handler, which may call exit. */
@@ -702,36 +716,9 @@ int xerror(Display *dis, XErrorEvent *ee) {
return xerrorxlib(dis, ee); /* may call exit */
}
-void sigchld() {
- if(signal(SIGCHLD, sigchld) == SIG_ERR)
- die("error: can't install SIGCHLD handler\n");
- while(0 < waitpid(-1, NULL, WNOHANG));
-}
-
-void spawn(const Arg *arg) {
- if(fork() == 0) {
- if(dis) close(ConnectionNumber(dis));
- setsid();
- execvp((char*)arg->com[0], (char**)arg->com);
- fprintf(stderr, "error: execvp %s", (char *)arg->com[0]);
- perror(" failed"); /* also prints the err msg */
- exit(EXIT_SUCCESS);
- }
-}
-
-void run(void) {
- XEvent ev;
- while(running && !XNextEvent(dis, &ev))
- if(events[ev.type])
- events[ev.type](&ev);
-}
-
-void die(const char *errstr, ...) {
- va_list ap;
- va_start(ap, errstr);
- vfprintf(stderr, errstr, ap);
- va_end(ap);
- exit(EXIT_FAILURE);
+int xerrorstart() {
+ die("error: another window manager is already running\n");
+ return -1;
}
int main(int argc, char *argv[]) {