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)
297 for(i = 0; i < nviews; i++) {
298 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);
403 XFreeFontSet(dpy, dc.font.set);
405 XFreeFont(dpy, dc.font.xfont);
407 XUngrabKey(dpy, AnyKey, AnyModifier, root);
408 XFreePixmap(dpy, dc.drawable);
410 XFreeCursor(dpy, cursor[CurNormal]);
411 XFreeCursor(dpy, cursor[CurResize]);
412 XFreeCursor(dpy, cursor[CurMove]);
413 for(i = 0; i < nviews; i++)
414 XDestroyWindow(dpy, views[i].barwin);
416 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
420 configure(Client *c) {
423 ce.type = ConfigureNotify;
431 ce.border_width = c->border;
433 ce.override_redirect = False;
434 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
438 configurenotify(XEvent *e) {
439 XConfigureEvent *ev = &e->xconfigure;
442 if(ev->window == root && (ev->width != v->w || ev->height != v->h)) {
443 /* TODO -- update Xinerama dimensions here */
446 XFreePixmap(dpy, dc.drawable);
447 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(root, screen), bh, DefaultDepth(dpy, screen));
448 XResizeWindow(dpy, v->barwin, v->w, bh);
449 updatebarpos(selview);
455 configurerequest(XEvent *e) {
457 XConfigureRequestEvent *ev = &e->xconfigurerequest;
460 if((c = getclient(ev->window))) {
461 View *v = getview(c);
462 if(ev->value_mask & CWBorderWidth)
463 c->border = ev->border_width;
464 if(c->isfixed || c->isfloating || (floating == v->layout->arrange)) {
465 if(ev->value_mask & CWX)
467 if(ev->value_mask & CWY)
469 if(ev->value_mask & CWWidth)
471 if(ev->value_mask & CWHeight)
473 if((c->x - v->x + c->w) > v->w && c->isfloating)
474 c->x = v->x + (v->w / 2 - c->w / 2); /* center in x direction */
475 if((c->y - v->y + c->h) > v->h && c->isfloating)
476 c->y = v->y + (v->h / 2 - c->h / 2); /* center in y direction */
477 if((ev->value_mask & (CWX|CWY))
478 && !(ev->value_mask & (CWWidth|CWHeight)))
481 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
489 wc.width = ev->width;
490 wc.height = ev->height;
491 wc.border_width = ev->border_width;
492 wc.sibling = ev->above;
493 wc.stack_mode = ev->detail;
494 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
500 conflicts(Client *c, unsigned int tidx) {
503 for(i = 0; i < LENGTH(tags); i++)
504 if(c->tags[i] && vtags[i] != vtags[tidx])
505 return True; /* conflict */
510 destroynotify(XEvent *e) {
512 XDestroyWindowEvent *ev = &e->xdestroywindow;
514 if((c = getclient(ev->window)))
521 c->prev->next = c->next;
523 c->next->prev = c->prev;
526 c->next = c->prev = NULL;
530 detachstack(Client *c) {
533 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
543 for(c = stack; c && (!isvisible(c) || getview(c) != v); c = c->snext);
544 for(i = 0; i < LENGTH(tags); i++) {
545 if(&views[vtags[i]] != v)
547 dc.w = textw(tags[i]);
549 drawtext(tags[i], dc.sel, isurgent(i));
550 drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.sel);
553 drawtext(tags[i], dc.norm, isurgent(i));
554 drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.norm);
559 drawtext(v->layout->symbol, dc.norm, False);
568 drawtext(stext, dc.norm, False);
572 if((dc.w = dc.x - x) > bh) {
575 drawtext(c->name, dc.sel, False);
576 drawsquare(False, c->isfloating, False, dc.sel);
579 drawtext(NULL, dc.norm, False);
581 XCopyArea(dpy, dc.drawable, v->barwin, dc.gc, 0, 0, v->w, bh, 0, 0);
586 drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
589 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
591 gcv.foreground = col[invert ? ColBG : ColFG];
592 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
593 x = (dc.font.ascent + dc.font.descent + 2) / 4;
597 r.width = r.height = x + 1;
598 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
601 r.width = r.height = x;
602 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
607 drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
609 unsigned int len, olen;
610 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
612 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
613 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
617 olen = len = strlen(text);
618 if(len >= sizeof buf)
619 len = sizeof buf - 1;
620 memcpy(buf, text, len);
622 h = dc.font.ascent + dc.font.descent;
623 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
625 /* shorten text if necessary */
626 while(len && (w = textnw(buf, len)) > dc.w - h)
637 return; /* too long */
638 XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
640 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
642 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
646 emallocz(unsigned int size) {
647 void *res = calloc(1, size);
650 eprint("fatal: could not malloc() %u bytes\n", size);
655 enternotify(XEvent *e) {
657 XCrossingEvent *ev = &e->xcrossing;
659 if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
661 if((c = getclient(ev->window)))
668 eprint(const char *errstr, ...) {
671 va_start(ap, errstr);
672 vfprintf(stderr, errstr, ap);
680 XExposeEvent *ev = &e->xexpose;
682 if(ev->count == 0 && ((v = getviewbar(ev->window))))
690 for(i = 0; i < LENGTH(tags); i++)
691 if(vtags[i] == v->id)
693 return 0; /* safe fallback */
697 floating(View *v) { /* default floating layout */
700 domwfact = dozoom = False;
701 for(c = clients; c; c = c->next)
703 resize(c, c->x, c->y, c->w, c->h, True);
710 selview = getview(c);
713 if(!c || (c && !isvisible(c)))
714 /* TODO: isvisible might take getview(c) as constraint? */
715 for(c = stack; c && (!isvisible(c) || getview(c) != selview); c = c->snext);
716 if(sel && sel != c) {
717 grabbuttons(sel, False);
718 XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
723 grabbuttons(c, True);
727 XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
728 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
729 selview = getview(c);
732 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
737 focusin(XEvent *e) { /* there are some broken focus acquiring clients */
738 XFocusChangeEvent *ev = &e->xfocus;
740 if(sel && ev->window != sel->win)
741 XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
745 focusnext(const char *arg) {
750 for(c = sel->next; c && !isvisible(c); c = c->next);
752 for(c = clients; c && !isvisible(c); c = c->next);
760 focusprev(const char *arg) {
765 for(c = sel->prev; c && !isvisible(c); c = c->prev);
767 for(c = clients; c && c->next; c = c->next);
768 for(; c && !isvisible(c); c = c->prev);
777 getclient(Window w) {
780 for(c = clients; c && c->win != w; c = c->next);
785 getcolor(const char *colstr) {
786 Colormap cmap = DefaultColormap(dpy, screen);
789 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
790 eprint("error, cannot allocate color '%s'\n", colstr);
798 for(i = 0; i < LENGTH(tags); i++)
800 return &views[vtags[i]];
805 getviewbar(Window barwin) {
808 for(i = 0; i < nviews; i++)
809 if(views[i].barwin == barwin)
818 unsigned char *p = NULL;
819 unsigned long n, extra;
822 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
823 &real, &format, &n, &extra, (unsigned char **)&p);
824 if(status != Success)
833 gettextprop(Window w, Atom atom, char *text, unsigned int size) {
838 if(!text || size == 0)
841 XGetTextProperty(dpy, w, &name, atom);
844 if(name.encoding == XA_STRING)
845 strncpy(text, (char *)name.value, size - 1);
847 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
849 strncpy(text, *list, size - 1);
850 XFreeStringList(list);
853 text[size - 1] = '\0';
859 grabbuttons(Client *c, Bool focused) {
860 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
863 XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
864 GrabModeAsync, GrabModeSync, None, None);
865 XGrabButton(dpy, Button1, MODKEY|LockMask, c->win, False, BUTTONMASK,
866 GrabModeAsync, GrabModeSync, None, None);
867 XGrabButton(dpy, Button1, MODKEY|numlockmask, c->win, False, BUTTONMASK,
868 GrabModeAsync, GrabModeSync, None, None);
869 XGrabButton(dpy, Button1, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
870 GrabModeAsync, GrabModeSync, None, None);
872 XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
873 GrabModeAsync, GrabModeSync, None, None);
874 XGrabButton(dpy, Button2, MODKEY|LockMask, c->win, False, BUTTONMASK,
875 GrabModeAsync, GrabModeSync, None, None);
876 XGrabButton(dpy, Button2, MODKEY|numlockmask, c->win, False, BUTTONMASK,
877 GrabModeAsync, GrabModeSync, None, None);
878 XGrabButton(dpy, Button2, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
879 GrabModeAsync, GrabModeSync, None, None);
881 XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
882 GrabModeAsync, GrabModeSync, None, None);
883 XGrabButton(dpy, Button3, MODKEY|LockMask, c->win, False, BUTTONMASK,
884 GrabModeAsync, GrabModeSync, None, None);
885 XGrabButton(dpy, Button3, MODKEY|numlockmask, c->win, False, BUTTONMASK,
886 GrabModeAsync, GrabModeSync, None, None);
887 XGrabButton(dpy, Button3, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
888 GrabModeAsync, GrabModeSync, None, None);
891 XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
892 GrabModeAsync, GrabModeSync, None, None);
899 XModifierKeymap *modmap;
901 /* init modifier map */
902 modmap = XGetModifierMapping(dpy);
903 for(i = 0; i < 8; i++)
904 for(j = 0; j < modmap->max_keypermod; j++) {
905 if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
906 numlockmask = (1 << i);
908 XFreeModifiermap(modmap);
910 XUngrabKey(dpy, AnyKey, AnyModifier, root);
911 for(i = 0; i < LENGTH(keys); i++) {
912 code = XKeysymToKeycode(dpy, keys[i].keysym);
913 XGrabKey(dpy, code, keys[i].mod, root, True,
914 GrabModeAsync, GrabModeAsync);
915 XGrabKey(dpy, code, keys[i].mod|LockMask, root, True,
916 GrabModeAsync, GrabModeAsync);
917 XGrabKey(dpy, code, keys[i].mod|numlockmask, root, True,
918 GrabModeAsync, GrabModeAsync);
919 XGrabKey(dpy, code, keys[i].mod|numlockmask|LockMask, root, True,
920 GrabModeAsync, GrabModeAsync);
925 idxoftag(const char *t) {
928 for(i = 0; (i < LENGTH(tags)) && (tags[i] != t); i++);
929 return (i < LENGTH(tags)) ? i : firstag(selview);
933 initfont(const char *fontstr) {
934 char *def, **missing;
939 XFreeFontSet(dpy, dc.font.set);
940 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
943 fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
944 XFreeStringList(missing);
947 XFontSetExtents *font_extents;
948 XFontStruct **xfonts;
950 dc.font.ascent = dc.font.descent = 0;
951 font_extents = XExtentsOfFontSet(dc.font.set);
952 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
953 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
954 if(dc.font.ascent < (*xfonts)->ascent)
955 dc.font.ascent = (*xfonts)->ascent;
956 if(dc.font.descent < (*xfonts)->descent)
957 dc.font.descent = (*xfonts)->descent;
963 XFreeFont(dpy, dc.font.xfont);
964 dc.font.xfont = NULL;
965 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
966 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
967 eprint("error, cannot load font: '%s'\n", fontstr);
968 dc.font.ascent = dc.font.xfont->ascent;
969 dc.font.descent = dc.font.xfont->descent;
971 dc.font.height = dc.font.ascent + dc.font.descent;
975 isoccupied(unsigned int t) {
978 for(c = clients; c; c = c->next)
985 isprotodel(Client *c) {
990 if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
991 for(i = 0; !ret && i < n; i++)
992 if(protocols[i] == wmatom[WMDelete])
1000 isurgent(unsigned int t) {
1003 for(c = clients; c; c = c->next)
1004 if(c->isurgent && c->tags[t])
1010 isvisible(Client *c) {
1013 for(i = 0; i < LENGTH(tags); i++)
1014 if(c->tags[i] && seltags[i])
1020 keypress(XEvent *e) {
1026 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
1027 for(i = 0; i < LENGTH(keys); i++)
1028 if(keysym == keys[i].keysym
1029 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
1032 keys[i].func(keys[i].arg);
1037 killclient(const char *arg) {
1042 if(isprotodel(sel)) {
1043 ev.type = ClientMessage;
1044 ev.xclient.window = sel->win;
1045 ev.xclient.message_type = wmatom[WMProtocols];
1046 ev.xclient.format = 32;
1047 ev.xclient.data.l[0] = wmatom[WMDelete];
1048 ev.xclient.data.l[1] = CurrentTime;
1049 XSendEvent(dpy, sel->win, False, NoEventMask, &ev);
1052 XKillClient(dpy, sel->win);
1056 manage(Window w, XWindowAttributes *wa) {
1057 Client *c, *t = NULL;
1063 c = emallocz(sizeof(Client));
1064 c->tags = emallocz(TAGSZ);
1071 c->x = wa->x + v->x;
1072 c->y = wa->y + v->y;
1075 c->oldborder = wa->border_width;
1077 if(c->w == v->w && c->h == v->h) {
1080 c->border = wa->border_width;
1083 if(c->x + c->w + 2 * c->border > v->wax + v->waw)
1084 c->x = v->wax + v->waw - c->w - 2 * c->border;
1085 if(c->y + c->h + 2 * c->border > v->way + v->wah)
1086 c->y = v->way + v->wah - c->h - 2 * c->border;
1091 c->border = BORDERPX;
1093 wc.border_width = c->border;
1094 XConfigureWindow(dpy, w, CWBorderWidth, &wc);
1095 XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
1096 configure(c); /* propagates border_width, if size doesn't change */
1098 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
1099 grabbuttons(c, False);
1101 if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
1102 for(t = clients; t && t->win != trans; t = t->next);
1104 memcpy(c->tags, t->tags, TAGSZ);
1106 c->isfloating = (rettrans == Success) || c->isfixed;
1109 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
1111 XMapWindow(dpy, c->win);
1112 setclientstate(c, NormalState);
1117 mappingnotify(XEvent *e) {
1118 XMappingEvent *ev = &e->xmapping;
1120 XRefreshKeyboardMapping(ev);
1121 if(ev->request == MappingKeyboard)
1126 maprequest(XEvent *e) {
1127 static XWindowAttributes wa;
1128 XMapRequestEvent *ev = &e->xmaprequest;
1130 if(!XGetWindowAttributes(dpy, ev->window, &wa))
1132 if(wa.override_redirect)
1134 if(!getclient(ev->window))
1135 manage(ev->window, &wa);
1139 movemouse(Client *c) {
1140 int x1, y1, ocx, ocy, di, nx, ny;
1149 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
1150 None, cursor[CurMove], CurrentTime) != GrabSuccess)
1152 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
1154 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
1157 XUngrabPointer(dpy, CurrentTime);
1159 case ConfigureRequest:
1162 handler[ev.type](&ev);
1166 nx = ocx + (ev.xmotion.x - x1);
1167 ny = ocy + (ev.xmotion.y - y1);
1168 if(abs(v->wax - nx) < SNAP)
1170 else if(abs((v->wax + v->waw) - (nx + c->w + 2 * c->border)) < SNAP)
1171 nx = v->wax + v->waw - c->w - 2 * c->border;
1172 if(abs(v->way - ny) < SNAP)
1174 else if(abs((v->way + v->wah) - (ny + c->h + 2 * c->border)) < SNAP)
1175 ny = v->way + v->wah - c->h - 2 * c->border;
1176 if(!c->isfloating && (v->layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP))
1177 togglefloating(NULL);
1178 if((v->layout->arrange == floating) || c->isfloating)
1179 resize(c, nx, ny, c->w, c->h, False);
1186 nexttiled(Client *c, View *v) {
1187 for(; c && (c->isfloating || getview(c) != v || !isvisible(c)); c = c->next);
1192 propertynotify(XEvent *e) {
1195 XPropertyEvent *ev = &e->xproperty;
1197 if(ev->state == PropertyDelete)
1198 return; /* ignore */
1199 if((c = getclient(ev->window))) {
1202 case XA_WM_TRANSIENT_FOR:
1203 XGetTransientForHint(dpy, c->win, &trans);
1204 if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
1207 case XA_WM_NORMAL_HINTS:
1212 drawbar(getview(c));
1215 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
1224 quit(const char *arg) {
1225 readin = running = False;
1229 reapply(const char *arg) {
1230 static Bool zerotags[LENGTH(tags)] = { 0 };
1233 for(c = clients; c; c = c->next) {
1234 memcpy(c->tags, zerotags, sizeof zerotags);
1241 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
1247 /* set minimum possible */
1253 /* temporarily remove base dimensions */
1257 /* adjust for aspect limits */
1258 if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) {
1259 if (w * c->maxay > h * c->maxax)
1260 w = h * c->maxax / c->maxay;
1261 else if (w * c->minay < h * c->minax)
1262 h = w * c->minay / c->minax;
1265 /* adjust for increment value */
1271 /* restore base dimensions */
1275 if(c->minw > 0 && w < c->minw)
1277 if(c->minh > 0 && h < c->minh)
1279 if(c->maxw > 0 && w > c->maxw)
1281 if(c->maxh > 0 && h > c->maxh)
1284 if(w <= 0 || h <= 0)
1287 x = v->w - w - 2 * c->border;
1289 y = v->h - h - 2 * c->border;
1290 if(x + w + 2 * c->border < v->x)
1292 if(y + h + 2 * c->border < v->y)
1294 if(c->x != x || c->y != y || c->w != w || c->h != h) {
1297 c->w = wc.width = w;
1298 c->h = wc.height = h;
1299 wc.border_width = c->border;
1300 XConfigureWindow(dpy, c->win,
1301 CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
1308 resizemouse(Client *c) {
1317 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
1318 None, cursor[CurResize], CurrentTime) != GrabSuccess)
1320 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
1322 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask , &ev);
1325 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
1326 c->w + c->border - 1, c->h + c->border - 1);
1327 XUngrabPointer(dpy, CurrentTime);
1328 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1330 case ConfigureRequest:
1333 handler[ev.type](&ev);
1337 if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
1339 if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
1341 if(!c->isfloating && (v->layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP))
1342 togglefloating(NULL);
1343 if((v->layout->arrange == floating) || c->isfloating)
1344 resize(c, c->x, c->y, nw, nh, True);
1359 if(sel->isfloating || (v->layout->arrange == floating))
1360 XRaiseWindow(dpy, sel->win);
1361 if(v->layout->arrange != floating) {
1362 wc.stack_mode = Below;
1363 wc.sibling = v->barwin;
1364 if(!sel->isfloating) {
1365 XConfigureWindow(dpy, sel->win, CWSibling|CWStackMode, &wc);
1366 wc.sibling = sel->win;
1368 for(c = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
1371 XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
1372 wc.sibling = c->win;
1376 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1382 char sbuf[sizeof stext];
1385 unsigned int len, offset;
1388 /* main event loop, also reads status text from stdin */
1390 xfd = ConnectionNumber(dpy);
1393 len = sizeof stext - 1;
1394 sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
1398 FD_SET(STDIN_FILENO, &rd);
1400 if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
1403 eprint("select failed\n");
1405 if(FD_ISSET(STDIN_FILENO, &rd)) {
1406 switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
1408 strncpy(stext, strerror(errno), len);
1412 strncpy(stext, "EOF", 4);
1416 for(p = sbuf + offset; r > 0; p++, r--, offset++)
1417 if(*p == '\n' || *p == '\0') {
1419 strncpy(stext, sbuf, len);
1420 p += r - 1; /* p is sbuf + offset + r - 1 */
1421 for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
1424 memmove(sbuf, p - r + 1, r);
1431 while(XPending(dpy)) {
1432 XNextEvent(dpy, &ev);
1433 if(handler[ev.type])
1434 (handler[ev.type])(&ev); /* call handler */
1441 unsigned int i, num;
1442 Window *wins, d1, d2;
1443 XWindowAttributes wa;
1446 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
1447 for(i = 0; i < num; i++) {
1448 if(!XGetWindowAttributes(dpy, wins[i], &wa)
1449 || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
1451 if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
1452 manage(wins[i], &wa);
1454 for(i = 0; i < num; i++) { /* now the transients */
1455 if(!XGetWindowAttributes(dpy, wins[i], &wa))
1457 if(XGetTransientForHint(dpy, wins[i], &d1)
1458 && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
1459 manage(wins[i], &wa);
1467 setclientstate(Client *c, long state) {
1468 long data[] = {state, None};
1470 XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
1471 PropModeReplace, (unsigned char *)data, 2);
1475 setlayout(const char *arg) {
1481 if(v->layout == &layouts[LENGTH(layouts)])
1482 v->layout = &layouts[0];
1485 for(i = 0; i < LENGTH(layouts); i++)
1486 if(!strcmp(arg, layouts[i].symbol))
1488 if(i == LENGTH(layouts))
1490 v->layout = &layouts[i];
1499 setmwfact(const char *arg) {
1505 /* arg handling, manipulate mwfact */
1508 else if(sscanf(arg, "%lf", &delta) == 1) {
1509 if(arg[0] == '+' || arg[0] == '-')
1515 else if(v->mwfact > 0.9)
1525 XSetWindowAttributes wa;
1526 XineramaScreenInfo *info = NULL;
1529 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
1530 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
1531 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
1532 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
1533 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
1534 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
1537 wa.cursor = cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
1538 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
1539 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
1541 if(XineramaIsActive(dpy))
1542 info = XineramaQueryScreens(dpy, &nviews);
1544 #if defined(AIM_XINERAMA)
1545 nviews = 2; /* aim Xinerama */
1547 views = emallocz(nviews * sizeof(View));
1549 screen = DefaultScreen(dpy);
1550 root = RootWindow(dpy, screen);
1552 /* init appearance */
1553 dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
1554 dc.norm[ColBG] = getcolor(NORMBGCOLOR);
1555 dc.norm[ColFG] = getcolor(NORMFGCOLOR);
1556 dc.sel[ColBorder] = getcolor(SELBORDERCOLOR);
1557 dc.sel[ColBG] = getcolor(SELBGCOLOR);
1558 dc.sel[ColFG] = getcolor(SELFGCOLOR);
1560 dc.h = bh = dc.font.height + 2;
1561 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
1562 dc.gc = XCreateGC(dpy, root, 0, 0);
1563 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
1565 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
1567 for(blw = i = 0; i < LENGTH(layouts); i++) {
1568 i = textw(layouts[i].symbol);
1573 seltags = emallocz(TAGSZ);
1574 prevtags = emallocz(TAGSZ);
1576 /* check, if vtags need assistance, because there is only 1 view */
1578 for(i = 0; i < LENGTH(tags); i++)
1581 for(i = 0; i < nviews; i++) {
1586 /* select first tag of view */
1588 seltags[j] = prevtags[j] = True;
1592 #if defined(AIM_XINERAMA)
1593 v->w = DisplayWidth(dpy, screen) / 2;
1594 v->x = (i == 0) ? 0 : v->w;
1596 v->h = DisplayHeight(dpy, screen);
1598 v->x = info[i].x_org;
1599 v->y = info[i].y_org;
1600 v->w = info[i].width;
1601 v->h = info[i].height;
1607 v->w = DisplayWidth(dpy, screen);
1608 v->h = DisplayHeight(dpy, screen);
1613 v->layout = &layouts[0];
1615 // TODO: bpos per screen?
1617 wa.override_redirect = 1;
1618 wa.background_pixmap = ParentRelative;
1619 wa.event_mask = ButtonPressMask|ExposureMask;
1622 v->barwin = XCreateWindow(dpy, root, v->x, v->y, v->w, bh, 0,
1623 DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
1624 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
1625 XDefineCursor(dpy, v->barwin, cursor[CurNormal]);
1627 XMapRaised(dpy, v->barwin);
1628 strcpy(stext, "dwm-"VERSION);
1630 /* EWMH support per view */
1631 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
1632 PropModeReplace, (unsigned char *) netatom, NetLast);
1634 /* select for events */
1635 wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
1636 |EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
1637 XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
1638 XSelectInput(dpy, root, wa.event_mask);
1652 spawn(const char *arg) {
1653 static char *shell = NULL;
1655 if(!shell && !(shell = getenv("SHELL")))
1659 /* The double-fork construct avoids zombie processes and keeps the code
1660 * clean from stupid signal handlers. */
1664 close(ConnectionNumber(dpy));
1666 execl(shell, shell, "-c", arg, (char *)NULL);
1667 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg);
1676 tag(const char *arg) {
1681 for(i = 0; i < LENGTH(tags); i++)
1682 sel->tags[i] = (NULL == arg) && (vtags[i] == getview(sel)->id);
1684 if(!conflicts(sel, i))
1685 sel->tags[idxoftag(arg)] = True;
1690 textnw(const char *text, unsigned int len) {
1694 XmbTextExtents(dc.font.set, text, len, NULL, &r);
1697 return XTextWidth(dc.font.xfont, text, len);
1701 textw(const char *text) {
1702 return textnw(text, strlen(text)) + dc.font.height;
1707 unsigned int i, n, nx, ny, nw, nh, mw, th;
1710 domwfact = dozoom = True;
1714 for(n = 0, c = nexttiled(clients, v); c; c = nexttiled(c->next, v))
1718 mw = (n == 1) ? v->waw : v->mwfact * v->waw;
1719 th = (n > 1) ? v->wah / (n - 1) : 0;
1720 if(n > 1 && th < bh)
1723 for(i = 0, c = mc = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
1724 if(i == 0) { /* master */
1725 nw = mw - 2 * c->border;
1726 nh = v->wah - 2 * c->border;
1728 else { /* tile window */
1731 nx += mc->w + 2 * mc->border;
1732 nw = v->waw - mw - 2 * c->border;
1734 if(i + 1 == n) /* remainder */
1735 nh = (v->way + v->wah) - ny - 2 * c->border;
1737 nh = th - 2 * c->border;
1739 resize(c, nx, ny, nw, nh, RESIZEHINTS);
1740 if((RESIZEHINTS) && ((c->h < bh) || (c->h > nh) || (c->w < bh) || (c->w > nw)))
1741 /* client doesn't accept size constraints */
1742 resize(c, nx, ny, nw, nh, False);
1743 if(n > 1 && th != v->wah)
1744 ny = c->y + c->h + 2 * c->border;
1750 togglebar(const char *arg) {
1752 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
1755 updatebarpos(selview);
1760 togglefloating(const char *arg) {
1763 sel->isfloating = !sel->isfloating;
1765 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
1770 toggletag(const char *arg) {
1776 if(conflicts(sel, i))
1778 sel->tags[i] = !sel->tags[i];
1779 for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++);
1780 if(j == LENGTH(tags))
1781 sel->tags[i] = True; /* at least one tag must be enabled */
1786 toggleview(const char *arg) {
1790 seltags[i] = !seltags[i];
1791 for(j = 0; j < LENGTH(tags) && !seltags[j]; j++);
1792 if(j == LENGTH(tags))
1793 seltags[i] = True; /* at least one tag must be viewed */
1801 XMoveWindow(dpy, c->win, c->x, c->y);
1802 c->isbanned = False;
1806 unmanage(Client *c) {
1809 wc.border_width = c->oldborder;
1810 /* The server grab construct avoids race conditions. */
1812 XSetErrorHandler(xerrordummy);
1813 XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
1818 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
1819 setclientstate(c, WithdrawnState);
1823 XSetErrorHandler(xerror);
1829 unmapnotify(XEvent *e) {
1831 XUnmapEvent *ev = &e->xunmap;
1833 if((c = getclient(ev->window)))
1838 updatebarpos(View *v) {
1849 XMoveWindow(dpy, v->barwin, v->x, v->y);
1853 XMoveWindow(dpy, v->barwin, v->x, v->y + v->wah);
1856 XMoveWindow(dpy, v->barwin, v->x, v->y - bh);
1860 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1864 updatesizehints(Client *c) {
1868 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
1870 c->flags = size.flags;
1871 if(c->flags & PBaseSize) {
1872 c->basew = size.base_width;
1873 c->baseh = size.base_height;
1875 else if(c->flags & PMinSize) {
1876 c->basew = size.min_width;
1877 c->baseh = size.min_height;
1880 c->basew = c->baseh = 0;
1881 if(c->flags & PResizeInc) {
1882 c->incw = size.width_inc;
1883 c->inch = size.height_inc;
1886 c->incw = c->inch = 0;
1887 if(c->flags & PMaxSize) {
1888 c->maxw = size.max_width;
1889 c->maxh = size.max_height;
1892 c->maxw = c->maxh = 0;
1893 if(c->flags & PMinSize) {
1894 c->minw = size.min_width;
1895 c->minh = size.min_height;
1897 else if(c->flags & PBaseSize) {
1898 c->minw = size.base_width;
1899 c->minh = size.base_height;
1902 c->minw = c->minh = 0;
1903 if(c->flags & PAspect) {
1904 c->minax = size.min_aspect.x;
1905 c->maxax = size.max_aspect.x;
1906 c->minay = size.min_aspect.y;
1907 c->maxay = size.max_aspect.y;
1910 c->minax = c->maxax = c->minay = c->maxay = 0;
1911 c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
1912 && c->maxw == c->minw && c->maxh == c->minh);
1916 updatetitle(Client *c) {
1917 if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
1918 gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);
1922 updatewmhints(Client *c) {
1925 if((wmh = XGetWMHints(dpy, c->win))) {
1926 c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
1932 view(const char *arg) {
1934 Bool tmp[LENGTH(tags)];
1936 memcpy(tmp, seltags, TAGSZ);
1938 for(i = 0; i < LENGTH(tags); i++)
1939 tmp[i] = (vtags[i] == selview->id);
1943 for(j = 0; j < LENGTH(tags); j++)
1944 if(selview->id == vtags[i]) {
1945 /* view tag of selview */
1946 if(selview->id == vtags[j])
1950 /* only touch the view the focus should go */
1951 if(vtags[j] == vtags[i])
1954 selview = &views[vtags[i]];
1957 if(memcmp(seltags, tmp, TAGSZ) != 0) {
1958 memcpy(prevtags, seltags, TAGSZ);
1959 memcpy(seltags, tmp, TAGSZ);
1970 XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask);
1971 for(i = 0; i < nviews; i++) {
1972 if((x >= views[i].x && x < views[i].x + views[i].w)
1973 && (y >= views[i].y && y < views[i].y + views[i].h))
1980 viewprevtag(const char *arg) {
1981 static Bool tmp[LENGTH(tags)];
1983 memcpy(tmp, seltags, TAGSZ);
1984 memcpy(seltags, prevtags, TAGSZ);
1985 memcpy(prevtags, tmp, TAGSZ);
1989 /* There's no way to check accesses to destroyed windows, thus those cases are
1990 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1991 * default error handler, which may call exit. */
1993 xerror(Display *dpy, XErrorEvent *ee) {
1994 if(ee->error_code == BadWindow
1995 || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
1996 || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
1997 || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
1998 || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
1999 || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
2000 || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
2001 || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
2003 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
2004 ee->request_code, ee->error_code);
2005 return xerrorxlib(dpy, ee); /* may call exit */
2009 xerrordummy(Display *dpy, XErrorEvent *ee) {
2013 /* Startup Error handler to check if another window manager
2014 * is already running. */
2016 xerrorstart(Display *dpy, XErrorEvent *ee) {
2022 zoom(const char *arg) {
2025 if(!sel || !dozoom || sel->isfloating)
2027 if(c == nexttiled(clients, getview(c)))
2028 if(!(c = nexttiled(c->next, getview(c))))
2037 main(int argc, char *argv[]) {
2038 if(argc == 2 && !strcmp("-v", argv[1]))
2039 eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n");
2041 eprint("usage: dwm [-v]\n");
2043 setlocale(LC_CTYPE, "");
2044 if(!(dpy = XOpenDisplay(0)))
2045 eprint("dwm: cannot open display\n");