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;
72 unsigned int border, oldborder;
73 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 *);
120 int x, y, w, h, wax, way, wah, waw;
126 /* function declarations */
127 void applyrules(Client *c);
129 void attach(Client *c);
130 void attachstack(Client *c);
132 void buttonpress(XEvent *e);
133 void checkotherwm(void);
135 void compileregs(void);
136 void configure(Client *c);
137 void configurenotify(XEvent *e);
138 void configurerequest(XEvent *e);
139 void destroynotify(XEvent *e);
140 void detach(Client *c);
141 void detachstack(Client *c);
142 void drawbar(View *v);
143 void drawsquare(View *v, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
144 void drawtext(View *v, const char *text, unsigned long col[ColLast], Bool invert);
145 void *emallocz(unsigned int size);
146 void enternotify(XEvent *e);
147 void eprint(const char *errstr, ...);
148 void expose(XEvent *e);
149 void floating(View *v); /* default floating layout */
150 void focus(Client *c);
151 void focusin(XEvent *e);
152 void focusnext(const char *arg);
153 void focusprev(const char *arg);
154 Client *getclient(Window w);
155 unsigned long getcolor(const char *colstr);
156 View *getviewbar(Window barwin);
157 View *getview(Client *c);
158 long getstate(Window w);
159 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
160 void grabbuttons(Client *c, Bool focused);
162 unsigned int idxoftag(const char *tag);
163 void initfont(const char *fontstr);
164 Bool isoccupied(unsigned int t);
165 Bool isprotodel(Client *c);
166 Bool isurgent(unsigned int t);
167 Bool isvisible(Client *c);
168 void keypress(XEvent *e);
169 void killclient(const char *arg);
170 void manage(Window w, XWindowAttributes *wa);
171 void mappingnotify(XEvent *e);
172 void maprequest(XEvent *e);
174 void movemouse(Client *c);
175 Client *nexttiled(Client *c, View *v);
176 void propertynotify(XEvent *e);
177 void quit(const char *arg);
178 void reapply(const char *arg);
179 void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
180 void resizemouse(Client *c);
181 void restack(View *v);
184 void setclientstate(Client *c, long state);
185 void setlayout(const char *arg);
186 void setmwfact(const char *arg);
188 void spawn(const char *arg);
189 void tag(const char *arg);
190 unsigned int textnw(const char *text, unsigned int len);
191 unsigned int textw(const char *text);
193 void togglebar(const char *arg);
194 void togglefloating(const char *arg);
195 void toggletag(const char *arg);
196 void toggleview(const char *arg);
197 void unban(Client *c);
198 void unmanage(Client *c);
199 void unmapnotify(XEvent *e);
200 void updatebarpos(View *v);
201 void updatesizehints(Client *c);
202 void updatetitle(Client *c);
203 void updatewmhints(Client *c);
204 void view(const char *arg);
205 void viewprevtag(const char *arg); /* views previous selected tags */
206 int xerror(Display *dpy, XErrorEvent *ee);
207 int xerrordummy(Display *dpy, XErrorEvent *ee);
208 int xerrorstart(Display *dpy, XErrorEvent *ee);
209 void zoom(const char *arg);
210 void selectview(const char *arg);
219 int (*xerrorxlib)(Display *, XErrorEvent *);
220 unsigned int bh, bpos;
221 unsigned int blw = 0;
222 unsigned int numlockmask = 0;
223 void (*handler[LASTEvent]) (XEvent *) = {
224 [ButtonPress] = buttonpress,
225 [ConfigureRequest] = configurerequest,
226 [ConfigureNotify] = configurenotify,
227 [DestroyNotify] = destroynotify,
228 [EnterNotify] = enternotify,
231 [KeyPress] = keypress,
232 [MappingNotify] = mappingnotify,
233 [MapRequest] = maprequest,
234 [PropertyNotify] = propertynotify,
235 [UnmapNotify] = unmapnotify
237 Atom wmatom[WMLast], netatom[NetLast];
238 Bool isxinerama = False;
239 Bool domwfact = True;
241 Bool otherwm, readin;
243 Client *clients = NULL;
245 Client *stack = NULL;
246 Cursor cursor[CurLast];
253 /* configuration, allows nested code to access above variables */
256 /* function implementations */
258 applyrules(Client *c) {
259 static char buf[512];
262 Bool matched_tag = False;
263 XClassHint ch = { 0 };
266 XGetClassHint(dpy, c->win, &ch);
267 snprintf(buf, sizeof buf, "%s:%s:%s",
268 ch.res_class ? ch.res_class : "",
269 ch.res_name ? ch.res_name : "", c->name);
270 for(i = 0; i < LENGTH(rules); i++)
271 if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
272 c->isfloating = rules[i].isfloating;
273 for(j = 0; regs[i].tagregex && j < LENGTH(tags); j++) {
274 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
276 c->tags[j] = selview->id;
285 memcpy(c->tags, seltags, sizeof initags);
295 for(c = clients; c; c = c->next)
301 for(i = 0; i < nviews; i++) {
302 views[i].layout->arrange(&views[i]);
317 attachstack(Client *c) {
326 XMoveWindow(dpy, c->win, c->x + 3 * getview(c)->w, c->y);
331 buttonpress(XEvent *e) {
334 XButtonPressedEvent *ev = &e->xbutton;
338 if(ev->window == v->barwin) {
340 for(i = 0; i < LENGTH(tags); i++) {
343 if(ev->button == Button1) {
344 if(ev->state & MODKEY)
349 else if(ev->button == Button3) {
350 if(ev->state & MODKEY)
358 if((ev->x < x + blw) && ev->button == Button1)
361 else if((c = getclient(ev->window))) {
363 if(CLEANMASK(ev->state) != MODKEY)
365 if(ev->button == Button1) {
369 else if(ev->button == Button2) {
370 if((floating != v->layout->arrange) && c->isfloating)
371 togglefloating(NULL);
375 else if(ev->button == Button3 && !c->isfixed) {
385 XSetErrorHandler(xerrorstart);
387 /* this causes an error if some other window manager is running */
388 XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
391 eprint("dwm: another window manager is already running\n");
393 XSetErrorHandler(NULL);
394 xerrorxlib = XSetErrorHandler(xerror);
407 XFreeFontSet(dpy, dc.font.set);
409 XFreeFont(dpy, dc.font.xfont);
411 XUngrabKey(dpy, AnyKey, AnyModifier, root);
412 XFreePixmap(dpy, dc.drawable);
414 XFreeCursor(dpy, cursor[CurNormal]);
415 XFreeCursor(dpy, cursor[CurResize]);
416 XFreeCursor(dpy, cursor[CurMove]);
417 for(i = 0; i < nviews; i++)
418 XDestroyWindow(dpy, views[i].barwin);
420 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
430 regs = emallocz(LENGTH(rules) * sizeof(Regs));
431 for(i = 0; i < LENGTH(rules); i++) {
433 reg = emallocz(sizeof(regex_t));
434 if(regcomp(reg, rules[i].prop, REG_EXTENDED))
437 regs[i].propregex = reg;
440 reg = emallocz(sizeof(regex_t));
441 if(regcomp(reg, rules[i].tags, REG_EXTENDED))
444 regs[i].tagregex = reg;
450 configure(Client *c) {
453 ce.type = ConfigureNotify;
461 ce.border_width = c->border;
463 ce.override_redirect = False;
464 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
468 configurenotify(XEvent *e) {
469 XConfigureEvent *ev = &e->xconfigure;
472 if(ev->window == root && (ev->width != v->w || ev->height != v->h)) {
473 /* TODO -- update Xinerama dimensions here */
476 XFreePixmap(dpy, dc.drawable);
477 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(root, screen), bh, DefaultDepth(dpy, screen));
478 XResizeWindow(dpy, v->barwin, v->w, bh);
485 configurerequest(XEvent *e) {
487 XConfigureRequestEvent *ev = &e->xconfigurerequest;
490 if((c = getclient(ev->window))) {
491 View *v = getview(c);
492 if(ev->value_mask & CWBorderWidth)
493 c->border = ev->border_width;
494 if(c->isfixed || c->isfloating || (floating == v->layout->arrange)) {
495 if(ev->value_mask & CWX)
497 if(ev->value_mask & CWY)
499 if(ev->value_mask & CWWidth)
501 if(ev->value_mask & CWHeight)
503 if((c->x - v->x + c->w) > v->w && c->isfloating)
504 c->x = v->x + (v->w / 2 - c->w / 2); /* center in x direction */
505 if((c->y - v->y + c->h) > v->h && c->isfloating)
506 c->y = v->y + (v->h / 2 - c->h / 2); /* center in y direction */
507 if((ev->value_mask & (CWX|CWY))
508 && !(ev->value_mask & (CWWidth|CWHeight)))
511 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
519 wc.width = ev->width;
520 wc.height = ev->height;
521 wc.border_width = ev->border_width;
522 wc.sibling = ev->above;
523 wc.stack_mode = ev->detail;
524 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
530 destroynotify(XEvent *e) {
532 XDestroyWindowEvent *ev = &e->xdestroywindow;
534 if((c = getclient(ev->window)))
541 c->prev->next = c->next;
543 c->next->prev = c->prev;
546 c->next = c->prev = NULL;
550 detachstack(Client *c) {
553 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
563 for(c = stack; c && (!isvisible(c) || getview(c) != v); c = c->snext);
564 for(i = 0; i < LENGTH(tags); i++) {
565 dc.w = textw(tags[i]);
566 if(seltags[i] && seltags[i] == v->id) {
567 drawtext(v, tags[i], dc.sel, isurgent(i));
568 drawsquare(v, c && c->tags[i], isoccupied(i), isurgent(i), dc.sel);
571 drawtext(v, tags[i], dc.norm, isurgent(i));
572 drawsquare(v, c && c->tags[i], isoccupied(i), isurgent(i), dc.norm);
577 drawtext(v, v->layout->symbol, dc.norm, False);
586 drawtext(v, stext, dc.norm, False);
590 if((dc.w = dc.x - x) > bh) {
593 drawtext(v, c->name, dc.sel, False);
594 drawsquare(v, False, c->isfloating, False, dc.sel);
597 drawtext(v, NULL, dc.norm, False);
599 XCopyArea(dpy, dc.drawable, v->barwin, dc.gc, 0, 0, v->w, bh, 0, 0);
604 drawsquare(View *v, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
607 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
609 gcv.foreground = col[invert ? ColBG : ColFG];
610 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
611 x = (dc.font.ascent + dc.font.descent + 2) / 4;
615 r.width = r.height = x + 1;
616 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
619 r.width = r.height = x;
620 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
625 drawtext(View *v, const char *text, unsigned long col[ColLast], Bool invert) {
627 static char buf[256];
628 unsigned int len, olen;
629 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
631 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
632 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
636 olen = len = strlen(text);
637 if(len >= sizeof buf)
638 len = sizeof buf - 1;
639 memcpy(buf, text, len);
641 h = dc.font.ascent + dc.font.descent;
642 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
644 /* shorten text if necessary */
645 while(len && (w = textnw(buf, len)) > dc.w - h)
656 return; /* too long */
657 XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
659 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
661 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
665 emallocz(unsigned int size) {
666 void *res = calloc(1, size);
669 eprint("fatal: could not malloc() %u bytes\n", size);
674 enternotify(XEvent *e) {
676 XCrossingEvent *ev = &e->xcrossing;
678 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) {
679 if(!isxinerama || ev->window != root)
682 if((c = getclient(ev->window)))
689 eprint(const char *errstr, ...) {
692 va_start(ap, errstr);
693 vfprintf(stderr, errstr, ap);
701 XExposeEvent *ev = &e->xexpose;
703 if(ev->count == 0 && (v = getviewbar(ev->window)))
708 floating(View *v) { /* default floating layout */
711 domwfact = dozoom = False;
712 for(c = clients; c; c = c->next)
714 resize(c, c->x, c->y, c->w, c->h, True);
721 selview = getview(c);
726 if(!c || (c && !isvisible(c)))
727 for(c = stack; c && (!isvisible(c) || getview(c) != selview); c = c->snext);
728 if(sel && sel != c) {
729 grabbuttons(sel, False);
730 XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
735 grabbuttons(c, True);
739 XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
740 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
741 selview = getview(c);
744 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
749 focusin(XEvent *e) { /* there are some broken focus acquiring clients */
750 XFocusChangeEvent *ev = &e->xfocus;
752 if(sel && ev->window != sel->win)
753 XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
757 focusnext(const char *arg) {
762 for(c = sel->next; c && !isvisible(c); c = c->next);
764 for(c = clients; c && !isvisible(c); c = c->next);
772 focusprev(const char *arg) {
777 for(c = sel->prev; c && !isvisible(c); c = c->prev);
779 for(c = clients; c && c->next; c = c->next);
780 for(; c && !isvisible(c); c = c->prev);
789 getclient(Window w) {
792 for(c = clients; c && c->win != w; c = c->next);
797 getcolor(const char *colstr) {
798 Colormap cmap = DefaultColormap(dpy, screen);
801 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
802 eprint("error, cannot allocate color '%s'\n", colstr);
807 getviewbar(Window barwin) {
810 for(i = 0; i < nviews; i++)
811 if(views[i].barwin == barwin)
820 for(i = 0; i < LENGTH(tags); i++)
822 return &views[c->tags[i] - 1];
823 return &views[0]; /* fallback */
830 unsigned char *p = NULL;
831 unsigned long n, extra;
834 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
835 &real, &format, &n, &extra, (unsigned char **)&p);
836 if(status != Success)
845 gettextprop(Window w, Atom atom, char *text, unsigned int size) {
850 if(!text || size == 0)
853 XGetTextProperty(dpy, w, &name, atom);
856 if(name.encoding == XA_STRING)
857 strncpy(text, (char *)name.value, size - 1);
859 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
861 strncpy(text, *list, size - 1);
862 XFreeStringList(list);
865 text[size - 1] = '\0';
871 grabbuttons(Client *c, Bool focused) {
872 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
875 XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
876 GrabModeAsync, GrabModeSync, None, None);
877 XGrabButton(dpy, Button1, MODKEY|LockMask, c->win, False, BUTTONMASK,
878 GrabModeAsync, GrabModeSync, None, None);
879 XGrabButton(dpy, Button1, MODKEY|numlockmask, c->win, False, BUTTONMASK,
880 GrabModeAsync, GrabModeSync, None, None);
881 XGrabButton(dpy, Button1, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
882 GrabModeAsync, GrabModeSync, None, None);
884 XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
885 GrabModeAsync, GrabModeSync, None, None);
886 XGrabButton(dpy, Button2, MODKEY|LockMask, c->win, False, BUTTONMASK,
887 GrabModeAsync, GrabModeSync, None, None);
888 XGrabButton(dpy, Button2, MODKEY|numlockmask, c->win, False, BUTTONMASK,
889 GrabModeAsync, GrabModeSync, None, None);
890 XGrabButton(dpy, Button2, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
891 GrabModeAsync, GrabModeSync, None, None);
893 XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
894 GrabModeAsync, GrabModeSync, None, None);
895 XGrabButton(dpy, Button3, MODKEY|LockMask, c->win, False, BUTTONMASK,
896 GrabModeAsync, GrabModeSync, None, None);
897 XGrabButton(dpy, Button3, MODKEY|numlockmask, c->win, False, BUTTONMASK,
898 GrabModeAsync, GrabModeSync, None, None);
899 XGrabButton(dpy, Button3, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
900 GrabModeAsync, GrabModeSync, None, None);
903 XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
904 GrabModeAsync, GrabModeSync, None, None);
911 XModifierKeymap *modmap;
913 /* init modifier map */
914 modmap = XGetModifierMapping(dpy);
915 for(i = 0; i < 8; i++)
916 for(j = 0; j < modmap->max_keypermod; j++) {
917 if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
918 numlockmask = (1 << i);
920 XFreeModifiermap(modmap);
922 XUngrabKey(dpy, AnyKey, AnyModifier, root);
923 for(i = 0; i < LENGTH(keys); i++) {
924 code = XKeysymToKeycode(dpy, keys[i].keysym);
925 XGrabKey(dpy, code, keys[i].mod, root, True,
926 GrabModeAsync, GrabModeAsync);
927 XGrabKey(dpy, code, keys[i].mod|LockMask, root, True,
928 GrabModeAsync, GrabModeAsync);
929 XGrabKey(dpy, code, keys[i].mod|numlockmask, root, True,
930 GrabModeAsync, GrabModeAsync);
931 XGrabKey(dpy, code, keys[i].mod|numlockmask|LockMask, root, True,
932 GrabModeAsync, GrabModeAsync);
937 idxoftag(const char *tag) {
940 for(i = 0; (i < LENGTH(tags)) && (tags[i] != tag); i++);
941 return (i < LENGTH(tags)) ? i : 0;
945 initfont(const char *fontstr) {
946 char *def, **missing;
951 XFreeFontSet(dpy, dc.font.set);
952 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
955 fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
956 XFreeStringList(missing);
959 XFontSetExtents *font_extents;
960 XFontStruct **xfonts;
962 dc.font.ascent = dc.font.descent = 0;
963 font_extents = XExtentsOfFontSet(dc.font.set);
964 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
965 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
966 if(dc.font.ascent < (*xfonts)->ascent)
967 dc.font.ascent = (*xfonts)->ascent;
968 if(dc.font.descent < (*xfonts)->descent)
969 dc.font.descent = (*xfonts)->descent;
975 XFreeFont(dpy, dc.font.xfont);
976 dc.font.xfont = NULL;
977 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
978 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
979 eprint("error, cannot load font: '%s'\n", fontstr);
980 dc.font.ascent = dc.font.xfont->ascent;
981 dc.font.descent = dc.font.xfont->descent;
983 dc.font.height = dc.font.ascent + dc.font.descent;
987 isoccupied(unsigned int t) {
990 for(c = clients; c; c = c->next)
997 isprotodel(Client *c) {
1002 if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
1003 for(i = 0; !ret && i < n; i++)
1004 if(protocols[i] == wmatom[WMDelete])
1012 isurgent(unsigned int t) {
1015 for(c = clients; c; c = c->next)
1016 if(c->isurgent && c->tags[t])
1022 isvisible(Client *c) {
1025 for(i = 0; i < LENGTH(tags); i++)
1026 if(c->tags[i] && seltags[i])
1032 keypress(XEvent *e) {
1038 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
1039 for(i = 0; i < LENGTH(keys); i++)
1040 if(keysym == keys[i].keysym
1041 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
1044 keys[i].func(keys[i].arg);
1049 killclient(const char *arg) {
1054 if(isprotodel(sel)) {
1055 ev.type = ClientMessage;
1056 ev.xclient.window = sel->win;
1057 ev.xclient.message_type = wmatom[WMProtocols];
1058 ev.xclient.format = 32;
1059 ev.xclient.data.l[0] = wmatom[WMDelete];
1060 ev.xclient.data.l[1] = CurrentTime;
1061 XSendEvent(dpy, sel->win, False, NoEventMask, &ev);
1064 XKillClient(dpy, sel->win);
1068 manage(Window w, XWindowAttributes *wa) {
1069 Client *c, *t = NULL;
1075 c = emallocz(sizeof(Client));
1076 c->tags = emallocz(sizeof initags);
1083 c->x = wa->x + v->x;
1084 c->y = wa->y + v->y;
1087 c->oldborder = wa->border_width;
1089 if(c->w == v->w && c->h == v->h) {
1092 c->border = wa->border_width;
1095 if(c->x + c->w + 2 * c->border > v->wax + v->waw)
1096 c->x = v->wax + v->waw - c->w - 2 * c->border;
1097 if(c->y + c->h + 2 * c->border > v->way + v->wah)
1098 c->y = v->way + v->wah - c->h - 2 * c->border;
1103 c->border = BORDERPX;
1105 wc.border_width = c->border;
1106 XConfigureWindow(dpy, w, CWBorderWidth, &wc);
1107 XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
1108 configure(c); /* propagates border_width, if size doesn't change */
1110 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
1111 grabbuttons(c, False);
1113 if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
1114 for(t = clients; t && t->win != trans; t = t->next);
1116 memcpy(c->tags, t->tags, sizeof initags);
1118 c->isfloating = (rettrans == Success) || c->isfixed;
1121 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
1123 XMapWindow(dpy, c->win);
1124 setclientstate(c, NormalState);
1129 mappingnotify(XEvent *e) {
1130 XMappingEvent *ev = &e->xmapping;
1132 XRefreshKeyboardMapping(ev);
1133 if(ev->request == MappingKeyboard)
1138 maprequest(XEvent *e) {
1139 static XWindowAttributes wa;
1140 XMapRequestEvent *ev = &e->xmaprequest;
1142 if(!XGetWindowAttributes(dpy, ev->window, &wa))
1144 if(wa.override_redirect)
1146 if(!getclient(ev->window))
1147 manage(ev->window, &wa);
1156 XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask);
1157 for(i = 0; i < nviews; i++) {
1158 if((x >= views[i].x && x < views[i].x + views[i].w)
1159 && (y >= views[i].y && y < views[i].y + views[i].h))
1166 movemouse(Client *c) {
1167 int x1, y1, ocx, ocy, di, nx, ny;
1176 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
1177 None, cursor[CurMove], CurrentTime) != GrabSuccess)
1179 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
1181 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
1184 XUngrabPointer(dpy, CurrentTime);
1186 case ConfigureRequest:
1189 handler[ev.type](&ev);
1193 nx = ocx + (ev.xmotion.x - x1);
1194 ny = ocy + (ev.xmotion.y - y1);
1195 if(abs(v->wax - nx) < SNAP)
1197 else if(abs((v->wax + v->waw) - (nx + c->w + 2 * c->border)) < SNAP)
1198 nx = v->wax + v->waw - c->w - 2 * c->border;
1199 if(abs(v->way - ny) < SNAP)
1201 else if(abs((v->way + v->wah) - (ny + c->h + 2 * c->border)) < SNAP)
1202 ny = v->way + v->wah - c->h - 2 * c->border;
1203 if(!c->isfloating && (v->layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP))
1204 togglefloating(NULL);
1205 if((v->layout->arrange == floating) || c->isfloating)
1206 resize(c, nx, ny, c->w, c->h, False);
1213 nexttiled(Client *c, View *v) {
1214 for(; c && (c->isfloating || getview(c) != v || !isvisible(c)); c = c->next);
1219 propertynotify(XEvent *e) {
1222 XPropertyEvent *ev = &e->xproperty;
1224 if(ev->state == PropertyDelete)
1225 return; /* ignore */
1226 if((c = getclient(ev->window))) {
1229 case XA_WM_TRANSIENT_FOR:
1230 XGetTransientForHint(dpy, c->win, &trans);
1231 if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
1234 case XA_WM_NORMAL_HINTS:
1239 drawbar(getview(c));
1242 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
1251 quit(const char *arg) {
1252 readin = running = False;
1256 reapply(const char *arg) {
1257 static Bool zerotags[LENGTH(tags)] = { 0 };
1260 for(c = clients; c; c = c->next) {
1261 memcpy(c->tags, zerotags, sizeof zerotags);
1268 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
1274 /* set minimum possible */
1280 /* temporarily remove base dimensions */
1284 /* adjust for aspect limits */
1285 if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) {
1286 if (w * c->maxay > h * c->maxax)
1287 w = h * c->maxax / c->maxay;
1288 else if (w * c->minay < h * c->minax)
1289 h = w * c->minay / c->minax;
1292 /* adjust for increment value */
1298 /* restore base dimensions */
1302 if(c->minw > 0 && w < c->minw)
1304 if(c->minh > 0 && h < c->minh)
1306 if(c->maxw > 0 && w > c->maxw)
1308 if(c->maxh > 0 && h > c->maxh)
1311 if(w <= 0 || h <= 0)
1314 x = v->w - w - 2 * c->border;
1316 y = v->h - h - 2 * c->border;
1317 if(x + w + 2 * c->border < v->x)
1319 if(y + h + 2 * c->border < v->y)
1321 if(c->x != x || c->y != y || c->w != w || c->h != h) {
1324 c->w = wc.width = w;
1325 c->h = wc.height = h;
1326 wc.border_width = c->border;
1327 XConfigureWindow(dpy, c->win,
1328 CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
1335 resizemouse(Client *c) {
1344 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
1345 None, cursor[CurResize], CurrentTime) != GrabSuccess)
1347 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
1349 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask , &ev);
1352 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
1353 c->w + c->border - 1, c->h + c->border - 1);
1354 XUngrabPointer(dpy, CurrentTime);
1355 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1357 case ConfigureRequest:
1360 handler[ev.type](&ev);
1364 if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
1366 if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
1368 if(!c->isfloating && (v->layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP))
1369 togglefloating(NULL);
1370 if((v->layout->arrange == floating) || c->isfloating)
1371 resize(c, c->x, c->y, nw, nh, True);
1386 if(sel->isfloating || (v->layout->arrange == floating))
1387 XRaiseWindow(dpy, sel->win);
1388 if(v->layout->arrange != floating) {
1389 wc.stack_mode = Below;
1390 wc.sibling = v->barwin;
1391 if(!sel->isfloating) {
1392 XConfigureWindow(dpy, sel->win, CWSibling|CWStackMode, &wc);
1393 wc.sibling = sel->win;
1395 for(c = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
1398 XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
1399 wc.sibling = c->win;
1403 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1409 char buf[sizeof stext];
1412 unsigned int len, offset;
1415 /* main event loop, also reads status text from stdin */
1417 xfd = ConnectionNumber(dpy);
1420 len = sizeof stext - 1;
1421 buf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
1425 FD_SET(STDIN_FILENO, &rd);
1427 if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
1430 eprint("select failed\n");
1432 if(FD_ISSET(STDIN_FILENO, &rd)) {
1433 switch((r = read(STDIN_FILENO, buf + offset, len - offset))) {
1435 strncpy(stext, strerror(errno), len);
1439 strncpy(stext, "EOF", 4);
1443 for(p = buf + offset; r > 0; p++, r--, offset++)
1444 if(*p == '\n' || *p == '\0') {
1446 strncpy(stext, buf, len);
1447 p += r - 1; /* p is buf + offset + r - 1 */
1448 for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
1451 memmove(buf, p - r + 1, r);
1458 while(XPending(dpy)) {
1459 XNextEvent(dpy, &ev);
1460 if(handler[ev.type])
1461 (handler[ev.type])(&ev); /* call handler */
1468 unsigned int i, num;
1469 Window *wins, d1, d2;
1470 XWindowAttributes wa;
1473 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
1474 for(i = 0; i < num; i++) {
1475 if(!XGetWindowAttributes(dpy, wins[i], &wa)
1476 || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
1478 if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
1479 manage(wins[i], &wa);
1481 for(i = 0; i < num; i++) { /* now the transients */
1482 if(!XGetWindowAttributes(dpy, wins[i], &wa))
1484 if(XGetTransientForHint(dpy, wins[i], &d1)
1485 && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
1486 manage(wins[i], &wa);
1494 setclientstate(Client *c, long state) {
1495 long data[] = {state, None};
1497 XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
1498 PropModeReplace, (unsigned char *)data, 2);
1502 setlayout(const char *arg) {
1508 if(v->layout == &layouts[LENGTH(layouts)])
1509 v->layout = &layouts[0];
1512 for(i = 0; i < LENGTH(layouts); i++)
1513 if(!strcmp(arg, layouts[i].symbol))
1515 if(i == LENGTH(layouts))
1517 v->layout = &layouts[i];
1526 setmwfact(const char *arg) {
1533 /* arg handling, manipulate mwfact */
1536 else if(sscanf(arg, "%lf", &delta) == 1) {
1537 if(arg[0] == '+' || arg[0] == '-')
1543 else if(v->mwfact > 0.9)
1553 XSetWindowAttributes wa;
1554 XineramaScreenInfo *info = NULL;
1557 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
1558 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
1559 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
1560 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
1561 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
1562 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
1565 wa.cursor = cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
1566 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
1567 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
1569 if((isxinerama = XineramaIsActive(dpy)))
1570 info = XineramaQueryScreens(dpy, &nviews);
1571 #if defined(AIM_XINERAMA)
1573 nviews = 2; /* aim Xinerama */
1575 selview = views = emallocz(nviews * sizeof(View));
1577 screen = DefaultScreen(dpy);
1578 root = RootWindow(dpy, screen);
1580 /* init appearance */
1581 dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
1582 dc.norm[ColBG] = getcolor(NORMBGCOLOR);
1583 dc.norm[ColFG] = getcolor(NORMFGCOLOR);
1584 dc.sel[ColBorder] = getcolor(SELBORDERCOLOR);
1585 dc.sel[ColBG] = getcolor(SELBGCOLOR);
1586 dc.sel[ColFG] = getcolor(SELFGCOLOR);
1588 dc.h = bh = dc.font.height + 2;
1589 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
1590 dc.gc = XCreateGC(dpy, root, 0, 0);
1591 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
1593 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
1595 for(blw = i = 0; i < LENGTH(layouts); i++) {
1596 i = textw(layouts[i].symbol);
1601 seltags = emallocz(sizeof initags);
1602 prevtags = emallocz(sizeof initags);
1603 memcpy(seltags, initags, sizeof initags);
1604 memcpy(prevtags, initags, sizeof initags);
1606 for(i = 0; i < nviews; i++) {
1611 if(nviews != 1 && isxinerama) {
1613 #if defined(AIM_XINERAMA)
1614 v->w = DisplayWidth(dpy, screen) / 2;
1615 v->x = (i == 0) ? 0 : v->w;
1617 v->h = DisplayHeight(dpy, screen);
1619 v->x = info[i].x_org;
1620 v->y = info[i].y_org;
1621 v->w = info[i].width;
1622 v->h = info[i].height;
1628 v->w = DisplayWidth(dpy, screen);
1629 v->h = DisplayHeight(dpy, screen);
1634 v->layout = &layouts[0];
1636 // TODO: bpos per screen?
1638 wa.override_redirect = 1;
1639 wa.background_pixmap = ParentRelative;
1640 wa.event_mask = ButtonPressMask|ExposureMask;
1643 v->barwin = XCreateWindow(dpy, root, v->x, v->y, v->w, bh, 0,
1644 DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
1645 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
1646 XDefineCursor(dpy, v->barwin, cursor[CurNormal]);
1648 XMapRaised(dpy, v->barwin);
1649 strcpy(stext, "dwm-"VERSION);
1651 /* EWMH support per view */
1652 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
1653 PropModeReplace, (unsigned char *) netatom, NetLast);
1655 /* select for events */
1656 wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
1657 |EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
1658 XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
1659 XSelectInput(dpy, root, wa.event_mask);
1672 selview = &views[0];
1676 spawn(const char *arg) {
1677 static char *shell = NULL;
1679 if(!shell && !(shell = getenv("SHELL")))
1683 /* The double-fork construct avoids zombie processes and keeps the code
1684 * clean from stupid signal handlers. */
1688 close(ConnectionNumber(dpy));
1690 execl(shell, shell, "-c", arg, (char *)NULL);
1691 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg);
1700 tag(const char *arg) {
1705 for(i = 0; i < LENGTH(tags); i++)
1706 sel->tags[i] = (NULL == arg) ? selview->id : 0;
1707 sel->tags[idxoftag(arg)] = selview->id;
1712 textnw(const char *text, unsigned int len) {
1716 XmbTextExtents(dc.font.set, text, len, NULL, &r);
1719 return XTextWidth(dc.font.xfont, text, len);
1723 textw(const char *text) {
1724 return textnw(text, strlen(text)) + dc.font.height;
1729 unsigned int i, n, nx, ny, nw, nh, mw, th;
1732 domwfact = dozoom = True;
1736 for(n = 0, c = nexttiled(clients, v); c; c = nexttiled(c->next, v))
1740 mw = (n == 1) ? v->waw : v->mwfact * v->waw;
1741 th = (n > 1) ? v->wah / (n - 1) : 0;
1742 if(n > 1 && th < bh)
1745 for(i = 0, c = mc = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
1746 if(i == 0) { /* master */
1749 nw = mw - 2 * c->border;
1750 nh = v->wah - 2 * c->border;
1752 else { /* tile window */
1755 nx += mc->w + 2 * mc->border;
1756 nw = v->waw - mw - 2 * c->border;
1758 if(i + 1 == n) /* remainder */
1759 nh = (v->way + v->wah) - ny - 2 * c->border;
1761 nh = th - 2 * c->border;
1763 resize(c, nx, ny, nw, nh, RESIZEHINTS);
1764 if((RESIZEHINTS) && ((c->h < bh) || (c->h > nh) || (c->w < bh) || (c->w > nw)))
1765 /* client doesn't accept size constraints */
1766 resize(c, nx, ny, nw, nh, False);
1767 if(n > 1 && th != v->wah)
1768 ny = c->y + c->h + 2 * c->border;
1774 togglebar(const char *arg) {
1776 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
1779 updatebarpos(selview);
1784 togglefloating(const char *arg) {
1787 sel->isfloating = !sel->isfloating;
1789 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
1794 toggletag(const char *arg) {
1800 sel->tags[i] = !sel->tags[i];
1801 for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++);
1802 if(j == LENGTH(tags))
1803 sel->tags[i] = selview->id; /* at least one tag must be enabled */
1808 toggleview(const char *arg) {
1812 seltags[i] = !seltags[i];
1813 for(j = 0; j < LENGTH(tags) && !seltags[j]; j++);
1814 if(j == LENGTH(tags))
1815 seltags[i] = selview->id; /* at least one tag must be viewed */
1823 XMoveWindow(dpy, c->win, c->x, c->y);
1824 c->isbanned = False;
1828 unmanage(Client *c) {
1831 wc.border_width = c->oldborder;
1832 /* The server grab construct avoids race conditions. */
1834 XSetErrorHandler(xerrordummy);
1835 XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
1840 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
1841 setclientstate(c, WithdrawnState);
1845 XSetErrorHandler(xerror);
1851 unmapnotify(XEvent *e) {
1853 XUnmapEvent *ev = &e->xunmap;
1855 if((c = getclient(ev->window)))
1860 updatebarpos(View *v) {
1871 XMoveWindow(dpy, v->barwin, v->x, v->y);
1875 XMoveWindow(dpy, v->barwin, v->x, v->y + v->wah);
1878 XMoveWindow(dpy, v->barwin, v->x, v->y - bh);
1882 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1886 updatesizehints(Client *c) {
1890 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
1892 c->flags = size.flags;
1893 if(c->flags & PBaseSize) {
1894 c->basew = size.base_width;
1895 c->baseh = size.base_height;
1897 else if(c->flags & PMinSize) {
1898 c->basew = size.min_width;
1899 c->baseh = size.min_height;
1902 c->basew = c->baseh = 0;
1903 if(c->flags & PResizeInc) {
1904 c->incw = size.width_inc;
1905 c->inch = size.height_inc;
1908 c->incw = c->inch = 0;
1909 if(c->flags & PMaxSize) {
1910 c->maxw = size.max_width;
1911 c->maxh = size.max_height;
1914 c->maxw = c->maxh = 0;
1915 if(c->flags & PMinSize) {
1916 c->minw = size.min_width;
1917 c->minh = size.min_height;
1919 else if(c->flags & PBaseSize) {
1920 c->minw = size.base_width;
1921 c->minh = size.base_height;
1924 c->minw = c->minh = 0;
1925 if(c->flags & PAspect) {
1926 c->minax = size.min_aspect.x;
1927 c->maxax = size.max_aspect.x;
1928 c->minay = size.min_aspect.y;
1929 c->maxay = size.max_aspect.y;
1932 c->minax = c->maxax = c->minay = c->maxay = 0;
1933 c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
1934 && c->maxw == c->minw && c->maxh == c->minh);
1938 updatetitle(Client *c) {
1939 if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
1940 gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);
1944 updatewmhints(Client *c) {
1947 if((wmh = XGetWMHints(dpy, c->win))) {
1948 c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
1953 /* There's no way to check accesses to destroyed windows, thus those cases are
1954 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1955 * default error handler, which may call exit. */
1957 xerror(Display *dpy, XErrorEvent *ee) {
1958 if(ee->error_code == BadWindow
1959 || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
1960 || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
1961 || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
1962 || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
1963 || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
1964 || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
1965 || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
1967 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
1968 ee->request_code, ee->error_code);
1969 return xerrorxlib(dpy, ee); /* may call exit */
1973 xerrordummy(Display *dpy, XErrorEvent *ee) {
1977 /* Startup Error handler to check if another window manager
1978 * is already running. */
1980 xerrorstart(Display *dpy, XErrorEvent *ee) {
1986 view(const char *arg) {
1988 int tmp[LENGTH(tags)];
1990 for(i = 0; i < LENGTH(tags); i++)
1991 tmp[i] = (NULL == arg) ? selview->id : 0;
1992 tmp[idxoftag(arg)] = selview->id;
1993 if(memcmp(seltags, tmp, sizeof initags) != 0) {
1994 memcpy(prevtags, seltags, sizeof initags);
1995 memcpy(seltags, tmp, sizeof initags);
2001 viewprevtag(const char *arg) {
2002 static Bool tmp[LENGTH(tags)];
2004 memcpy(tmp, seltags, sizeof initags);
2005 memcpy(seltags, prevtags, sizeof initags);
2006 memcpy(prevtags, tmp, sizeof initags);
2011 zoom(const char *arg) {
2014 if(!sel || !dozoom || sel->isfloating)
2016 if(c == nexttiled(clients, getview(c)))
2017 if(!(c = nexttiled(c->next, getview(c))))
2026 selectview(const char *arg) {
2034 v = &views[i % nviews];
2035 XWarpPointer(dpy, None, root, 0, 0, 0, 0, v->wax+v->waw/2, v->way+v->wah/2);
2041 main(int argc, char *argv[]) {
2042 if(argc == 2 && !strcmp("-v", argv[1]))
2043 eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n");
2045 eprint("usage: dwm [-v]\n");
2047 setlocale(LC_CTYPE, "");
2048 if(!(dpy = XOpenDisplay(0)))
2049 eprint("dwm: cannot open display\n");