Xinqi Bao's Git
1c52d805466ebaaf5e1c50ff7b74cc7e8462070b
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 */
64 typedef unsigned int uint
;
65 typedef unsigned long ulong
;
66 typedef struct Client Client
;
70 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
73 Bool isbanned
, isfixed
, isfloating
, ismoved
, isurgent
;
93 } DC
; /* draw context */
105 void (*func
)(const Arg
*);
111 void (*arrange
)(void);
116 const char *instance
;
122 /* function declarations */
123 static void applyrules(Client
*c
);
124 static void arrange(void);
125 static void attach(Client
*c
);
126 static void attachstack(Client
*c
);
127 static void buttonpress(XEvent
*e
);
128 static void checkotherwm(void);
129 static void cleanup(void);
130 static void configure(Client
*c
);
131 static void configurenotify(XEvent
*e
);
132 static void configurerequest(XEvent
*e
);
133 static void destroynotify(XEvent
*e
);
134 static void detach(Client
*c
);
135 static void detachstack(Client
*c
);
136 static void drawbar(void);
137 static void drawsquare(Bool filled
, Bool empty
, Bool invert
, ulong col
[ColLast
]);
138 static void drawtext(const char *text
, ulong col
[ColLast
], Bool invert
);
139 static void enternotify(XEvent
*e
);
140 static void eprint(const char *errstr
, ...);
141 static void expose(XEvent
*e
);
142 static void focus(Client
*c
);
143 static void focusin(XEvent
*e
);
144 static void focusstack(const Arg
*arg
);
145 static Client
*getclient(Window w
);
146 static ulong
getcolor(const char *colstr
);
147 static long getstate(Window w
);
148 static Bool
gettextprop(Window w
, Atom atom
, char *text
, uint size
);
149 static void grabbuttons(Client
*c
, Bool focused
);
150 static void grabkeys(void);
151 static void initfont(const char *fontstr
);
152 static Bool
isoccupied(uint t
);
153 static Bool
isprotodel(Client
*c
);
154 static Bool
isurgent(uint t
);
155 static void keypress(XEvent
*e
);
156 static void killclient(const Arg
*arg
);
157 static void manage(Window w
, XWindowAttributes
*wa
);
158 static void mappingnotify(XEvent
*e
);
159 static void maprequest(XEvent
*e
);
160 static void movemouse(Client
*c
);
161 static Client
*nexttiled(Client
*c
);
162 static void propertynotify(XEvent
*e
);
163 static void quit(const Arg
*arg
);
164 static void resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
);
165 static void resizemouse(Client
*c
);
166 static void restack(void);
167 static void run(void);
168 static void scan(void);
169 static void setclientstate(Client
*c
, long state
);
170 static void setmfact(const Arg
*arg
);
171 static void setup(void);
172 static void spawn(const Arg
*arg
);
173 static void tag(const Arg
*arg
);
174 static int textnw(const char *text
, uint len
);
175 static void tile(void);
176 static void togglebar(const Arg
*arg
);
177 static void togglefloating(const Arg
*arg
);
178 static void togglelayout(const Arg
*arg
);
179 static void togglemax(const Arg
*arg
);
180 static void toggletag(const Arg
*arg
);
181 static void toggleview(const Arg
*arg
);
182 static void unmanage(Client
*c
);
183 static void unmapnotify(XEvent
*e
);
184 static void updatebar(void);
185 static void updategeom(void);
186 static void updatesizehints(Client
*c
);
187 static void updatetitle(Client
*c
);
188 static void updatewmhints(Client
*c
);
189 static void view(const Arg
*arg
);
190 static int xerror(Display
*dpy
, XErrorEvent
*ee
);
191 static int xerrordummy(Display
*dpy
, XErrorEvent
*ee
);
192 static int xerrorstart(Display
*dpy
, XErrorEvent
*ee
);
193 static void zoom(const Arg
*arg
);
196 static char stext
[256];
197 static int screen
, sx
, sy
, sw
, sh
;
198 static int by
, bh
, blw
, wx
, wy
, ww
, wh
;
199 static uint seltags
= 0;
200 static int (*xerrorxlib
)(Display
*, XErrorEvent
*);
201 static uint numlockmask
= 0;
202 static void (*handler
[LASTEvent
]) (XEvent
*) = {
203 [ButtonPress
] = buttonpress
,
204 [ConfigureRequest
] = configurerequest
,
205 [ConfigureNotify
] = configurenotify
,
206 [DestroyNotify
] = destroynotify
,
207 [EnterNotify
] = enternotify
,
210 [KeyPress
] = keypress
,
211 [MappingNotify
] = mappingnotify
,
212 [MapRequest
] = maprequest
,
213 [PropertyNotify
] = propertynotify
,
214 [UnmapNotify
] = unmapnotify
216 static Atom wmatom
[WMLast
], netatom
[NetLast
];
217 static Bool ismax
= False
;
218 static Bool otherwm
, readin
;
219 static Bool running
= True
;
220 static uint tagset
[] = {1, 1}; /* after start, first tag is selected */
221 static Client
*clients
= NULL
;
222 static Client
*sel
= NULL
;
223 static Client
*stack
= NULL
;
224 static Cursor cursor
[CurLast
];
227 static Window root
, barwin
;
229 /* configuration, allows nested code to access above variables */
232 static Layout
*lt
= layouts
;
234 /* compile-time check if all tags fit into an uint bit array. */
235 struct NumTags
{ char limitexceeded
[sizeof(uint
) * 8 < LENGTH(tags
) ? -1 : 1]; };
237 /* function implementations */
239 applyrules(Client
*c
) {
242 XClassHint ch
= { 0 };
245 XGetClassHint(dpy
, c
->win
, &ch
);
246 for(i
= 0; i
< LENGTH(rules
); i
++) {
248 if((!r
->title
|| strstr(c
->name
, r
->title
))
249 && (!r
->class || (ch
.res_class
&& strstr(ch
.res_class
, r
->class)))
250 && (!r
->instance
|| (ch
.res_name
&& strstr(ch
.res_name
, r
->instance
)))) {
251 c
->isfloating
= r
->isfloating
;
252 c
->tags
|= r
->tags
& TAGMASK
;
260 c
->tags
= tagset
[seltags
];
267 for(c
= clients
; c
; c
= c
->next
)
268 if(c
->tags
& tagset
[seltags
]) { /* is visible */
269 if(ismax
&& !c
->isfixed
) {
270 XMoveResizeWindow(dpy
, c
->win
, wx
, wy
, ww
- 2 * c
->bw
, wh
- 2 * c
->bw
);
273 else if(!lt
->arrange
|| c
->isfloating
)
274 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, True
);
277 else if(!c
->isbanned
) {
278 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
279 c
->isbanned
= c
->ismoved
= True
;
283 if(lt
->arrange
&& !ismax
)
295 attachstack(Client
*c
) {
301 buttonpress(XEvent
*e
) {
305 XButtonPressedEvent
*ev
= &e
->xbutton
;
307 if(ev
->window
== barwin
) {
309 for(i
= 0; i
< LENGTH(tags
); i
++) {
313 if(ev
->button
== Button1
) {
314 if(ev
->state
& MODKEY
)
319 else if(ev
->button
== Button3
) {
320 if(ev
->state
& MODKEY
)
321 toggletag((Arg
*)&mask
);
323 toggleview((Arg
*)&mask
);
328 if(ev
->x
< x
+ blw
) {
329 if(ev
->button
== Button1
)
331 else if(ev
->button
== Button3
)
335 else if((c
= getclient(ev
->window
))) {
337 if(CLEANMASK(ev
->state
) != MODKEY
|| (ismax
&& !c
->isfixed
))
339 if(ev
->button
== Button1
)
341 else if(ev
->button
== Button2
)
342 togglefloating(NULL
);
343 else if(ev
->button
== Button3
&& !c
->isfixed
)
351 XSetErrorHandler(xerrorstart
);
353 /* this causes an error if some other window manager is running */
354 XSelectInput(dpy
, DefaultRootWindow(dpy
), SubstructureRedirectMask
);
357 eprint("dwm: another window manager is already running\n");
358 XSetErrorHandler(NULL
);
359 xerrorxlib
= XSetErrorHandler(xerror
);
371 XFreeFontSet(dpy
, dc
.font
.set
);
373 XFreeFont(dpy
, dc
.font
.xfont
);
374 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
375 XFreePixmap(dpy
, dc
.drawable
);
377 XFreeCursor(dpy
, cursor
[CurNormal
]);
378 XFreeCursor(dpy
, cursor
[CurResize
]);
379 XFreeCursor(dpy
, cursor
[CurMove
]);
380 XDestroyWindow(dpy
, barwin
);
382 XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
386 configure(Client
*c
) {
389 ce
.type
= ConfigureNotify
;
397 ce
.border_width
= c
->bw
;
399 ce
.override_redirect
= False
;
400 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
404 configurenotify(XEvent
*e
) {
405 XConfigureEvent
*ev
= &e
->xconfigure
;
407 if(ev
->window
== root
&& (ev
->width
!= sw
|| ev
->height
!= sh
)) {
417 configurerequest(XEvent
*e
) {
419 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
422 if((c
= getclient(ev
->window
))) {
423 if(ev
->value_mask
& CWBorderWidth
)
424 c
->bw
= ev
->border_width
;
425 if(ismax
&& !c
->isbanned
&& !c
->isfixed
)
426 XMoveResizeWindow(dpy
, c
->win
, wx
, wy
, ww
- 2 * c
->bw
, wh
+ 2 * c
->bw
);
427 else if(c
->isfloating
|| !lt
->arrange
) {
428 if(ev
->value_mask
& CWX
)
430 if(ev
->value_mask
& CWY
)
432 if(ev
->value_mask
& CWWidth
)
434 if(ev
->value_mask
& CWHeight
)
436 if((c
->x
- sx
+ c
->w
) > sw
&& c
->isfloating
)
437 c
->x
= sx
+ (sw
/ 2 - c
->w
/ 2); /* center in x direction */
438 if((c
->y
- sy
+ c
->h
) > sh
&& c
->isfloating
)
439 c
->y
= sy
+ (sh
/ 2 - c
->h
/ 2); /* center in y direction */
440 if((ev
->value_mask
& (CWX
|CWY
))
441 && !(ev
->value_mask
& (CWWidth
|CWHeight
)))
444 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
452 wc
.width
= ev
->width
;
453 wc
.height
= ev
->height
;
454 wc
.border_width
= ev
->border_width
;
455 wc
.sibling
= ev
->above
;
456 wc
.stack_mode
= ev
->detail
;
457 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
463 destroynotify(XEvent
*e
) {
465 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
467 if((c
= getclient(ev
->window
)))
476 for(i
= clients
; i
->next
!= c
; i
= i
->next
);
486 detachstack(Client
*c
) {
489 for(tc
= &stack
; *tc
&& *tc
!= c
; tc
= &(*tc
)->snext
);
499 for(c
= stack
; c
&& c
->isbanned
; c
= c
->snext
);
500 for(i
= 0; i
< LENGTH(tags
); i
++) {
501 dc
.w
= TEXTW(tags
[i
]);
502 if(tagset
[seltags
] & 1 << i
) {
503 drawtext(tags
[i
], dc
.sel
, isurgent(i
));
504 drawsquare(c
&& c
->tags
& 1 << i
, isoccupied(i
), isurgent(i
), dc
.sel
);
507 drawtext(tags
[i
], dc
.norm
, isurgent(i
));
508 drawsquare(c
&& c
->tags
& 1 << i
, isoccupied(i
), isurgent(i
), dc
.norm
);
514 drawtext(lt
->symbol
, dc
.norm
, ismax
);
525 drawtext(stext
, dc
.norm
, False
);
526 if((dc
.w
= dc
.x
- x
) > bh
) {
529 drawtext(c
->name
, dc
.sel
, False
);
530 drawsquare(c
->isfixed
, c
->isfloating
, False
, dc
.sel
);
533 drawtext(NULL
, dc
.norm
, False
);
535 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, ww
, bh
, 0, 0);
540 drawsquare(Bool filled
, Bool empty
, Bool invert
, ulong col
[ColLast
]) {
543 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
545 gcv
.foreground
= col
[invert
? ColBG
: ColFG
];
546 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
547 x
= (dc
.font
.ascent
+ dc
.font
.descent
+ 2) / 4;
551 r
.width
= r
.height
= x
+ 1;
552 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
555 r
.width
= r
.height
= x
;
556 XDrawRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
561 drawtext(const char *text
, ulong col
[ColLast
], Bool invert
) {
562 int i
, x
, y
, h
, len
, olen
;
563 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
566 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColFG
: ColBG
]);
567 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
571 len
= MIN(olen
, sizeof buf
);
572 memcpy(buf
, text
, len
);
573 h
= dc
.font
.ascent
+ dc
.font
.descent
;
574 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
576 /* shorten text if necessary */
577 for(; len
&& (i
= textnw(buf
, len
)) > dc
.w
- h
; len
--);
581 for(i
= len
; i
&& i
> len
- 3; buf
[--i
] = '.');
582 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColBG
: ColFG
]);
584 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
586 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
590 enternotify(XEvent
*e
) {
592 XCrossingEvent
*ev
= &e
->xcrossing
;
594 if((ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
) && ev
->window
!= root
)
596 if((c
= getclient(ev
->window
)))
603 eprint(const char *errstr
, ...) {
606 va_start(ap
, errstr
);
607 vfprintf(stderr
, errstr
, ap
);
614 XExposeEvent
*ev
= &e
->xexpose
;
616 if(ev
->count
== 0 && (ev
->window
== barwin
))
622 if(!c
|| c
->isbanned
)
623 for(c
= stack
; c
&& c
->isbanned
; c
= c
->snext
);
624 if(sel
&& sel
!= c
) {
625 grabbuttons(sel
, False
);
626 XSetWindowBorder(dpy
, sel
->win
, dc
.norm
[ColBorder
]);
631 grabbuttons(c
, True
);
632 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBorder
]);
633 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
636 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
642 focusin(XEvent
*e
) { /* there are some broken focus acquiring clients */
643 XFocusChangeEvent
*ev
= &e
->xfocus
;
645 if(sel
&& ev
->window
!= sel
->win
)
646 XSetInputFocus(dpy
, sel
->win
, RevertToPointerRoot
, CurrentTime
);
650 focusstack(const Arg
*arg
) {
651 Client
*c
= NULL
, *i
;
656 for(c
= sel
->next
; c
&& c
->isbanned
; c
= c
->next
);
658 for(c
= clients
; c
&& c
->isbanned
; c
= c
->next
);
661 for(i
= clients
; i
!= sel
; i
= i
->next
)
665 for(; i
; i
= i
->next
)
676 getclient(Window w
) {
679 for(c
= clients
; c
&& c
->win
!= w
; c
= c
->next
);
684 getcolor(const char *colstr
) {
685 Colormap cmap
= DefaultColormap(dpy
, screen
);
688 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
689 eprint("error, cannot allocate color '%s'\n", colstr
);
697 unsigned char *p
= NULL
;
701 status
= XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
702 &real
, &format
, &n
, &extra
, (unsigned char **)&p
);
703 if(status
!= Success
)
712 gettextprop(Window w
, Atom atom
, char *text
, uint size
) {
717 if(!text
|| size
== 0)
720 XGetTextProperty(dpy
, w
, &name
, atom
);
723 if(name
.encoding
== XA_STRING
)
724 strncpy(text
, (char *)name
.value
, size
- 1);
726 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
728 strncpy(text
, *list
, size
- 1);
729 XFreeStringList(list
);
732 text
[size
- 1] = '\0';
738 grabbuttons(Client
*c
, Bool focused
) {
740 uint buttons
[] = { Button1
, Button2
, Button3
};
741 uint modifiers
[] = { MODKEY
, MODKEY
|LockMask
, MODKEY
|numlockmask
, MODKEY
|numlockmask
|LockMask
};
743 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
745 for(i
= 0; i
< LENGTH(buttons
); i
++)
746 for(j
= 0; j
< LENGTH(modifiers
); j
++)
747 XGrabButton(dpy
, buttons
[i
], modifiers
[j
], c
->win
, False
,
748 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
750 XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
,
751 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
758 XModifierKeymap
*modmap
;
760 /* init modifier map */
761 modmap
= XGetModifierMapping(dpy
);
762 for(i
= 0; i
< 8; i
++)
763 for(j
= 0; j
< modmap
->max_keypermod
; j
++) {
764 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
] == XKeysymToKeycode(dpy
, XK_Num_Lock
))
765 numlockmask
= (1 << i
);
767 XFreeModifiermap(modmap
);
769 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
770 for(i
= 0; i
< LENGTH(keys
); i
++) {
771 code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
);
772 XGrabKey(dpy
, code
, keys
[i
].mod
, root
, True
,
773 GrabModeAsync
, GrabModeAsync
);
774 XGrabKey(dpy
, code
, keys
[i
].mod
|LockMask
, root
, True
,
775 GrabModeAsync
, GrabModeAsync
);
776 XGrabKey(dpy
, code
, keys
[i
].mod
|numlockmask
, root
, True
,
777 GrabModeAsync
, GrabModeAsync
);
778 XGrabKey(dpy
, code
, keys
[i
].mod
|numlockmask
|LockMask
, root
, True
,
779 GrabModeAsync
, GrabModeAsync
);
784 initfont(const char *fontstr
) {
785 char *def
, **missing
;
790 XFreeFontSet(dpy
, dc
.font
.set
);
791 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
794 fprintf(stderr
, "dwm: missing fontset: %s\n", missing
[n
]);
795 XFreeStringList(missing
);
798 XFontSetExtents
*font_extents
;
799 XFontStruct
**xfonts
;
801 dc
.font
.ascent
= dc
.font
.descent
= 0;
802 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
803 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
804 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
805 dc
.font
.ascent
= MAX(dc
.font
.ascent
, (*xfonts
)->ascent
);
806 dc
.font
.descent
= MAX(dc
.font
.descent
,(*xfonts
)->descent
);
812 XFreeFont(dpy
, dc
.font
.xfont
);
813 dc
.font
.xfont
= NULL
;
814 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
))
815 && !(dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed")))
816 eprint("error, cannot load font: '%s'\n", fontstr
);
817 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
818 dc
.font
.descent
= dc
.font
.xfont
->descent
;
820 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
827 for(c
= clients
; c
; c
= c
->next
)
834 isprotodel(Client
*c
) {
839 if(XGetWMProtocols(dpy
, c
->win
, &protocols
, &n
)) {
840 for(i
= 0; !ret
&& i
< n
; i
++)
841 if(protocols
[i
] == wmatom
[WMDelete
])
852 for(c
= clients
; c
; c
= c
->next
)
853 if(c
->isurgent
&& c
->tags
& 1 << t
)
859 keypress(XEvent
*e
) {
865 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
866 for(i
= 0; i
< LENGTH(keys
); i
++)
867 if(keysym
== keys
[i
].keysym
868 && CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
)
870 keys
[i
].func(&(keys
[i
].arg
));
874 killclient(const Arg
*arg
) {
879 if(isprotodel(sel
)) {
880 ev
.type
= ClientMessage
;
881 ev
.xclient
.window
= sel
->win
;
882 ev
.xclient
.message_type
= wmatom
[WMProtocols
];
883 ev
.xclient
.format
= 32;
884 ev
.xclient
.data
.l
[0] = wmatom
[WMDelete
];
885 ev
.xclient
.data
.l
[1] = CurrentTime
;
886 XSendEvent(dpy
, sel
->win
, False
, NoEventMask
, &ev
);
889 XKillClient(dpy
, sel
->win
);
893 manage(Window w
, XWindowAttributes
*wa
) {
894 Client
*c
, *t
= NULL
;
899 if(!(c
= calloc(1, sizeof(Client
))))
900 eprint("fatal: could not calloc() %u bytes\n", sizeof(Client
));
908 c
->oldbw
= wa
->border_width
;
909 if(c
->w
== sw
&& c
->h
== sh
) {
912 c
->bw
= wa
->border_width
;
915 if(c
->x
+ c
->w
+ 2 * c
->bw
> sx
+ sw
)
916 c
->x
= sx
+ sw
- c
->w
- 2 * c
->bw
;
917 if(c
->y
+ c
->h
+ 2 * c
->bw
> sy
+ sh
)
918 c
->y
= sy
+ sh
- c
->h
- 2 * c
->bw
;
919 c
->x
= MAX(c
->x
, sx
);
920 c
->y
= MAX(c
->y
, by
== 0 ? bh
: sy
);
924 wc
.border_width
= c
->bw
;
925 XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
926 XSetWindowBorder(dpy
, w
, dc
.norm
[ColBorder
]);
927 configure(c
); /* propagates border_width, if size doesn't change */
929 XSelectInput(dpy
, w
, EnterWindowMask
|FocusChangeMask
|PropertyChangeMask
|StructureNotifyMask
);
930 grabbuttons(c
, False
);
932 if((rettrans
= XGetTransientForHint(dpy
, w
, &trans
) == Success
))
933 for(t
= clients
; t
&& t
->win
!= trans
; t
= t
->next
);
939 c
->isfloating
= (rettrans
== Success
) || c
->isfixed
;
941 XRaiseWindow(dpy
, c
->win
);
944 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
); /* some windows require this */
945 XMapWindow(dpy
, c
->win
);
946 setclientstate(c
, NormalState
);
951 mappingnotify(XEvent
*e
) {
952 XMappingEvent
*ev
= &e
->xmapping
;
954 XRefreshKeyboardMapping(ev
);
955 if(ev
->request
== MappingKeyboard
)
960 maprequest(XEvent
*e
) {
961 static XWindowAttributes wa
;
962 XMapRequestEvent
*ev
= &e
->xmaprequest
;
964 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
966 if(wa
.override_redirect
)
968 if(!getclient(ev
->window
))
969 manage(ev
->window
, &wa
);
973 movemouse(Client
*c
) {
974 int x1
, y1
, ocx
, ocy
, di
, nx
, ny
;
982 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
983 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
985 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
987 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
990 XUngrabPointer(dpy
, CurrentTime
);
992 case ConfigureRequest
:
995 handler
[ev
.type
](&ev
);
999 nx
= ocx
+ (ev
.xmotion
.x
- x1
);
1000 ny
= ocy
+ (ev
.xmotion
.y
- y1
);
1001 if(snap
&& nx
>= wx
&& nx
<= wx
+ ww
1002 && ny
>= wy
&& ny
<= wy
+ wh
) {
1003 if(abs(wx
- nx
) < snap
)
1005 else if(abs((wx
+ ww
) - (nx
+ c
->w
+ 2 * c
->bw
)) < snap
)
1006 nx
= wx
+ ww
- c
->w
- 2 * c
->bw
;
1007 if(abs(wy
- ny
) < snap
)
1009 else if(abs((wy
+ wh
) - (ny
+ c
->h
+ 2 * c
->bw
)) < snap
)
1010 ny
= wy
+ wh
- c
->h
- 2 * c
->bw
;
1011 if(!c
->isfloating
&& lt
->arrange
&& (abs(nx
- c
->x
) > snap
|| abs(ny
- c
->y
) > snap
))
1012 togglefloating(NULL
);
1014 if(!lt
->arrange
|| c
->isfloating
)
1015 resize(c
, nx
, ny
, c
->w
, c
->h
, False
);
1022 nexttiled(Client
*c
) {
1023 for(; c
&& (c
->isfloating
|| c
->isbanned
); c
= c
->next
);
1028 propertynotify(XEvent
*e
) {
1031 XPropertyEvent
*ev
= &e
->xproperty
;
1033 if(ev
->state
== PropertyDelete
)
1034 return; /* ignore */
1035 if((c
= getclient(ev
->window
))) {
1038 case XA_WM_TRANSIENT_FOR
:
1039 XGetTransientForHint(dpy
, c
->win
, &trans
);
1040 if(!c
->isfloating
&& (c
->isfloating
= (getclient(trans
) != NULL
)))
1043 case XA_WM_NORMAL_HINTS
:
1051 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
1060 quit(const Arg
*arg
) {
1061 readin
= running
= False
;
1065 resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
) {
1069 /* set minimum possible */
1073 /* temporarily remove base dimensions */
1077 /* adjust for aspect limits */
1078 if(c
->mina
> 0 && c
->maxa
> 0) {
1079 if(c
->maxa
< (float) w
/h
)
1081 else if(c
->mina
> (float) h
/w
)
1085 /* adjust for increment value */
1091 /* restore base dimensions */
1095 w
= MAX(w
, c
->minw
);
1096 h
= MAX(h
, c
->minh
);
1099 w
= MIN(w
, c
->maxw
);
1102 h
= MIN(h
, c
->maxh
);
1104 if(w
<= 0 || h
<= 0)
1107 x
= sw
- w
- 2 * c
->bw
;
1109 y
= sh
- h
- 2 * c
->bw
;
1110 if(x
+ w
+ 2 * c
->bw
< sx
)
1112 if(y
+ h
+ 2 * c
->bw
< sy
)
1118 if(c
->x
!= x
|| c
->y
!= y
|| c
->w
!= w
|| c
->h
!= h
|| c
->ismoved
) {
1122 c
->w
= wc
.width
= w
;
1123 c
->h
= wc
.height
= h
;
1124 wc
.border_width
= c
->bw
;
1125 XConfigureWindow(dpy
, c
->win
,
1126 CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
, &wc
);
1133 resizemouse(Client
*c
) {
1141 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1142 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
1144 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1146 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1149 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0,
1150 c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1151 XUngrabPointer(dpy
, CurrentTime
);
1152 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1154 case ConfigureRequest
:
1157 handler
[ev
.type
](&ev
);
1161 nw
= MAX(ev
.xmotion
.x
- ocx
- 2 * c
->bw
+ 1, 1);
1162 nh
= MAX(ev
.xmotion
.y
- ocy
- 2 * c
->bw
+ 1, 1);
1164 if(snap
&& nw
>= wx
&& nw
<= wx
+ ww
1165 && nh
>= wy
&& nh
<= wy
+ wh
) {
1166 if(!c
->isfloating
&& lt
->arrange
1167 && (abs(nw
- c
->w
) > snap
|| abs(nh
- c
->h
) > snap
))
1168 togglefloating(NULL
);
1170 if(!lt
->arrange
|| c
->isfloating
)
1171 resize(c
, c
->x
, c
->y
, nw
, nh
, True
);
1186 if(ismax
|| sel
->isfloating
|| !lt
->arrange
)
1187 XRaiseWindow(dpy
, sel
->win
);
1188 if(!ismax
&& lt
->arrange
) {
1189 wc
.stack_mode
= Below
;
1190 wc
.sibling
= barwin
;
1191 for(c
= stack
; c
; c
= c
->snext
)
1192 if(!c
->isfloating
&& !c
->isbanned
) {
1193 XConfigureWindow(dpy
, c
->win
, CWSibling
|CWStackMode
, &wc
);
1194 wc
.sibling
= c
->win
;
1198 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1204 char sbuf
[sizeof stext
];
1210 /* main event loop, also reads status text from stdin */
1212 xfd
= ConnectionNumber(dpy
);
1215 len
= sizeof stext
- 1;
1216 sbuf
[len
] = stext
[len
] = '\0'; /* 0-terminator is never touched */
1220 FD_SET(STDIN_FILENO
, &rd
);
1222 if(select(xfd
+ 1, &rd
, NULL
, NULL
, NULL
) == -1) {
1225 eprint("select failed\n");
1227 if(FD_ISSET(STDIN_FILENO
, &rd
)) {
1228 switch((r
= read(STDIN_FILENO
, sbuf
+ offset
, len
- offset
))) {
1230 strncpy(stext
, strerror(errno
), len
);
1234 strncpy(stext
, "EOF", 4);
1238 for(p
= sbuf
+ offset
; r
> 0; p
++, r
--, offset
++)
1239 if(*p
== '\n' || *p
== '\0') {
1241 strncpy(stext
, sbuf
, len
);
1242 p
+= r
- 1; /* p is sbuf + offset + r - 1 */
1243 for(r
= 0; *(p
- r
) && *(p
- r
) != '\n'; r
++);
1246 memmove(sbuf
, p
- r
+ 1, r
);
1253 while(XPending(dpy
)) {
1254 XNextEvent(dpy
, &ev
);
1255 if(handler
[ev
.type
])
1256 (handler
[ev
.type
])(&ev
); /* call handler */
1264 Window
*wins
, d1
, d2
;
1265 XWindowAttributes wa
;
1268 if(XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
1269 for(i
= 0; i
< num
; i
++) {
1270 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
1271 || wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
1273 if(wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
1274 manage(wins
[i
], &wa
);
1276 for(i
= 0; i
< num
; i
++) { /* now the transients */
1277 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
1279 if(XGetTransientForHint(dpy
, wins
[i
], &d1
)
1280 && (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
1281 manage(wins
[i
], &wa
);
1289 setclientstate(Client
*c
, long state
) {
1290 long data
[] = {state
, None
};
1292 XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
1293 PropModeReplace
, (unsigned char *)data
, 2);
1296 /* arg > 1.0 will set mfact absolutly */
1298 setmfact(const Arg
*arg
) {
1301 if(!arg
|| !lt
->arrange
)
1303 f
= arg
->f
< 1.0 ? arg
->f
+ mfact
: arg
->f
- 1.0;
1304 if(f
< 0.1 || f
> 0.9)
1314 XSetWindowAttributes wa
;
1317 screen
= DefaultScreen(dpy
);
1318 root
= RootWindow(dpy
, screen
);
1322 sw
= DisplayWidth(dpy
, screen
);
1323 sh
= DisplayHeight(dpy
, screen
);
1324 bh
= dc
.font
.height
+ 2;
1328 wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
1329 wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
1330 wmatom
[WMName
] = XInternAtom(dpy
, "WM_NAME", False
);
1331 wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
1332 netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
1333 netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
1336 wa
.cursor
= cursor
[CurNormal
] = XCreateFontCursor(dpy
, XC_left_ptr
);
1337 cursor
[CurResize
] = XCreateFontCursor(dpy
, XC_sizing
);
1338 cursor
[CurMove
] = XCreateFontCursor(dpy
, XC_fleur
);
1340 /* init appearance */
1341 dc
.norm
[ColBorder
] = getcolor(NORMBORDERCOLOR
);
1342 dc
.norm
[ColBG
] = getcolor(NORMBGCOLOR
);
1343 dc
.norm
[ColFG
] = getcolor(NORMFGCOLOR
);
1344 dc
.sel
[ColBorder
] = getcolor(SELBORDERCOLOR
);
1345 dc
.sel
[ColBG
] = getcolor(SELBGCOLOR
);
1346 dc
.sel
[ColFG
] = getcolor(SELFGCOLOR
);
1349 dc
.drawable
= XCreatePixmap(dpy
, root
, DisplayWidth(dpy
, screen
), bh
, DefaultDepth(dpy
, screen
));
1350 dc
.gc
= XCreateGC(dpy
, root
, 0, 0);
1351 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
1353 XSetFont(dpy
, dc
.gc
, dc
.font
.xfont
->fid
);
1356 for(blw
= i
= 0; LENGTH(layouts
) > 1 && i
< LENGTH(layouts
); i
++) {
1357 w
= TEXTW(layouts
[i
].symbol
);
1361 wa
.override_redirect
= 1;
1362 wa
.background_pixmap
= ParentRelative
;
1363 wa
.event_mask
= ButtonPressMask
|ExposureMask
;
1365 barwin
= XCreateWindow(dpy
, root
, wx
, by
, ww
, bh
, 0, DefaultDepth(dpy
, screen
),
1366 CopyFromParent
, DefaultVisual(dpy
, screen
),
1367 CWOverrideRedirect
|CWBackPixmap
|CWEventMask
, &wa
);
1368 XDefineCursor(dpy
, barwin
, cursor
[CurNormal
]);
1369 XMapRaised(dpy
, barwin
);
1370 strcpy(stext
, "dwm-"VERSION
);
1373 /* EWMH support per view */
1374 XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
1375 PropModeReplace
, (unsigned char *) netatom
, NetLast
);
1377 /* select for events */
1378 wa
.event_mask
= SubstructureRedirectMask
|SubstructureNotifyMask
1379 |EnterWindowMask
|LeaveWindowMask
|StructureNotifyMask
;
1380 XChangeWindowAttributes(dpy
, root
, CWEventMask
|CWCursor
, &wa
);
1381 XSelectInput(dpy
, root
, wa
.event_mask
);
1389 spawn(const Arg
*arg
) {
1390 /* The double-fork construct avoids zombie processes and keeps the code
1391 * clean from stupid signal handlers. */
1395 close(ConnectionNumber(dpy
));
1397 execvp(((char **)arg
->v
)[0], (char **)arg
->v
);
1398 fprintf(stderr
, "dwm: execvp %s", ((char **)arg
->v
)[0]);
1407 tag(const Arg
*arg
) {
1408 if(sel
&& arg
->ui
& TAGMASK
) {
1409 sel
->tags
= arg
->ui
& TAGMASK
;
1415 textnw(const char *text
, uint len
) {
1419 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
1422 return XTextWidth(dc
.font
.xfont
, text
, len
);
1431 for(n
= 0, c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
), n
++);
1436 c
= nexttiled(clients
);
1438 resize(c
, wx
, wy
, (n
== 1 ? ww
: mw
) - 2 * c
->bw
, wh
- 2 * c
->bw
, resizehints
);
1444 x
= (wx
+ mw
> c
->x
+ c
->w
) ? c
->x
+ c
->w
+ 2 * c
->bw
: wx
+ mw
;
1446 w
= (wx
+ mw
> c
->x
+ c
->w
) ? wx
+ ww
- x
: ww
- mw
;
1451 for(i
= 0, c
= nexttiled(c
->next
); c
; c
= nexttiled(c
->next
), i
++) {
1452 resize(c
, x
, y
, w
- 2 * c
->bw
, /* remainder */ ((i
+ 1 == n
)
1453 ? (wy
+ wh
) - y
: h
) - 2 * c
->bw
, resizehints
);
1455 y
= c
->y
+ c
->h
+ 2 * c
->bw
;
1460 togglebar(const Arg
*arg
) {
1468 togglefloating(const Arg
*arg
) {
1471 sel
->isfloating
= !sel
->isfloating
|| sel
->isfixed
;
1473 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
);
1478 togglelayout(const Arg
*arg
) {
1479 if(++lt
== &layouts
[LENGTH(layouts
)])
1488 togglemax(const Arg
*arg
) {
1494 toggletag(const Arg
*arg
) {
1495 if(sel
&& (sel
->tags
^= (arg
->ui
& TAGMASK
)))
1500 toggleview(const Arg
*arg
) {
1501 if((tagset
[seltags
] ^= (arg
->ui
& TAGMASK
)))
1506 unmanage(Client
*c
) {
1509 wc
.border_width
= c
->oldbw
;
1510 /* The server grab construct avoids race conditions. */
1512 XSetErrorHandler(xerrordummy
);
1513 XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
1518 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1519 setclientstate(c
, WithdrawnState
);
1522 XSetErrorHandler(xerror
);
1528 unmapnotify(XEvent
*e
) {
1530 XUnmapEvent
*ev
= &e
->xunmap
;
1532 if((c
= getclient(ev
->window
)))
1538 if(dc
.drawable
!= 0)
1539 XFreePixmap(dpy
, dc
.drawable
);
1540 dc
.drawable
= XCreatePixmap(dpy
, root
, ww
, bh
, DefaultDepth(dpy
, screen
));
1541 XMoveResizeWindow(dpy
, barwin
, wx
, by
, ww
, bh
);
1548 XineramaScreenInfo
*info
= NULL
;
1550 /* window area geometry */
1551 if(XineramaIsActive(dpy
)) {
1552 info
= XineramaQueryScreens(dpy
, &i
);
1554 wy
= showbar
&& topbar
? info
[0].y_org
+ bh
: info
[0].y_org
;
1556 wh
= showbar
? info
[0].height
- bh
: info
[0].height
;
1563 wy
= showbar
&& topbar
? sy
+ bh
: sy
;
1565 wh
= showbar
? sh
- bh
: sh
;
1569 by
= showbar
? (topbar
? wy
- bh
: wy
+ wh
) : -bh
;
1573 updatesizehints(Client
*c
) {
1577 XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
);
1578 if(size
.flags
& PBaseSize
) {
1579 c
->basew
= size
.base_width
;
1580 c
->baseh
= size
.base_height
;
1582 else if(size
.flags
& PMinSize
) {
1583 c
->basew
= size
.min_width
;
1584 c
->baseh
= size
.min_height
;
1587 c
->basew
= c
->baseh
= 0;
1588 if(size
.flags
& PResizeInc
) {
1589 c
->incw
= size
.width_inc
;
1590 c
->inch
= size
.height_inc
;
1593 c
->incw
= c
->inch
= 0;
1594 if(size
.flags
& PMaxSize
) {
1595 c
->maxw
= size
.max_width
;
1596 c
->maxh
= size
.max_height
;
1599 c
->maxw
= c
->maxh
= 0;
1600 if(size
.flags
& PMinSize
) {
1601 c
->minw
= size
.min_width
;
1602 c
->minh
= size
.min_height
;
1604 else if(size
.flags
& PBaseSize
) {
1605 c
->minw
= size
.base_width
;
1606 c
->minh
= size
.base_height
;
1609 c
->minw
= c
->minh
= 0;
1610 if(size
.flags
& PAspect
) {
1611 c
->mina
= (float)size
.min_aspect
.y
/ (float)size
.min_aspect
.x
;
1612 c
->maxa
= (float)size
.max_aspect
.x
/ (float)size
.max_aspect
.y
;
1615 c
->maxa
= c
->mina
= 0.0;
1616 c
->isfixed
= (c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
1617 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
1621 updatetitle(Client
*c
) {
1622 if(!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
1623 gettextprop(c
->win
, wmatom
[WMName
], c
->name
, sizeof c
->name
);
1627 updatewmhints(Client
*c
) {
1630 if((wmh
= XGetWMHints(dpy
, c
->win
))) {
1632 sel
->isurgent
= False
;
1634 c
->isurgent
= (wmh
->flags
& XUrgencyHint
) ? True
: False
;
1640 view(const Arg
*arg
) {
1641 seltags
^= 1; /* toggle sel tagset */
1642 if(arg
&& (arg
->ui
& TAGMASK
))
1643 tagset
[seltags
] = arg
->i
& TAGMASK
;
1647 /* There's no way to check accesses to destroyed windows, thus those cases are
1648 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1649 * default error handler, which may call exit. */
1651 xerror(Display
*dpy
, XErrorEvent
*ee
) {
1652 if(ee
->error_code
== BadWindow
1653 || (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
1654 || (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
1655 || (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
1656 || (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
1657 || (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
1658 || (ee
->request_code
== X_GrabButton
&& ee
->error_code
== BadAccess
)
1659 || (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
1660 || (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
1662 fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
1663 ee
->request_code
, ee
->error_code
);
1664 return xerrorxlib(dpy
, ee
); /* may call exit */
1668 xerrordummy(Display
*dpy
, XErrorEvent
*ee
) {
1672 /* Startup Error handler to check if another window manager
1673 * is already running. */
1675 xerrorstart(Display
*dpy
, XErrorEvent
*ee
) {
1681 zoom(const Arg
*arg
) {
1684 if(ismax
|| !lt
->arrange
|| (sel
&& sel
->isfloating
))
1686 if(c
== nexttiled(clients
))
1687 if(!c
|| !(c
= nexttiled(c
->next
)))
1696 main(int argc
, char *argv
[]) {
1697 if(argc
== 2 && !strcmp("-v", argv
[1]))
1698 eprint("dwm-"VERSION
", © 2006-2008 dwm engineers, see LICENSE for details\n");
1700 eprint("usage: dwm [-v]\n");
1702 setlocale(LC_CTYPE
, "");
1703 if(!(dpy
= XOpenDisplay(0)))
1704 eprint("dwm: cannot open display\n");