dwm.c
changeset 1225 6211d430f5da
parent 1224 47496de04028
child 1226 6830cb2bbecf
equal deleted inserted replaced
1224:47496de04028 1225:6211d430f5da
    92 } DC; /* draw context */
    92 } DC; /* draw context */
    93 
    93 
    94 typedef struct {
    94 typedef struct {
    95 	unsigned long mod;
    95 	unsigned long mod;
    96 	KeySym keysym;
    96 	KeySym keysym;
    97 	void (*func)(void *arg);
    97 	void (*func)(const void *arg);
    98 	void *arg;
    98 	const void *arg;
    99 } Key;
    99 } Key;
   100 
   100 
   101 typedef struct {
   101 typedef struct {
   102 	const char *symbol;
   102 	const char *symbol;
   103 	void (*arrange)(void);
   103 	void (*arrange)(void);
   134 void enternotify(XEvent *e);
   134 void enternotify(XEvent *e);
   135 void eprint(const char *errstr, ...);
   135 void eprint(const char *errstr, ...);
   136 void expose(XEvent *e);
   136 void expose(XEvent *e);
   137 void focus(Client *c);
   137 void focus(Client *c);
   138 void focusin(XEvent *e);
   138 void focusin(XEvent *e);
   139 void focusnext(void *arg);
   139 void focusnext(const void *arg);
   140 void focusprev(void *arg);
   140 void focusprev(const void *arg);
   141 Client *getclient(Window w);
   141 Client *getclient(Window w);
   142 unsigned long getcolor(const char *colstr);
   142 unsigned long getcolor(const char *colstr);
   143 long getstate(Window w);
   143 long getstate(Window w);
   144 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   144 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   145 void grabbuttons(Client *c, Bool focused);
   145 void grabbuttons(Client *c, Bool focused);
   148 Bool isoccupied(unsigned int t);
   148 Bool isoccupied(unsigned int t);
   149 Bool isprotodel(Client *c);
   149 Bool isprotodel(Client *c);
   150 Bool isurgent(unsigned int t);
   150 Bool isurgent(unsigned int t);
   151 Bool isvisible(Client *c);
   151 Bool isvisible(Client *c);
   152 void keypress(XEvent *e);
   152 void keypress(XEvent *e);
   153 void killclient(void *arg);
   153 void killclient(const void *arg);
   154 void manage(Window w, XWindowAttributes *wa);
   154 void manage(Window w, XWindowAttributes *wa);
   155 void mappingnotify(XEvent *e);
   155 void mappingnotify(XEvent *e);
   156 void maprequest(XEvent *e);
   156 void maprequest(XEvent *e);
   157 void movemouse(Client *c);
   157 void movemouse(Client *c);
   158 Client *nextunfloating(Client *c);
   158 Client *nextunfloating(Client *c);
   159 void propertynotify(XEvent *e);
   159 void propertynotify(XEvent *e);
   160 void quit(void *arg);
   160 void quit(const void *arg);
   161 void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
   161 void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
   162 void resizemouse(Client *c);
   162 void resizemouse(Client *c);
   163 void restack(void);
   163 void restack(void);
   164 void run(void);
   164 void run(void);
   165 void scan(void);
   165 void scan(void);
   166 void setclientstate(Client *c, long state);
   166 void setclientstate(Client *c, long state);
   167 void setmfact(void *arg);
   167 void setmfact(const void *arg);
   168 void setup(void);
   168 void setup(void);
   169 void spawn(void *arg);
   169 void spawn(const void *arg);
   170 void tag(void *arg);
   170 void tag(const void *arg);
   171 unsigned int textnw(const char *text, unsigned int len);
   171 unsigned int textnw(const char *text, unsigned int len);
   172 unsigned int textw(const char *text);
   172 unsigned int textw(const char *text);
   173 void tile(void);
   173 void tile(void);
   174 void tileresize(Client *c, int x, int y, int w, int h);
   174 void tileresize(Client *c, int x, int y, int w, int h);
   175 void togglebar(void *arg);
   175 void togglebar(const void *arg);
   176 void togglefloating(void *arg);
   176 void togglefloating(const void *arg);
   177 void togglelayout(void *arg);
   177 void togglelayout(const void *arg);
   178 void toggletag(void *arg);
   178 void toggletag(const void *arg);
   179 void toggleview(void *arg);
   179 void toggleview(const void *arg);
   180 void unban(Client *c);
   180 void unban(Client *c);
   181 void unmanage(Client *c);
   181 void unmanage(Client *c);
   182 void unmapnotify(XEvent *e);
   182 void unmapnotify(XEvent *e);
   183 void updatebar(void);
   183 void updatebar(void);
   184 void updategeom(void);
   184 void updategeom(void);
   185 void updatesizehints(Client *c);
   185 void updatesizehints(Client *c);
   186 void updatetilegeom(void);
   186 void updatetilegeom(void);
   187 void updatetitle(Client *c);
   187 void updatetitle(Client *c);
   188 void updatewmhints(Client *c);
   188 void updatewmhints(Client *c);
   189 void view(void *arg);
   189 void view(const void *arg);
   190 void viewprevtag(void *arg);
   190 void viewprevtag(const void *arg);
   191 int xerror(Display *dpy, XErrorEvent *ee);
   191 int xerror(Display *dpy, XErrorEvent *ee);
   192 int xerrordummy(Display *dpy, XErrorEvent *ee);
   192 int xerrordummy(Display *dpy, XErrorEvent *ee);
   193 int xerrorstart(Display *dpy, XErrorEvent *ee);
   193 int xerrorstart(Display *dpy, XErrorEvent *ee);
   194 void zoom(void *arg);
   194 void zoom(const void *arg);
   195 
   195 
   196 /* variables */
   196 /* variables */
   197 char stext[256];
   197 char stext[256];
   198 int screen, sx, sy, sw, sh;
   198 int screen, sx, sy, sw, sh;
   199 int bx, by, bw, bh, blw, wx, wy, ww, wh;
   199 int bx, by, bw, bh, blw, wx, wy, ww, wh;
   665 	if(sel && ev->window != sel->win)
   665 	if(sel && ev->window != sel->win)
   666 		XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
   666 		XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
   667 }
   667 }
   668 
   668 
   669 void
   669 void
   670 focusnext(void *arg) {
   670 focusnext(const void *arg) {
   671 	Client *c;
   671 	Client *c;
   672 
   672 
   673 	if(!sel)
   673 	if(!sel)
   674 		return;
   674 		return;
   675 	for(c = sel->next; c && !isvisible(c); c = c->next);
   675 	for(c = sel->next; c && !isvisible(c); c = c->next);
   680 		restack();
   680 		restack();
   681 	}
   681 	}
   682 }
   682 }
   683 
   683 
   684 void
   684 void
   685 focusprev(void *arg) {
   685 focusprev(const void *arg) {
   686 	Client *c;
   686 	Client *c;
   687 
   687 
   688 	if(!sel)
   688 	if(!sel)
   689 		return;
   689 		return;
   690 	for(c = sel->prev; c && !isvisible(c); c = c->prev);
   690 	for(c = sel->prev; c && !isvisible(c); c = c->prev);
   903 				keys[i].func(keys[i].arg);
   903 				keys[i].func(keys[i].arg);
   904 		}
   904 		}
   905 }
   905 }
   906 
   906 
   907 void
   907 void
   908 killclient(void *arg) {
   908 killclient(const void *arg) {
   909 	XEvent ev;
   909 	XEvent ev;
   910 
   910 
   911 	if(!sel)
   911 	if(!sel)
   912 		return;
   912 		return;
   913 	if(isprotodel(sel)) {
   913 	if(isprotodel(sel)) {
  1086 		}
  1086 		}
  1087 	}
  1087 	}
  1088 }
  1088 }
  1089 
  1089 
  1090 void
  1090 void
  1091 quit(void *arg) {
  1091 quit(const void *arg) {
  1092 	readin = running = False;
  1092 	readin = running = False;
  1093 }
  1093 }
  1094 
  1094 
  1095 void
  1095 void
  1096 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1096 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1319 			PropModeReplace, (unsigned char *)data, 2);
  1319 			PropModeReplace, (unsigned char *)data, 2);
  1320 }
  1320 }
  1321 
  1321 
  1322 /* arg > 1.0 will set mfact absolutly */
  1322 /* arg > 1.0 will set mfact absolutly */
  1323 void
  1323 void
  1324 setmfact(void *arg) {
  1324 setmfact(const void *arg) {
  1325 	double d = *((double*) arg);
  1325 	double d = *((double*) arg);
  1326 
  1326 
  1327 	if(!d || lt->arrange != tile)
  1327 	if(!d || lt->arrange != tile)
  1328 		return;
  1328 		return;
  1329 	d = d < 1.0 ? d + mfact : d - 1.0;
  1329 	d = d < 1.0 ? d + mfact : d - 1.0;
  1410 	/* grab keys */
  1410 	/* grab keys */
  1411 	grabkeys();
  1411 	grabkeys();
  1412 }
  1412 }
  1413 
  1413 
  1414 void
  1414 void
  1415 spawn(void *arg) {
  1415 spawn(const void *arg) {
  1416 	static char *shell = NULL;
  1416 	static char *shell = NULL;
  1417 
  1417 
  1418 	if(!shell && !(shell = getenv("SHELL")))
  1418 	if(!shell && !(shell = getenv("SHELL")))
  1419 		shell = "/bin/sh";
  1419 		shell = "/bin/sh";
  1420 	/* The double-fork construct avoids zombie processes and keeps the code
  1420 	/* The double-fork construct avoids zombie processes and keeps the code
  1432 	}
  1432 	}
  1433 	wait(0);
  1433 	wait(0);
  1434 }
  1434 }
  1435 
  1435 
  1436 void
  1436 void
  1437 tag(void *arg) {
  1437 tag(const void *arg) {
  1438 	if(sel && *(int *)arg & TAGMASK) {
  1438 	if(sel && *(int *)arg & TAGMASK) {
  1439 		sel->tags = *(int *)arg & TAGMASK;
  1439 		sel->tags = *(int *)arg & TAGMASK;
  1440 		arrange();
  1440 		arrange();
  1441 	}
  1441 	}
  1442 }
  1442 }
  1503 		/* client doesn't accept size constraints */
  1503 		/* client doesn't accept size constraints */
  1504 		resize(c, x, y, w, h, False);
  1504 		resize(c, x, y, w, h, False);
  1505 }
  1505 }
  1506 
  1506 
  1507 void
  1507 void
  1508 togglebar(void *arg) {
  1508 togglebar(const void *arg) {
  1509 	showbar = !showbar;
  1509 	showbar = !showbar;
  1510 	updategeom();
  1510 	updategeom();
  1511 	updatebar();
  1511 	updatebar();
  1512 	arrange();
  1512 	arrange();
  1513 }
  1513 }
  1514 
  1514 
  1515 void
  1515 void
  1516 togglefloating(void *arg) {
  1516 togglefloating(const void *arg) {
  1517 	if(!sel)
  1517 	if(!sel)
  1518 		return;
  1518 		return;
  1519 	sel->isfloating = !sel->isfloating;
  1519 	sel->isfloating = !sel->isfloating;
  1520 	if(sel->isfloating)
  1520 	if(sel->isfloating)
  1521 		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
  1521 		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
  1522 	arrange();
  1522 	arrange();
  1523 }
  1523 }
  1524 
  1524 
  1525 void
  1525 void
  1526 togglelayout(void *arg) {
  1526 togglelayout(const void *arg) {
  1527 	unsigned int i;
  1527 	unsigned int i;
  1528 
  1528 
  1529 	if(!arg) {
  1529 	if(!arg) {
  1530 		if(++lt == &layouts[LENGTH(layouts)])
  1530 		if(++lt == &layouts[LENGTH(layouts)])
  1531 			lt = &layouts[0];
  1531 			lt = &layouts[0];
  1543 	else
  1543 	else
  1544 		drawbar();
  1544 		drawbar();
  1545 }
  1545 }
  1546 
  1546 
  1547 void
  1547 void
  1548 toggletag(void *arg) {
  1548 toggletag(const void *arg) {
  1549 	int i, m = *(int *)arg;
  1549 	int i, m = *(int *)arg;
  1550 	for(i = 0; i < sizeof(int) * 8; i++)
  1550 	for(i = 0; i < sizeof(int) * 8; i++)
  1551 		fputc(m & 1 << i ? '1' : '0', stdout);
  1551 		fputc(m & 1 << i ? '1' : '0', stdout);
  1552 	puts("");
  1552 	puts("");
  1553 	for(i = 0; i < sizeof(int) * 8; i++)
  1553 	for(i = 0; i < sizeof(int) * 8; i++)
  1559 		arrange();
  1559 		arrange();
  1560 	}
  1560 	}
  1561 }
  1561 }
  1562 
  1562 
  1563 void
  1563 void
  1564 toggleview(void *arg) {
  1564 toggleview(const void *arg) {
  1565 	if((tagset[seltags] ^ ((*(int *)arg) & TAGMASK))) {
  1565 	if((tagset[seltags] ^ ((*(int *)arg) & TAGMASK))) {
  1566 		tagset[seltags] ^= (*(int *)arg) & TAGMASK;
  1566 		tagset[seltags] ^= (*(int *)arg) & TAGMASK;
  1567 		arrange();
  1567 		arrange();
  1568 	}
  1568 	}
  1569 }
  1569 }
  1735 		XFree(wmh);
  1735 		XFree(wmh);
  1736 	}
  1736 	}
  1737 }
  1737 }
  1738 
  1738 
  1739 void
  1739 void
  1740 view(void *arg) {
  1740 view(const void *arg) {
  1741 	if(*(int *)arg & TAGMASK) {
  1741 	if(*(int *)arg & TAGMASK) {
  1742 		seltags ^= 1; /* toggle sel tagset */
  1742 		seltags ^= 1; /* toggle sel tagset */
  1743 		tagset[seltags] = *(int *)arg & TAGMASK;
  1743 		tagset[seltags] = *(int *)arg & TAGMASK;
  1744 		arrange();
  1744 		arrange();
  1745 	}
  1745 	}
  1746 }
  1746 }
  1747 
  1747 
  1748 void
  1748 void
  1749 viewprevtag(void *arg) {
  1749 viewprevtag(const void *arg) {
  1750 	seltags ^= 1; /* toggle sel tagset */
  1750 	seltags ^= 1; /* toggle sel tagset */
  1751 	arrange();
  1751 	arrange();
  1752 }
  1752 }
  1753 
  1753 
  1754 /* There's no way to check accesses to destroyed windows, thus those cases are
  1754 /* There's no way to check accesses to destroyed windows, thus those cases are
  1783 	otherwm = True;
  1783 	otherwm = True;
  1784 	return -1;
  1784 	return -1;
  1785 }
  1785 }
  1786 
  1786 
  1787 void
  1787 void
  1788 zoom(void *arg) {
  1788 zoom(const void *arg) {
  1789 	Client *c = sel;
  1789 	Client *c = sel;
  1790 
  1790 
  1791 	if(c == nextunfloating(clients))
  1791 	if(c == nextunfloating(clients))
  1792 		if(!c || !(c = nextunfloating(c->next)))
  1792 		if(!c || !(c = nextunfloating(c->next)))
  1793 			return;
  1793 			return;