Configuration file for DWM on MacBook Air
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1949 lines
47 KiB

17 years ago
16 years ago
15 years ago
16 years ago
15 years ago
15 years ago
15 years ago
17 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
15 years ago
16 years ago
  1. /* See LICENSE file for copyright and license details.
  2. *
  3. * dynamic window manager is designed like any other X client as well. It is
  4. * driven through handling X events. In contrast to other X clients, a window
  5. * manager selects for SubstructureRedirectMask on the root window, to receive
  6. * events about window (dis-)appearance. Only one X connection at a time is
  7. * allowed to select for this event mask.
  8. *
  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
  11. * in O(1) time.
  12. *
  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 linked client
  15. * list on each monitor, the focus history is remembered through a stack list
  16. * on each monitor. Each client contains a bit array to indicate the tags of a
  17. * client.
  18. *
  19. * Keys and tagging rules are organized as arrays and defined in config.h.
  20. *
  21. * To understand everything else, start reading main().
  22. */
  23. #include <errno.h>
  24. #include <locale.h>
  25. #include <stdarg.h>
  26. #include <signal.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <unistd.h>
  31. #include <sys/types.h>
  32. #include <sys/wait.h>
  33. #include <X11/cursorfont.h>
  34. #include <X11/keysym.h>
  35. #include <X11/Xatom.h>
  36. #include <X11/Xlib.h>
  37. #include <X11/Xproto.h>
  38. #include <X11/Xutil.h>
  39. #ifdef XINERAMA
  40. #include <X11/extensions/Xinerama.h>
  41. #endif /* XINERAMA */
  42. /* macros */
  43. #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
  44. #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
  45. #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
  46. #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
  47. #define LENGTH(X) (sizeof X / sizeof X[0])
  48. #define MAX(A, B) ((A) > (B) ? (A) : (B))
  49. #define MIN(A, B) ((A) < (B) ? (A) : (B))
  50. #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
  51. #define WIDTH(X) ((X)->w + 2 * (X)->bw)
  52. #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
  53. #define TAGMASK ((int)((1LL << LENGTH(tags)) - 1))
  54. #define TEXTW(X) (textnw(X, strlen(X)) + dc.font.height)
  55. /* enums */
  56. enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
  57. enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
  58. enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
  59. enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */
  60. enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
  61. ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
  62. typedef union {
  63. int i;
  64. unsigned int ui;
  65. float f;
  66. void *v;
  67. } Arg;
  68. typedef struct {
  69. unsigned int click;
  70. unsigned int mask;
  71. unsigned int button;
  72. void (*func)(const Arg *arg);
  73. const Arg arg;
  74. } Button;
  75. typedef struct Monitor Monitor;
  76. typedef struct Client Client;
  77. struct Client {
  78. char name[256];
  79. float mina, maxa;
  80. int x, y, w, h;
  81. int basew, baseh, incw, inch, maxw, maxh, minw, minh;
  82. int bw, oldbw;
  83. unsigned int tags;
  84. Bool isfixed, isfloating, isurgent;
  85. Client *next;
  86. Client *snext;
  87. Monitor *mon;
  88. Window win;
  89. };
  90. typedef struct {
  91. int x, y, w, h;
  92. unsigned long norm[ColLast];
  93. unsigned long sel[ColLast];
  94. Drawable drawable;
  95. GC gc;
  96. struct {
  97. int ascent;
  98. int descent;
  99. int height;
  100. XFontSet set;
  101. XFontStruct *xfont;
  102. } font;
  103. } DC; /* draw context */
  104. typedef struct {
  105. unsigned int mod;
  106. KeySym keysym;
  107. void (*func)(const Arg *);
  108. const Arg arg;
  109. } Key;
  110. typedef struct {
  111. const char *symbol;
  112. void (*arrange)(Monitor *);
  113. } Layout;
  114. struct Monitor {
  115. int screen_number;
  116. float mfact;
  117. int by, btx; /* bar geometry */
  118. int mx, my, mw, mh; /* screen size */
  119. int wx, wy, ww, wh; /* window area */
  120. unsigned int seltags;
  121. unsigned int sellt;
  122. unsigned int tagset[2];
  123. Bool showbar;
  124. Bool topbar;
  125. Client *clients;
  126. Client *sel;
  127. Client *stack;
  128. Monitor *next;
  129. Window barwin;
  130. };
  131. typedef struct {
  132. const char *class;
  133. const char *instance;
  134. const char *title;
  135. unsigned int tags;
  136. Bool isfloating;
  137. } Rule;
  138. /* function declarations */
  139. static void applyrules(Client *c);
  140. static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact);
  141. static void arrange(void);
  142. static void attach(Client *c);
  143. static void attachstack(Client *c);
  144. static void buttonpress(XEvent *e);
  145. static void checkotherwm(void);
  146. static void cleanup(void);
  147. static void cleanupmons(void);
  148. static void clearurgent(Client *c);
  149. static void configure(Client *c);
  150. static void configurenotify(XEvent *e);
  151. static void configurerequest(XEvent *e);
  152. static void destroynotify(XEvent *e);
  153. static void detach(Client *c);
  154. static void detachstack(Client *c);
  155. static void die(const char *errstr, ...);
  156. static Monitor *dirtomon(int dir);
  157. static void drawbar(Monitor *m);
  158. static void drawbars(void);
  159. static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
  160. static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
  161. static void enternotify(XEvent *e);
  162. static void expose(XEvent *e);
  163. static void focus(Client *c);
  164. static void focusin(XEvent *e);
  165. static void focusmon(const Arg *arg);
  166. static void focusstack(const Arg *arg);
  167. static unsigned long getcolor(const char *colstr);
  168. static Bool getrootpointer(int *x, int *y);
  169. static long getstate(Window w);
  170. static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
  171. static void grabbuttons(Client *c, Bool focused);
  172. static void grabkeys(void);
  173. static void initfont(const char *fontstr);
  174. static Bool isprotodel(Client *c);
  175. static void keypress(XEvent *e);
  176. static void killclient(const Arg *arg);
  177. static void manage(Window w, XWindowAttributes *wa);
  178. static void mappingnotify(XEvent *e);
  179. static void maprequest(XEvent *e);
  180. static void monocle(Monitor *m);
  181. static void movemouse(const Arg *arg);
  182. static Client *nexttiled(Client *c);
  183. static Monitor *pointertomon(int x, int y);
  184. static void propertynotify(XEvent *e);
  185. static void quit(const Arg *arg);
  186. static void resize(Client *c, int x, int y, int w, int h, Bool interact);
  187. static void resizemouse(const Arg *arg);
  188. static void restack(Monitor *m);
  189. static void run(void);
  190. static void scan(void);
  191. static void sendmon(Client *c, Monitor *m);
  192. static void setclientstate(Client *c, long state);
  193. static void setlayout(const Arg *arg);
  194. static void setmfact(const Arg *arg);
  195. static void setup(void);
  196. static void showhide(Client *c);
  197. static void sigchld(int signal);
  198. static void spawn(const Arg *arg);
  199. static void tag(const Arg *arg);
  200. static void tagmon(const Arg *arg);
  201. static int textnw(const char *text, unsigned int len);
  202. static void tile(Monitor *);
  203. static void togglebar(const Arg *arg);
  204. static void togglefloating(const Arg *arg);
  205. static void toggletag(const Arg *arg);
  206. static void toggleview(const Arg *arg);
  207. static void unfocus(Client *c);
  208. static void unmanage(Client *c);
  209. static void unmapnotify(XEvent *e);
  210. static void updategeom(void);
  211. static void updatebarpos(Monitor *m);
  212. static void updatebars(void);
  213. static void updatenumlockmask(void);
  214. static void updatesizehints(Client *c);
  215. static void updatestatus(void);
  216. static void updatetitle(Client *c);
  217. static void updatewmhints(Client *c);
  218. static void view(const Arg *arg);
  219. static Client *wintoclient(Window w);
  220. static Monitor *wintomon(Window w);
  221. static int xerror(Display *dpy, XErrorEvent *ee);
  222. static int xerrordummy(Display *dpy, XErrorEvent *ee);
  223. static int xerrorstart(Display *dpy, XErrorEvent *ee);
  224. static void zoom(const Arg *arg);
  225. /* variables */
  226. static char stext[256];
  227. static int screen;
  228. static int sw, sh; /* X display screen geometry x, y, width, height */
  229. static int bh, blw = 0; /* bar geometry */
  230. static int (*xerrorxlib)(Display *, XErrorEvent *);
  231. static unsigned int numlockmask = 0;
  232. static void (*handler[LASTEvent]) (XEvent *) = {
  233. [ButtonPress] = buttonpress,
  234. [ConfigureRequest] = configurerequest,
  235. [ConfigureNotify] = configurenotify,
  236. [DestroyNotify] = destroynotify,
  237. [EnterNotify] = enternotify,
  238. [Expose] = expose,
  239. [FocusIn] = focusin,
  240. [KeyPress] = keypress,
  241. [MappingNotify] = mappingnotify,
  242. [MapRequest] = maprequest,
  243. [PropertyNotify] = propertynotify,
  244. [UnmapNotify] = unmapnotify
  245. };
  246. static Atom wmatom[WMLast], netatom[NetLast];
  247. static Bool otherwm;
  248. static Bool running = True;
  249. static Cursor cursor[CurLast];
  250. static Display *dpy;
  251. static DC dc;
  252. static Layout *lt[] = { NULL, NULL };
  253. static Monitor *mons = NULL, *selmon = NULL;
  254. static Window root;
  255. /* configuration, allows nested code to access above variables */
  256. #include "config.h"
  257. /* compile-time check if all tags fit into an unsigned int bit array. */
  258. struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
  259. /* function implementations */
  260. void
  261. applyrules(Client *c) {
  262. unsigned int i;
  263. Rule *r;
  264. XClassHint ch = { 0 };
  265. /* rule matching */
  266. c->isfloating = c->tags = 0;
  267. if(XGetClassHint(dpy, c->win, &ch)) {
  268. for(i = 0; i < LENGTH(rules); i++) {
  269. r = &rules[i];
  270. if((!r->title || strstr(c->name, r->title))
  271. && (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
  272. && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance))))
  273. {
  274. c->isfloating = r->isfloating;
  275. c->tags |= r->tags;
  276. }
  277. }
  278. if(ch.res_class)
  279. XFree(ch.res_class);
  280. if(ch.res_name)
  281. XFree(ch.res_name);
  282. }
  283. c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
  284. }
  285. Bool
  286. applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) {
  287. Bool baseismin;
  288. Monitor *m = c->mon;
  289. /* set minimum possible */
  290. *w = MAX(1, *w);
  291. *h = MAX(1, *h);
  292. if(interact) {
  293. if(*x > sw)
  294. *x = sw - WIDTH(c);
  295. if(*y > sh)
  296. *y = sh - HEIGHT(c);
  297. if(*x + *w + 2 * c->bw < 0)
  298. *x = 0;
  299. if(*y + *h + 2 * c->bw < 0)
  300. *y = 0;
  301. }
  302. else {
  303. if(*x > m->mx + m->mw)
  304. *x = m->mx + m->mw - WIDTH(c);
  305. if(*y > m->my + m->mh)
  306. *y = m->my + m->mh - HEIGHT(c);
  307. if(*x + *w + 2 * c->bw < m->mx)
  308. *x = m->mx;
  309. if(*y + *h + 2 * c->bw < m->my)
  310. *y = m->my;
  311. }
  312. if(*h < bh)
  313. *h = bh;
  314. if(*w < bh)
  315. *w = bh;
  316. if(resizehints || c->isfloating) {
  317. /* see last two sentences in ICCCM 4.1.2.3 */
  318. baseismin = c->basew == c->minw && c->baseh == c->minh;
  319. if(!baseismin) { /* temporarily remove base dimensions */
  320. *w -= c->basew;
  321. *h -= c->baseh;
  322. }
  323. /* adjust for aspect limits */
  324. if(c->mina > 0 && c->maxa > 0) {
  325. if(c->maxa < (float)*w / *h)
  326. *w = *h * c->maxa;
  327. else if(c->mina < (float)*h / *w)
  328. *h = *w * c->mina;
  329. }
  330. if(baseismin) { /* increment calculation requires this */
  331. *w -= c->basew;
  332. *h -= c->baseh;
  333. }
  334. /* adjust for increment value */
  335. if(c->incw)
  336. *w -= *w % c->incw;
  337. if(c->inch)
  338. *h -= *h % c->inch;
  339. /* restore base dimensions */
  340. *w += c->basew;
  341. *h += c->baseh;
  342. *w = MAX(*w, c->minw);
  343. *h = MAX(*h, c->minh);
  344. if(c->maxw)
  345. *w = MIN(*w, c->maxw);
  346. if(c->maxh)
  347. *h = MIN(*h, c->maxh);
  348. }
  349. return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
  350. }
  351. void
  352. arrange(void) {
  353. Monitor *m;
  354. /* optimise two loops into one, check focus(NULL) */
  355. for(m = mons; m; m = m->next)
  356. showhide(m->stack);
  357. focus(NULL);
  358. for(m = mons; m; m = m->next) {
  359. if(lt[m->sellt]->arrange)
  360. lt[m->sellt]->arrange(m);
  361. restack(m);
  362. }
  363. }
  364. void
  365. attach(Client *c) {
  366. c->next = c->mon->clients;
  367. c->mon->clients = c;
  368. }
  369. void
  370. attachstack(Client *c) {
  371. c->snext = c->mon->stack;
  372. c->mon->stack = c;
  373. }
  374. void
  375. buttonpress(XEvent *e) {
  376. unsigned int i, x, click;
  377. Arg arg = {0};
  378. Client *c;
  379. Monitor *m;
  380. XButtonPressedEvent *ev = &e->xbutton;
  381. click = ClkRootWin;
  382. /* focus monitor if necessary */
  383. if((m = wintomon(ev->window)) && m != selmon) {
  384. unfocus(selmon->sel);
  385. selmon = m;
  386. focus(NULL);
  387. }
  388. if(ev->window == selmon->barwin && ev->x >= selmon->btx) {
  389. i = 0;
  390. x = selmon->btx;
  391. do
  392. x += TEXTW(tags[i]);
  393. while(ev->x >= x && ++i < LENGTH(tags));
  394. if(i < LENGTH(tags)) {
  395. click = ClkTagBar;
  396. arg.ui = 1 << i;
  397. }
  398. else if(ev->x < x + blw)
  399. click = ClkLtSymbol;
  400. else if(ev->x > selmon->wx + selmon->ww - TEXTW(stext))
  401. click = ClkStatusText;
  402. else
  403. click = ClkWinTitle;
  404. }
  405. else if((c = wintoclient(ev->window))) {
  406. focus(c);
  407. click = ClkClientWin;
  408. }
  409. for(i = 0; i < LENGTH(buttons); i++)
  410. if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
  411. && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
  412. buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
  413. }
  414. void
  415. checkotherwm(void) {
  416. otherwm = False;
  417. xerrorxlib = XSetErrorHandler(xerrorstart);
  418. /* this causes an error if some other window manager is running */
  419. XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
  420. XSync(dpy, False);
  421. if(otherwm)
  422. die("dwm: another window manager is already running\n");
  423. XSetErrorHandler(xerror);
  424. XSync(dpy, False);
  425. }
  426. void
  427. cleanup(void) {
  428. Arg a = {.ui = ~0};
  429. Layout foo = { "", NULL };
  430. Monitor *m;
  431. view(&a);
  432. lt[selmon->sellt] = &foo;
  433. for(m = mons; m; m = m->next)
  434. while(m->stack)
  435. unmanage(m->stack);
  436. if(dc.font.set)
  437. XFreeFontSet(dpy, dc.font.set);
  438. else
  439. XFreeFont(dpy, dc.font.xfont);
  440. XUngrabKey(dpy, AnyKey, AnyModifier, root);
  441. XFreePixmap(dpy, dc.drawable);
  442. XFreeGC(dpy, dc.gc);
  443. XFreeCursor(dpy, cursor[CurNormal]);
  444. XFreeCursor(dpy, cursor[CurResize]);
  445. XFreeCursor(dpy, cursor[CurMove]);
  446. cleanupmons();
  447. XSync(dpy, False);
  448. XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
  449. }
  450. void
  451. cleanupmons(void) {
  452. Monitor *m;
  453. while(mons) {
  454. m = mons->next;
  455. XUnmapWindow(dpy, mons->barwin);
  456. XDestroyWindow(dpy, mons->barwin);
  457. free(mons);
  458. mons = m;
  459. }
  460. }
  461. void
  462. clearurgent(Client *c) {
  463. XWMHints *wmh;
  464. c->isurgent = False;
  465. if(!(wmh = XGetWMHints(dpy, c->win)))
  466. return;
  467. wmh->flags &= ~XUrgencyHint;
  468. XSetWMHints(dpy, c->win, wmh);
  469. XFree(wmh);
  470. }
  471. void
  472. configure(Client *c) {
  473. XConfigureEvent ce;
  474. ce.type = ConfigureNotify;
  475. ce.display = dpy;
  476. ce.event = c->win;
  477. ce.window = c->win;
  478. ce.x = c->x;
  479. ce.y = c->y;
  480. ce.width = c->w;
  481. ce.height = c->h;
  482. ce.border_width = c->bw;
  483. ce.above = None;
  484. ce.override_redirect = False;
  485. XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
  486. }
  487. void
  488. configurenotify(XEvent *e) {
  489. Monitor *m;
  490. XConfigureEvent *ev = &e->xconfigure;
  491. if(ev->window == root && (ev->width != sw || ev->height != sh)) {
  492. sw = ev->width;
  493. sh = ev->height;
  494. updategeom();
  495. if(dc.drawable != 0)
  496. XFreePixmap(dpy, dc.drawable);
  497. dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
  498. updatebars();
  499. for(m = mons; m; m = m->next)
  500. XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
  501. arrange();
  502. }
  503. }
  504. void
  505. configurerequest(XEvent *e) {
  506. Client *c;
  507. Monitor *m;
  508. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  509. XWindowChanges wc;
  510. if((c = wintoclient(ev->window))) {
  511. if(ev->value_mask & CWBorderWidth)
  512. c->bw = ev->border_width;
  513. else if(c->isfloating || !lt[selmon->sellt]->arrange) {
  514. m = c->mon;
  515. if(ev->value_mask & CWX)
  516. c->x = m->mx + ev->x;
  517. if(ev->value_mask & CWY)
  518. c->y = m->my + ev->y;
  519. if(ev->value_mask & CWWidth)
  520. c->w = ev->width;
  521. if(ev->value_mask & CWHeight)
  522. c->h = ev->height;
  523. if((c->x - m->mx + c->w) > m->mw && c->isfloating)
  524. c->x = m->mx + (m->mw / 2 - c->w / 2); /* center in x direction */
  525. if((c->y - m->my + c->h) > m->mh && c->isfloating)
  526. c->y = m->my + (m->mh / 2 - c->h / 2); /* center in y direction */
  527. if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
  528. configure(c);
  529. if(ISVISIBLE(c))
  530. XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
  531. }
  532. else
  533. configure(c);
  534. }
  535. else {
  536. wc.x = ev->x;
  537. wc.y = ev->y;
  538. wc.width = ev->width;
  539. wc.height = ev->height;
  540. wc.border_width = ev->border_width;
  541. wc.sibling = ev->above;
  542. wc.stack_mode = ev->detail;
  543. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  544. }
  545. XSync(dpy, False);
  546. }
  547. void
  548. destroynotify(XEvent *e) {
  549. Client *c;
  550. XDestroyWindowEvent *ev = &e->xdestroywindow;
  551. if((c = wintoclient(ev->window)))
  552. unmanage(c);
  553. }
  554. void
  555. detach(Client *c) {
  556. Client **tc;
  557. for(tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
  558. *tc = c->next;
  559. }
  560. void
  561. detachstack(Client *c) {
  562. Client **tc, *t;
  563. for(tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext);
  564. *tc = c->snext;
  565. if(c == c->mon->sel) {
  566. for(t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext);
  567. c->mon->sel = t;
  568. }
  569. }
  570. void
  571. die(const char *errstr, ...) {
  572. va_list ap;
  573. va_start(ap, errstr);
  574. vfprintf(stderr, errstr, ap);
  575. va_end(ap);
  576. exit(EXIT_FAILURE);
  577. }
  578. Monitor *
  579. dirtomon(int dir) {
  580. Monitor *m = NULL;
  581. if(dir > 0) {
  582. if(!(m = selmon->next))
  583. m = mons;
  584. }
  585. else {
  586. if(selmon == mons)
  587. for(m = mons; m->next; m = m->next);
  588. else
  589. for(m = mons; m->next != selmon; m = m->next);
  590. }
  591. return m;
  592. }
  593. void
  594. drawbar(Monitor *m) {
  595. int x;
  596. unsigned int i, occ = 0, urg = 0;
  597. unsigned long *col;
  598. Client *c;
  599. for(c = m->clients; c; c = c->next) {
  600. occ |= c->tags;
  601. if(c->isurgent)
  602. urg |= c->tags;
  603. }
  604. dc.x = 0;
  605. if(mons->next) { /* more than a single monitor */
  606. dc.w = TEXTW(monsyms[m->screen_number]);
  607. drawtext(monsyms[m->screen_number], selmon == m ? dc.sel : dc.norm, False);
  608. dc.x += dc.w;
  609. }
  610. m->btx = dc.x;
  611. for(i = 0; i < LENGTH(tags); i++) {
  612. dc.w = TEXTW(tags[i]);
  613. col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
  614. drawtext(tags[i], col, urg & 1 << i);
  615. drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
  616. occ & 1 << i, urg & 1 << i, col);
  617. dc.x += dc.w;
  618. }
  619. if(blw > 0) {
  620. dc.w = blw;
  621. drawtext(lt[m->sellt]->symbol, dc.norm, False);
  622. x = dc.x + dc.w;
  623. }
  624. else
  625. x = dc.x;
  626. if(m == selmon) { /* status is only drawn on selected monitor */
  627. dc.w = TEXTW(stext);
  628. dc.x = m->ww - dc.w;
  629. if(dc.x < x) {
  630. dc.x = x;
  631. dc.w = m->ww - x;
  632. }
  633. drawtext(stext, dc.norm, False);
  634. }
  635. else
  636. dc.x = m->ww;
  637. if((dc.w = dc.x - x) > bh) {
  638. dc.x = x;
  639. if(m->sel) {
  640. col = m == selmon ? dc.sel : dc.norm;
  641. drawtext(m->sel->name, col, False);
  642. drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
  643. }
  644. else
  645. drawtext(NULL, dc.norm, False);
  646. }
  647. XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
  648. XSync(dpy, False);
  649. }
  650. void
  651. drawbars(void) {
  652. Monitor *m;
  653. for(m = mons; m; m = m->next)
  654. drawbar(m);
  655. }
  656. void
  657. drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
  658. int x;
  659. XGCValues gcv;
  660. XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  661. gcv.foreground = col[invert ? ColBG : ColFG];
  662. XChangeGC(dpy, dc.gc, GCForeground, &gcv);
  663. x = (dc.font.ascent + dc.font.descent + 2) / 4;
  664. r.x = dc.x + 1;
  665. r.y = dc.y + 1;
  666. if(filled) {
  667. r.width = r.height = x + 1;
  668. XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  669. }
  670. else if(empty) {
  671. r.width = r.height = x;
  672. XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  673. }
  674. }
  675. void
  676. drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
  677. char buf[256];
  678. int i, x, y, h, len, olen;
  679. XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  680. XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
  681. XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  682. if(!text)
  683. return;
  684. olen = strlen(text);
  685. h = dc.font.ascent + dc.font.descent;
  686. y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
  687. x = dc.x + (h / 2);
  688. /* shorten text if necessary */
  689. for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
  690. if(!len)
  691. return;
  692. memcpy(buf, text, len);
  693. if(len < olen)
  694. for(i = len; i && i > len - 3; buf[--i] = '.');
  695. XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
  696. if(dc.font.set)
  697. XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
  698. else
  699. XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
  700. }
  701. void
  702. enternotify(XEvent *e) {
  703. Client *c;
  704. Monitor *m;
  705. XCrossingEvent *ev = &e->xcrossing;
  706. if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
  707. return;
  708. if((m = wintomon(ev->window)) && m != selmon) {
  709. unfocus(selmon->sel);
  710. selmon = m;
  711. }
  712. if((c = wintoclient(ev->window)))
  713. focus(c);
  714. else
  715. focus(NULL);
  716. }
  717. void
  718. expose(XEvent *e) {
  719. Monitor *m;
  720. XExposeEvent *ev = &e->xexpose;
  721. if(ev->count == 0 && (m = wintomon(ev->window)))
  722. drawbar(m);
  723. }
  724. void
  725. focus(Client *c) {
  726. if(!c || !ISVISIBLE(c))
  727. for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
  728. if(selmon->sel)
  729. unfocus(selmon->sel);
  730. if(c) {
  731. if(c->mon != selmon)
  732. selmon = c->mon;
  733. if(c->isurgent)
  734. clearurgent(c);
  735. detachstack(c);
  736. attachstack(c);
  737. grabbuttons(c, True);
  738. XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
  739. XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
  740. }
  741. else
  742. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  743. selmon->sel = c;
  744. drawbars();
  745. }
  746. void
  747. focusin(XEvent *e) { /* there are some broken focus acquiring clients */
  748. XFocusChangeEvent *ev = &e->xfocus;
  749. if(selmon->sel && ev->window != selmon->sel->win)
  750. XSetInputFocus(dpy, selmon->sel->win, RevertToPointerRoot, CurrentTime);
  751. }
  752. void
  753. focusmon(const Arg *arg) {
  754. Monitor *m = NULL;
  755. if(!mons->next)
  756. return;
  757. m = dirtomon(arg->i);
  758. unfocus(selmon->sel);
  759. selmon = m;
  760. focus(NULL);
  761. }
  762. void
  763. focusstack(const Arg *arg) {
  764. Client *c = NULL, *i;
  765. if(!selmon->sel)
  766. return;
  767. if(arg->i > 0) {
  768. for(c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
  769. if(!c)
  770. for(c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
  771. }
  772. else {
  773. for(i = selmon->clients; i != selmon->sel; i = i->next)
  774. if(ISVISIBLE(i))
  775. c = i;
  776. if(!c)
  777. for(; i; i = i->next)
  778. if(ISVISIBLE(i))
  779. c = i;
  780. }
  781. if(c) {
  782. focus(c);
  783. restack(selmon);
  784. }
  785. }
  786. unsigned long
  787. getcolor(const char *colstr) {
  788. Colormap cmap = DefaultColormap(dpy, screen);
  789. XColor color;
  790. if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
  791. die("error, cannot allocate color '%s'\n", colstr);
  792. return color.pixel;
  793. }
  794. Bool
  795. getrootpointer(int *x, int *y) {
  796. int di;
  797. unsigned int dui;
  798. Window dummy;
  799. return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
  800. }
  801. long
  802. getstate(Window w) {
  803. int format, status;
  804. long result = -1;
  805. unsigned char *p = NULL;
  806. unsigned long n, extra;
  807. Atom real;
  808. status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
  809. &real, &format, &n, &extra, (unsigned char **)&p);
  810. if(status != Success)
  811. return -1;
  812. if(n != 0)
  813. result = *p;
  814. XFree(p);
  815. return result;
  816. }
  817. Bool
  818. gettextprop(Window w, Atom atom, char *text, unsigned int size) {
  819. char **list = NULL;
  820. int n;
  821. XTextProperty name;
  822. if(!text || size == 0)
  823. return False;
  824. text[0] = '\0';
  825. XGetTextProperty(dpy, w, &name, atom);
  826. if(!name.nitems)
  827. return False;
  828. if(name.encoding == XA_STRING)
  829. strncpy(text, (char *)name.value, size - 1);
  830. else {
  831. if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
  832. && n > 0 && *list)
  833. {
  834. strncpy(text, *list, size - 1);
  835. XFreeStringList(list);
  836. }
  837. }
  838. text[size - 1] = '\0';
  839. XFree(name.value);
  840. return True;
  841. }
  842. void
  843. grabbuttons(Client *c, Bool focused) {
  844. updatenumlockmask();
  845. {
  846. unsigned int i, j;
  847. unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
  848. XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  849. if(focused) {
  850. for(i = 0; i < LENGTH(buttons); i++)
  851. if(buttons[i].click == ClkClientWin)
  852. for(j = 0; j < LENGTH(modifiers); j++)
  853. XGrabButton(dpy, buttons[i].button,
  854. buttons[i].mask | modifiers[j],
  855. c->win, False, BUTTONMASK,
  856. GrabModeAsync, GrabModeSync, None, None);
  857. }
  858. else
  859. XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
  860. BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
  861. }
  862. }
  863. void
  864. grabkeys(void) {
  865. updatenumlockmask();
  866. {
  867. unsigned int i, j;
  868. unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
  869. KeyCode code;
  870. XUngrabKey(dpy, AnyKey, AnyModifier, root);
  871. for(i = 0; i < LENGTH(keys); i++) {
  872. if((code = XKeysymToKeycode(dpy, keys[i].keysym)))
  873. for(j = 0; j < LENGTH(modifiers); j++)
  874. XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
  875. True, GrabModeAsync, GrabModeAsync);
  876. }
  877. }
  878. }
  879. void
  880. initfont(const char *fontstr) {
  881. char *def, **missing;
  882. int i, n;
  883. missing = NULL;
  884. dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
  885. if(missing) {
  886. while(n--)
  887. fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
  888. XFreeStringList(missing);
  889. }
  890. if(dc.font.set) {
  891. XFontSetExtents *font_extents;
  892. XFontStruct **xfonts;
  893. char **font_names;
  894. dc.font.ascent = dc.font.descent = 0;
  895. font_extents = XExtentsOfFontSet(dc.font.set);
  896. n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
  897. for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
  898. dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
  899. dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
  900. xfonts++;
  901. }
  902. }
  903. else {
  904. if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
  905. && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
  906. die("error, cannot load font: '%s'\n", fontstr);
  907. dc.font.ascent = dc.font.xfont->ascent;
  908. dc.font.descent = dc.font.xfont->descent;
  909. }
  910. dc.font.height = dc.font.ascent + dc.font.descent;
  911. }
  912. Bool
  913. isprotodel(Client *c) {
  914. int i, n;
  915. Atom *protocols;
  916. Bool ret = False;
  917. if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
  918. for(i = 0; !ret && i < n; i++)
  919. if(protocols[i] == wmatom[WMDelete])
  920. ret = True;
  921. XFree(protocols);
  922. }
  923. return ret;
  924. }
  925. void
  926. keypress(XEvent *e) {
  927. unsigned int i;
  928. KeySym keysym;
  929. XKeyEvent *ev;
  930. ev = &e->xkey;
  931. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  932. for(i = 0; i < LENGTH(keys); i++)
  933. if(keysym == keys[i].keysym
  934. && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
  935. && keys[i].func)
  936. keys[i].func(&(keys[i].arg));
  937. }
  938. void
  939. killclient(const Arg *arg) {
  940. XEvent ev;
  941. if(!selmon->sel)
  942. return;
  943. if(isprotodel(selmon->sel)) {
  944. ev.type = ClientMessage;
  945. ev.xclient.window = selmon->sel->win;
  946. ev.xclient.message_type = wmatom[WMProtocols];
  947. ev.xclient.format = 32;
  948. ev.xclient.data.l[0] = wmatom[WMDelete];
  949. ev.xclient.data.l[1] = CurrentTime;
  950. XSendEvent(dpy, selmon->sel->win, False, NoEventMask, &ev);
  951. }
  952. else
  953. XKillClient(dpy, selmon->sel->win);
  954. }
  955. void
  956. manage(Window w, XWindowAttributes *wa) {
  957. static Client cz;
  958. Client *c, *t = NULL;
  959. Window trans = None;
  960. XWindowChanges wc;
  961. if(!(c = malloc(sizeof(Client))))
  962. die("fatal: could not malloc() %u bytes\n", sizeof(Client));
  963. *c = cz;
  964. c->win = w;
  965. if(XGetTransientForHint(dpy, w, &trans))
  966. t = wintoclient(trans);
  967. if(t) {
  968. c->mon = t->mon;
  969. c->tags = t->tags;
  970. }
  971. else {
  972. c->mon = selmon;
  973. applyrules(c);
  974. }
  975. /* geometry */
  976. c->x = wa->x + c->mon->wx;
  977. c->y = wa->y + c->mon->wy;
  978. c->w = wa->width;
  979. c->h = wa->height;
  980. c->oldbw = wa->border_width;
  981. if(c->w == c->mon->mw && c->h == c->mon->mh) {
  982. c->x = c->mon->mx;
  983. c->y = c->mon->my;
  984. c->bw = 0;
  985. }
  986. else {
  987. if(c->x + WIDTH(c) > c->mon->mx + c->mon->mw)
  988. c->x = c->mon->mx + c->mon->mw - WIDTH(c);
  989. if(c->y + HEIGHT(c) > c->mon->my + c->mon->mh)
  990. c->y = c->mon->my + c->mon->mh - HEIGHT(c);
  991. c->x = MAX(c->x, c->mon->mx);
  992. /* only fix client y-offset, if the client center might cover the bar */
  993. c->y = MAX(c->y, ((c->mon->by == 0) && (c->x + (c->w / 2) >= c->mon->wx)
  994. && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
  995. c->bw = borderpx;
  996. }
  997. wc.border_width = c->bw;
  998. XConfigureWindow(dpy, w, CWBorderWidth, &wc);
  999. XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
  1000. configure(c); /* propagates border_width, if size doesn't change */
  1001. updatesizehints(c);
  1002. XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
  1003. grabbuttons(c, False);
  1004. updatetitle(c);
  1005. if(!c->isfloating)
  1006. c->isfloating = trans != None || c->isfixed;
  1007. if(c->isfloating)
  1008. XRaiseWindow(dpy, c->win);
  1009. attach(c);
  1010. attachstack(c);
  1011. XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
  1012. XMapWindow(dpy, c->win);
  1013. setclientstate(c, NormalState);
  1014. arrange();
  1015. }
  1016. void
  1017. mappingnotify(XEvent *e) {
  1018. XMappingEvent *ev = &e->xmapping;
  1019. XRefreshKeyboardMapping(ev);
  1020. if(ev->request == MappingKeyboard)
  1021. grabkeys();
  1022. }
  1023. void
  1024. maprequest(XEvent *e) {
  1025. static XWindowAttributes wa;
  1026. XMapRequestEvent *ev = &e->xmaprequest;
  1027. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  1028. return;
  1029. if(wa.override_redirect)
  1030. return;
  1031. if(!wintoclient(ev->window))
  1032. manage(ev->window, &wa);
  1033. }
  1034. void
  1035. monocle(Monitor *m) {
  1036. Client *c;
  1037. for(c = nexttiled(m->clients); c; c = nexttiled(c->next))
  1038. resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, False);
  1039. }
  1040. void
  1041. movemouse(const Arg *arg) {
  1042. int x, y, ocx, ocy, nx, ny;
  1043. Client *c;
  1044. Monitor *m;
  1045. XEvent ev;
  1046. if(!(c = selmon->sel))
  1047. return;
  1048. restack(selmon);
  1049. ocx = c->x;
  1050. ocy = c->y;
  1051. if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1052. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  1053. return;
  1054. if(!getrootpointer(&x, &y))
  1055. return;
  1056. do {
  1057. XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
  1058. switch (ev.type) {
  1059. case ConfigureRequest:
  1060. case Expose:
  1061. case MapRequest:
  1062. handler[ev.type](&ev);
  1063. break;
  1064. case MotionNotify:
  1065. nx = ocx + (ev.xmotion.x - x);
  1066. ny = ocy + (ev.xmotion.y - y);
  1067. if(snap && nx >= selmon->wx && nx <= selmon->wx + selmon->ww
  1068. && ny >= selmon->wy && ny <= selmon->wy + selmon->wh) {
  1069. if(abs(selmon->wx - nx) < snap)
  1070. nx = selmon->wx;
  1071. else if(abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap)
  1072. nx = selmon->wx + selmon->ww - WIDTH(c);
  1073. if(abs(selmon->wy - ny) < snap)
  1074. ny = selmon->wy;
  1075. else if(abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap)
  1076. ny = selmon->wy + selmon->wh - HEIGHT(c);
  1077. if(!c->isfloating && lt[selmon->sellt]->arrange
  1078. && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
  1079. togglefloating(NULL);
  1080. }
  1081. if(!lt[selmon->sellt]->arrange || c->isfloating)
  1082. resize(c, nx, ny, c->w, c->h, True);
  1083. break;
  1084. }
  1085. }
  1086. while(ev.type != ButtonRelease);
  1087. XUngrabPointer(dpy, CurrentTime);
  1088. if((m = pointertomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
  1089. sendmon(c, m);
  1090. selmon = m;
  1091. focus(NULL);
  1092. }
  1093. }
  1094. Client *
  1095. nexttiled(Client *c) {
  1096. for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
  1097. return c;
  1098. }
  1099. Monitor *
  1100. pointertomon(int x, int y) {
  1101. Monitor *m;
  1102. for(m = mons; m; m = m->next)
  1103. if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
  1104. return m;
  1105. return selmon;
  1106. }
  1107. void
  1108. propertynotify(XEvent *e) {
  1109. Client *c;
  1110. Window trans;
  1111. XPropertyEvent *ev = &e->xproperty;
  1112. if((ev->window == root) && (ev->atom == XA_WM_NAME))
  1113. updatestatus();
  1114. else if(ev->state == PropertyDelete)
  1115. return; /* ignore */
  1116. else if((c = wintoclient(ev->window))) {
  1117. switch (ev->atom) {
  1118. default: break;
  1119. case XA_WM_TRANSIENT_FOR:
  1120. XGetTransientForHint(dpy, c->win, &trans);
  1121. if(!c->isfloating && (c->isfloating = (wintoclient(trans) != NULL)))
  1122. arrange();
  1123. break;
  1124. case XA_WM_NORMAL_HINTS:
  1125. updatesizehints(c);
  1126. break;
  1127. case XA_WM_HINTS:
  1128. updatewmhints(c);
  1129. drawbars();
  1130. break;
  1131. }
  1132. if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
  1133. updatetitle(c);
  1134. if(c == selmon->sel)
  1135. drawbars();
  1136. }
  1137. }
  1138. }
  1139. void
  1140. quit(const Arg *arg) {
  1141. running = False;
  1142. }
  1143. void
  1144. resize(Client *c, int x, int y, int w, int h, Bool interact) {
  1145. XWindowChanges wc;
  1146. if(applysizehints(c, &x, &y, &w, &h, interact)) {
  1147. c->x = wc.x = x;
  1148. c->y = wc.y = y;
  1149. c->w = wc.width = w;
  1150. c->h = wc.height = h;
  1151. wc.border_width = c->bw;
  1152. XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
  1153. configure(c);
  1154. XSync(dpy, False);
  1155. }
  1156. }
  1157. void
  1158. resizemouse(const Arg *arg) {
  1159. int ocx, ocy;
  1160. int nw, nh;
  1161. Client *c;
  1162. Monitor *m;
  1163. XEvent ev;
  1164. if(!(c = selmon->sel))
  1165. return;
  1166. restack(selmon);
  1167. ocx = c->x;
  1168. ocy = c->y;
  1169. if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1170. None, cursor[CurResize], CurrentTime) != GrabSuccess)
  1171. return;
  1172. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1173. do {
  1174. XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
  1175. switch(ev.type) {
  1176. case ConfigureRequest:
  1177. case Expose:
  1178. case MapRequest:
  1179. handler[ev.type](&ev);
  1180. break;
  1181. case MotionNotify:
  1182. nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
  1183. nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
  1184. if(snap && nw >= selmon->wx && nw <= selmon->wx + selmon->ww
  1185. && nh >= selmon->wy && nh <= selmon->wy + selmon->wh) {
  1186. if(!c->isfloating && lt[selmon->sellt]->arrange
  1187. && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1188. togglefloating(NULL);
  1189. }
  1190. if(!lt[selmon->sellt]->arrange || c->isfloating)
  1191. resize(c, c->x, c->y, nw, nh, True);
  1192. break;
  1193. }
  1194. }
  1195. while(ev.type != ButtonRelease);
  1196. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1197. XUngrabPointer(dpy, CurrentTime);
  1198. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1199. if((m = pointertomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
  1200. sendmon(c, m);
  1201. selmon = m;
  1202. focus(NULL);
  1203. }
  1204. }
  1205. void
  1206. restack(Monitor *m) {
  1207. Client *c;
  1208. XEvent ev;
  1209. XWindowChanges wc;
  1210. drawbars();
  1211. if(!m->sel)
  1212. return;
  1213. if(m->sel->isfloating || !lt[m->sellt]->arrange)
  1214. XRaiseWindow(dpy, m->sel->win);
  1215. if(lt[m->sellt]->arrange) {
  1216. wc.stack_mode = Below;
  1217. wc.sibling = m->barwin;
  1218. for(c = m->stack; c; c = c->snext)
  1219. if(!c->isfloating && ISVISIBLE(c)) {
  1220. XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1221. wc.sibling = c->win;
  1222. }
  1223. }
  1224. XSync(dpy, False);
  1225. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1226. }
  1227. void
  1228. run(void) {
  1229. XEvent ev;
  1230. /* main event loop */
  1231. XSync(dpy, False);
  1232. while(running && !XNextEvent(dpy, &ev)) {
  1233. if(handler[ev.type])
  1234. (handler[ev.type])(&ev); /* call handler */
  1235. }
  1236. }
  1237. void
  1238. scan(void) {
  1239. unsigned int i, num;
  1240. Window d1, d2, *wins = NULL;
  1241. XWindowAttributes wa;
  1242. if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
  1243. for(i = 0; i < num; i++) {
  1244. if(!XGetWindowAttributes(dpy, wins[i], &wa)
  1245. || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
  1246. continue;
  1247. if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
  1248. manage(wins[i], &wa);
  1249. }
  1250. for(i = 0; i < num; i++) { /* now the transients */
  1251. if(!XGetWindowAttributes(dpy, wins[i], &wa))
  1252. continue;
  1253. if(XGetTransientForHint(dpy, wins[i], &d1)
  1254. && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
  1255. manage(wins[i], &wa);
  1256. }
  1257. if(wins)
  1258. XFree(wins);
  1259. }
  1260. }
  1261. void
  1262. sendmon(Client *c, Monitor *m) {
  1263. if(c->mon == m)
  1264. return;
  1265. unfocus(c);
  1266. detach(c);
  1267. detachstack(c);
  1268. c->mon = m;
  1269. c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
  1270. attach(c);
  1271. attachstack(c);
  1272. focus(NULL);
  1273. arrange();
  1274. }
  1275. void
  1276. setclientstate(Client *c, long state) {
  1277. long data[] = { state, None };
  1278. XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
  1279. PropModeReplace, (unsigned char *)data, 2);
  1280. }
  1281. void
  1282. setlayout(const Arg *arg) {
  1283. if(!arg || !arg->v || arg->v != lt[selmon->sellt])
  1284. selmon->sellt ^= 1;
  1285. if(arg && arg->v)
  1286. lt[selmon->sellt] = (Layout *)arg->v;
  1287. if(selmon->sel)
  1288. arrange();
  1289. else
  1290. drawbars();
  1291. }
  1292. /* arg > 1.0 will set mfact absolutly */
  1293. void
  1294. setmfact(const Arg *arg) {
  1295. float f;
  1296. if(!arg || !lt[selmon->sellt]->arrange)
  1297. return;
  1298. f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
  1299. if(f < 0.1 || f > 0.9)
  1300. return;
  1301. selmon->mfact = f;
  1302. arrange();
  1303. }
  1304. void
  1305. setup(void) {
  1306. unsigned int i;
  1307. int w;
  1308. XSetWindowAttributes wa;
  1309. /* init screen */
  1310. screen = DefaultScreen(dpy);
  1311. root = RootWindow(dpy, screen);
  1312. initfont(font);
  1313. sw = DisplayWidth(dpy, screen);
  1314. sh = DisplayHeight(dpy, screen);
  1315. bh = dc.h = dc.font.height + 2;
  1316. lt[0] = &layouts[0];
  1317. lt[1] = &layouts[1 % LENGTH(layouts)];
  1318. updategeom();
  1319. /* init atoms */
  1320. wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  1321. wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  1322. wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
  1323. netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
  1324. netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
  1325. /* init cursors */
  1326. cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  1327. cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  1328. cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  1329. /* init appearance */
  1330. dc.norm[ColBorder] = getcolor(normbordercolor);
  1331. dc.norm[ColBG] = getcolor(normbgcolor);
  1332. dc.norm[ColFG] = getcolor(normfgcolor);
  1333. dc.sel[ColBorder] = getcolor(selbordercolor);
  1334. dc.sel[ColBG] = getcolor(selbgcolor);
  1335. dc.sel[ColFG] = getcolor(selfgcolor);
  1336. dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
  1337. dc.gc = XCreateGC(dpy, root, 0, NULL);
  1338. XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  1339. if(!dc.font.set)
  1340. XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  1341. /* init bars */
  1342. for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
  1343. w = TEXTW(layouts[i].symbol);
  1344. blw = MAX(blw, w);
  1345. }
  1346. updatebars();
  1347. updatestatus();
  1348. /* EWMH support per view */
  1349. XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
  1350. PropModeReplace, (unsigned char *) netatom, NetLast);
  1351. /* select for events */
  1352. wa.cursor = cursor[CurNormal];
  1353. wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
  1354. |EnterWindowMask|LeaveWindowMask|StructureNotifyMask
  1355. |PropertyChangeMask;
  1356. XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
  1357. XSelectInput(dpy, root, wa.event_mask);
  1358. grabkeys();
  1359. }
  1360. void
  1361. showhide(Client *c) {
  1362. if(!c)
  1363. return;
  1364. if(ISVISIBLE(c)) { /* show clients top down */
  1365. XMoveWindow(dpy, c->win, c->x, c->y);
  1366. if(!lt[c->mon->sellt]->arrange || c->isfloating)
  1367. resize(c, c->x, c->y, c->w, c->h, False);
  1368. showhide(c->snext);
  1369. }
  1370. else { /* hide clients bottom up */
  1371. showhide(c->snext);
  1372. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  1373. }
  1374. }
  1375. void
  1376. sigchld(int signal) {
  1377. while(0 < waitpid(-1, NULL, WNOHANG));
  1378. }
  1379. void
  1380. spawn(const Arg *arg) {
  1381. signal(SIGCHLD, sigchld);
  1382. if(fork() == 0) {
  1383. if(dpy)
  1384. close(ConnectionNumber(dpy));
  1385. setsid();
  1386. execvp(((char **)arg->v)[0], (char **)arg->v);
  1387. fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]);
  1388. perror(" failed");
  1389. exit(0);
  1390. }
  1391. }
  1392. void
  1393. tag(const Arg *arg) {
  1394. if(selmon->sel && arg->ui & TAGMASK) {
  1395. selmon->sel->tags = arg->ui & TAGMASK;
  1396. arrange();
  1397. }
  1398. }
  1399. void
  1400. tagmon(const Arg *arg) {
  1401. if(!selmon->sel || !mons->next)
  1402. return;
  1403. sendmon(selmon->sel, dirtomon(arg->i));
  1404. }
  1405. int
  1406. textnw(const char *text, unsigned int len) {
  1407. XRectangle r;
  1408. if(dc.font.set) {
  1409. XmbTextExtents(dc.font.set, text, len, NULL, &r);
  1410. return r.width;
  1411. }
  1412. return XTextWidth(dc.font.xfont, text, len);
  1413. }
  1414. void
  1415. tile(Monitor *m) {
  1416. int x, y, h, w, mw;
  1417. unsigned int i, n;
  1418. Client *c;
  1419. for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
  1420. if(n == 0)
  1421. return;
  1422. /* master */
  1423. c = nexttiled(m->clients);
  1424. mw = m->mfact * m->ww;
  1425. resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False);
  1426. if(--n == 0)
  1427. return;
  1428. /* tile stack */
  1429. x = (m->wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : m->wx + mw;
  1430. y = m->wy;
  1431. w = (m->wx + mw > c->x + c->w) ? m->wx + m->ww - x : m->ww - mw;
  1432. h = m->wh / n;
  1433. if(h < bh)
  1434. h = m->wh;
  1435. for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1436. resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1437. ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw), False);
  1438. if(h != m->wh)
  1439. y = c->y + HEIGHT(c);
  1440. }
  1441. }
  1442. void
  1443. togglebar(const Arg *arg) {
  1444. selmon->showbar = !selmon->showbar;
  1445. updatebarpos(selmon);
  1446. XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
  1447. arrange();
  1448. }
  1449. void
  1450. togglefloating(const Arg *arg) {
  1451. if(!selmon->sel)
  1452. return;
  1453. selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
  1454. if(selmon->sel->isfloating)
  1455. resize(selmon->sel, selmon->sel->x, selmon->sel->y,
  1456. selmon->sel->w, selmon->sel->h, False);
  1457. arrange();
  1458. }
  1459. void
  1460. toggletag(const Arg *arg) {
  1461. unsigned int mask;
  1462. if(!selmon->sel)
  1463. return;
  1464. mask = selmon->sel->tags ^ (arg->ui & TAGMASK);
  1465. if(mask) {
  1466. selmon->sel->tags = mask;
  1467. arrange();
  1468. }
  1469. }
  1470. void
  1471. toggleview(const Arg *arg) {
  1472. unsigned int mask = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
  1473. if(mask) {
  1474. selmon->tagset[selmon->seltags] = mask;
  1475. arrange();
  1476. }
  1477. }
  1478. void
  1479. unfocus(Client *c) {
  1480. if(!c)
  1481. return;
  1482. grabbuttons(c, False);
  1483. XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
  1484. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  1485. }
  1486. void
  1487. unmanage(Client *c) {
  1488. XWindowChanges wc;
  1489. wc.border_width = c->oldbw;
  1490. /* The server grab construct avoids race conditions. */
  1491. XGrabServer(dpy);
  1492. XSetErrorHandler(xerrordummy);
  1493. XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
  1494. detach(c);
  1495. detachstack(c);
  1496. XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  1497. setclientstate(c, WithdrawnState);
  1498. free(c);
  1499. XSync(dpy, False);
  1500. XSetErrorHandler(xerror);
  1501. XUngrabServer(dpy);
  1502. focus(NULL);
  1503. arrange();
  1504. }
  1505. void
  1506. unmapnotify(XEvent *e) {
  1507. Client *c;
  1508. XUnmapEvent *ev = &e->xunmap;
  1509. if((c = wintoclient(ev->window)))
  1510. unmanage(c);
  1511. }
  1512. void
  1513. updatebars(void) {
  1514. Monitor *m;
  1515. XSetWindowAttributes wa;
  1516. wa.override_redirect = True;
  1517. wa.background_pixmap = ParentRelative;
  1518. wa.event_mask = ButtonPressMask|ExposureMask;
  1519. for(m = mons; m; m = m->next) {
  1520. m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
  1521. CopyFromParent, DefaultVisual(dpy, screen),
  1522. CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
  1523. XDefineCursor(dpy, m->barwin, cursor[CurNormal]);
  1524. XMapRaised(dpy, m->barwin);
  1525. }
  1526. }
  1527. void
  1528. updatebarpos(Monitor *m) {
  1529. m->wy = m->my;
  1530. m->wh = m->mh;
  1531. if(m->showbar) {
  1532. m->wh -= bh;
  1533. m->by = m->topbar ? m->wy : m->wy + m->wh;
  1534. m->wy = m->topbar ? m->wy + bh : m->wy;
  1535. }
  1536. else
  1537. m->by = -bh;
  1538. }
  1539. void
  1540. updategeom(void) {
  1541. int i, n = 1;
  1542. Client *c;
  1543. Monitor *newmons = NULL, *m, *tm;
  1544. #ifdef XINERAMA
  1545. XineramaScreenInfo *info = NULL;
  1546. if(XineramaIsActive(dpy))
  1547. info = XineramaQueryScreens(dpy, &n);
  1548. #endif /* XINERAMA */
  1549. /* allocate monitor(s) for the new geometry setup */
  1550. for(i = 0; i < n; i++) {
  1551. m = (Monitor *)malloc(sizeof(Monitor));
  1552. m->next = newmons;
  1553. newmons = m;
  1554. }
  1555. /* initialise monitor(s) */
  1556. #ifdef XINERAMA
  1557. if(XineramaIsActive(dpy)) {
  1558. for(i = 0, m = newmons; m; m = m->next, i++) {
  1559. m->screen_number = info[i].screen_number;
  1560. m->mx = m->wx = info[i].x_org;
  1561. m->my = m->wy = info[i].y_org;
  1562. m->mw = m->ww = info[i].width;
  1563. m->mh = m->wh = info[i].height;
  1564. }
  1565. XFree(info);
  1566. }
  1567. else
  1568. #endif /* XINERAMA */
  1569. /* default monitor setup */
  1570. {
  1571. m->screen_number = 0;
  1572. m->mx = m->wx = 0;
  1573. m->my = m->wy = 0;
  1574. m->mw = m->ww = sw;
  1575. m->mh = m->wh = sh;
  1576. }
  1577. /* bar geometry setup */
  1578. for(m = newmons; m; m = m->next) {
  1579. m->sel = m->stack = m->clients = NULL;
  1580. m->seltags = 0;
  1581. m->sellt = 0;
  1582. m->tagset[0] = m->tagset[1] = 1;
  1583. m->mfact = mfact;
  1584. m->showbar = SHOWBAR;
  1585. m->topbar = TOPBAR;
  1586. updatebarpos(m);
  1587. }
  1588. /* reassign left over clients of disappeared monitors */
  1589. for(tm = mons; tm; tm = tm->next)
  1590. while(tm->clients) {
  1591. c = tm->clients;
  1592. tm->clients = c->next;
  1593. detachstack(c);
  1594. c->mon = newmons;
  1595. attach(c);
  1596. attachstack(c);
  1597. }
  1598. /* select focused monitor */
  1599. cleanupmons();
  1600. selmon = mons = newmons;
  1601. selmon = wintomon(root);
  1602. }
  1603. void
  1604. updatenumlockmask(void) {
  1605. unsigned int i, j;
  1606. XModifierKeymap *modmap;
  1607. numlockmask = 0;
  1608. modmap = XGetModifierMapping(dpy);
  1609. for(i = 0; i < 8; i++)
  1610. for(j = 0; j < modmap->max_keypermod; j++)
  1611. if(modmap->modifiermap[i * modmap->max_keypermod + j]
  1612. == XKeysymToKeycode(dpy, XK_Num_Lock))
  1613. numlockmask = (1 << i);
  1614. XFreeModifiermap(modmap);
  1615. }
  1616. void
  1617. updatesizehints(Client *c) {
  1618. long msize;
  1619. XSizeHints size;
  1620. if(!XGetWMNormalHints(dpy, c->win, &size, &msize))
  1621. /* size is uninitialized, ensure that size.flags aren't used */
  1622. size.flags = PSize;
  1623. if(size.flags & PBaseSize) {
  1624. c->basew = size.base_width;
  1625. c->baseh = size.base_height;
  1626. }
  1627. else if(size.flags & PMinSize) {
  1628. c->basew = size.min_width;
  1629. c->baseh = size.min_height;
  1630. }
  1631. else
  1632. c->basew = c->baseh = 0;
  1633. if(size.flags & PResizeInc) {
  1634. c->incw = size.width_inc;
  1635. c->inch = size.height_inc;
  1636. }
  1637. else
  1638. c->incw = c->inch = 0;
  1639. if(size.flags & PMaxSize) {
  1640. c->maxw = size.max_width;
  1641. c->maxh = size.max_height;
  1642. }
  1643. else
  1644. c->maxw = c->maxh = 0;
  1645. if(size.flags & PMinSize) {
  1646. c->minw = size.min_width;
  1647. c->minh = size.min_height;
  1648. }
  1649. else if(size.flags & PBaseSize) {
  1650. c->minw = size.base_width;
  1651. c->minh = size.base_height;
  1652. }
  1653. else
  1654. c->minw = c->minh = 0;
  1655. if(size.flags & PAspect) {
  1656. c->mina = (float)size.min_aspect.y / (float)size.min_aspect.x;
  1657. c->maxa = (float)size.max_aspect.x / (float)size.max_aspect.y;
  1658. }
  1659. else
  1660. c->maxa = c->mina = 0.0;
  1661. c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
  1662. && c->maxw == c->minw && c->maxh == c->minh);
  1663. }
  1664. void
  1665. updatetitle(Client *c) {
  1666. if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
  1667. gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name);
  1668. }
  1669. void
  1670. updatestatus(void) {
  1671. if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
  1672. strcpy(stext, "dwm-"VERSION);
  1673. drawbar(selmon);
  1674. }
  1675. void
  1676. updatewmhints(Client *c) {
  1677. XWMHints *wmh;
  1678. if((wmh = XGetWMHints(dpy, c->win))) {
  1679. if(c == selmon->sel && wmh->flags & XUrgencyHint) {
  1680. wmh->flags &= ~XUrgencyHint;
  1681. XSetWMHints(dpy, c->win, wmh);
  1682. }
  1683. else
  1684. c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
  1685. XFree(wmh);
  1686. }
  1687. }
  1688. void
  1689. view(const Arg *arg) {
  1690. if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
  1691. return;
  1692. selmon->seltags ^= 1; /* toggle sel tagset */
  1693. if(arg->ui & TAGMASK)
  1694. selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
  1695. arrange();
  1696. }
  1697. Client *
  1698. wintoclient(Window w) {
  1699. Client *c;
  1700. Monitor *m;
  1701. for(m = mons; m; m = m->next)
  1702. for(c = m->clients; c; c = c->next)
  1703. if(c->win == w)
  1704. return c;
  1705. return NULL;
  1706. }
  1707. Monitor *
  1708. wintomon(Window w) {
  1709. int x, y;
  1710. Client *c;
  1711. Monitor *m;
  1712. if(w == root && getrootpointer(&x, &y))
  1713. return pointertomon(x, y);
  1714. for(m = mons; m; m = m->next)
  1715. if(w == m->barwin)
  1716. return m;
  1717. if((c = wintoclient(w)))
  1718. return c->mon;
  1719. return selmon;
  1720. }
  1721. /* There's no way to check accesses to destroyed windows, thus those cases are
  1722. * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
  1723. * default error handler, which may call exit. */
  1724. int
  1725. xerror(Display *dpy, XErrorEvent *ee) {
  1726. if(ee->error_code == BadWindow
  1727. || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
  1728. || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
  1729. || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
  1730. || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
  1731. || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
  1732. || (ee->request_code == X_GrabButton && ee->error_code == BadAccess)
  1733. || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
  1734. || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
  1735. return 0;
  1736. fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
  1737. ee->request_code, ee->error_code);
  1738. return xerrorxlib(dpy, ee); /* may call exit */
  1739. }
  1740. int
  1741. xerrordummy(Display *dpy, XErrorEvent *ee) {
  1742. return 0;
  1743. }
  1744. /* Startup Error handler to check if another window manager
  1745. * is already running. */
  1746. int
  1747. xerrorstart(Display *dpy, XErrorEvent *ee) {
  1748. otherwm = True;
  1749. return -1;
  1750. }
  1751. void
  1752. zoom(const Arg *arg) {
  1753. Client *c = selmon->sel;
  1754. if(!lt[selmon->sellt]->arrange
  1755. || lt[selmon->sellt]->arrange == monocle
  1756. || (selmon->sel && selmon->sel->isfloating))
  1757. return;
  1758. if(c == nexttiled(selmon->clients))
  1759. if(!c || !(c = nexttiled(c->next)))
  1760. return;
  1761. detach(c);
  1762. attach(c);
  1763. focus(c);
  1764. arrange();
  1765. }
  1766. int
  1767. main(int argc, char *argv[]) {
  1768. if(argc == 2 && !strcmp("-v", argv[1]))
  1769. die("dwm-"VERSION", © 2006-2009 dwm engineers, see LICENSE for details\n");
  1770. else if(argc != 1)
  1771. die("usage: dwm [-v]\n");
  1772. if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
  1773. fputs("warning: no locale support\n", stderr);
  1774. if(!(dpy = XOpenDisplay(NULL)))
  1775. die("dwm: cannot open display\n");
  1776. checkotherwm();
  1777. setup();
  1778. scan();
  1779. run();
  1780. cleanup();
  1781. XCloseDisplay(dpy);
  1782. return 0;
  1783. }