1 /* See LICENSE file for copyright and license details.
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.
9 * Calls to fetch an X event from the event queue are blocking. Due reading
10 * status text from standard input, a select()-driven main loop has been
11 * implemented which selects for reads on the X connection and STDIN_FILENO to
12 * handle all data smoothly. The event handlers of dwm are organized in an
13 * array which is accessed whenever a new event has been fetched. This allows
14 * event dispatching in O(1) time.
16 * Each child of the root window is called a client, except windows which have
17 * set the override_redirect flag. Clients are organized in a global
18 * doubly-linked client list, the focus history is remembered through a global
19 * stack list. Each client contains an array of Bools of the same size as the
20 * global tags array to indicate the tags of a client.
22 * Keys and tagging rules are organized as arrays and defined in config.h.
24 * To understand everything else, start reading main().
33 #include <sys/select.h>
34 #include <sys/types.h>
37 #include <X11/cursorfont.h>
38 #include <X11/keysym.h>
39 #include <X11/Xatom.h>
41 #include <X11/Xproto.h>
42 #include <X11/Xutil.h>
44 #include <X11/extensions/Xinerama.h>
48 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
49 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
50 #define LENGTH(x) (sizeof x / sizeof x[0])
52 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
56 enum { BarTop, BarBot, BarOff }; /* bar position */
57 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
58 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
59 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
60 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
63 typedef struct View View;
64 typedef struct Client Client;
68 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
69 int minax, maxax, minay, maxay;
71 unsigned int border, oldborder;
72 Bool isbanned, isfixed, isfloating, isurgent;
82 unsigned long norm[ColLast];
83 unsigned long sel[ColLast];
93 } DC; /* draw context */
98 void (*func)(const char *arg);
104 void (*arrange)(View *);
115 int x, y, w, h, wax, way, wah, waw;
121 /* function declarations */
122 void applyrules(Client *c);
124 void attach(Client *c);
125 void attachstack(Client *c);
127 void buttonpress(XEvent *e);
128 void checkotherwm(void);
130 void configure(Client *c);
131 void configurenotify(XEvent *e);
132 void configurerequest(XEvent *e);
133 Bool conflicts(Client *c, unsigned int tidx);
134 void destroynotify(XEvent *e);
135 void detach(Client *c);
136 void detachstack(Client *c);
137 void drawbar(View *v);
138 void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
139 void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
140 void *emallocz(unsigned int size);
141 void enternotify(XEvent *e);
142 void eprint(const char *errstr, ...);
143 void expose(XEvent *e);
144 unsigned int firstag(View *v);
145 void floating(View *v); /* default floating layout */
146 void focus(Client *c);
147 void focusin(XEvent *e);
148 void focusnext(const char *arg);
149 void focusprev(const char *arg);
150 Client *getclient(Window w);
151 unsigned long getcolor(const char *colstr);
152 View *getview(Client *c);
153 View *getviewbar(Window barwin);
154 long getstate(Window w);
155 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
156 void grabbuttons(Client *c, Bool focused);
158 unsigned int idxoftag(const char *t);
159 void initfont(const char *fontstr);
160 Bool isoccupied(unsigned int t);
161 Bool isprotodel(Client *c);
162 Bool isurgent(unsigned int t);
163 Bool isvisible(Client *c);
164 void keypress(XEvent *e);
165 void killclient(const char *arg);
166 void manage(Window w, XWindowAttributes *wa);
167 void mappingnotify(XEvent *e);
168 void maprequest(XEvent *e);
170 void movemouse(Client *c);
171 Client *nexttiled(Client *c, View *v);
172 void propertynotify(XEvent *e);
173 void quit(const char *arg);
174 void reapply(const char *arg);
175 void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
176 void resizemouse(Client *c);
177 void restack(View *v);
180 void setclientstate(Client *c, long state);
181 void setlayout(const char *arg);
182 void setmwfact(const char *arg);
184 void spawn(const char *arg);
185 void tag(const char *arg);
186 unsigned int textnw(const char *text, unsigned int len);
187 unsigned int textw(const char *text);
189 void togglebar(const char *arg);
190 void togglefloating(const char *arg);
191 void toggletag(const char *arg);
192 void toggleview(const char *arg);
193 void unban(Client *c);
194 void unmanage(Client *c);
195 void unmapnotify(XEvent *e);
196 void updatebarpos(View *v);
197 void updatesizehints(Client *c);
198 void updatetitle(Client *c);
199 void updatewmhints(Client *c);
200 void view(const char *arg);
201 void viewprevtag(const char *arg); /* views previous selected tags */
202 int xerror(Display *dpy, XErrorEvent *ee);
203 int xerrordummy(Display *dpy, XErrorEvent *ee);
204 int xerrorstart(Display *dpy, XErrorEvent *ee);
205 void zoom(const char *arg);
206 void selectview(const char *arg);
209 char stext[256], buf[256];
212 int (*xerrorxlib)(Display *, XErrorEvent *);
213 unsigned int bh, bpos;
214 unsigned int blw = 0;
215 unsigned int numlockmask = 0;
216 void (*handler[LASTEvent]) (XEvent *) = {
217 [ButtonPress] = buttonpress,
218 [ConfigureRequest] = configurerequest,
219 [ConfigureNotify] = configurenotify,
220 [DestroyNotify] = destroynotify,
221 [EnterNotify] = enternotify,
224 [KeyPress] = keypress,
225 [MappingNotify] = mappingnotify,
226 [MapRequest] = maprequest,
227 [PropertyNotify] = propertynotify,
228 [UnmapNotify] = unmapnotify
230 Atom wmatom[WMLast], netatom[NetLast];
231 Bool domwfact = True;
233 Bool otherwm, readin;
237 Client *clients = NULL;
239 Client *stack = NULL;
240 Cursor cursor[CurLast];
247 /* configuration, allows nested code to access above variables */
249 #define TAGSZ (LENGTH(tags) * sizeof(Bool))
251 /* function implementations */
254 applyrules(Client *c) {
256 Bool matched = False;
258 XClassHint ch = { 0 };
261 XGetClassHint(dpy, c->win, &ch);
262 for(i = 0; i < LENGTH(rules); i++) {
264 if(strstr(c->name, r->prop)
265 || (ch.res_class && strstr(ch.res_class, r->prop))
266 || (ch.res_name && strstr(ch.res_name, r->prop)))
268 c->isfloating = r->isfloating;
269 if(r->tag && !conflicts(c, (idx = idxoftag(r->tag)))) {
280 for(i = 0; i < LENGTH(tags); i++)
281 if(seltags[i] && vtags[i] == selview->id)
291 for(c = clients; c; c = c->next)
298 for(i = 0; i < nviews; i++) {
299 views[i].layout->arrange(&views[i]);
313 attachstack(Client *c) {
322 XMoveWindow(dpy, c->win, c->x + 3 * getview(c)->w, c->y);
327 buttonpress(XEvent *e) {
330 XButtonPressedEvent *ev = &e->xbutton;
332 if(ev->window == selview->barwin) {
334 for(i = 0; i < LENGTH(tags); i++) {
335 if(&views[vtags[i]] != selview)
339 if(ev->button == Button1) {
340 if(ev->state & MODKEY)
345 else if(ev->button == Button3) {
346 if(ev->state & MODKEY)
354 if((ev->x < x + blw) && ev->button == Button1)
357 else if((c = getclient(ev->window))) {
359 if(CLEANMASK(ev->state) != MODKEY)
361 if(ev->button == Button1) {
365 else if(ev->button == Button2) {
366 if((floating != getview(c)->layout->arrange) && c->isfloating)
367 togglefloating(NULL);
371 else if(ev->button == Button3 && !c->isfixed) {
381 XSetErrorHandler(xerrorstart);
383 /* this causes an error if some other window manager is running */
384 XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
387 eprint("dwm: another window manager is already running\n");
389 XSetErrorHandler(NULL);
390 xerrorxlib = XSetErrorHandler(xerror);
404 XFreeFontSet(dpy, dc.font.set);
406 XFreeFont(dpy, dc.font.xfont);
408 XUngrabKey(dpy, AnyKey, AnyModifier, root);
409 XFreePixmap(dpy, dc.drawable);
411 XFreeCursor(dpy, cursor[CurNormal]);
412 XFreeCursor(dpy, cursor[CurResize]);
413 XFreeCursor(dpy, cursor[CurMove]);
414 for(i = 0; i < nviews; i++)
415 XDestroyWindow(dpy, views[i].barwin);
417 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
421 configure(Client *c) {
424 ce.type = ConfigureNotify;
432 ce.border_width = c->border;
434 ce.override_redirect = False;
435 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
439 configurenotify(XEvent *e) {
440 XConfigureEvent *ev = &e->xconfigure;
443 if(ev->window == root && (ev->width != v->w || ev->height != v->h)) {
444 /* TODO -- update Xinerama dimensions here */
447 XFreePixmap(dpy, dc.drawable);
448 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(root, screen), bh, DefaultDepth(dpy, screen));
449 XResizeWindow(dpy, v->barwin, v->w, bh);
450 updatebarpos(selview);
456 configurerequest(XEvent *e) {
458 XConfigureRequestEvent *ev = &e->xconfigurerequest;
461 if((c = getclient(ev->window))) {
462 View *v = getview(c);
463 if(ev->value_mask & CWBorderWidth)
464 c->border = ev->border_width;
465 if(c->isfixed || c->isfloating || (floating == v->layout->arrange)) {
466 if(ev->value_mask & CWX)
468 if(ev->value_mask & CWY)
470 if(ev->value_mask & CWWidth)
472 if(ev->value_mask & CWHeight)
474 if((c->x - v->x + c->w) > v->w && c->isfloating)
475 c->x = v->x + (v->w / 2 - c->w / 2); /* center in x direction */
476 if((c->y - v->y + c->h) > v->h && c->isfloating)
477 c->y = v->y + (v->h / 2 - c->h / 2); /* center in y direction */
478 if((ev->value_mask & (CWX|CWY))
479 && !(ev->value_mask & (CWWidth|CWHeight)))
482 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
490 wc.width = ev->width;
491 wc.height = ev->height;
492 wc.border_width = ev->border_width;
493 wc.sibling = ev->above;
494 wc.stack_mode = ev->detail;
495 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
501 conflicts(Client *c, unsigned int tidx) {
504 for(i = 0; i < LENGTH(tags); i++)
505 if(c->tags[i] && vtags[i] != vtags[tidx])
506 return True; /* conflict */
511 destroynotify(XEvent *e) {
513 XDestroyWindowEvent *ev = &e->xdestroywindow;
515 if((c = getclient(ev->window)))
522 c->prev->next = c->next;
524 c->next->prev = c->prev;
527 c->next = c->prev = NULL;
531 detachstack(Client *c) {
534 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
544 for(c = stack; c && (!isvisible(c) || getview(c) != v); c = c->snext);
545 for(i = 0; i < LENGTH(tags); i++) {
546 if(&views[vtags[i]] != v)
548 dc.w = textw(tags[i]);
550 drawtext(tags[i], dc.sel, isurgent(i));
551 drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.sel);
554 drawtext(tags[i], dc.norm, isurgent(i));
555 drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.norm);
560 drawtext(v->layout->symbol, dc.norm, False);
569 drawtext(stext, dc.norm, False);
573 if((dc.w = dc.x - x) > bh) {
576 drawtext(c->name, dc.sel, False);
577 drawsquare(False, c->isfloating, False, dc.sel);
580 drawtext(NULL, dc.norm, False);
582 XCopyArea(dpy, dc.drawable, v->barwin, dc.gc, 0, 0, v->w, bh, 0, 0);
587 drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
590 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
592 gcv.foreground = col[invert ? ColBG : ColFG];
593 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
594 x = (dc.font.ascent + dc.font.descent + 2) / 4;
598 r.width = r.height = x + 1;
599 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
602 r.width = r.height = x;
603 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
608 drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
610 unsigned int len, olen;
611 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
613 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
614 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
618 olen = len = strlen(text);
619 if(len >= sizeof buf)
620 len = sizeof buf - 1;
621 memcpy(buf, text, len);
623 h = dc.font.ascent + dc.font.descent;
624 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
626 /* shorten text if necessary */
627 while(len && (w = textnw(buf, len)) > dc.w - h)
638 return; /* too long */
639 XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
641 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
643 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
647 emallocz(unsigned int size) {
648 void *res = calloc(1, size);
651 eprint("fatal: could not malloc() %u bytes\n", size);
656 enternotify(XEvent *e) {
658 XCrossingEvent *ev = &e->xcrossing;
660 if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
662 if((c = getclient(ev->window)))
669 eprint(const char *errstr, ...) {
672 va_start(ap, errstr);
673 vfprintf(stderr, errstr, ap);
681 XExposeEvent *ev = &e->xexpose;
683 if(ev->count == 0 && ((v = getviewbar(ev->window))))
691 for(i = 0; i < LENGTH(tags); i++)
692 if(vtags[i] == v->id)
694 return 0; /* safe fallback */
698 floating(View *v) { /* default floating layout */
701 domwfact = dozoom = False;
702 for(c = clients; c; c = c->next)
704 resize(c, c->x, c->y, c->w, c->h, True);
712 selview = getview(c);
715 if(!c || (c && !isvisible(c)))
716 /* TODO: isvisible might take getview(c) as constraint? */
717 for(c = stack; c && (!isvisible(c) || getview(c) != selview); c = c->snext);
718 if(sel && sel != c) {
719 grabbuttons(sel, False);
720 XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
725 grabbuttons(c, True);
729 XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
730 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
731 selview = getview(c);
734 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
739 focusin(XEvent *e) { /* there are some broken focus acquiring clients */
740 XFocusChangeEvent *ev = &e->xfocus;
742 if(sel && ev->window != sel->win)
743 XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
747 focusnext(const char *arg) {
752 for(c = sel->next; c && !isvisible(c); c = c->next);
754 for(c = clients; c && !isvisible(c); c = c->next);
762 focusprev(const char *arg) {
767 for(c = sel->prev; c && !isvisible(c); c = c->prev);
769 for(c = clients; c && c->next; c = c->next);
770 for(; c && !isvisible(c); c = c->prev);
779 getclient(Window w) {
782 for(c = clients; c && c->win != w; c = c->next);
787 getcolor(const char *colstr) {
788 Colormap cmap = DefaultColormap(dpy, screen);
791 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
792 eprint("error, cannot allocate color '%s'\n", colstr);
800 for(i = 0; i < LENGTH(tags); i++)
802 return &views[vtags[i]];
807 getviewbar(Window barwin) {
810 for(i = 0; i < nviews; i++)
811 if(views[i].barwin == barwin)
820 unsigned char *p = NULL;
821 unsigned long n, extra;
824 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
825 &real, &format, &n, &extra, (unsigned char **)&p);
826 if(status != Success)
835 gettextprop(Window w, Atom atom, char *text, unsigned int size) {
840 if(!text || size == 0)
843 XGetTextProperty(dpy, w, &name, atom);
846 if(name.encoding == XA_STRING)
847 strncpy(text, (char *)name.value, size - 1);
849 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
851 strncpy(text, *list, size - 1);
852 XFreeStringList(list);
855 text[size - 1] = '\0';
861 grabbuttons(Client *c, Bool focused) {
862 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
865 XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
866 GrabModeAsync, GrabModeSync, None, None);
867 XGrabButton(dpy, Button1, MODKEY|LockMask, c->win, False, BUTTONMASK,
868 GrabModeAsync, GrabModeSync, None, None);
869 XGrabButton(dpy, Button1, MODKEY|numlockmask, c->win, False, BUTTONMASK,
870 GrabModeAsync, GrabModeSync, None, None);
871 XGrabButton(dpy, Button1, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
872 GrabModeAsync, GrabModeSync, None, None);
874 XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
875 GrabModeAsync, GrabModeSync, None, None);
876 XGrabButton(dpy, Button2, MODKEY|LockMask, c->win, False, BUTTONMASK,
877 GrabModeAsync, GrabModeSync, None, None);
878 XGrabButton(dpy, Button2, MODKEY|numlockmask, c->win, False, BUTTONMASK,
879 GrabModeAsync, GrabModeSync, None, None);
880 XGrabButton(dpy, Button2, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
881 GrabModeAsync, GrabModeSync, None, None);
883 XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
884 GrabModeAsync, GrabModeSync, None, None);
885 XGrabButton(dpy, Button3, MODKEY|LockMask, c->win, False, BUTTONMASK,
886 GrabModeAsync, GrabModeSync, None, None);
887 XGrabButton(dpy, Button3, MODKEY|numlockmask, c->win, False, BUTTONMASK,
888 GrabModeAsync, GrabModeSync, None, None);
889 XGrabButton(dpy, Button3, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
890 GrabModeAsync, GrabModeSync, None, None);
893 XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
894 GrabModeAsync, GrabModeSync, None, None);
901 XModifierKeymap *modmap;
903 /* init modifier map */
904 modmap = XGetModifierMapping(dpy);
905 for(i = 0; i < 8; i++)
906 for(j = 0; j < modmap->max_keypermod; j++) {
907 if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
908 numlockmask = (1 << i);
910 XFreeModifiermap(modmap);
912 XUngrabKey(dpy, AnyKey, AnyModifier, root);
913 for(i = 0; i < LENGTH(keys); i++) {
914 code = XKeysymToKeycode(dpy, keys[i].keysym);
915 XGrabKey(dpy, code, keys[i].mod, root, True,
916 GrabModeAsync, GrabModeAsync);
917 XGrabKey(dpy, code, keys[i].mod|LockMask, root, True,
918 GrabModeAsync, GrabModeAsync);
919 XGrabKey(dpy, code, keys[i].mod|numlockmask, root, True,
920 GrabModeAsync, GrabModeAsync);
921 XGrabKey(dpy, code, keys[i].mod|numlockmask|LockMask, root, True,
922 GrabModeAsync, GrabModeAsync);
927 idxoftag(const char *t) {
930 for(i = 0; (i < LENGTH(tags)) && (tags[i] != t); i++);
931 return (i < LENGTH(tags)) ? i : firstag(selview);
935 initfont(const char *fontstr) {
936 char *def, **missing;
941 XFreeFontSet(dpy, dc.font.set);
942 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
945 fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
946 XFreeStringList(missing);
949 XFontSetExtents *font_extents;
950 XFontStruct **xfonts;
952 dc.font.ascent = dc.font.descent = 0;
953 font_extents = XExtentsOfFontSet(dc.font.set);
954 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
955 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
956 if(dc.font.ascent < (*xfonts)->ascent)
957 dc.font.ascent = (*xfonts)->ascent;
958 if(dc.font.descent < (*xfonts)->descent)
959 dc.font.descent = (*xfonts)->descent;
965 XFreeFont(dpy, dc.font.xfont);
966 dc.font.xfont = NULL;
967 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
968 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
969 eprint("error, cannot load font: '%s'\n", fontstr);
970 dc.font.ascent = dc.font.xfont->ascent;
971 dc.font.descent = dc.font.xfont->descent;
973 dc.font.height = dc.font.ascent + dc.font.descent;
977 isoccupied(unsigned int t) {
980 for(c = clients; c; c = c->next)
987 isprotodel(Client *c) {
992 if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
993 for(i = 0; !ret && i < n; i++)
994 if(protocols[i] == wmatom[WMDelete])
1002 isurgent(unsigned int t) {
1005 for(c = clients; c; c = c->next)
1006 if(c->isurgent && c->tags[t])
1012 isvisible(Client *c) {
1015 for(i = 0; i < LENGTH(tags); i++)
1016 if(c->tags[i] && seltags[i])
1022 keypress(XEvent *e) {
1028 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
1029 for(i = 0; i < LENGTH(keys); i++)
1030 if(keysym == keys[i].keysym
1031 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
1034 keys[i].func(keys[i].arg);
1039 killclient(const char *arg) {
1044 if(isprotodel(sel)) {
1045 ev.type = ClientMessage;
1046 ev.xclient.window = sel->win;
1047 ev.xclient.message_type = wmatom[WMProtocols];
1048 ev.xclient.format = 32;
1049 ev.xclient.data.l[0] = wmatom[WMDelete];
1050 ev.xclient.data.l[1] = CurrentTime;
1051 XSendEvent(dpy, sel->win, False, NoEventMask, &ev);
1054 XKillClient(dpy, sel->win);
1058 manage(Window w, XWindowAttributes *wa) {
1059 Client *c, *t = NULL;
1065 c = emallocz(sizeof(Client));
1066 c->tags = emallocz(TAGSZ);
1073 c->x = wa->x + v->x;
1074 c->y = wa->y + v->y;
1077 c->oldborder = wa->border_width;
1079 if(c->w == v->w && c->h == v->h) {
1082 c->border = wa->border_width;
1085 if(c->x + c->w + 2 * c->border > v->wax + v->waw)
1086 c->x = v->wax + v->waw - c->w - 2 * c->border;
1087 if(c->y + c->h + 2 * c->border > v->way + v->wah)
1088 c->y = v->way + v->wah - c->h - 2 * c->border;
1093 c->border = BORDERPX;
1095 wc.border_width = c->border;
1096 XConfigureWindow(dpy, w, CWBorderWidth, &wc);
1097 XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
1098 configure(c); /* propagates border_width, if size doesn't change */
1100 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
1101 grabbuttons(c, False);
1103 if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
1104 for(t = clients; t && t->win != trans; t = t->next);
1106 memcpy(c->tags, t->tags, TAGSZ);
1108 c->isfloating = (rettrans == Success) || c->isfixed;
1111 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
1113 XMapWindow(dpy, c->win);
1114 setclientstate(c, NormalState);
1119 mappingnotify(XEvent *e) {
1120 XMappingEvent *ev = &e->xmapping;
1122 XRefreshKeyboardMapping(ev);
1123 if(ev->request == MappingKeyboard)
1128 maprequest(XEvent *e) {
1129 static XWindowAttributes wa;
1130 XMapRequestEvent *ev = &e->xmaprequest;
1132 if(!XGetWindowAttributes(dpy, ev->window, &wa))
1134 if(wa.override_redirect)
1136 if(!getclient(ev->window))
1137 manage(ev->window, &wa);
1141 movemouse(Client *c) {
1142 int x1, y1, ocx, ocy, di, nx, ny;
1151 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
1152 None, cursor[CurMove], CurrentTime) != GrabSuccess)
1154 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
1156 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
1159 XUngrabPointer(dpy, CurrentTime);
1161 case ConfigureRequest:
1164 handler[ev.type](&ev);
1168 nx = ocx + (ev.xmotion.x - x1);
1169 ny = ocy + (ev.xmotion.y - y1);
1170 if(abs(v->wax - nx) < SNAP)
1172 else if(abs((v->wax + v->waw) - (nx + c->w + 2 * c->border)) < SNAP)
1173 nx = v->wax + v->waw - c->w - 2 * c->border;
1174 if(abs(v->way - ny) < SNAP)
1176 else if(abs((v->way + v->wah) - (ny + c->h + 2 * c->border)) < SNAP)
1177 ny = v->way + v->wah - c->h - 2 * c->border;
1178 if(!c->isfloating && (v->layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP))
1179 togglefloating(NULL);
1180 if((v->layout->arrange == floating) || c->isfloating)
1181 resize(c, nx, ny, c->w, c->h, False);
1188 nexttiled(Client *c, View *v) {
1189 for(; c && (c->isfloating || getview(c) != v || !isvisible(c)); c = c->next);
1194 propertynotify(XEvent *e) {
1197 XPropertyEvent *ev = &e->xproperty;
1199 if(ev->state == PropertyDelete)
1200 return; /* ignore */
1201 if((c = getclient(ev->window))) {
1204 case XA_WM_TRANSIENT_FOR:
1205 XGetTransientForHint(dpy, c->win, &trans);
1206 if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
1209 case XA_WM_NORMAL_HINTS:
1214 drawbar(getview(c));
1217 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
1226 quit(const char *arg) {
1227 readin = running = False;
1231 reapply(const char *arg) {
1232 static Bool zerotags[LENGTH(tags)] = { 0 };
1235 for(c = clients; c; c = c->next) {
1236 memcpy(c->tags, zerotags, sizeof zerotags);
1243 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
1249 /* set minimum possible */
1255 /* temporarily remove base dimensions */
1259 /* adjust for aspect limits */
1260 if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) {
1261 if (w * c->maxay > h * c->maxax)
1262 w = h * c->maxax / c->maxay;
1263 else if (w * c->minay < h * c->minax)
1264 h = w * c->minay / c->minax;
1267 /* adjust for increment value */
1273 /* restore base dimensions */
1277 if(c->minw > 0 && w < c->minw)
1279 if(c->minh > 0 && h < c->minh)
1281 if(c->maxw > 0 && w > c->maxw)
1283 if(c->maxh > 0 && h > c->maxh)
1286 if(w <= 0 || h <= 0)
1289 x = v->w - w - 2 * c->border;
1291 y = v->h - h - 2 * c->border;
1292 if(x + w + 2 * c->border < v->x)
1294 if(y + h + 2 * c->border < v->y)
1296 if(c->x != x || c->y != y || c->w != w || c->h != h) {
1299 c->w = wc.width = w;
1300 c->h = wc.height = h;
1301 wc.border_width = c->border;
1302 XConfigureWindow(dpy, c->win,
1303 CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
1310 resizemouse(Client *c) {
1319 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
1320 None, cursor[CurResize], CurrentTime) != GrabSuccess)
1322 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
1324 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask , &ev);
1327 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
1328 c->w + c->border - 1, c->h + c->border - 1);
1329 XUngrabPointer(dpy, CurrentTime);
1330 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1332 case ConfigureRequest:
1335 handler[ev.type](&ev);
1339 if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
1341 if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
1343 if(!c->isfloating && (v->layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP))
1344 togglefloating(NULL);
1345 if((v->layout->arrange == floating) || c->isfloating)
1346 resize(c, c->x, c->y, nw, nh, True);
1361 if(sel->isfloating || (v->layout->arrange == floating))
1362 XRaiseWindow(dpy, sel->win);
1363 if(v->layout->arrange != floating) {
1364 wc.stack_mode = Below;
1365 wc.sibling = v->barwin;
1366 if(!sel->isfloating) {
1367 XConfigureWindow(dpy, sel->win, CWSibling|CWStackMode, &wc);
1368 wc.sibling = sel->win;
1370 for(c = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
1373 XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
1374 wc.sibling = c->win;
1378 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1384 char sbuf[sizeof stext];
1387 unsigned int len, offset;
1390 /* main event loop, also reads status text from stdin */
1392 xfd = ConnectionNumber(dpy);
1395 len = sizeof stext - 1;
1396 sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
1400 FD_SET(STDIN_FILENO, &rd);
1402 if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
1405 eprint("select failed\n");
1407 if(FD_ISSET(STDIN_FILENO, &rd)) {
1408 switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
1410 strncpy(stext, strerror(errno), len);
1414 strncpy(stext, "EOF", 4);
1418 for(p = sbuf + offset; r > 0; p++, r--, offset++)
1419 if(*p == '\n' || *p == '\0') {
1421 strncpy(stext, sbuf, len);
1422 p += r - 1; /* p is sbuf + offset + r - 1 */
1423 for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
1426 memmove(sbuf, p - r + 1, r);
1433 while(XPending(dpy)) {
1434 XNextEvent(dpy, &ev);
1435 if(handler[ev.type])
1436 (handler[ev.type])(&ev); /* call handler */
1443 unsigned int i, num;
1444 Window *wins, d1, d2;
1445 XWindowAttributes wa;
1448 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
1449 for(i = 0; i < num; i++) {
1450 if(!XGetWindowAttributes(dpy, wins[i], &wa)
1451 || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
1453 if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
1454 manage(wins[i], &wa);
1456 for(i = 0; i < num; i++) { /* now the transients */
1457 if(!XGetWindowAttributes(dpy, wins[i], &wa))
1459 if(XGetTransientForHint(dpy, wins[i], &d1)
1460 && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
1461 manage(wins[i], &wa);
1469 setclientstate(Client *c, long state) {
1470 long data[] = {state, None};
1472 XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
1473 PropModeReplace, (unsigned char *)data, 2);
1477 setlayout(const char *arg) {
1483 if(v->layout == &layouts[LENGTH(layouts)])
1484 v->layout = &layouts[0];
1487 for(i = 0; i < LENGTH(layouts); i++)
1488 if(!strcmp(arg, layouts[i].symbol))
1490 if(i == LENGTH(layouts))
1492 v->layout = &layouts[i];
1501 setmwfact(const char *arg) {
1507 /* arg handling, manipulate mwfact */
1510 else if(sscanf(arg, "%lf", &delta) == 1) {
1511 if(arg[0] == '+' || arg[0] == '-')
1517 else if(v->mwfact > 0.9)
1527 XSetWindowAttributes wa;
1528 XineramaScreenInfo *info = NULL;
1531 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
1532 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
1533 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
1534 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
1535 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
1536 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
1539 wa.cursor = cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
1540 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
1541 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
1543 if(XineramaIsActive(dpy))
1544 info = XineramaQueryScreens(dpy, &nviews);
1546 #if defined(AIM_XINERAMA)
1547 nviews = 2; /* aim Xinerama */
1549 views = emallocz(nviews * sizeof(View));
1551 screen = DefaultScreen(dpy);
1552 root = RootWindow(dpy, screen);
1554 /* init appearance */
1555 dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
1556 dc.norm[ColBG] = getcolor(NORMBGCOLOR);
1557 dc.norm[ColFG] = getcolor(NORMFGCOLOR);
1558 dc.sel[ColBorder] = getcolor(SELBORDERCOLOR);
1559 dc.sel[ColBG] = getcolor(SELBGCOLOR);
1560 dc.sel[ColFG] = getcolor(SELFGCOLOR);
1562 dc.h = bh = dc.font.height + 2;
1563 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
1564 dc.gc = XCreateGC(dpy, root, 0, 0);
1565 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
1567 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
1569 for(blw = i = 0; i < LENGTH(layouts); i++) {
1570 i = textw(layouts[i].symbol);
1575 seltags = emallocz(TAGSZ);
1576 prevtags = emallocz(TAGSZ);
1578 /* check, if vtags need assistance, because there is only 1 view */
1580 for(i = 0; i < LENGTH(tags); i++)
1583 for(i = 0; i < nviews; i++) {
1588 /* select first tag of view */
1590 seltags[j] = prevtags[j] = True;
1594 #if defined(AIM_XINERAMA)
1595 v->w = DisplayWidth(dpy, screen) / 2;
1596 v->x = (i == 0) ? 0 : v->w;
1598 v->h = DisplayHeight(dpy, screen);
1600 v->x = info[i].x_org;
1601 v->y = info[i].y_org;
1602 v->w = info[i].width;
1603 v->h = info[i].height;
1609 v->w = DisplayWidth(dpy, screen);
1610 v->h = DisplayHeight(dpy, screen);
1615 v->layout = &layouts[0];
1617 // TODO: bpos per screen?
1619 wa.override_redirect = 1;
1620 wa.background_pixmap = ParentRelative;
1621 wa.event_mask = ButtonPressMask|ExposureMask;
1624 v->barwin = XCreateWindow(dpy, root, v->x, v->y, v->w, bh, 0,
1625 DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
1626 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
1627 XDefineCursor(dpy, v->barwin, cursor[CurNormal]);
1629 XMapRaised(dpy, v->barwin);
1630 strcpy(stext, "dwm-"VERSION);
1632 /* EWMH support per view */
1633 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
1634 PropModeReplace, (unsigned char *) netatom, NetLast);
1636 /* select for events */
1637 wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
1638 |EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
1639 XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
1640 XSelectInput(dpy, root, wa.event_mask);
1654 spawn(const char *arg) {
1655 static char *shell = NULL;
1657 if(!shell && !(shell = getenv("SHELL")))
1661 /* The double-fork construct avoids zombie processes and keeps the code
1662 * clean from stupid signal handlers. */
1666 close(ConnectionNumber(dpy));
1668 execl(shell, shell, "-c", arg, (char *)NULL);
1669 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg);
1678 tag(const char *arg) {
1683 for(i = 0; i < LENGTH(tags); i++)
1684 sel->tags[i] = (NULL == arg) && (vtags[i] == getview(sel)->id);
1686 if(!conflicts(sel, i))
1687 sel->tags[idxoftag(arg)] = True;
1692 textnw(const char *text, unsigned int len) {
1696 XmbTextExtents(dc.font.set, text, len, NULL, &r);
1699 return XTextWidth(dc.font.xfont, text, len);
1703 textw(const char *text) {
1704 return textnw(text, strlen(text)) + dc.font.height;
1709 unsigned int i, n, nx, ny, nw, nh, mw, th;
1712 domwfact = dozoom = True;
1716 for(n = 0, c = nexttiled(clients, v); c; c = nexttiled(c->next, v))
1720 mw = (n == 1) ? v->waw : v->mwfact * v->waw;
1721 th = (n > 1) ? v->wah / (n - 1) : 0;
1722 if(n > 1 && th < bh)
1725 for(i = 0, c = mc = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
1726 if(i == 0) { /* master */
1727 nw = mw - 2 * c->border;
1728 nh = v->wah - 2 * c->border;
1730 else { /* tile window */
1733 nx += mc->w + 2 * mc->border;
1734 nw = v->waw - mw - 2 * c->border;
1736 if(i + 1 == n) /* remainder */
1737 nh = (v->way + v->wah) - ny - 2 * c->border;
1739 nh = th - 2 * c->border;
1741 resize(c, nx, ny, nw, nh, RESIZEHINTS);
1742 if((RESIZEHINTS) && ((c->h < bh) || (c->h > nh) || (c->w < bh) || (c->w > nw)))
1743 /* client doesn't accept size constraints */
1744 resize(c, nx, ny, nw, nh, False);
1745 if(n > 1 && th != v->wah)
1746 ny = c->y + c->h + 2 * c->border;
1752 togglebar(const char *arg) {
1754 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
1757 updatebarpos(selview);
1762 togglefloating(const char *arg) {
1765 sel->isfloating = !sel->isfloating;
1767 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
1772 toggletag(const char *arg) {
1778 if(conflicts(sel, i))
1780 sel->tags[i] = !sel->tags[i];
1781 for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++);
1782 if(j == LENGTH(tags))
1783 sel->tags[i] = True; /* at least one tag must be enabled */
1788 toggleview(const char *arg) {
1792 seltags[i] = !seltags[i];
1793 for(j = 0; j < LENGTH(tags) && !seltags[j]; j++);
1794 if(j == LENGTH(tags))
1795 seltags[i] = True; /* at least one tag must be viewed */
1803 XMoveWindow(dpy, c->win, c->x, c->y);
1804 c->isbanned = False;
1808 unmanage(Client *c) {
1811 wc.border_width = c->oldborder;
1812 /* The server grab construct avoids race conditions. */
1814 XSetErrorHandler(xerrordummy);
1815 XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
1820 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
1821 setclientstate(c, WithdrawnState);
1825 XSetErrorHandler(xerror);
1831 unmapnotify(XEvent *e) {
1833 XUnmapEvent *ev = &e->xunmap;
1835 if((c = getclient(ev->window)))
1840 updatebarpos(View *v) {
1851 XMoveWindow(dpy, v->barwin, v->x, v->y);
1855 XMoveWindow(dpy, v->barwin, v->x, v->y + v->wah);
1858 XMoveWindow(dpy, v->barwin, v->x, v->y - bh);
1862 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1866 updatesizehints(Client *c) {
1870 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
1872 c->flags = size.flags;
1873 if(c->flags & PBaseSize) {
1874 c->basew = size.base_width;
1875 c->baseh = size.base_height;
1877 else if(c->flags & PMinSize) {
1878 c->basew = size.min_width;
1879 c->baseh = size.min_height;
1882 c->basew = c->baseh = 0;
1883 if(c->flags & PResizeInc) {
1884 c->incw = size.width_inc;
1885 c->inch = size.height_inc;
1888 c->incw = c->inch = 0;
1889 if(c->flags & PMaxSize) {
1890 c->maxw = size.max_width;
1891 c->maxh = size.max_height;
1894 c->maxw = c->maxh = 0;
1895 if(c->flags & PMinSize) {
1896 c->minw = size.min_width;
1897 c->minh = size.min_height;
1899 else if(c->flags & PBaseSize) {
1900 c->minw = size.base_width;
1901 c->minh = size.base_height;
1904 c->minw = c->minh = 0;
1905 if(c->flags & PAspect) {
1906 c->minax = size.min_aspect.x;
1907 c->maxax = size.max_aspect.x;
1908 c->minay = size.min_aspect.y;
1909 c->maxay = size.max_aspect.y;
1912 c->minax = c->maxax = c->minay = c->maxay = 0;
1913 c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
1914 && c->maxw == c->minw && c->maxh == c->minh);
1918 updatetitle(Client *c) {
1919 if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
1920 gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);
1924 updatewmhints(Client *c) {
1927 if((wmh = XGetWMHints(dpy, c->win))) {
1928 c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
1934 view(const char *arg) {
1936 Bool tmp[LENGTH(tags)];
1938 memcpy(tmp, seltags, TAGSZ);
1940 for(i = 0; i < LENGTH(tags); i++)
1941 tmp[i] = (vtags[i] == selview->id);
1945 for(j = 0; j < LENGTH(tags); j++)
1946 if(selview->id == vtags[i]) {
1947 /* view tag of selview */
1948 if(selview->id == vtags[j])
1952 /* only touch the view the focus should go */
1953 if(vtags[j] == vtags[i])
1956 selview = &views[vtags[i]];
1959 if(memcmp(seltags, tmp, TAGSZ) != 0) {
1960 memcpy(prevtags, seltags, TAGSZ);
1961 memcpy(seltags, tmp, TAGSZ);
1972 XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask);
1973 for(i = 0; i < nviews; i++) {
1974 if((x >= views[i].x && x < views[i].x + views[i].w)
1975 && (y >= views[i].y && y < views[i].y + views[i].h))
1982 viewprevtag(const char *arg) {
1983 static Bool tmp[LENGTH(tags)];
1985 memcpy(tmp, seltags, TAGSZ);
1986 memcpy(seltags, prevtags, TAGSZ);
1987 memcpy(prevtags, tmp, TAGSZ);
1991 /* There's no way to check accesses to destroyed windows, thus those cases are
1992 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1993 * default error handler, which may call exit. */
1995 xerror(Display *dpy, XErrorEvent *ee) {
1996 if(ee->error_code == BadWindow
1997 || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
1998 || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
1999 || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
2000 || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
2001 || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
2002 || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
2003 || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
2005 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
2006 ee->request_code, ee->error_code);
2007 return xerrorxlib(dpy, ee); /* may call exit */
2011 xerrordummy(Display *dpy, XErrorEvent *ee) {
2015 /* Startup Error handler to check if another window manager
2016 * is already running. */
2018 xerrorstart(Display *dpy, XErrorEvent *ee) {
2024 zoom(const char *arg) {
2027 if(!sel || !dozoom || sel->isfloating)
2029 if(c == nexttiled(clients, getview(c)))
2030 if(!(c = nexttiled(c->next, getview(c))))
2039 main(int argc, char *argv[]) {
2040 if(argc == 2 && !strcmp("-v", argv[1]))
2041 eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n");
2043 eprint("usage: dwm [-v]\n");
2045 setlocale(LC_CTYPE, "");
2046 if(!(dpy = XOpenDisplay(0)))
2047 eprint("dwm: cannot open display\n");