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 * The event handlers of dwm are organized in an array which is accessed
10 * whenever a new event has been fetched. This allows event dispatching
13 * Each child of the root window is called a client, except windows which have
14 * set the override_redirect flag. Clients are organized in a global
15 * linked client list, the focus history is remembered through a global
16 * stack list. Each client contains a bit array to indicate the tags of a
19 * Keys and tagging rules are organized as arrays and defined in config.h.
21 * To understand everything else, start reading main().
31 #include <sys/types.h>
33 #include <X11/cursorfont.h>
34 #include <X11/keysym.h>
35 #include <X11/Xatom.h>
37 #include <X11/Xproto.h>
38 #include <X11/Xutil.h>
40 #include <X11/extensions/Xinerama.h>
44 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
45 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
46 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
47 #define ISVISIBLE(x) (x->tags & tagset[seltags])
48 #define LENGTH(x) (sizeof x / sizeof x[0])
49 #define MAX(a, b) ((a) > (b) ? (a) : (b))
50 #define MIN(a, b) ((a) < (b) ? (a) : (b))
52 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
53 #define WIDTH(x) ((x)->w + 2 * (x)->bw)
54 #define HEIGHT(x) ((x)->h + 2 * (x)->bw)
55 #define TAGMASK ((int)((1LL << LENGTH(tags)) - 1))
56 #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height)
59 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
60 enum { ColBorder
, ColFG
, ColBG
, ColLast
}; /* color */
61 enum { NetSupported
, NetWMName
, NetLast
}; /* EWMH atoms */
62 enum { WMProtocols
, WMDelete
, WMState
, WMLast
}; /* default atoms */
63 enum { ClkTagBar
, ClkLtSymbol
, ClkStatusText
, ClkWinTitle
,
64 ClkClientWin
, ClkRootWin
, ClkLast
}; /* clicks */
77 void (*func
)(const Arg
*arg
);
81 typedef struct Client Client
;
86 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
89 Bool isfixed
, isfloating
, isurgent
;
97 unsigned long norm
[ColLast
];
98 unsigned long sel
[ColLast
];
108 } DC
; /* draw context */
113 void (*func
)(const Arg
*);
119 void (*arrange
)(void);
124 const char *instance
;
130 /* function declarations */
131 static void applyrules(Client
*c
);
132 static Bool
applysizehints(Client
*c
, int *x
, int *y
, int *w
, int *h
);
133 static void arrange(void);
134 static void attach(Client
*c
);
135 static void attachstack(Client
*c
);
136 static void buttonpress(XEvent
*e
);
137 static void checkotherwm(void);
138 static void cleanup(void);
139 static void clearurgent(Client
*c
);
140 static void configure(Client
*c
);
141 static void configurenotify(XEvent
*e
);
142 static void configurerequest(XEvent
*e
);
143 static void destroynotify(XEvent
*e
);
144 static void detach(Client
*c
);
145 static void detachstack(Client
*c
);
146 static void die(const char *errstr
, ...);
147 static void drawbar(void);
148 static void drawsquare(Bool filled
, Bool empty
, Bool invert
, unsigned long col
[ColLast
]);
149 static void drawtext(const char *text
, unsigned long col
[ColLast
], Bool invert
);
150 static void enternotify(XEvent
*e
);
151 static void expose(XEvent
*e
);
152 static void focus(Client
*c
);
153 static void focusin(XEvent
*e
);
154 static void focusstack(const Arg
*arg
);
155 static Client
*getclient(Window w
);
156 static unsigned long getcolor(const char *colstr
);
157 static long getstate(Window w
);
158 static Bool
gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
);
159 static void grabbuttons(Client
*c
, Bool focused
);
160 static void grabkeys(void);
161 static void initfont(const char *fontstr
);
162 static Bool
isprotodel(Client
*c
);
163 static void keypress(XEvent
*e
);
164 static void killclient(const Arg
*arg
);
165 static void manage(Window w
, XWindowAttributes
*wa
);
166 static void mappingnotify(XEvent
*e
);
167 static void maprequest(XEvent
*e
);
168 static void monocle(void);
169 static void movemouse(const Arg
*arg
);
170 static Client
*nexttiled(Client
*c
);
171 static void propertynotify(XEvent
*e
);
172 static void quit(const Arg
*arg
);
173 static void resize(Client
*c
, int x
, int y
, int w
, int h
);
174 static void resizemouse(const Arg
*arg
);
175 static void restack(void);
176 static void run(void);
177 static void scan(void);
178 static void setclientstate(Client
*c
, long state
);
179 static void setlayout(const Arg
*arg
);
180 static void setmfact(const Arg
*arg
);
181 static void setup(void);
182 static void showhide(Client
*c
);
183 static void sigchld(int signal
);
184 static void spawn(const Arg
*arg
);
185 static void tag(const Arg
*arg
);
186 static int textnw(const char *text
, unsigned int len
);
187 static void tile(void);
188 static void togglebar(const Arg
*arg
);
189 static void togglefloating(const Arg
*arg
);
190 static void toggletag(const Arg
*arg
);
191 static void toggleview(const Arg
*arg
);
192 static void unmanage(Client
*c
);
193 static void unmapnotify(XEvent
*e
);
194 static void updatebar(void);
195 static void updategeom(void);
196 static void updatenumlockmask(void);
197 static void updatesizehints(Client
*c
);
198 static void updatestatus(void);
199 static void updatetitle(Client
*c
);
200 static void updatewmhints(Client
*c
);
201 static void view(const Arg
*arg
);
202 static int xerror(Display
*dpy
, XErrorEvent
*ee
);
203 static int xerrordummy(Display
*dpy
, XErrorEvent
*ee
);
204 static int xerrorstart(Display
*dpy
, XErrorEvent
*ee
);
205 static void zoom(const Arg
*arg
);
208 static char stext
[256];
210 static int sx
, sy
, sw
, sh
; /* X display screen geometry x, y, width, height */
211 static int by
, bh
, blw
; /* bar geometry y, height and layout symbol width */
212 static int wx
, wy
, ww
, wh
; /* window area geometry x, y, width, height, bar excluded */
213 static unsigned int seltags
= 0, sellt
= 0;
214 static int (*xerrorxlib
)(Display
*, XErrorEvent
*);
215 static unsigned int numlockmask
= 0;
216 static 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 static Atom wmatom
[WMLast
], netatom
[NetLast
];
232 static Bool running
= True
;
233 static Client
*clients
= NULL
;
234 static Client
*sel
= NULL
;
235 static Client
*stack
= NULL
;
236 static Cursor cursor
[CurLast
];
239 static Layout
*lt
[] = { NULL
, NULL
};
240 static Window root
, barwin
;
241 /* configuration, allows nested code to access above variables */
244 /* compile-time check if all tags fit into an unsigned int bit array. */
245 struct NumTags
{ char limitexceeded
[sizeof(unsigned int) * 8 < LENGTH(tags
) ? -1 : 1]; };
247 /* function implementations */
249 applyrules(Client
*c
) {
252 XClassHint ch
= { 0 };
255 c
->isfloating
= c
->tags
= 0;
256 if(XGetClassHint(dpy
, c
->win
, &ch
)) {
257 for(i
= 0; i
< LENGTH(rules
); i
++) {
259 if((!r
->title
|| strstr(c
->name
, r
->title
))
260 && (!r
->class || (ch
.res_class
&& strstr(ch
.res_class
, r
->class)))
261 && (!r
->instance
|| (ch
.res_name
&& strstr(ch
.res_name
, r
->instance
)))) {
262 c
->isfloating
= r
->isfloating
;
271 c
->tags
= c
->tags
& TAGMASK
? c
->tags
& TAGMASK
: tagset
[seltags
];
275 applysizehints(Client
*c
, int *x
, int *y
, int *w
, int *h
) {
278 /* set minimum possible */
286 if(*x
+ *w
+ 2 * c
->bw
< sx
)
288 if(*y
+ *h
+ 2 * c
->bw
< sy
)
295 if(resizehints
|| c
->isfloating
) {
296 /* see last two sentences in ICCCM 4.1.2.3 */
297 baseismin
= c
->basew
== c
->minw
&& c
->baseh
== c
->minh
;
299 if(!baseismin
) { /* temporarily remove base dimensions */
304 /* adjust for aspect limits */
305 if(c
->mina
> 0 && c
->maxa
> 0) {
306 if(c
->maxa
< (float)*w
/ *h
)
308 else if(c
->mina
< (float)*h
/ *w
)
312 if(baseismin
) { /* increment calculation requires this */
317 /* adjust for increment value */
323 /* restore base dimensions */
327 *w
= MAX(*w
, c
->minw
);
328 *h
= MAX(*h
, c
->minh
);
331 *w
= MIN(*w
, c
->maxw
);
334 *h
= MIN(*h
, c
->maxh
);
336 return *x
!= c
->x
|| *y
!= c
->y
|| *w
!= c
->w
|| *h
!= c
->h
;
343 if(lt
[sellt
]->arrange
)
344 lt
[sellt
]->arrange();
355 attachstack(Client
*c
) {
361 buttonpress(XEvent
*e
) {
362 unsigned int i
, x
, click
;
365 XButtonPressedEvent
*ev
= &e
->xbutton
;
368 if(ev
->window
== barwin
) {
370 do x
+= TEXTW(tags
[i
]); while(ev
->x
>= x
&& ++i
< LENGTH(tags
));
371 if(i
< LENGTH(tags
)) {
375 else if(ev
->x
< x
+ blw
)
377 else if(ev
->x
> wx
+ ww
- TEXTW(stext
))
378 click
= ClkStatusText
;
382 else if((c
= getclient(ev
->window
))) {
384 click
= ClkClientWin
;
387 for(i
= 0; i
< LENGTH(buttons
); i
++)
388 if(click
== buttons
[i
].click
&& buttons
[i
].func
&& buttons
[i
].button
== ev
->button
389 && CLEANMASK(buttons
[i
].mask
) == CLEANMASK(ev
->state
))
390 buttons
[i
].func(click
== ClkTagBar
&& buttons
[i
].arg
.i
== 0 ? &arg
: &buttons
[i
].arg
);
396 xerrorxlib
= XSetErrorHandler(xerrorstart
);
398 /* this causes an error if some other window manager is running */
399 XSelectInput(dpy
, DefaultRootWindow(dpy
), SubstructureRedirectMask
);
402 die("dwm: another window manager is already running\n");
403 XSetErrorHandler(xerror
);
410 Layout foo
= { "", NULL
};
417 XFreeFontSet(dpy
, dc
.font
.set
);
419 XFreeFont(dpy
, dc
.font
.xfont
);
420 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
421 XFreePixmap(dpy
, dc
.drawable
);
423 XFreeCursor(dpy
, cursor
[CurNormal
]);
424 XFreeCursor(dpy
, cursor
[CurResize
]);
425 XFreeCursor(dpy
, cursor
[CurMove
]);
426 XDestroyWindow(dpy
, barwin
);
428 XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
432 clearurgent(Client
*c
) {
436 if(!(wmh
= XGetWMHints(dpy
, c
->win
)))
438 wmh
->flags
&= ~XUrgencyHint
;
439 XSetWMHints(dpy
, c
->win
, wmh
);
444 configure(Client
*c
) {
447 ce
.type
= ConfigureNotify
;
455 ce
.border_width
= c
->bw
;
457 ce
.override_redirect
= False
;
458 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
462 configurenotify(XEvent
*e
) {
463 XConfigureEvent
*ev
= &e
->xconfigure
;
465 if(ev
->window
== root
&& (ev
->width
!= sw
|| ev
->height
!= sh
)) {
475 configurerequest(XEvent
*e
) {
477 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
480 if((c
= getclient(ev
->window
))) {
481 if(ev
->value_mask
& CWBorderWidth
)
482 c
->bw
= ev
->border_width
;
483 else if(c
->isfloating
|| !lt
[sellt
]->arrange
) {
484 if(ev
->value_mask
& CWX
)
486 if(ev
->value_mask
& CWY
)
488 if(ev
->value_mask
& CWWidth
)
490 if(ev
->value_mask
& CWHeight
)
492 if((c
->x
- sx
+ c
->w
) > sw
&& c
->isfloating
)
493 c
->x
= sx
+ (sw
/ 2 - c
->w
/ 2); /* center in x direction */
494 if((c
->y
- sy
+ c
->h
) > sh
&& c
->isfloating
)
495 c
->y
= sy
+ (sh
/ 2 - c
->h
/ 2); /* center in y direction */
496 if((ev
->value_mask
& (CWX
|CWY
)) && !(ev
->value_mask
& (CWWidth
|CWHeight
)))
499 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
507 wc
.width
= ev
->width
;
508 wc
.height
= ev
->height
;
509 wc
.border_width
= ev
->border_width
;
510 wc
.sibling
= ev
->above
;
511 wc
.stack_mode
= ev
->detail
;
512 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
518 destroynotify(XEvent
*e
) {
520 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
522 if((c
= getclient(ev
->window
)))
530 for(tc
= &clients
; *tc
&& *tc
!= c
; tc
= &(*tc
)->next
);
535 detachstack(Client
*c
) {
538 for(tc
= &stack
; *tc
&& *tc
!= c
; tc
= &(*tc
)->snext
);
543 die(const char *errstr
, ...) {
546 va_start(ap
, errstr
);
547 vfprintf(stderr
, errstr
, ap
);
555 unsigned int i
, occ
= 0, urg
= 0;
559 for(c
= clients
; c
; c
= c
->next
) {
566 for(i
= 0; i
< LENGTH(tags
); i
++) {
567 dc
.w
= TEXTW(tags
[i
]);
568 col
= tagset
[seltags
] & 1 << i
? dc
.sel
: dc
.norm
;
569 drawtext(tags
[i
], col
, urg
& 1 << i
);
570 drawsquare(sel
&& sel
->tags
& 1 << i
, occ
& 1 << i
, urg
& 1 << i
, col
);
575 drawtext(lt
[sellt
]->symbol
, dc
.norm
, False
);
586 drawtext(stext
, dc
.norm
, False
);
587 if((dc
.w
= dc
.x
- x
) > bh
) {
590 drawtext(sel
->name
, dc
.sel
, False
);
591 drawsquare(sel
->isfixed
, sel
->isfloating
, False
, dc
.sel
);
594 drawtext(NULL
, dc
.norm
, False
);
596 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, ww
, bh
, 0, 0);
601 drawsquare(Bool filled
, Bool empty
, Bool invert
, unsigned long col
[ColLast
]) {
604 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
606 gcv
.foreground
= col
[invert
? ColBG
: ColFG
];
607 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
608 x
= (dc
.font
.ascent
+ dc
.font
.descent
+ 2) / 4;
612 r
.width
= r
.height
= x
+ 1;
613 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
616 r
.width
= r
.height
= x
;
617 XDrawRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
622 drawtext(const char *text
, unsigned long col
[ColLast
], Bool invert
) {
624 int i
, x
, y
, h
, len
, olen
;
625 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
627 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColFG
: ColBG
]);
628 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
632 h
= dc
.font
.ascent
+ dc
.font
.descent
;
633 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
635 /* shorten text if necessary */
636 for(len
= MIN(olen
, sizeof buf
); len
&& textnw(text
, len
) > dc
.w
- h
; len
--);
639 memcpy(buf
, text
, len
);
641 for(i
= len
; i
&& i
> len
- 3; buf
[--i
] = '.');
642 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColBG
: ColFG
]);
644 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
646 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
650 enternotify(XEvent
*e
) {
652 XCrossingEvent
*ev
= &e
->xcrossing
;
654 if((ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
) && ev
->window
!= root
)
656 if((c
= getclient(ev
->window
)))
664 XExposeEvent
*ev
= &e
->xexpose
;
666 if(ev
->count
== 0 && (ev
->window
== barwin
))
672 if(!c
|| !ISVISIBLE(c
))
673 for(c
= stack
; c
&& !ISVISIBLE(c
); c
= c
->snext
);
674 if(sel
&& sel
!= c
) {
675 grabbuttons(sel
, False
);
676 XSetWindowBorder(dpy
, sel
->win
, dc
.norm
[ColBorder
]);
683 grabbuttons(c
, True
);
684 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBorder
]);
685 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
688 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
694 focusin(XEvent
*e
) { /* there are some broken focus acquiring clients */
695 XFocusChangeEvent
*ev
= &e
->xfocus
;
697 if(sel
&& ev
->window
!= sel
->win
)
698 XSetInputFocus(dpy
, sel
->win
, RevertToPointerRoot
, CurrentTime
);
702 focusstack(const Arg
*arg
) {
703 Client
*c
= NULL
, *i
;
708 for(c
= sel
->next
; c
&& !ISVISIBLE(c
); c
= c
->next
);
710 for(c
= clients
; c
&& !ISVISIBLE(c
); c
= c
->next
);
713 for(i
= clients
; i
!= sel
; i
= i
->next
)
717 for(; i
; i
= i
->next
)
728 getclient(Window w
) {
731 for(c
= clients
; c
&& c
->win
!= w
; c
= c
->next
);
736 getcolor(const char *colstr
) {
737 Colormap cmap
= DefaultColormap(dpy
, screen
);
740 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
741 die("error, cannot allocate color '%s'\n", colstr
);
749 unsigned char *p
= NULL
;
750 unsigned long n
, extra
;
753 status
= XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
754 &real
, &format
, &n
, &extra
, (unsigned char **)&p
);
755 if(status
!= Success
)
764 gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
) {
769 if(!text
|| size
== 0)
772 XGetTextProperty(dpy
, w
, &name
, atom
);
775 if(name
.encoding
== XA_STRING
)
776 strncpy(text
, (char *)name
.value
, size
- 1);
778 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
780 strncpy(text
, *list
, size
- 1);
781 XFreeStringList(list
);
784 text
[size
- 1] = '\0';
790 grabbuttons(Client
*c
, Bool focused
) {
794 unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
795 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
797 for(i
= 0; i
< LENGTH(buttons
); i
++)
798 if(buttons
[i
].click
== ClkClientWin
)
799 for(j
= 0; j
< LENGTH(modifiers
); j
++)
800 XGrabButton(dpy
, buttons
[i
].button
, buttons
[i
].mask
| modifiers
[j
], c
->win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
802 XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
,
803 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
812 unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
815 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
816 for(i
= 0; i
< LENGTH(keys
); i
++) {
817 if((code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
)))
818 for(j
= 0; j
< LENGTH(modifiers
); j
++)
819 XGrabKey(dpy
, code
, keys
[i
].mod
| modifiers
[j
], root
,
820 True
, GrabModeAsync
, GrabModeAsync
);
826 initfont(const char *fontstr
) {
827 char *def
, **missing
;
831 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
834 fprintf(stderr
, "dwm: missing fontset: %s\n", missing
[n
]);
835 XFreeStringList(missing
);
838 XFontSetExtents
*font_extents
;
839 XFontStruct
**xfonts
;
841 dc
.font
.ascent
= dc
.font
.descent
= 0;
842 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
843 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
844 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
845 dc
.font
.ascent
= MAX(dc
.font
.ascent
, (*xfonts
)->ascent
);
846 dc
.font
.descent
= MAX(dc
.font
.descent
,(*xfonts
)->descent
);
851 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
))
852 && !(dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed")))
853 die("error, cannot load font: '%s'\n", fontstr
);
854 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
855 dc
.font
.descent
= dc
.font
.xfont
->descent
;
857 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
861 isprotodel(Client
*c
) {
866 if(XGetWMProtocols(dpy
, c
->win
, &protocols
, &n
)) {
867 for(i
= 0; !ret
&& i
< n
; i
++)
868 if(protocols
[i
] == wmatom
[WMDelete
])
876 keypress(XEvent
*e
) {
882 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
883 for(i
= 0; i
< LENGTH(keys
); i
++)
884 if(keysym
== keys
[i
].keysym
885 && CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
)
887 keys
[i
].func(&(keys
[i
].arg
));
891 killclient(const Arg
*arg
) {
896 if(isprotodel(sel
)) {
897 ev
.type
= ClientMessage
;
898 ev
.xclient
.window
= sel
->win
;
899 ev
.xclient
.message_type
= wmatom
[WMProtocols
];
900 ev
.xclient
.format
= 32;
901 ev
.xclient
.data
.l
[0] = wmatom
[WMDelete
];
902 ev
.xclient
.data
.l
[1] = CurrentTime
;
903 XSendEvent(dpy
, sel
->win
, False
, NoEventMask
, &ev
);
906 XKillClient(dpy
, sel
->win
);
910 manage(Window w
, XWindowAttributes
*wa
) {
912 Client
*c
, *t
= NULL
;
916 if(!(c
= malloc(sizeof(Client
))))
917 die("fatal: could not malloc() %u bytes\n", sizeof(Client
));
926 c
->oldbw
= wa
->border_width
;
927 if(c
->w
== sw
&& c
->h
== sh
) {
933 if(c
->x
+ WIDTH(c
) > sx
+ sw
)
934 c
->x
= sx
+ sw
- WIDTH(c
);
935 if(c
->y
+ HEIGHT(c
) > sy
+ sh
)
936 c
->y
= sy
+ sh
- HEIGHT(c
);
937 c
->x
= MAX(c
->x
, sx
);
938 /* only fix client y-offset, if the client center might cover the bar */
939 c
->y
= MAX(c
->y
, ((by
== 0) && (c
->x
+ (c
->w
/ 2) >= wx
) && (c
->x
+ (c
->w
/ 2) < wx
+ ww
)) ? bh
: sy
);
943 wc
.border_width
= c
->bw
;
944 XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
945 XSetWindowBorder(dpy
, w
, dc
.norm
[ColBorder
]);
946 configure(c
); /* propagates border_width, if size doesn't change */
948 XSelectInput(dpy
, w
, EnterWindowMask
|FocusChangeMask
|PropertyChangeMask
|StructureNotifyMask
);
949 grabbuttons(c
, False
);
951 if(XGetTransientForHint(dpy
, w
, &trans
))
952 t
= getclient(trans
);
958 c
->isfloating
= trans
!= None
|| c
->isfixed
;
960 XRaiseWindow(dpy
, c
->win
);
963 XMoveResizeWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
, c
->w
, c
->h
); /* some windows require this */
964 XMapWindow(dpy
, c
->win
);
965 setclientstate(c
, NormalState
);
970 mappingnotify(XEvent
*e
) {
971 XMappingEvent
*ev
= &e
->xmapping
;
973 XRefreshKeyboardMapping(ev
);
974 if(ev
->request
== MappingKeyboard
)
979 maprequest(XEvent
*e
) {
980 static XWindowAttributes wa
;
981 XMapRequestEvent
*ev
= &e
->xmaprequest
;
983 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
985 if(wa
.override_redirect
)
987 if(!getclient(ev
->window
))
988 manage(ev
->window
, &wa
);
995 for(c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
)) {
996 resize(c
, wx
, wy
, ww
- 2 * c
->bw
, wh
- 2 * c
->bw
);
1001 movemouse(const Arg
*arg
) {
1002 int x
, y
, ocx
, ocy
, di
, nx
, ny
;
1013 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1014 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
1016 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x
, &y
, &di
, &di
, &dui
);
1018 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1020 case ConfigureRequest
:
1023 handler
[ev
.type
](&ev
);
1026 nx
= ocx
+ (ev
.xmotion
.x
- x
);
1027 ny
= ocy
+ (ev
.xmotion
.y
- y
);
1028 if(snap
&& nx
>= wx
&& nx
<= wx
+ ww
1029 && ny
>= wy
&& ny
<= wy
+ wh
) {
1030 if(abs(wx
- nx
) < snap
)
1032 else if(abs((wx
+ ww
) - (nx
+ WIDTH(c
))) < snap
)
1033 nx
= wx
+ ww
- WIDTH(c
);
1034 if(abs(wy
- ny
) < snap
)
1036 else if(abs((wy
+ wh
) - (ny
+ HEIGHT(c
))) < snap
)
1037 ny
= wy
+ wh
- HEIGHT(c
);
1038 if(!c
->isfloating
&& lt
[sellt
]->arrange
&& (abs(nx
- c
->x
) > snap
|| abs(ny
- c
->y
) > snap
))
1039 togglefloating(NULL
);
1041 if(!lt
[sellt
]->arrange
|| c
->isfloating
)
1042 resize(c
, nx
, ny
, c
->w
, c
->h
);
1046 while(ev
.type
!= ButtonRelease
);
1047 XUngrabPointer(dpy
, CurrentTime
);
1051 nexttiled(Client
*c
) {
1052 for(; c
&& (c
->isfloating
|| !ISVISIBLE(c
)); c
= c
->next
);
1057 propertynotify(XEvent
*e
) {
1060 XPropertyEvent
*ev
= &e
->xproperty
;
1062 if((ev
->window
== root
) && (ev
->atom
== XA_WM_NAME
))
1064 else if(ev
->state
== PropertyDelete
)
1065 return; /* ignore */
1066 else if((c
= getclient(ev
->window
))) {
1069 case XA_WM_TRANSIENT_FOR
:
1070 XGetTransientForHint(dpy
, c
->win
, &trans
);
1071 if(!c
->isfloating
&& (c
->isfloating
= (getclient(trans
) != NULL
)))
1074 case XA_WM_NORMAL_HINTS
:
1082 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
1091 quit(const Arg
*arg
) {
1096 resize(Client
*c
, int x
, int y
, int w
, int h
) {
1099 if(applysizehints(c
, &x
, &y
, &w
, &h
)) {
1102 c
->w
= wc
.width
= w
;
1103 c
->h
= wc
.height
= h
;
1104 wc
.border_width
= c
->bw
;
1105 XConfigureWindow(dpy
, c
->win
,
1106 CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
, &wc
);
1113 resizemouse(const Arg
*arg
) {
1124 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1125 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
1127 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1129 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1131 case ConfigureRequest
:
1134 handler
[ev
.type
](&ev
);
1137 nw
= MAX(ev
.xmotion
.x
- ocx
- 2 * c
->bw
+ 1, 1);
1138 nh
= MAX(ev
.xmotion
.y
- ocy
- 2 * c
->bw
+ 1, 1);
1140 if(snap
&& nw
>= wx
&& nw
<= wx
+ ww
1141 && nh
>= wy
&& nh
<= wy
+ wh
) {
1142 if(!c
->isfloating
&& lt
[sellt
]->arrange
1143 && (abs(nw
- c
->w
) > snap
|| abs(nh
- c
->h
) > snap
))
1144 togglefloating(NULL
);
1146 if(!lt
[sellt
]->arrange
|| c
->isfloating
)
1147 resize(c
, c
->x
, c
->y
, nw
, nh
);
1151 while(ev
.type
!= ButtonRelease
);
1152 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1153 XUngrabPointer(dpy
, CurrentTime
);
1154 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1166 if(sel
->isfloating
|| !lt
[sellt
]->arrange
)
1167 XRaiseWindow(dpy
, sel
->win
);
1168 if(lt
[sellt
]->arrange
) {
1169 wc
.stack_mode
= Below
;
1170 wc
.sibling
= barwin
;
1171 for(c
= stack
; c
; c
= c
->snext
)
1172 if(!c
->isfloating
&& ISVISIBLE(c
)) {
1173 XConfigureWindow(dpy
, c
->win
, CWSibling
|CWStackMode
, &wc
);
1174 wc
.sibling
= c
->win
;
1178 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1185 /* main event loop */
1187 while(running
&& !XNextEvent(dpy
, &ev
)) {
1188 if(handler
[ev
.type
])
1189 (handler
[ev
.type
])(&ev
); /* call handler */
1195 unsigned int i
, num
;
1196 Window d1
, d2
, *wins
= NULL
;
1197 XWindowAttributes wa
;
1199 if(XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
1200 for(i
= 0; i
< num
; i
++) {
1201 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
1202 || wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
1204 if(wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
1205 manage(wins
[i
], &wa
);
1207 for(i
= 0; i
< num
; i
++) { /* now the transients */
1208 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
1210 if(XGetTransientForHint(dpy
, wins
[i
], &d1
)
1211 && (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
1212 manage(wins
[i
], &wa
);
1220 setclientstate(Client
*c
, long state
) {
1221 long data
[] = {state
, None
};
1223 XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
1224 PropModeReplace
, (unsigned char *)data
, 2);
1228 setlayout(const Arg
*arg
) {
1229 if(!arg
|| !arg
->v
|| arg
->v
!= lt
[sellt
])
1232 lt
[sellt
] = (Layout
*)arg
->v
;
1239 /* arg > 1.0 will set mfact absolutly */
1241 setmfact(const Arg
*arg
) {
1244 if(!arg
|| !lt
[sellt
]->arrange
)
1246 f
= arg
->f
< 1.0 ? arg
->f
+ mfact
: arg
->f
- 1.0;
1247 if(f
< 0.1 || f
> 0.9)
1257 XSetWindowAttributes wa
;
1260 screen
= DefaultScreen(dpy
);
1261 root
= RootWindow(dpy
, screen
);
1265 sw
= DisplayWidth(dpy
, screen
);
1266 sh
= DisplayHeight(dpy
, screen
);
1267 bh
= dc
.h
= dc
.font
.height
+ 2;
1268 lt
[0] = &layouts
[0];
1269 lt
[1] = &layouts
[1 % LENGTH(layouts
)];
1273 wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
1274 wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
1275 wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
1276 netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
1277 netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
1280 wa
.cursor
= cursor
[CurNormal
] = XCreateFontCursor(dpy
, XC_left_ptr
);
1281 cursor
[CurResize
] = XCreateFontCursor(dpy
, XC_sizing
);
1282 cursor
[CurMove
] = XCreateFontCursor(dpy
, XC_fleur
);
1284 /* init appearance */
1285 dc
.norm
[ColBorder
] = getcolor(normbordercolor
);
1286 dc
.norm
[ColBG
] = getcolor(normbgcolor
);
1287 dc
.norm
[ColFG
] = getcolor(normfgcolor
);
1288 dc
.sel
[ColBorder
] = getcolor(selbordercolor
);
1289 dc
.sel
[ColBG
] = getcolor(selbgcolor
);
1290 dc
.sel
[ColFG
] = getcolor(selfgcolor
);
1291 dc
.drawable
= XCreatePixmap(dpy
, root
, DisplayWidth(dpy
, screen
), bh
, DefaultDepth(dpy
, screen
));
1292 dc
.gc
= XCreateGC(dpy
, root
, 0, NULL
);
1293 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
1295 XSetFont(dpy
, dc
.gc
, dc
.font
.xfont
->fid
);
1298 for(blw
= i
= 0; LENGTH(layouts
) > 1 && i
< LENGTH(layouts
); i
++) {
1299 w
= TEXTW(layouts
[i
].symbol
);
1303 wa
.override_redirect
= True
;
1304 wa
.background_pixmap
= ParentRelative
;
1305 wa
.event_mask
= ButtonPressMask
|ExposureMask
;
1307 barwin
= XCreateWindow(dpy
, root
, wx
, by
, ww
, bh
, 0, DefaultDepth(dpy
, screen
),
1308 CopyFromParent
, DefaultVisual(dpy
, screen
),
1309 CWOverrideRedirect
|CWBackPixmap
|CWEventMask
, &wa
);
1310 XDefineCursor(dpy
, barwin
, cursor
[CurNormal
]);
1311 XMapRaised(dpy
, barwin
);
1314 /* EWMH support per view */
1315 XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
1316 PropModeReplace
, (unsigned char *) netatom
, NetLast
);
1318 /* select for events */
1319 wa
.event_mask
= SubstructureRedirectMask
|SubstructureNotifyMask
|ButtonPressMask
1320 |EnterWindowMask
|LeaveWindowMask
|StructureNotifyMask
1321 |PropertyChangeMask
;
1322 XChangeWindowAttributes(dpy
, root
, CWEventMask
|CWCursor
, &wa
);
1323 XSelectInput(dpy
, root
, wa
.event_mask
);
1329 showhide(Client
*c
) {
1332 if(ISVISIBLE(c
)) { /* show clients top down */
1333 XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
1334 if(!lt
[sellt
]->arrange
|| c
->isfloating
)
1335 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
);
1338 else { /* hide clients bottom up */
1340 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
1346 sigchld(int signal
) {
1347 while(0 < waitpid(-1, NULL
, WNOHANG
));
1351 spawn(const Arg
*arg
) {
1352 signal(SIGCHLD
, sigchld
);
1355 close(ConnectionNumber(dpy
));
1357 execvp(((char **)arg
->v
)[0], (char **)arg
->v
);
1358 fprintf(stderr
, "dwm: execvp %s", ((char **)arg
->v
)[0]);
1365 tag(const Arg
*arg
) {
1366 if(sel
&& arg
->ui
& TAGMASK
) {
1367 sel
->tags
= arg
->ui
& TAGMASK
;
1373 textnw(const char *text
, unsigned int len
) {
1377 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
1380 return XTextWidth(dc
.font
.xfont
, text
, len
);
1389 for(n
= 0, c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
), n
++);
1394 c
= nexttiled(clients
);
1396 resize(c
, wx
, wy
, (n
== 1 ? ww
: mw
) - 2 * c
->bw
, wh
- 2 * c
->bw
);
1402 x
= (wx
+ mw
> c
->x
+ c
->w
) ? c
->x
+ c
->w
+ 2 * c
->bw
: wx
+ mw
;
1404 w
= (wx
+ mw
> c
->x
+ c
->w
) ? wx
+ ww
- x
: ww
- mw
;
1409 for(i
= 0, c
= nexttiled(c
->next
); c
; c
= nexttiled(c
->next
), i
++) {
1410 resize(c
, x
, y
, w
- 2 * c
->bw
, /* remainder */ ((i
+ 1 == n
)
1411 ? wy
+ wh
- y
- 2 * c
->bw
: h
- 2 * c
->bw
));
1413 y
= c
->y
+ HEIGHT(c
);
1418 togglebar(const Arg
*arg
) {
1426 togglefloating(const Arg
*arg
) {
1429 sel
->isfloating
= !sel
->isfloating
|| sel
->isfixed
;
1431 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
);
1436 toggletag(const Arg
*arg
) {
1442 mask
= sel
->tags
^ (arg
->ui
& TAGMASK
);
1450 toggleview(const Arg
*arg
) {
1451 unsigned int mask
= tagset
[seltags
] ^ (arg
->ui
& TAGMASK
);
1454 tagset
[seltags
] = mask
;
1460 unmanage(Client
*c
) {
1463 wc
.border_width
= c
->oldbw
;
1464 /* The server grab construct avoids race conditions. */
1466 XSetErrorHandler(xerrordummy
);
1467 XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
1472 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1473 setclientstate(c
, WithdrawnState
);
1476 XSetErrorHandler(xerror
);
1482 unmapnotify(XEvent
*e
) {
1484 XUnmapEvent
*ev
= &e
->xunmap
;
1486 if((c
= getclient(ev
->window
)))
1492 if(dc
.drawable
!= 0)
1493 XFreePixmap(dpy
, dc
.drawable
);
1494 dc
.drawable
= XCreatePixmap(dpy
, root
, ww
, bh
, DefaultDepth(dpy
, screen
));
1495 XMoveResizeWindow(dpy
, barwin
, wx
, by
, ww
, bh
);
1502 XineramaScreenInfo
*info
= NULL
;
1504 /* window area geometry */
1505 if(XineramaIsActive(dpy
) && (info
= XineramaQueryScreens(dpy
, &n
))) {
1510 if(XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x
, &y
, &di
, &di
, &dui
))
1511 for(i
= 0; i
< n
; i
++)
1512 if(INRECT(x
, y
, info
[i
].x_org
, info
[i
].y_org
, info
[i
].width
, info
[i
].height
))
1516 wy
= showbar
&& topbar
? info
[i
].y_org
+ bh
: info
[i
].y_org
;
1518 wh
= showbar
? info
[i
].height
- bh
: info
[i
].height
;
1525 wy
= showbar
&& topbar
? sy
+ bh
: sy
;
1527 wh
= showbar
? sh
- bh
: sh
;
1531 by
= showbar
? (topbar
? wy
- bh
: wy
+ wh
) : -bh
;
1535 updatenumlockmask(void) {
1537 XModifierKeymap
*modmap
;
1540 modmap
= XGetModifierMapping(dpy
);
1541 for(i
= 0; i
< 8; i
++)
1542 for(j
= 0; j
< modmap
->max_keypermod
; j
++)
1543 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
] == XKeysymToKeycode(dpy
, XK_Num_Lock
))
1544 numlockmask
= (1 << i
);
1545 XFreeModifiermap(modmap
);
1549 updatesizehints(Client
*c
) {
1553 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
))
1554 /* size is uninitialized, ensure that size.flags aren't used */
1556 if(size
.flags
& PBaseSize
) {
1557 c
->basew
= size
.base_width
;
1558 c
->baseh
= size
.base_height
;
1560 else if(size
.flags
& PMinSize
) {
1561 c
->basew
= size
.min_width
;
1562 c
->baseh
= size
.min_height
;
1565 c
->basew
= c
->baseh
= 0;
1566 if(size
.flags
& PResizeInc
) {
1567 c
->incw
= size
.width_inc
;
1568 c
->inch
= size
.height_inc
;
1571 c
->incw
= c
->inch
= 0;
1572 if(size
.flags
& PMaxSize
) {
1573 c
->maxw
= size
.max_width
;
1574 c
->maxh
= size
.max_height
;
1577 c
->maxw
= c
->maxh
= 0;
1578 if(size
.flags
& PMinSize
) {
1579 c
->minw
= size
.min_width
;
1580 c
->minh
= size
.min_height
;
1582 else if(size
.flags
& PBaseSize
) {
1583 c
->minw
= size
.base_width
;
1584 c
->minh
= size
.base_height
;
1587 c
->minw
= c
->minh
= 0;
1588 if(size
.flags
& PAspect
) {
1589 c
->mina
= (float)size
.min_aspect
.y
/ (float)size
.min_aspect
.x
;
1590 c
->maxa
= (float)size
.max_aspect
.x
/ (float)size
.max_aspect
.y
;
1593 c
->maxa
= c
->mina
= 0.0;
1594 c
->isfixed
= (c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
1595 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
1599 updatetitle(Client
*c
) {
1600 if(!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
1601 gettextprop(c
->win
, XA_WM_NAME
, c
->name
, sizeof c
->name
);
1606 if(!gettextprop(root
, XA_WM_NAME
, stext
, sizeof(stext
)))
1607 strcpy(stext
, "dwm-"VERSION
);
1612 updatewmhints(Client
*c
) {
1615 if((wmh
= XGetWMHints(dpy
, c
->win
))) {
1616 if(c
== sel
&& wmh
->flags
& XUrgencyHint
) {
1617 wmh
->flags
&= ~XUrgencyHint
;
1618 XSetWMHints(dpy
, c
->win
, wmh
);
1621 c
->isurgent
= (wmh
->flags
& XUrgencyHint
) ? True
: False
;
1628 view(const Arg
*arg
) {
1629 if((arg
->ui
& TAGMASK
) == tagset
[seltags
])
1631 seltags
^= 1; /* toggle sel tagset */
1632 if(arg
->ui
& TAGMASK
)
1633 tagset
[seltags
] = arg
->ui
& TAGMASK
;
1637 /* There's no way to check accesses to destroyed windows, thus those cases are
1638 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1639 * default error handler, which may call exit. */
1641 xerror(Display
*dpy
, XErrorEvent
*ee
) {
1642 if(ee
->error_code
== BadWindow
1643 || (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
1644 || (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
1645 || (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
1646 || (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
1647 || (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
1648 || (ee
->request_code
== X_GrabButton
&& ee
->error_code
== BadAccess
)
1649 || (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
1650 || (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
1652 fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
1653 ee
->request_code
, ee
->error_code
);
1654 return xerrorxlib(dpy
, ee
); /* may call exit */
1658 xerrordummy(Display
*dpy
, XErrorEvent
*ee
) {
1662 /* Startup Error handler to check if another window manager
1663 * is already running. */
1665 xerrorstart(Display
*dpy
, XErrorEvent
*ee
) {
1671 zoom(const Arg
*arg
) {
1674 if(!lt
[sellt
]->arrange
|| lt
[sellt
]->arrange
== monocle
|| (sel
&& sel
->isfloating
))
1676 if(c
== nexttiled(clients
))
1677 if(!c
|| !(c
= nexttiled(c
->next
)))
1686 main(int argc
, char *argv
[]) {
1687 if(argc
== 2 && !strcmp("-v", argv
[1]))
1688 die("dwm-"VERSION
", © 2006-2009 dwm engineers, see LICENSE for details\n");
1690 die("usage: dwm [-v]\n");
1692 if(!setlocale(LC_CTYPE
, "") || !XSupportsLocale())
1693 fputs("warning: no locale support\n", stderr
);
1695 if(!(dpy
= XOpenDisplay(NULL
)))
1696 die("dwm: cannot open display\n");