dwm.c
changeset 1445 4ad1f24d38ec
parent 1444 19dc2b0c61e2
child 1446 c3ea02998d91
equal deleted inserted replaced
1444:19dc2b0c61e2 1445:4ad1f24d38ec
     9  * The event handlers of dwm are organized in an array which is accessed
     9  * The event handlers of dwm are organized in an array which is accessed
    10  * whenever a new event has been fetched. This allows event dispatching
    10  * whenever a new event has been fetched. This allows event dispatching
    11  * in O(1) time.
    11  * in O(1) time.
    12  *
    12  *
    13  * Each child of the root window is called a client, except windows which have
    13  * Each child of the root window is called a client, except windows which have
    14  * set the override_redirect flag.  Clients are organized in a global
    14  * set the override_redirect flag.  Clients are organized in a linked client
    15  * linked client list, the focus history is remembered through a global
    15  * list on each monitor, the focus history is remembered through a stack list
    16  * stack list. Each client contains a bit array to indicate the tags of a
    16  * on each monitor. Each client contains a bit array to indicate the tags of a
    17  * client.
    17  * client.
    18  *
    18  *
    19  * Keys and tagging rules are organized as arrays and defined in config.h.
    19  * Keys and tagging rules are organized as arrays and defined in config.h.
    20  *
    20  *
    21  * To understand everything else, start reading main().
    21  * To understand everything else, start reading main().
   162 static void configurerequest(XEvent *e);
   162 static void configurerequest(XEvent *e);
   163 static void destroynotify(XEvent *e);
   163 static void destroynotify(XEvent *e);
   164 static void detach(Client *c);
   164 static void detach(Client *c);
   165 static void detachstack(Client *c);
   165 static void detachstack(Client *c);
   166 static void die(const char *errstr, ...);
   166 static void die(const char *errstr, ...);
       
   167 static Monitor *dirtomon(int dir);
   167 static void drawbar(Monitor *m);
   168 static void drawbar(Monitor *m);
   168 static void drawbars(void);
   169 static void drawbars(void);
   169 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
   170 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
   170 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
   171 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
   171 static void enternotify(XEvent *e);
   172 static void enternotify(XEvent *e);
   178 static Bool getrootpointer(int *x, int *y);
   179 static Bool getrootpointer(int *x, int *y);
   179 static long getstate(Window w);
   180 static long getstate(Window w);
   180 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   181 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   181 static void grabbuttons(Client *c, Bool focused);
   182 static void grabbuttons(Client *c, Bool focused);
   182 static void grabkeys(void);
   183 static void grabkeys(void);
   183 static Monitor *idxtomon(unsigned int n);
       
   184 static void initfont(const char *fontstr);
   184 static void initfont(const char *fontstr);
   185 static Bool isprotodel(Client *c);
   185 static Bool isprotodel(Client *c);
   186 static void keypress(XEvent *e);
   186 static void keypress(XEvent *e);
   187 static void killclient(const Arg *arg);
   187 static void killclient(const Arg *arg);
   188 static void manage(Window w, XWindowAttributes *wa);
   188 static void manage(Window w, XWindowAttributes *wa);
   619 	vfprintf(stderr, errstr, ap);
   619 	vfprintf(stderr, errstr, ap);
   620 	va_end(ap);
   620 	va_end(ap);
   621 	exit(EXIT_FAILURE);
   621 	exit(EXIT_FAILURE);
   622 }
   622 }
   623 
   623 
       
   624 Monitor *
       
   625 dirtomon(int dir) {
       
   626 	Monitor *m = NULL;
       
   627 
       
   628 	if(dir > 0)
       
   629 		if(!(m = selmon->next))
       
   630 			m = mons;
       
   631 	else {
       
   632 		if(selmon == mons)
       
   633 			for(m = mons; m->next; m = m->next);
       
   634 		else
       
   635 			for(m = mons; m->next != selmon; m = m->next);
       
   636 	}
       
   637 	return m;
       
   638 }
       
   639 
   624 void
   640 void
   625 drawbar(Monitor *m) {
   641 drawbar(Monitor *m) {
   626 	int x;
   642 	int x;
   627 	unsigned int i, occ = 0, urg = 0;
   643 	unsigned int i, occ = 0, urg = 0;
   628 	unsigned long *col;
   644 	unsigned long *col;
   795 		XSetInputFocus(dpy, selmon->sel->win, RevertToPointerRoot, CurrentTime);
   811 		XSetInputFocus(dpy, selmon->sel->win, RevertToPointerRoot, CurrentTime);
   796 }
   812 }
   797 
   813 
   798 void
   814 void
   799 focusmon(const Arg *arg) {
   815 focusmon(const Arg *arg) {
   800 	Monitor *m;
   816 	Monitor *m = NULL;
   801 
   817 
   802 	if(!(m = idxtomon(arg->ui)) || m == selmon)
   818 	if(!mons->next)
   803 		return;
   819 		return;
       
   820 	m = dirtomon(arg->i);
   804 	unfocus(selmon->sel);
   821 	unfocus(selmon->sel);
   805 	selmon = m;
   822 	selmon = m;
   806 	focus(NULL);
   823 	focus(NULL);
   807 }
   824 }
   808 
   825 
   930 				for(j = 0; j < LENGTH(modifiers); j++)
   947 				for(j = 0; j < LENGTH(modifiers); j++)
   931 					XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
   948 					XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
   932 						 True, GrabModeAsync, GrabModeAsync);
   949 						 True, GrabModeAsync, GrabModeAsync);
   933 		}
   950 		}
   934 	}
   951 	}
   935 }
       
   936 
       
   937 Monitor *
       
   938 idxtomon(unsigned int n) {
       
   939 	unsigned int i;
       
   940 	Monitor *m;
       
   941 
       
   942 	for(m = mons, i = 0; m && i != n; m = m->next, i++);
       
   943 	return m;
       
   944 }
   952 }
   945 
   953 
   946 void
   954 void
   947 initfont(const char *fontstr) {
   955 initfont(const char *fontstr) {
   948 	char *def, **missing;
   956 	char *def, **missing;
  1510 	}
  1518 	}
  1511 }
  1519 }
  1512 
  1520 
  1513 void
  1521 void
  1514 tagmon(const Arg *arg) {
  1522 tagmon(const Arg *arg) {
  1515 	Monitor *m;
  1523 	if(!selmon->sel || !mons->next)
  1516 
  1524 		return
  1517 	if(!selmon->sel || !(m = idxtomon(arg->ui)))
  1525 	sendmon(selmon->sel, dirtomon(arg->i));
  1518 		return;
       
  1519 	sendmon(selmon->sel, m);
       
  1520 }
  1526 }
  1521 
  1527 
  1522 int
  1528 int
  1523 textnw(const char *text, unsigned int len) {
  1529 textnw(const char *text, unsigned int len) {
  1524 	XRectangle r;
  1530 	XRectangle r;