Xinqi Bao's Git
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 a bit array to indicate the tags of a
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>
36 #include <X11/cursorfont.h>
37 #include <X11/keysym.h>
38 #include <X11/Xatom.h>
40 #include <X11/Xproto.h>
41 #include <X11/Xutil.h>
43 #include <X11/extensions/Xinerama.h>
47 #define MAX(a, b) ((a) > (b) ? (a) : (b))
48 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
50 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
51 #define LENGTH(x) (sizeof x / sizeof x[0])
53 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
54 #define TAGMASK ((int)((1LL << LENGTH(tags)) - 1))
55 #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height)
58 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
59 enum { ColBorder
, ColFG
, ColBG
, ColLast
}; /* color */
60 enum { NetSupported
, NetWMName
, NetLast
}; /* EWMH atoms */
61 enum { WMProtocols
, WMDelete
, WMName
, WMState
, WMLast
};/* default atoms */
62 enum { ClkLtSymbol
= 64, ClkStatusText
, ClkWinTitle
,
63 ClkClientWin
, ClkLast
}; /* clicks */
66 typedef unsigned int uint
;
67 typedef unsigned long ulong
;
80 void (*func
)(const Arg
*arg
);
84 typedef struct Client Client
;
88 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
91 Bool isbanned
, isfixed
, isfloating
, ismoved
, isurgent
;
111 } DC
; /* draw context */
116 void (*func
)(const Arg
*);
122 void (*arrange
)(void);
127 const char *instance
;
133 /* function declarations */
134 static void applyrules(Client
*c
);
135 static void arrange(void);
136 static void attach(Client
*c
);
137 static void attachstack(Client
*c
);
138 static void buttonpress(XEvent
*e
);
139 static void checkotherwm(void);
140 static void cleanup(void);
141 static void configure(Client
*c
);
142 static void configurenotify(XEvent
*e
);
143 static void configurerequest(XEvent
*e
);
144 static void destroynotify(XEvent
*e
);
145 static void detach(Client
*c
);
146 static void detachstack(Client
*c
);
147 static void drawbar(void);
148 static void drawsquare(Bool filled
, Bool empty
, Bool invert
, ulong col
[ColLast
]);
149 static void drawtext(const char *text
, ulong col
[ColLast
], Bool invert
);
150 static void enternotify(XEvent
*e
);
151 static void eprint(const char *errstr
, ...);
152 static void expose(XEvent
*e
);
153 static void focus(Client
*c
);
154 static void focusin(XEvent
*e
);
155 static void focusstack(const Arg
*arg
);
156 static Client
*getclient(Window w
);
157 static ulong
getcolor(const char *colstr
);
158 static long getstate(Window w
);
159 static Bool
gettextprop(Window w
, Atom atom
, char *text
, uint size
);
160 static void grabbuttons(Client
*c
, Bool focused
);
161 static void grabkeys(void);
162 static void initfont(const char *fontstr
);
163 static Bool
isoccupied(uint t
);
164 static Bool
isprotodel(Client
*c
);
165 static Bool
isurgent(uint t
);
166 static void keypress(XEvent
*e
);
167 static void killclient(const Arg
*arg
);
168 static void manage(Window w
, XWindowAttributes
*wa
);
169 static void mappingnotify(XEvent
*e
);
170 static void maprequest(XEvent
*e
);
171 static void movemouse(const Arg
*arg
);
172 static Client
*nexttiled(Client
*c
);
173 static void propertynotify(XEvent
*e
);
174 static void quit(const Arg
*arg
);
175 static void resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
);
176 static void resizemouse(const Arg
*arg
);
177 static void restack(void);
178 static void run(void);
179 static void scan(void);
180 static void setclientstate(Client
*c
, long state
);
181 static void setmfact(const Arg
*arg
);
182 static void setup(void);
183 static void spawn(const Arg
*arg
);
184 static void tag(const Arg
*arg
);
185 static int textnw(const char *text
, uint len
);
186 static void tile(void);
187 static void togglebar(const Arg
*arg
);
188 static void togglefloating(const Arg
*arg
);
189 static void togglelayout(const Arg
*arg
);
190 static void togglemax(const Arg
*arg
);
191 static void toggletag(const Arg
*arg
);
192 static void toggleview(const Arg
*arg
);
193 static void unmanage(Client
*c
);
194 static void unmapnotify(XEvent
*e
);
195 static void updatebar(void);
196 static void updategeom(void);
197 static void updatesizehints(Client
*c
);
198 static void updatetitle(Client
*c
);
199 static void updatewmhints(Client
*c
);
200 static void view(const Arg
*arg
);
201 static int xerror(Display
*dpy
, XErrorEvent
*ee
);
202 static int xerrordummy(Display
*dpy
, XErrorEvent
*ee
);
203 static int xerrorstart(Display
*dpy
, XErrorEvent
*ee
);
204 static void zoom(const Arg
*arg
);
207 static char stext
[256];
208 static int screen
, sx
, sy
, sw
, sh
;
209 static int by
, bh
, blw
, wx
, wy
, ww
, wh
;
210 static uint seltags
= 0;
211 static int (*xerrorxlib
)(Display
*, XErrorEvent
*);
212 static uint numlockmask
= 0;
213 static void (*handler
[LASTEvent
]) (XEvent
*) = {
214 [ButtonPress
] = buttonpress
,
215 [ConfigureRequest
] = configurerequest
,
216 [ConfigureNotify
] = configurenotify
,
217 [DestroyNotify
] = destroynotify
,
218 [EnterNotify
] = enternotify
,
221 [KeyPress
] = keypress
,
222 [MappingNotify
] = mappingnotify
,
223 [MapRequest
] = maprequest
,
224 [PropertyNotify
] = propertynotify
,
225 [UnmapNotify
] = unmapnotify
227 static Atom wmatom
[WMLast
], netatom
[NetLast
];
228 static Bool ismax
= False
;
229 static Bool otherwm
, readin
;
230 static Bool running
= True
;
231 static uint tagset
[] = {1, 1}; /* after start, first tag is selected */
232 static Client
*clients
= NULL
;
233 static Client
*sel
= NULL
;
234 static Client
*stack
= NULL
;
235 static Cursor cursor
[CurLast
];
238 static Layout
*lt
= NULL
;
239 static Window root
, barwin
;
240 /* configuration, allows nested code to access above variables */
243 /* compile-time check if all tags fit into an uint bit array. */
244 struct NumTags
{ char limitexceeded
[sizeof(uint
) * 8 < LENGTH(tags
) ? -1 : 1]; };
246 /* function implementations */
248 applyrules(Client
*c
) {
251 XClassHint ch
= { 0 };
254 XGetClassHint(dpy
, c
->win
, &ch
);
255 for(i
= 0; i
< LENGTH(rules
); i
++) {
257 if((!r
->title
|| strstr(c
->name
, r
->title
))
258 && (!r
->class || (ch
.res_class
&& strstr(ch
.res_class
, r
->class)))
259 && (!r
->instance
|| (ch
.res_name
&& strstr(ch
.res_name
, r
->instance
)))) {
260 c
->isfloating
= r
->isfloating
;
261 c
->tags
|= r
->tags
& TAGMASK
;
269 c
->tags
= tagset
[seltags
];
276 for(c
= clients
; c
; c
= c
->next
)
277 if(c
->tags
& tagset
[seltags
]) { /* is visible */
278 if(ismax
&& !c
->isfixed
) {
279 XMoveResizeWindow(dpy
, c
->win
, wx
, wy
, ww
- 2 * c
->bw
, wh
- 2 * c
->bw
);
282 else if(!lt
->arrange
|| c
->isfloating
)
283 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, True
);
286 else if(!c
->isbanned
) {
287 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
288 c
->isbanned
= c
->ismoved
= True
;
292 if(lt
->arrange
&& !ismax
)
304 attachstack(Client
*c
) {
310 buttonpress(XEvent
*e
) {
313 XButtonPressedEvent
*ev
= &e
->xbutton
;
316 if(ev
->window
== barwin
) {
320 while(ev
->x
>= x
&& ++i
< LENGTH(tags
));
323 else if(ev
->x
< x
+ blw
)
325 else if(ev
->x
> wx
+ ww
- TEXTW(stext
))
326 click
= ClkStatusText
;
330 else if((c
= getclient(ev
->window
)))
331 click
= ClkClientWin
;
333 for(i
= 0; i
< LENGTH(buttons
); i
++)
334 if(click
== buttons
[i
].click
&& buttons
[i
].func
&& buttons
[i
].button
== ev
->button
335 && CLEANMASK(buttons
[i
].mask
) == CLEANMASK(ev
->state
))
336 buttons
[i
].func(&buttons
[i
].arg
);
342 XSetErrorHandler(xerrorstart
);
344 /* this causes an error if some other window manager is running */
345 XSelectInput(dpy
, DefaultRootWindow(dpy
), SubstructureRedirectMask
);
348 eprint("dwm: another window manager is already running\n");
349 XSetErrorHandler(NULL
);
350 xerrorxlib
= XSetErrorHandler(xerror
);
357 Layout foo
= { "", NULL
};
365 XFreeFontSet(dpy
, dc
.font
.set
);
367 XFreeFont(dpy
, dc
.font
.xfont
);
368 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
369 XFreePixmap(dpy
, dc
.drawable
);
371 XFreeCursor(dpy
, cursor
[CurNormal
]);
372 XFreeCursor(dpy
, cursor
[CurResize
]);
373 XFreeCursor(dpy
, cursor
[CurMove
]);
374 XDestroyWindow(dpy
, barwin
);
376 XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
380 configure(Client
*c
) {
383 ce
.type
= ConfigureNotify
;
391 ce
.border_width
= c
->bw
;
393 ce
.override_redirect
= False
;
394 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
398 configurenotify(XEvent
*e
) {
399 XConfigureEvent
*ev
= &e
->xconfigure
;
401 if(ev
->window
== root
&& (ev
->width
!= sw
|| ev
->height
!= sh
)) {
411 configurerequest(XEvent
*e
) {
413 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
416 if((c
= getclient(ev
->window
))) {
417 if(ev
->value_mask
& CWBorderWidth
)
418 c
->bw
= ev
->border_width
;
419 if(ismax
&& !c
->isbanned
&& !c
->isfixed
)
420 XMoveResizeWindow(dpy
, c
->win
, wx
, wy
, ww
- 2 * c
->bw
, wh
+ 2 * c
->bw
);
421 else if(c
->isfloating
|| !lt
->arrange
) {
422 if(ev
->value_mask
& CWX
)
424 if(ev
->value_mask
& CWY
)
426 if(ev
->value_mask
& CWWidth
)
428 if(ev
->value_mask
& CWHeight
)
430 if((c
->x
- sx
+ c
->w
) > sw
&& c
->isfloating
)
431 c
->x
= sx
+ (sw
/ 2 - c
->w
/ 2); /* center in x direction */
432 if((c
->y
- sy
+ c
->h
) > sh
&& c
->isfloating
)
433 c
->y
= sy
+ (sh
/ 2 - c
->h
/ 2); /* center in y direction */
434 if((ev
->value_mask
& (CWX
|CWY
))
435 && !(ev
->value_mask
& (CWWidth
|CWHeight
)))
438 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
446 wc
.width
= ev
->width
;
447 wc
.height
= ev
->height
;
448 wc
.border_width
= ev
->border_width
;
449 wc
.sibling
= ev
->above
;
450 wc
.stack_mode
= ev
->detail
;
451 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
457 destroynotify(XEvent
*e
) {
459 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
461 if((c
= getclient(ev
->window
)))
470 for(i
= clients
; i
->next
!= c
; i
= i
->next
);
480 detachstack(Client
*c
) {
483 for(tc
= &stack
; *tc
&& *tc
!= c
; tc
= &(*tc
)->snext
);
493 for(c
= stack
; c
&& c
->isbanned
; c
= c
->snext
);
494 for(i
= 0; i
< LENGTH(tags
); i
++) {
495 dc
.w
= TEXTW(tags
[i
]);
496 if(tagset
[seltags
] & 1 << i
) {
497 drawtext(tags
[i
], dc
.sel
, isurgent(i
));
498 drawsquare(c
&& c
->tags
& 1 << i
, isoccupied(i
), isurgent(i
), dc
.sel
);
501 drawtext(tags
[i
], dc
.norm
, isurgent(i
));
502 drawsquare(c
&& c
->tags
& 1 << i
, isoccupied(i
), isurgent(i
), dc
.norm
);
508 drawtext(lt
->symbol
, dc
.norm
, ismax
);
519 drawtext(stext
, dc
.norm
, False
);
520 if((dc
.w
= dc
.x
- x
) > bh
) {
523 drawtext(c
->name
, dc
.sel
, False
);
524 drawsquare(c
->isfixed
, c
->isfloating
, False
, dc
.sel
);
527 drawtext(NULL
, dc
.norm
, False
);
529 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, ww
, bh
, 0, 0);
534 drawsquare(Bool filled
, Bool empty
, Bool invert
, ulong col
[ColLast
]) {
537 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
539 gcv
.foreground
= col
[invert
? ColBG
: ColFG
];
540 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
541 x
= (dc
.font
.ascent
+ dc
.font
.descent
+ 2) / 4;
545 r
.width
= r
.height
= x
+ 1;
546 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
549 r
.width
= r
.height
= x
;
550 XDrawRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
555 drawtext(const char *text
, ulong col
[ColLast
], Bool invert
) {
556 int i
, x
, y
, h
, len
, olen
;
557 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
560 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColFG
: ColBG
]);
561 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
565 len
= MIN(olen
, sizeof buf
);
566 memcpy(buf
, text
, len
);
567 h
= dc
.font
.ascent
+ dc
.font
.descent
;
568 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
570 /* shorten text if necessary */
571 for(; len
&& (i
= textnw(buf
, len
)) > dc
.w
- h
; len
--);
575 for(i
= len
; i
&& i
> len
- 3; buf
[--i
] = '.');
576 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColBG
: ColFG
]);
578 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
580 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
584 enternotify(XEvent
*e
) {
586 XCrossingEvent
*ev
= &e
->xcrossing
;
588 if((ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
) && ev
->window
!= root
)
590 if((c
= getclient(ev
->window
)))
597 eprint(const char *errstr
, ...) {
600 va_start(ap
, errstr
);
601 vfprintf(stderr
, errstr
, ap
);
608 XExposeEvent
*ev
= &e
->xexpose
;
610 if(ev
->count
== 0 && (ev
->window
== barwin
))
616 if(!c
|| c
->isbanned
)
617 for(c
= stack
; c
&& c
->isbanned
; c
= c
->snext
);
618 if(sel
&& sel
!= c
) {
619 grabbuttons(sel
, False
);
620 XSetWindowBorder(dpy
, sel
->win
, dc
.norm
[ColBorder
]);
625 grabbuttons(c
, True
);
626 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBorder
]);
627 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
630 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
636 focusin(XEvent
*e
) { /* there are some broken focus acquiring clients */
637 XFocusChangeEvent
*ev
= &e
->xfocus
;
639 if(sel
&& ev
->window
!= sel
->win
)
640 XSetInputFocus(dpy
, sel
->win
, RevertToPointerRoot
, CurrentTime
);
644 focusstack(const Arg
*arg
) {
645 Client
*c
= NULL
, *i
;
650 for(c
= sel
->next
; c
&& c
->isbanned
; c
= c
->next
);
652 for(c
= clients
; c
&& c
->isbanned
; c
= c
->next
);
655 for(i
= clients
; i
!= sel
; i
= i
->next
)
659 for(; i
; i
= i
->next
)
670 getclient(Window w
) {
673 for(c
= clients
; c
&& c
->win
!= w
; c
= c
->next
);
678 getcolor(const char *colstr
) {
679 Colormap cmap
= DefaultColormap(dpy
, screen
);
682 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
683 eprint("error, cannot allocate color '%s'\n", colstr
);
691 unsigned char *p
= NULL
;
695 status
= XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
696 &real
, &format
, &n
, &extra
, (unsigned char **)&p
);
697 if(status
!= Success
)
706 gettextprop(Window w
, Atom atom
, char *text
, uint size
) {
711 if(!text
|| size
== 0)
714 XGetTextProperty(dpy
, w
, &name
, atom
);
717 if(name
.encoding
== XA_STRING
)
718 strncpy(text
, (char *)name
.value
, size
- 1);
720 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
722 strncpy(text
, *list
, size
- 1);
723 XFreeStringList(list
);
726 text
[size
- 1] = '\0';
732 grabbuttons(Client
*c
, Bool focused
) {
734 uint buttons
[] = { Button1
, Button2
, Button3
};
735 uint modifiers
[] = { MODKEY
, MODKEY
|LockMask
, MODKEY
|numlockmask
, MODKEY
|numlockmask
|LockMask
};
737 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
739 for(i
= 0; i
< LENGTH(buttons
); i
++)
740 for(j
= 0; j
< LENGTH(modifiers
); j
++)
741 XGrabButton(dpy
, buttons
[i
], modifiers
[j
], c
->win
, False
,
742 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
744 XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
,
745 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
752 XModifierKeymap
*modmap
;
754 /* init modifier map */
755 modmap
= XGetModifierMapping(dpy
);
756 for(i
= 0; i
< 8; i
++)
757 for(j
= 0; j
< modmap
->max_keypermod
; j
++) {
758 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
] == XKeysymToKeycode(dpy
, XK_Num_Lock
))
759 numlockmask
= (1 << i
);
761 XFreeModifiermap(modmap
);
763 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
764 for(i
= 0; i
< LENGTH(keys
); i
++) {
765 code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
);
766 XGrabKey(dpy
, code
, keys
[i
].mod
, root
, True
,
767 GrabModeAsync
, GrabModeAsync
);
768 XGrabKey(dpy
, code
, keys
[i
].mod
|LockMask
, root
, True
,
769 GrabModeAsync
, GrabModeAsync
);
770 XGrabKey(dpy
, code
, keys
[i
].mod
|numlockmask
, root
, True
,
771 GrabModeAsync
, GrabModeAsync
);
772 XGrabKey(dpy
, code
, keys
[i
].mod
|numlockmask
|LockMask
, root
, True
,
773 GrabModeAsync
, GrabModeAsync
);
778 initfont(const char *fontstr
) {
779 char *def
, **missing
;
784 XFreeFontSet(dpy
, dc
.font
.set
);
785 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
788 fprintf(stderr
, "dwm: missing fontset: %s\n", missing
[n
]);
789 XFreeStringList(missing
);
792 XFontSetExtents
*font_extents
;
793 XFontStruct
**xfonts
;
795 dc
.font
.ascent
= dc
.font
.descent
= 0;
796 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
797 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
798 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
799 dc
.font
.ascent
= MAX(dc
.font
.ascent
, (*xfonts
)->ascent
);
800 dc
.font
.descent
= MAX(dc
.font
.descent
,(*xfonts
)->descent
);
806 XFreeFont(dpy
, dc
.font
.xfont
);
807 dc
.font
.xfont
= NULL
;
808 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
))
809 && !(dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed")))
810 eprint("error, cannot load font: '%s'\n", fontstr
);
811 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
812 dc
.font
.descent
= dc
.font
.xfont
->descent
;
814 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
821 for(c
= clients
; c
; c
= c
->next
)
828 isprotodel(Client
*c
) {
833 if(XGetWMProtocols(dpy
, c
->win
, &protocols
, &n
)) {
834 for(i
= 0; !ret
&& i
< n
; i
++)
835 if(protocols
[i
] == wmatom
[WMDelete
])
846 for(c
= clients
; c
; c
= c
->next
)
847 if(c
->isurgent
&& c
->tags
& 1 << t
)
853 keypress(XEvent
*e
) {
859 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
860 for(i
= 0; i
< LENGTH(keys
); i
++)
861 if(keysym
== keys
[i
].keysym
862 && CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
)
864 keys
[i
].func(&(keys
[i
].arg
));
868 killclient(const Arg
*arg
) {
873 if(isprotodel(sel
)) {
874 ev
.type
= ClientMessage
;
875 ev
.xclient
.window
= sel
->win
;
876 ev
.xclient
.message_type
= wmatom
[WMProtocols
];
877 ev
.xclient
.format
= 32;
878 ev
.xclient
.data
.l
[0] = wmatom
[WMDelete
];
879 ev
.xclient
.data
.l
[1] = CurrentTime
;
880 XSendEvent(dpy
, sel
->win
, False
, NoEventMask
, &ev
);
883 XKillClient(dpy
, sel
->win
);
887 manage(Window w
, XWindowAttributes
*wa
) {
888 Client
*c
, *t
= NULL
;
893 if(!(c
= calloc(1, sizeof(Client
))))
894 eprint("fatal: could not calloc() %u bytes\n", sizeof(Client
));
902 c
->oldbw
= wa
->border_width
;
903 if(c
->w
== sw
&& c
->h
== sh
) {
906 c
->bw
= wa
->border_width
;
909 if(c
->x
+ c
->w
+ 2 * c
->bw
> sx
+ sw
)
910 c
->x
= sx
+ sw
- c
->w
- 2 * c
->bw
;
911 if(c
->y
+ c
->h
+ 2 * c
->bw
> sy
+ sh
)
912 c
->y
= sy
+ sh
- c
->h
- 2 * c
->bw
;
913 c
->x
= MAX(c
->x
, sx
);
914 c
->y
= MAX(c
->y
, by
== 0 ? bh
: sy
);
918 wc
.border_width
= c
->bw
;
919 XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
920 XSetWindowBorder(dpy
, w
, dc
.norm
[ColBorder
]);
921 configure(c
); /* propagates border_width, if size doesn't change */
923 XSelectInput(dpy
, w
, EnterWindowMask
|FocusChangeMask
|PropertyChangeMask
|StructureNotifyMask
);
924 grabbuttons(c
, False
);
926 if((rettrans
= XGetTransientForHint(dpy
, w
, &trans
) == Success
))
927 for(t
= clients
; t
&& t
->win
!= trans
; t
= t
->next
);
933 c
->isfloating
= (rettrans
== Success
) || c
->isfixed
;
935 XRaiseWindow(dpy
, c
->win
);
938 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
); /* some windows require this */
939 XMapWindow(dpy
, c
->win
);
940 setclientstate(c
, NormalState
);
945 mappingnotify(XEvent
*e
) {
946 XMappingEvent
*ev
= &e
->xmapping
;
948 XRefreshKeyboardMapping(ev
);
949 if(ev
->request
== MappingKeyboard
)
954 maprequest(XEvent
*e
) {
955 static XWindowAttributes wa
;
956 XMapRequestEvent
*ev
= &e
->xmaprequest
;
958 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
960 if(wa
.override_redirect
)
962 if(!getclient(ev
->window
))
963 manage(ev
->window
, &wa
);
967 movemouse(const Arg
*arg
) {
968 int x1
, y1
, ocx
, ocy
, di
, nx
, ny
;
979 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
980 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
982 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
983 if(x1
< c
->x
|| x1
> c
->x
+ c
->w
|| y1
< c
->y
|| y1
> c
->y
+ c
->h
) {
984 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, 0, 0);
989 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
992 XUngrabPointer(dpy
, CurrentTime
);
994 case ConfigureRequest
:
997 handler
[ev
.type
](&ev
);
1001 nx
= ocx
+ (ev
.xmotion
.x
- x1
);
1002 ny
= ocy
+ (ev
.xmotion
.y
- y1
);
1003 if(snap
&& nx
>= wx
&& nx
<= wx
+ ww
1004 && ny
>= wy
&& ny
<= wy
+ wh
) {
1005 if(abs(wx
- nx
) < snap
)
1007 else if(abs((wx
+ ww
) - (nx
+ c
->w
+ 2 * c
->bw
)) < snap
)
1008 nx
= wx
+ ww
- c
->w
- 2 * c
->bw
;
1009 if(abs(wy
- ny
) < snap
)
1011 else if(abs((wy
+ wh
) - (ny
+ c
->h
+ 2 * c
->bw
)) < snap
)
1012 ny
= wy
+ wh
- c
->h
- 2 * c
->bw
;
1013 if(!c
->isfloating
&& lt
->arrange
&& (abs(nx
- c
->x
) > snap
|| abs(ny
- c
->y
) > snap
))
1014 togglefloating(NULL
);
1016 if(!lt
->arrange
|| c
->isfloating
)
1017 resize(c
, nx
, ny
, c
->w
, c
->h
, False
);
1024 nexttiled(Client
*c
) {
1025 for(; c
&& (c
->isfloating
|| c
->isbanned
); c
= c
->next
);
1030 propertynotify(XEvent
*e
) {
1033 XPropertyEvent
*ev
= &e
->xproperty
;
1035 if(ev
->state
== PropertyDelete
)
1036 return; /* ignore */
1037 if((c
= getclient(ev
->window
))) {
1040 case XA_WM_TRANSIENT_FOR
:
1041 XGetTransientForHint(dpy
, c
->win
, &trans
);
1042 if(!c
->isfloating
&& (c
->isfloating
= (getclient(trans
) != NULL
)))
1045 case XA_WM_NORMAL_HINTS
:
1053 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
1062 quit(const Arg
*arg
) {
1063 readin
= running
= False
;
1067 resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
) {
1071 /* set minimum possible */
1075 /* temporarily remove base dimensions */
1079 /* adjust for aspect limits */
1080 if(c
->mina
> 0 && c
->maxa
> 0) {
1081 if(c
->maxa
< (float) w
/h
)
1083 else if(c
->mina
> (float) h
/w
)
1087 /* adjust for increment value */
1093 /* restore base dimensions */
1097 w
= MAX(w
, c
->minw
);
1098 h
= MAX(h
, c
->minh
);
1101 w
= MIN(w
, c
->maxw
);
1104 h
= MIN(h
, c
->maxh
);
1106 if(w
<= 0 || h
<= 0)
1109 x
= sw
- w
- 2 * c
->bw
;
1111 y
= sh
- h
- 2 * c
->bw
;
1112 if(x
+ w
+ 2 * c
->bw
< sx
)
1114 if(y
+ h
+ 2 * c
->bw
< sy
)
1120 if(c
->x
!= x
|| c
->y
!= y
|| c
->w
!= w
|| c
->h
!= h
|| c
->ismoved
) {
1124 c
->w
= wc
.width
= w
;
1125 c
->h
= wc
.height
= h
;
1126 wc
.border_width
= c
->bw
;
1127 XConfigureWindow(dpy
, c
->win
,
1128 CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
, &wc
);
1135 resizemouse(const Arg
*arg
) {
1146 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1147 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
1149 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1151 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1154 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0,
1155 c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1156 XUngrabPointer(dpy
, CurrentTime
);
1157 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1159 case ConfigureRequest
:
1162 handler
[ev
.type
](&ev
);
1166 nw
= MAX(ev
.xmotion
.x
- ocx
- 2 * c
->bw
+ 1, 1);
1167 nh
= MAX(ev
.xmotion
.y
- ocy
- 2 * c
->bw
+ 1, 1);
1169 if(snap
&& nw
>= wx
&& nw
<= wx
+ ww
1170 && nh
>= wy
&& nh
<= wy
+ wh
) {
1171 if(!c
->isfloating
&& lt
->arrange
1172 && (abs(nw
- c
->w
) > snap
|| abs(nh
- c
->h
) > snap
))
1173 togglefloating(NULL
);
1175 if(!lt
->arrange
|| c
->isfloating
)
1176 resize(c
, c
->x
, c
->y
, nw
, nh
, True
);
1191 if(ismax
|| sel
->isfloating
|| !lt
->arrange
)
1192 XRaiseWindow(dpy
, sel
->win
);
1193 if(!ismax
&& lt
->arrange
) {
1194 wc
.stack_mode
= Below
;
1195 wc
.sibling
= barwin
;
1196 for(c
= stack
; c
; c
= c
->snext
)
1197 if(!c
->isfloating
&& !c
->isbanned
) {
1198 XConfigureWindow(dpy
, c
->win
, CWSibling
|CWStackMode
, &wc
);
1199 wc
.sibling
= c
->win
;
1203 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1209 char sbuf
[sizeof stext
];
1215 /* main event loop, also reads status text from stdin */
1217 xfd
= ConnectionNumber(dpy
);
1220 len
= sizeof stext
- 1;
1221 sbuf
[len
] = stext
[len
] = '\0'; /* 0-terminator is never touched */
1225 FD_SET(STDIN_FILENO
, &rd
);
1227 if(select(xfd
+ 1, &rd
, NULL
, NULL
, NULL
) == -1) {
1230 eprint("select failed\n");
1232 if(FD_ISSET(STDIN_FILENO
, &rd
)) {
1233 switch((r
= read(STDIN_FILENO
, sbuf
+ offset
, len
- offset
))) {
1235 strncpy(stext
, strerror(errno
), len
);
1239 strncpy(stext
, "EOF", 4);
1243 for(p
= sbuf
+ offset
; r
> 0; p
++, r
--, offset
++)
1244 if(*p
== '\n' || *p
== '\0') {
1246 strncpy(stext
, sbuf
, len
);
1247 p
+= r
- 1; /* p is sbuf + offset + r - 1 */
1248 for(r
= 0; *(p
- r
) && *(p
- r
) != '\n'; r
++);
1251 memmove(sbuf
, p
- r
+ 1, r
);
1258 while(XPending(dpy
)) {
1259 XNextEvent(dpy
, &ev
);
1260 if(handler
[ev
.type
])
1261 (handler
[ev
.type
])(&ev
); /* call handler */
1269 Window
*wins
, d1
, d2
;
1270 XWindowAttributes wa
;
1273 if(XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
1274 for(i
= 0; i
< num
; i
++) {
1275 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
1276 || wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
1278 if(wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
1279 manage(wins
[i
], &wa
);
1281 for(i
= 0; i
< num
; i
++) { /* now the transients */
1282 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
1284 if(XGetTransientForHint(dpy
, wins
[i
], &d1
)
1285 && (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
1286 manage(wins
[i
], &wa
);
1294 setclientstate(Client
*c
, long state
) {
1295 long data
[] = {state
, None
};
1297 XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
1298 PropModeReplace
, (unsigned char *)data
, 2);
1301 /* arg > 1.0 will set mfact absolutly */
1303 setmfact(const Arg
*arg
) {
1306 if(!arg
|| !lt
->arrange
)
1308 f
= arg
->f
< 1.0 ? arg
->f
+ mfact
: arg
->f
- 1.0;
1309 if(f
< 0.1 || f
> 0.9)
1319 XSetWindowAttributes wa
;
1322 screen
= DefaultScreen(dpy
);
1323 root
= RootWindow(dpy
, screen
);
1327 sw
= DisplayWidth(dpy
, screen
);
1328 sh
= DisplayHeight(dpy
, screen
);
1329 bh
= dc
.h
= dc
.font
.height
+ 2;
1334 wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
1335 wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
1336 wmatom
[WMName
] = XInternAtom(dpy
, "WM_NAME", False
);
1337 wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
1338 netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
1339 netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
1342 wa
.cursor
= cursor
[CurNormal
] = XCreateFontCursor(dpy
, XC_left_ptr
);
1343 cursor
[CurResize
] = XCreateFontCursor(dpy
, XC_sizing
);
1344 cursor
[CurMove
] = XCreateFontCursor(dpy
, XC_fleur
);
1346 /* init appearance */
1347 dc
.norm
[ColBorder
] = getcolor(normbordercolor
);
1348 dc
.norm
[ColBG
] = getcolor(normbgcolor
);
1349 dc
.norm
[ColFG
] = getcolor(normfgcolor
);
1350 dc
.sel
[ColBorder
] = getcolor(selbordercolor
);
1351 dc
.sel
[ColBG
] = getcolor(selbgcolor
);
1352 dc
.sel
[ColFG
] = getcolor(selfgcolor
);
1353 dc
.drawable
= XCreatePixmap(dpy
, root
, DisplayWidth(dpy
, screen
), bh
, DefaultDepth(dpy
, screen
));
1354 dc
.gc
= XCreateGC(dpy
, root
, 0, 0);
1355 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
1357 XSetFont(dpy
, dc
.gc
, dc
.font
.xfont
->fid
);
1360 for(blw
= i
= 0; LENGTH(layouts
) > 1 && i
< LENGTH(layouts
); i
++) {
1361 w
= TEXTW(layouts
[i
].symbol
);
1365 wa
.override_redirect
= 1;
1366 wa
.background_pixmap
= ParentRelative
;
1367 wa
.event_mask
= ButtonPressMask
|ExposureMask
;
1369 barwin
= XCreateWindow(dpy
, root
, wx
, by
, ww
, bh
, 0, DefaultDepth(dpy
, screen
),
1370 CopyFromParent
, DefaultVisual(dpy
, screen
),
1371 CWOverrideRedirect
|CWBackPixmap
|CWEventMask
, &wa
);
1372 XDefineCursor(dpy
, barwin
, cursor
[CurNormal
]);
1373 XMapRaised(dpy
, barwin
);
1374 strcpy(stext
, "dwm-"VERSION
);
1377 /* EWMH support per view */
1378 XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
1379 PropModeReplace
, (unsigned char *) netatom
, NetLast
);
1381 /* select for events */
1382 wa
.event_mask
= SubstructureRedirectMask
|SubstructureNotifyMask
1383 |EnterWindowMask
|LeaveWindowMask
|StructureNotifyMask
;
1384 XChangeWindowAttributes(dpy
, root
, CWEventMask
|CWCursor
, &wa
);
1385 XSelectInput(dpy
, root
, wa
.event_mask
);
1393 spawn(const Arg
*arg
) {
1394 /* The double-fork construct avoids zombie processes and keeps the code
1395 * clean from stupid signal handlers. */
1399 close(ConnectionNumber(dpy
));
1401 execvp(((char **)arg
->v
)[0], (char **)arg
->v
);
1402 fprintf(stderr
, "dwm: execvp %s", ((char **)arg
->v
)[0]);
1411 tag(const Arg
*arg
) {
1412 if(sel
&& arg
->ui
& TAGMASK
) {
1413 sel
->tags
= arg
->ui
& TAGMASK
;
1419 textnw(const char *text
, uint len
) {
1423 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
1426 return XTextWidth(dc
.font
.xfont
, text
, len
);
1435 for(n
= 0, c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
), n
++);
1440 c
= nexttiled(clients
);
1442 resize(c
, wx
, wy
, (n
== 1 ? ww
: mw
) - 2 * c
->bw
, wh
- 2 * c
->bw
, resizehints
);
1448 x
= (wx
+ mw
> c
->x
+ c
->w
) ? c
->x
+ c
->w
+ 2 * c
->bw
: wx
+ mw
;
1450 w
= (wx
+ mw
> c
->x
+ c
->w
) ? wx
+ ww
- x
: ww
- mw
;
1455 for(i
= 0, c
= nexttiled(c
->next
); c
; c
= nexttiled(c
->next
), i
++) {
1456 resize(c
, x
, y
, w
- 2 * c
->bw
, /* remainder */ ((i
+ 1 == n
)
1457 ? (wy
+ wh
) - y
: h
) - 2 * c
->bw
, resizehints
);
1459 y
= c
->y
+ c
->h
+ 2 * c
->bw
;
1464 togglebar(const Arg
*arg
) {
1472 togglefloating(const Arg
*arg
) {
1475 sel
->isfloating
= !sel
->isfloating
|| sel
->isfixed
;
1477 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
);
1482 togglelayout(const Arg
*arg
) {
1484 lt
= (Layout
*)arg
->v
;
1485 else if(++lt
== &layouts
[LENGTH(layouts
)])
1494 togglemax(const Arg
*arg
) {
1500 toggletag(const Arg
*arg
) {
1501 if(sel
&& (sel
->tags
^= (arg
->ui
& TAGMASK
)))
1506 toggleview(const Arg
*arg
) {
1507 if((tagset
[seltags
] ^= (arg
->ui
& TAGMASK
)))
1512 unmanage(Client
*c
) {
1515 wc
.border_width
= c
->oldbw
;
1516 /* The server grab construct avoids race conditions. */
1518 XSetErrorHandler(xerrordummy
);
1519 XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
1524 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1525 setclientstate(c
, WithdrawnState
);
1528 XSetErrorHandler(xerror
);
1534 unmapnotify(XEvent
*e
) {
1536 XUnmapEvent
*ev
= &e
->xunmap
;
1538 if((c
= getclient(ev
->window
)))
1544 if(dc
.drawable
!= 0)
1545 XFreePixmap(dpy
, dc
.drawable
);
1546 dc
.drawable
= XCreatePixmap(dpy
, root
, ww
, bh
, DefaultDepth(dpy
, screen
));
1547 XMoveResizeWindow(dpy
, barwin
, wx
, by
, ww
, bh
);
1554 XineramaScreenInfo
*info
= NULL
;
1556 /* window area geometry */
1557 if(XineramaIsActive(dpy
)) {
1558 info
= XineramaQueryScreens(dpy
, &i
);
1559 wx
= info
[xidx
].x_org
;
1560 wy
= showbar
&& topbar
? info
[xidx
].y_org
+ bh
: info
[xidx
].y_org
;
1561 ww
= info
[xidx
].width
;
1562 wh
= showbar
? info
[xidx
].height
- bh
: info
[xidx
].height
;
1569 wy
= showbar
&& topbar
? sy
+ bh
: sy
;
1571 wh
= showbar
? sh
- bh
: sh
;
1575 by
= showbar
? (topbar
? wy
- bh
: wy
+ wh
) : -bh
;
1579 updatesizehints(Client
*c
) {
1583 XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
);
1584 if(size
.flags
& PBaseSize
) {
1585 c
->basew
= size
.base_width
;
1586 c
->baseh
= size
.base_height
;
1588 else if(size
.flags
& PMinSize
) {
1589 c
->basew
= size
.min_width
;
1590 c
->baseh
= size
.min_height
;
1593 c
->basew
= c
->baseh
= 0;
1594 if(size
.flags
& PResizeInc
) {
1595 c
->incw
= size
.width_inc
;
1596 c
->inch
= size
.height_inc
;
1599 c
->incw
= c
->inch
= 0;
1600 if(size
.flags
& PMaxSize
) {
1601 c
->maxw
= size
.max_width
;
1602 c
->maxh
= size
.max_height
;
1605 c
->maxw
= c
->maxh
= 0;
1606 if(size
.flags
& PMinSize
) {
1607 c
->minw
= size
.min_width
;
1608 c
->minh
= size
.min_height
;
1610 else if(size
.flags
& PBaseSize
) {
1611 c
->minw
= size
.base_width
;
1612 c
->minh
= size
.base_height
;
1615 c
->minw
= c
->minh
= 0;
1616 if(size
.flags
& PAspect
) {
1617 c
->mina
= (float)size
.min_aspect
.y
/ (float)size
.min_aspect
.x
;
1618 c
->maxa
= (float)size
.max_aspect
.x
/ (float)size
.max_aspect
.y
;
1621 c
->maxa
= c
->mina
= 0.0;
1622 c
->isfixed
= (c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
1623 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
1627 updatetitle(Client
*c
) {
1628 if(!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
1629 gettextprop(c
->win
, wmatom
[WMName
], c
->name
, sizeof c
->name
);
1633 updatewmhints(Client
*c
) {
1636 if((wmh
= XGetWMHints(dpy
, c
->win
))) {
1638 sel
->isurgent
= False
;
1640 c
->isurgent
= (wmh
->flags
& XUrgencyHint
) ? True
: False
;
1646 view(const Arg
*arg
) {
1647 seltags
^= 1; /* toggle sel tagset */
1648 if(arg
&& (arg
->ui
& TAGMASK
))
1649 tagset
[seltags
] = arg
->i
& TAGMASK
;
1653 /* There's no way to check accesses to destroyed windows, thus those cases are
1654 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1655 * default error handler, which may call exit. */
1657 xerror(Display
*dpy
, XErrorEvent
*ee
) {
1658 if(ee
->error_code
== BadWindow
1659 || (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
1660 || (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
1661 || (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
1662 || (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
1663 || (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
1664 || (ee
->request_code
== X_GrabButton
&& ee
->error_code
== BadAccess
)
1665 || (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
1666 || (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
1668 fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
1669 ee
->request_code
, ee
->error_code
);
1670 return xerrorxlib(dpy
, ee
); /* may call exit */
1674 xerrordummy(Display
*dpy
, XErrorEvent
*ee
) {
1678 /* Startup Error handler to check if another window manager
1679 * is already running. */
1681 xerrorstart(Display
*dpy
, XErrorEvent
*ee
) {
1687 zoom(const Arg
*arg
) {
1690 if(ismax
|| !lt
->arrange
|| (sel
&& sel
->isfloating
))
1692 if(c
== nexttiled(clients
))
1693 if(!c
|| !(c
= nexttiled(c
->next
)))
1702 main(int argc
, char *argv
[]) {
1703 if(argc
== 2 && !strcmp("-v", argv
[1]))
1704 eprint("dwm-"VERSION
", © 2006-2008 dwm engineers, see LICENSE for details\n");
1706 eprint("usage: dwm [-v]\n");
1708 setlocale(LC_CTYPE
, "");
1709 if(!(dpy
= XOpenDisplay(0)))
1710 eprint("dwm: cannot open display\n");