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 BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
48 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
49 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
50 #define ISVISIBLE(x) (x->tags & tagset[seltags])
51 #define LENGTH(x) (sizeof x / sizeof x[0])
52 #define MAX(a, b) ((a) > (b) ? (a) : (b))
53 #define MIN(a, b) ((a) < (b) ? (a) : (b))
55 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
56 #define TAGMASK ((int)((1LL << LENGTH(tags)) - 1))
57 #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height)
60 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
61 enum { ColBorder
, ColFG
, ColBG
, ColLast
}; /* color */
62 enum { NetSupported
, NetWMName
, NetLast
}; /* EWMH atoms */
63 enum { WMProtocols
, WMDelete
, WMName
, WMState
, WMLast
};/* default atoms */
64 enum { ClkTagBar
, ClkLtSymbol
, ClkStatusText
, ClkWinTitle
,
65 ClkClientWin
, ClkRootWin
, ClkLast
}; /* clicks */
78 void (*func
)(const Arg
*arg
);
82 typedef struct Client Client
;
87 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
90 Bool isfixed
, isfloating
, isurgent
;
98 unsigned long norm
[ColLast
];
99 unsigned long sel
[ColLast
];
109 } DC
; /* draw context */
114 void (*func
)(const Arg
*);
120 void (*arrange
)(void);
125 const char *instance
;
131 /* function declarations */
132 static void applyrules(Client
*c
);
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(void);
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
, Bool sizehints
);
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 spawn(const Arg
*arg
);
183 static void tag(const Arg
*arg
);
184 static int textnw(const char *text
, unsigned int len
);
185 static void tile(void);
186 static void togglebar(const Arg
*arg
);
187 static void togglefloating(const Arg
*arg
);
188 static void toggletag(const Arg
*arg
);
189 static void toggleview(const Arg
*arg
);
190 static void unmanage(Client
*c
);
191 static void unmapnotify(XEvent
*e
);
192 static void updatebar(void);
193 static void updategeom(void);
194 static void updatesizehints(Client
*c
);
195 static void updatetitle(Client
*c
);
196 static void updatewmhints(Client
*c
);
197 static void view(const Arg
*arg
);
198 static int xerror(Display
*dpy
, XErrorEvent
*ee
);
199 static int xerrordummy(Display
*dpy
, XErrorEvent
*ee
);
200 static int xerrorstart(Display
*dpy
, XErrorEvent
*ee
);
201 static void zoom(const Arg
*arg
);
204 static char stext
[256];
205 static int screen
, sx
, sy
, sw
, sh
;
206 static int by
, bh
, blw
, wx
, wy
, ww
, wh
;
207 static unsigned int seltags
= 0, sellt
= 0;
208 static int (*xerrorxlib
)(Display
*, XErrorEvent
*);
209 static unsigned int numlockmask
= 0;
210 static void (*handler
[LASTEvent
]) (XEvent
*) = {
211 [ButtonPress
] = buttonpress
,
212 [ConfigureRequest
] = configurerequest
,
213 [ConfigureNotify
] = configurenotify
,
214 [DestroyNotify
] = destroynotify
,
215 [EnterNotify
] = enternotify
,
218 [KeyPress
] = keypress
,
219 [MappingNotify
] = mappingnotify
,
220 [MapRequest
] = maprequest
,
221 [PropertyNotify
] = propertynotify
,
222 [UnmapNotify
] = unmapnotify
224 static Atom wmatom
[WMLast
], netatom
[NetLast
];
226 static Bool running
= True
;
227 static unsigned int tagset
[] = {1, 1}; /* after start, first tag is selected */
228 static Client
*clients
= NULL
;
229 static Client
*sel
= NULL
;
230 static Client
*stack
= NULL
;
231 static Cursor cursor
[CurLast
];
234 static Layout
*lt
[] = { NULL
, NULL
};
235 static Window root
, barwin
;
236 /* configuration, allows nested code to access above variables */
239 /* compile-time check if all tags fit into an unsigned int bit array. */
240 struct NumTags
{ char limitexceeded
[sizeof(unsigned int) * 8 < LENGTH(tags
) ? -1 : 1]; };
242 /* function implementations */
244 applyrules(Client
*c
) {
247 XClassHint ch
= { 0 };
250 XGetClassHint(dpy
, c
->win
, &ch
);
251 for(i
= 0; i
< LENGTH(rules
); i
++) {
253 if((!r
->title
|| strstr(c
->name
, r
->title
))
254 && (!r
->class || (ch
.res_class
&& strstr(ch
.res_class
, r
->class)))
255 && (!r
->instance
|| (ch
.res_name
&& strstr(ch
.res_name
, r
->instance
)))) {
256 c
->isfloating
= r
->isfloating
;
257 c
->tags
|= r
->tags
& TAGMASK
;
265 c
->tags
= tagset
[seltags
];
272 for(c
= clients
; c
; c
= c
->next
)
274 XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
275 if(!lt
[sellt
]->arrange
|| c
->isfloating
)
276 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, True
);
279 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
283 if(lt
[sellt
]->arrange
)
284 lt
[sellt
]->arrange();
295 attachstack(Client
*c
) {
301 buttonpress(XEvent
*e
) {
302 unsigned int i
, x
, click
;
305 XButtonPressedEvent
*ev
= &e
->xbutton
;
308 if(ev
->window
== barwin
) {
310 do x
+= TEXTW(tags
[i
]); while(ev
->x
>= x
&& ++i
< LENGTH(tags
));
311 if(i
< LENGTH(tags
)) {
315 else if(ev
->x
< x
+ blw
)
317 else if(ev
->x
> wx
+ ww
- TEXTW(stext
))
318 click
= ClkStatusText
;
322 else if((c
= getclient(ev
->window
))) {
324 click
= ClkClientWin
;
327 for(i
= 0; i
< LENGTH(buttons
); i
++)
328 if(click
== buttons
[i
].click
&& buttons
[i
].func
&& buttons
[i
].button
== ev
->button
329 && CLEANMASK(buttons
[i
].mask
) == CLEANMASK(ev
->state
))
330 buttons
[i
].func(click
== ClkTagBar
? &arg
: &buttons
[i
].arg
);
336 XSetErrorHandler(xerrorstart
);
338 /* this causes an error if some other window manager is running */
339 XSelectInput(dpy
, DefaultRootWindow(dpy
), SubstructureRedirectMask
);
342 die("dwm: another window manager is already running\n");
343 XSetErrorHandler(NULL
);
344 xerrorxlib
= XSetErrorHandler(xerror
);
351 Layout foo
= { "", NULL
};
359 XFreeFontSet(dpy
, dc
.font
.set
);
361 XFreeFont(dpy
, dc
.font
.xfont
);
362 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
363 XFreePixmap(dpy
, dc
.drawable
);
365 XFreeCursor(dpy
, cursor
[CurNormal
]);
366 XFreeCursor(dpy
, cursor
[CurResize
]);
367 XFreeCursor(dpy
, cursor
[CurMove
]);
368 XDestroyWindow(dpy
, barwin
);
370 XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
378 for(c
= clients
; c
; c
= c
->next
)
379 if(ISVISIBLE(c
) && c
->isurgent
) {
381 if (!(wmh
= XGetWMHints(dpy
, c
->win
)))
384 wmh
->flags
&= ~XUrgencyHint
;
385 XSetWMHints(dpy
, c
->win
, wmh
);
391 configure(Client
*c
) {
394 ce
.type
= ConfigureNotify
;
402 ce
.border_width
= c
->bw
;
404 ce
.override_redirect
= False
;
405 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
409 configurenotify(XEvent
*e
) {
410 XConfigureEvent
*ev
= &e
->xconfigure
;
412 if(ev
->window
== root
&& (ev
->width
!= sw
|| ev
->height
!= sh
)) {
422 configurerequest(XEvent
*e
) {
424 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
427 if((c
= getclient(ev
->window
))) {
428 if(ev
->value_mask
& CWBorderWidth
)
429 c
->bw
= ev
->border_width
;
430 else if(c
->isfloating
|| !lt
[sellt
]->arrange
) {
431 if(ev
->value_mask
& CWX
)
433 if(ev
->value_mask
& CWY
)
435 if(ev
->value_mask
& CWWidth
)
437 if(ev
->value_mask
& CWHeight
)
439 if((c
->x
- sx
+ c
->w
) > sw
&& c
->isfloating
)
440 c
->x
= sx
+ (sw
/ 2 - c
->w
/ 2); /* center in x direction */
441 if((c
->y
- sy
+ c
->h
) > sh
&& c
->isfloating
)
442 c
->y
= sy
+ (sh
/ 2 - c
->h
/ 2); /* center in y direction */
443 if((ev
->value_mask
& (CWX
|CWY
)) && !(ev
->value_mask
& (CWWidth
|CWHeight
)))
446 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
454 wc
.width
= ev
->width
;
455 wc
.height
= ev
->height
;
456 wc
.border_width
= ev
->border_width
;
457 wc
.sibling
= ev
->above
;
458 wc
.stack_mode
= ev
->detail
;
459 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
465 destroynotify(XEvent
*e
) {
467 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
469 if((c
= getclient(ev
->window
)))
477 for(tc
= &clients
; *tc
&& *tc
!= c
; tc
= &(*tc
)->next
);
482 detachstack(Client
*c
) {
485 for(tc
= &stack
; *tc
&& *tc
!= c
; tc
= &(*tc
)->snext
);
490 die(const char *errstr
, ...) {
493 va_start(ap
, errstr
);
494 vfprintf(stderr
, errstr
, ap
);
502 unsigned int i
, occ
= 0, urg
= 0;
506 for(c
= clients
; c
; c
= c
->next
) {
513 for(i
= 0; i
< LENGTH(tags
); i
++) {
514 dc
.w
= TEXTW(tags
[i
]);
515 col
= tagset
[seltags
] & 1 << i
? dc
.sel
: dc
.norm
;
516 drawtext(tags
[i
], col
, urg
& 1 << i
);
517 drawsquare(sel
&& sel
->tags
& 1 << i
, occ
& 1 << i
, urg
& 1 << i
, col
);
522 drawtext(lt
[sellt
]->symbol
, dc
.norm
, False
);
533 drawtext(stext
, dc
.norm
, False
);
534 if((dc
.w
= dc
.x
- x
) > bh
) {
537 drawtext(sel
->name
, dc
.sel
, False
);
538 drawsquare(sel
->isfixed
, sel
->isfloating
, False
, dc
.sel
);
541 drawtext(NULL
, dc
.norm
, False
);
543 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, ww
, bh
, 0, 0);
548 drawsquare(Bool filled
, Bool empty
, Bool invert
, unsigned long col
[ColLast
]) {
551 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
553 gcv
.foreground
= col
[invert
? ColBG
: ColFG
];
554 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
555 x
= (dc
.font
.ascent
+ dc
.font
.descent
+ 2) / 4;
559 r
.width
= r
.height
= x
+ 1;
560 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
563 r
.width
= r
.height
= x
;
564 XDrawRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
569 drawtext(const char *text
, unsigned long col
[ColLast
], Bool invert
) {
570 int i
, x
, y
, h
, len
, olen
;
571 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
574 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColFG
: ColBG
]);
575 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
579 len
= MIN(olen
, sizeof buf
);
580 memcpy(buf
, text
, len
);
581 h
= dc
.font
.ascent
+ dc
.font
.descent
;
582 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
584 /* shorten text if necessary */
585 for(; len
&& (i
= textnw(buf
, len
)) > dc
.w
- h
; len
--);
589 for(i
= len
; i
&& i
> len
- 3; buf
[--i
] = '.');
590 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColBG
: ColFG
]);
592 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
594 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
598 enternotify(XEvent
*e
) {
600 XCrossingEvent
*ev
= &e
->xcrossing
;
602 if((ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
) && ev
->window
!= root
)
604 if((c
= getclient(ev
->window
)))
612 XExposeEvent
*ev
= &e
->xexpose
;
614 if(ev
->count
== 0 && (ev
->window
== barwin
))
620 if(!c
|| !ISVISIBLE(c
))
621 for(c
= stack
; c
&& !ISVISIBLE(c
); c
= c
->snext
);
622 if(sel
&& sel
!= c
) {
623 grabbuttons(sel
, False
);
624 XSetWindowBorder(dpy
, sel
->win
, dc
.norm
[ColBorder
]);
629 grabbuttons(c
, True
);
630 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBorder
]);
631 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
634 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
640 focusin(XEvent
*e
) { /* there are some broken focus acquiring clients */
641 XFocusChangeEvent
*ev
= &e
->xfocus
;
643 if(sel
&& ev
->window
!= sel
->win
)
644 XSetInputFocus(dpy
, sel
->win
, RevertToPointerRoot
, CurrentTime
);
648 focusstack(const Arg
*arg
) {
649 Client
*c
= NULL
, *i
;
654 for(c
= sel
->next
; c
&& !ISVISIBLE(c
); c
= c
->next
);
656 for(c
= clients
; c
&& !ISVISIBLE(c
); c
= c
->next
);
659 for(i
= clients
; i
!= sel
; i
= i
->next
)
663 for(; i
; i
= i
->next
)
674 getclient(Window w
) {
677 for(c
= clients
; c
&& c
->win
!= w
; c
= c
->next
);
682 getcolor(const char *colstr
) {
683 Colormap cmap
= DefaultColormap(dpy
, screen
);
686 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
687 die("error, cannot allocate color '%s'\n", colstr
);
695 unsigned char *p
= NULL
;
696 unsigned long n
, extra
;
699 status
= XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
700 &real
, &format
, &n
, &extra
, (unsigned char **)&p
);
701 if(status
!= Success
)
710 gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
) {
715 if(!text
|| size
== 0)
718 XGetTextProperty(dpy
, w
, &name
, atom
);
721 if(name
.encoding
== XA_STRING
)
722 strncpy(text
, (char *)name
.value
, size
- 1);
724 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
726 strncpy(text
, *list
, size
- 1);
727 XFreeStringList(list
);
730 text
[size
- 1] = '\0';
736 grabbuttons(Client
*c
, Bool focused
) {
738 unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
740 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
742 for(i
= 0; i
< LENGTH(buttons
); i
++)
743 if(buttons
[i
].click
== ClkClientWin
)
744 for(j
= 0; j
< LENGTH(modifiers
); j
++)
745 XGrabButton(dpy
, buttons
[i
].button
, buttons
[i
].mask
| modifiers
[j
], c
->win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
747 XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
,
748 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
754 unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
756 XModifierKeymap
*modmap
;
758 /* init modifier map */
759 modmap
= XGetModifierMapping(dpy
);
760 for(i
= 0; i
< 8; i
++)
761 for(j
= 0; j
< modmap
->max_keypermod
; j
++) {
762 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
] == XKeysymToKeycode(dpy
, XK_Num_Lock
))
763 numlockmask
= (1 << i
);
765 XFreeModifiermap(modmap
);
767 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
768 for(i
= 0; i
< LENGTH(keys
); i
++) {
769 code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
);
770 for(j
= 0; j
< LENGTH(modifiers
); j
++)
771 XGrabKey(dpy
, code
, keys
[i
].mod
| modifiers
[j
], root
, True
,
772 GrabModeAsync
, GrabModeAsync
);
777 initfont(const char *fontstr
) {
778 char *def
, **missing
;
783 XFreeFontSet(dpy
, dc
.font
.set
);
784 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
787 fprintf(stderr
, "dwm: missing fontset: %s\n", missing
[n
]);
788 XFreeStringList(missing
);
791 XFontSetExtents
*font_extents
;
792 XFontStruct
**xfonts
;
794 dc
.font
.ascent
= dc
.font
.descent
= 0;
795 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
796 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
797 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
798 dc
.font
.ascent
= MAX(dc
.font
.ascent
, (*xfonts
)->ascent
);
799 dc
.font
.descent
= MAX(dc
.font
.descent
,(*xfonts
)->descent
);
805 XFreeFont(dpy
, dc
.font
.xfont
);
806 dc
.font
.xfont
= NULL
;
807 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
))
808 && !(dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed")))
809 die("error, cannot load font: '%s'\n", fontstr
);
810 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
811 dc
.font
.descent
= dc
.font
.xfont
->descent
;
813 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
817 isprotodel(Client
*c
) {
822 if(XGetWMProtocols(dpy
, c
->win
, &protocols
, &n
)) {
823 for(i
= 0; !ret
&& i
< n
; i
++)
824 if(protocols
[i
] == wmatom
[WMDelete
])
832 keypress(XEvent
*e
) {
838 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
839 for(i
= 0; i
< LENGTH(keys
); i
++)
840 if(keysym
== keys
[i
].keysym
841 && CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
)
843 keys
[i
].func(&(keys
[i
].arg
));
847 killclient(const Arg
*arg
) {
852 if(isprotodel(sel
)) {
853 ev
.type
= ClientMessage
;
854 ev
.xclient
.window
= sel
->win
;
855 ev
.xclient
.message_type
= wmatom
[WMProtocols
];
856 ev
.xclient
.format
= 32;
857 ev
.xclient
.data
.l
[0] = wmatom
[WMDelete
];
858 ev
.xclient
.data
.l
[1] = CurrentTime
;
859 XSendEvent(dpy
, sel
->win
, False
, NoEventMask
, &ev
);
862 XKillClient(dpy
, sel
->win
);
866 manage(Window w
, XWindowAttributes
*wa
) {
867 Client
*c
, *t
= NULL
;
871 if(!(c
= calloc(1, sizeof(Client
))))
872 die("fatal: could not calloc() %u bytes\n", sizeof(Client
));
880 c
->oldbw
= wa
->border_width
;
881 if(c
->w
== sw
&& c
->h
== sh
) {
887 if(c
->x
+ c
->w
+ 2 * c
->bw
> sx
+ sw
)
888 c
->x
= sx
+ sw
- c
->w
- 2 * c
->bw
;
889 if(c
->y
+ c
->h
+ 2 * c
->bw
> sy
+ sh
)
890 c
->y
= sy
+ sh
- c
->h
- 2 * c
->bw
;
891 c
->x
= MAX(c
->x
, sx
);
892 /* only fix client y-offset, if the client center might cover the bar */
893 c
->y
= MAX(c
->y
, ((by
== 0) && (c
->x
+ (c
->w
/ 2) >= wx
) && (c
->x
+ (c
->w
/ 2) < wx
+ ww
)) ? bh
: sy
);
897 wc
.border_width
= c
->bw
;
898 XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
899 XSetWindowBorder(dpy
, w
, dc
.norm
[ColBorder
]);
900 configure(c
); /* propagates border_width, if size doesn't change */
902 XSelectInput(dpy
, w
, EnterWindowMask
|FocusChangeMask
|PropertyChangeMask
|StructureNotifyMask
);
903 grabbuttons(c
, False
);
905 if(XGetTransientForHint(dpy
, w
, &trans
))
906 t
= getclient(trans
);
912 c
->isfloating
= trans
|| c
->isfixed
;
914 XRaiseWindow(dpy
, c
->win
);
917 XMoveResizeWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
, c
->w
, c
->h
); /* some windows require this */
918 XMapWindow(dpy
, c
->win
);
919 setclientstate(c
, NormalState
);
924 mappingnotify(XEvent
*e
) {
925 XMappingEvent
*ev
= &e
->xmapping
;
927 XRefreshKeyboardMapping(ev
);
928 if(ev
->request
== MappingKeyboard
)
933 maprequest(XEvent
*e
) {
934 static XWindowAttributes wa
;
935 XMapRequestEvent
*ev
= &e
->xmaprequest
;
937 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
939 if(wa
.override_redirect
)
941 if(!getclient(ev
->window
))
942 manage(ev
->window
, &wa
);
949 for(c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
))
950 resize(c
, wx
, wy
, ww
- 2 * c
->bw
, wh
- 2 * c
->bw
, resizehints
);
954 movemouse(const Arg
*arg
) {
955 int x
, y
, ocx
, ocy
, di
, nx
, ny
;
966 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
967 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
969 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x
, &y
, &di
, &di
, &dui
);
971 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
974 XUngrabPointer(dpy
, CurrentTime
);
976 case ConfigureRequest
:
979 handler
[ev
.type
](&ev
);
983 nx
= ocx
+ (ev
.xmotion
.x
- x
);
984 ny
= ocy
+ (ev
.xmotion
.y
- y
);
985 if(snap
&& nx
>= wx
&& nx
<= wx
+ ww
986 && ny
>= wy
&& ny
<= wy
+ wh
) {
987 if(abs(wx
- nx
) < snap
)
989 else if(abs((wx
+ ww
) - (nx
+ c
->w
+ 2 * c
->bw
)) < snap
)
990 nx
= wx
+ ww
- c
->w
- 2 * c
->bw
;
991 if(abs(wy
- ny
) < snap
)
993 else if(abs((wy
+ wh
) - (ny
+ c
->h
+ 2 * c
->bw
)) < snap
)
994 ny
= wy
+ wh
- c
->h
- 2 * c
->bw
;
995 if(!c
->isfloating
&& lt
[sellt
]->arrange
&& (abs(nx
- c
->x
) > snap
|| abs(ny
- c
->y
) > snap
))
996 togglefloating(NULL
);
998 if(!lt
[sellt
]->arrange
|| c
->isfloating
)
999 resize(c
, nx
, ny
, c
->w
, c
->h
, False
);
1006 nexttiled(Client
*c
) {
1007 for(; c
&& (c
->isfloating
|| !ISVISIBLE(c
)); c
= c
->next
);
1012 propertynotify(XEvent
*e
) {
1015 XPropertyEvent
*ev
= &e
->xproperty
;
1017 if(ev
->state
== PropertyDelete
)
1018 return; /* ignore */
1019 if((c
= getclient(ev
->window
))) {
1022 case XA_WM_TRANSIENT_FOR
:
1023 XGetTransientForHint(dpy
, c
->win
, &trans
);
1024 if(!c
->isfloating
&& (c
->isfloating
= (getclient(trans
) != NULL
)))
1027 case XA_WM_NORMAL_HINTS
:
1035 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
1044 quit(const Arg
*arg
) {
1045 readin
= running
= False
;
1049 resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
) {
1053 /* set minimum possible */
1057 /* temporarily remove base dimensions */
1061 /* adjust for aspect limits */
1062 if(c
->mina
> 0 && c
->maxa
> 0) {
1063 if(c
->maxa
< (float) w
/h
)
1065 else if(c
->mina
> (float) h
/w
)
1069 /* adjust for increment value */
1075 /* restore base dimensions */
1079 w
= MAX(w
, c
->minw
);
1080 h
= MAX(h
, c
->minh
);
1083 w
= MIN(w
, c
->maxw
);
1086 h
= MIN(h
, c
->maxh
);
1088 if(w
<= 0 || h
<= 0)
1091 x
= sw
- w
- 2 * c
->bw
;
1093 y
= sh
- h
- 2 * c
->bw
;
1094 if(x
+ w
+ 2 * c
->bw
< sx
)
1096 if(y
+ h
+ 2 * c
->bw
< sy
)
1102 if(c
->x
!= x
|| c
->y
!= y
|| c
->w
!= w
|| c
->h
!= h
) {
1105 c
->w
= wc
.width
= w
;
1106 c
->h
= wc
.height
= h
;
1107 wc
.border_width
= c
->bw
;
1108 XConfigureWindow(dpy
, c
->win
,
1109 CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
, &wc
);
1116 resizemouse(const Arg
*arg
) {
1127 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1128 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
1130 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1132 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1135 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0,
1136 c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1137 XUngrabPointer(dpy
, CurrentTime
);
1138 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1140 case ConfigureRequest
:
1143 handler
[ev
.type
](&ev
);
1147 nw
= MAX(ev
.xmotion
.x
- ocx
- 2 * c
->bw
+ 1, 1);
1148 nh
= MAX(ev
.xmotion
.y
- ocy
- 2 * c
->bw
+ 1, 1);
1150 if(snap
&& nw
>= wx
&& nw
<= wx
+ ww
1151 && nh
>= wy
&& nh
<= wy
+ wh
) {
1152 if(!c
->isfloating
&& lt
[sellt
]->arrange
1153 && (abs(nw
- c
->w
) > snap
|| abs(nh
- c
->h
) > snap
))
1154 togglefloating(NULL
);
1156 if(!lt
[sellt
]->arrange
|| c
->isfloating
)
1157 resize(c
, c
->x
, c
->y
, nw
, nh
, True
);
1172 if(sel
->isfloating
|| !lt
[sellt
]->arrange
)
1173 XRaiseWindow(dpy
, sel
->win
);
1174 if(lt
[sellt
]->arrange
) {
1175 wc
.stack_mode
= Below
;
1176 wc
.sibling
= barwin
;
1177 for(c
= stack
; c
; c
= c
->snext
)
1178 if(!c
->isfloating
&& ISVISIBLE(c
)) {
1179 XConfigureWindow(dpy
, c
->win
, CWSibling
|CWStackMode
, &wc
);
1180 wc
.sibling
= c
->win
;
1184 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1190 char sbuf
[sizeof stext
];
1193 unsigned int len
, offset
;
1196 /* main event loop, also reads status text from stdin */
1198 xfd
= ConnectionNumber(dpy
);
1200 len
= sizeof stext
- 1;
1201 sbuf
[len
] = stext
[len
] = '\0'; /* 0-terminator is never touched */
1205 FD_SET(STDIN_FILENO
, &rd
);
1207 if(select(xfd
+ 1, &rd
, NULL
, NULL
, NULL
) == -1) {
1210 die("select failed\n");
1212 if(FD_ISSET(STDIN_FILENO
, &rd
)) {
1213 switch((r
= read(STDIN_FILENO
, sbuf
+ offset
, len
- offset
))) {
1215 strncpy(stext
, strerror(errno
), len
);
1219 strncpy(stext
, "EOF", 4);
1223 for(p
= sbuf
+ offset
; r
> 0; p
++, r
--, offset
++)
1224 if(*p
== '\n' || *p
== '\0') {
1226 strncpy(stext
, sbuf
, len
);
1227 p
+= r
- 1; /* p is sbuf + offset + r - 1 */
1228 for(r
= 0; *(p
- r
) && *(p
- r
) != '\n'; r
++);
1231 memmove(sbuf
, p
- r
+ 1, r
);
1238 while(XPending(dpy
)) {
1239 XNextEvent(dpy
, &ev
);
1240 if(handler
[ev
.type
])
1241 (handler
[ev
.type
])(&ev
); /* call handler */
1248 unsigned int i
, num
;
1249 Window
*wins
, d1
, d2
;
1250 XWindowAttributes wa
;
1253 if(XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
1254 for(i
= 0; i
< num
; i
++) {
1255 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
1256 || wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
1258 if(wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
1259 manage(wins
[i
], &wa
);
1261 for(i
= 0; i
< num
; i
++) { /* now the transients */
1262 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
1264 if(XGetTransientForHint(dpy
, wins
[i
], &d1
)
1265 && (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
1266 manage(wins
[i
], &wa
);
1274 setclientstate(Client
*c
, long state
) {
1275 long data
[] = {state
, None
};
1277 XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
1278 PropModeReplace
, (unsigned char *)data
, 2);
1282 setlayout(const Arg
*arg
) {
1283 if(!arg
|| !arg
->v
|| arg
->v
!= lt
[sellt
])
1286 lt
[sellt
] = (Layout
*)arg
->v
;
1293 /* arg > 1.0 will set mfact absolutly */
1295 setmfact(const Arg
*arg
) {
1298 if(!arg
|| !lt
[sellt
]->arrange
)
1300 f
= arg
->f
< 1.0 ? arg
->f
+ mfact
: arg
->f
- 1.0;
1301 if(f
< 0.1 || f
> 0.9)
1311 XSetWindowAttributes wa
;
1314 screen
= DefaultScreen(dpy
);
1315 root
= RootWindow(dpy
, screen
);
1319 sw
= DisplayWidth(dpy
, screen
);
1320 sh
= DisplayHeight(dpy
, screen
);
1321 bh
= dc
.h
= dc
.font
.height
+ 2;
1322 lt
[0] = &layouts
[0];
1323 lt
[1] = &layouts
[1 % LENGTH(layouts
)];
1327 wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
1328 wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
1329 wmatom
[WMName
] = XInternAtom(dpy
, "WM_NAME", False
);
1330 wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
1331 netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
1332 netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
1335 wa
.cursor
= cursor
[CurNormal
] = XCreateFontCursor(dpy
, XC_left_ptr
);
1336 cursor
[CurResize
] = XCreateFontCursor(dpy
, XC_sizing
);
1337 cursor
[CurMove
] = XCreateFontCursor(dpy
, XC_fleur
);
1339 /* init appearance */
1340 dc
.norm
[ColBorder
] = getcolor(normbordercolor
);
1341 dc
.norm
[ColBG
] = getcolor(normbgcolor
);
1342 dc
.norm
[ColFG
] = getcolor(normfgcolor
);
1343 dc
.sel
[ColBorder
] = getcolor(selbordercolor
);
1344 dc
.sel
[ColBG
] = getcolor(selbgcolor
);
1345 dc
.sel
[ColFG
] = getcolor(selfgcolor
);
1346 dc
.drawable
= XCreatePixmap(dpy
, root
, DisplayWidth(dpy
, screen
), bh
, DefaultDepth(dpy
, screen
));
1347 dc
.gc
= XCreateGC(dpy
, root
, 0, 0);
1348 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
1350 XSetFont(dpy
, dc
.gc
, dc
.font
.xfont
->fid
);
1353 for(blw
= i
= 0; LENGTH(layouts
) > 1 && i
< LENGTH(layouts
); i
++) {
1354 w
= TEXTW(layouts
[i
].symbol
);
1358 wa
.override_redirect
= 1;
1359 wa
.background_pixmap
= ParentRelative
;
1360 wa
.event_mask
= ButtonPressMask
|ExposureMask
;
1362 barwin
= XCreateWindow(dpy
, root
, wx
, by
, ww
, bh
, 0, DefaultDepth(dpy
, screen
),
1363 CopyFromParent
, DefaultVisual(dpy
, screen
),
1364 CWOverrideRedirect
|CWBackPixmap
|CWEventMask
, &wa
);
1365 XDefineCursor(dpy
, barwin
, cursor
[CurNormal
]);
1366 XMapRaised(dpy
, barwin
);
1367 strcpy(stext
, "dwm-"VERSION
);
1370 /* EWMH support per view */
1371 XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
1372 PropModeReplace
, (unsigned char *) netatom
, NetLast
);
1374 /* select for events */
1375 wa
.event_mask
= SubstructureRedirectMask
|SubstructureNotifyMask
|ButtonPressMask
1376 |EnterWindowMask
|LeaveWindowMask
|StructureNotifyMask
;
1377 XChangeWindowAttributes(dpy
, root
, CWEventMask
|CWCursor
, &wa
);
1378 XSelectInput(dpy
, root
, wa
.event_mask
);
1386 spawn(const Arg
*arg
) {
1387 /* The double-fork construct avoids zombie processes and keeps the code
1388 * clean from stupid signal handlers. */
1392 close(ConnectionNumber(dpy
));
1394 execvp(((char **)arg
->v
)[0], (char **)arg
->v
);
1395 fprintf(stderr
, "dwm: execvp %s", ((char **)arg
->v
)[0]);
1404 tag(const Arg
*arg
) {
1405 if(sel
&& arg
->ui
& TAGMASK
) {
1406 sel
->tags
= arg
->ui
& TAGMASK
;
1412 textnw(const char *text
, unsigned int len
) {
1416 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
1419 return XTextWidth(dc
.font
.xfont
, text
, len
);
1428 for(n
= 0, c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
), n
++);
1433 c
= nexttiled(clients
);
1435 resize(c
, wx
, wy
, (n
== 1 ? ww
: mw
) - 2 * c
->bw
, wh
- 2 * c
->bw
, resizehints
);
1441 x
= (wx
+ mw
> c
->x
+ c
->w
) ? c
->x
+ c
->w
+ 2 * c
->bw
: wx
+ mw
;
1443 w
= (wx
+ mw
> c
->x
+ c
->w
) ? wx
+ ww
- x
: ww
- mw
;
1448 for(i
= 0, c
= nexttiled(c
->next
); c
; c
= nexttiled(c
->next
), i
++) {
1449 resize(c
, x
, y
, w
- 2 * c
->bw
, /* remainder */ ((i
+ 1 == n
)
1450 ? (wy
+ wh
) - y
: h
) - 2 * c
->bw
, resizehints
);
1452 y
= c
->y
+ c
->h
+ 2 * c
->bw
;
1457 togglebar(const Arg
*arg
) {
1465 togglefloating(const Arg
*arg
) {
1468 sel
->isfloating
= !sel
->isfloating
|| sel
->isfixed
;
1470 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
);
1475 toggletag(const Arg
*arg
) {
1476 unsigned int mask
= sel
->tags
^ (arg
->ui
& TAGMASK
);
1485 toggleview(const Arg
*arg
) {
1486 unsigned int mask
= tagset
[seltags
] ^ (arg
->ui
& TAGMASK
);
1489 tagset
[seltags
] = mask
;
1496 unmanage(Client
*c
) {
1499 wc
.border_width
= c
->oldbw
;
1500 /* The server grab construct avoids race conditions. */
1502 XSetErrorHandler(xerrordummy
);
1503 XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
1508 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1509 setclientstate(c
, WithdrawnState
);
1512 XSetErrorHandler(xerror
);
1518 unmapnotify(XEvent
*e
) {
1520 XUnmapEvent
*ev
= &e
->xunmap
;
1522 if((c
= getclient(ev
->window
)))
1528 if(dc
.drawable
!= 0)
1529 XFreePixmap(dpy
, dc
.drawable
);
1530 dc
.drawable
= XCreatePixmap(dpy
, root
, ww
, bh
, DefaultDepth(dpy
, screen
));
1531 XMoveResizeWindow(dpy
, barwin
, wx
, by
, ww
, bh
);
1538 XineramaScreenInfo
*info
= NULL
;
1540 /* window area geometry */
1541 if(XineramaIsActive(dpy
) && (info
= XineramaQueryScreens(dpy
, &n
))) {
1546 if(XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x
, &y
, &di
, &di
, &dui
))
1547 for(i
= 0; i
< n
; i
++)
1548 if(INRECT(x
, y
, info
[i
].x_org
, info
[i
].y_org
, info
[i
].width
, info
[i
].height
))
1552 wy
= showbar
&& topbar
? info
[i
].y_org
+ bh
: info
[i
].y_org
;
1554 wh
= showbar
? info
[i
].height
- bh
: info
[i
].height
;
1561 wy
= showbar
&& topbar
? sy
+ bh
: sy
;
1563 wh
= showbar
? sh
- bh
: sh
;
1567 by
= showbar
? (topbar
? wy
- bh
: wy
+ wh
) : -bh
;
1571 updatesizehints(Client
*c
) {
1575 XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
);
1576 if(size
.flags
& PBaseSize
) {
1577 c
->basew
= size
.base_width
;
1578 c
->baseh
= size
.base_height
;
1580 else if(size
.flags
& PMinSize
) {
1581 c
->basew
= size
.min_width
;
1582 c
->baseh
= size
.min_height
;
1585 c
->basew
= c
->baseh
= 0;
1586 if(size
.flags
& PResizeInc
) {
1587 c
->incw
= size
.width_inc
;
1588 c
->inch
= size
.height_inc
;
1591 c
->incw
= c
->inch
= 0;
1592 if(size
.flags
& PMaxSize
) {
1593 c
->maxw
= size
.max_width
;
1594 c
->maxh
= size
.max_height
;
1597 c
->maxw
= c
->maxh
= 0;
1598 if(size
.flags
& PMinSize
) {
1599 c
->minw
= size
.min_width
;
1600 c
->minh
= size
.min_height
;
1602 else if(size
.flags
& PBaseSize
) {
1603 c
->minw
= size
.base_width
;
1604 c
->minh
= size
.base_height
;
1607 c
->minw
= c
->minh
= 0;
1608 if(size
.flags
& PAspect
) {
1609 c
->mina
= (float)size
.min_aspect
.y
/ (float)size
.min_aspect
.x
;
1610 c
->maxa
= (float)size
.max_aspect
.x
/ (float)size
.max_aspect
.y
;
1613 c
->maxa
= c
->mina
= 0.0;
1614 c
->isfixed
= (c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
1615 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
1619 updatetitle(Client
*c
) {
1620 if(!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
1621 gettextprop(c
->win
, wmatom
[WMName
], c
->name
, sizeof c
->name
);
1625 updatewmhints(Client
*c
) {
1628 if((wmh
= XGetWMHints(dpy
, c
->win
))) {
1629 if(ISVISIBLE(c
) && wmh
->flags
& XUrgencyHint
) {
1630 wmh
->flags
&= ~XUrgencyHint
;
1631 XSetWMHints(dpy
, c
->win
, wmh
);
1634 c
->isurgent
= (wmh
->flags
& XUrgencyHint
) ? True
: False
;
1641 view(const Arg
*arg
) {
1642 if(arg
&& (arg
->ui
& TAGMASK
) == tagset
[seltags
])
1644 seltags
^= 1; /* toggle sel tagset */
1645 if(arg
&& (arg
->ui
& TAGMASK
))
1646 tagset
[seltags
] = arg
->ui
& TAGMASK
;
1651 /* There's no way to check accesses to destroyed windows, thus those cases are
1652 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1653 * default error handler, which may call exit. */
1655 xerror(Display
*dpy
, XErrorEvent
*ee
) {
1656 if(ee
->error_code
== BadWindow
1657 || (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
1658 || (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
1659 || (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
1660 || (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
1661 || (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
1662 || (ee
->request_code
== X_GrabButton
&& ee
->error_code
== BadAccess
)
1663 || (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
1664 || (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
1666 fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
1667 ee
->request_code
, ee
->error_code
);
1668 return xerrorxlib(dpy
, ee
); /* may call exit */
1672 xerrordummy(Display
*dpy
, XErrorEvent
*ee
) {
1676 /* Startup Error handler to check if another window manager
1677 * is already running. */
1679 xerrorstart(Display
*dpy
, XErrorEvent
*ee
) {
1685 zoom(const Arg
*arg
) {
1688 if(!lt
[sellt
]->arrange
|| lt
[sellt
]->arrange
== monocle
|| (sel
&& sel
->isfloating
))
1690 if(c
== nexttiled(clients
))
1691 if(!c
|| !(c
= nexttiled(c
->next
)))
1700 main(int argc
, char *argv
[]) {
1701 if(argc
== 2 && !strcmp("-v", argv
[1]))
1702 die("dwm-"VERSION
", © 2006-2008 dwm engineers, see LICENSE for details\n");
1704 die("usage: dwm [-v]\n");
1706 if(!setlocale(LC_CTYPE
, "") || !XSupportsLocale())
1707 fprintf(stderr
, "warning: no locale support\n");
1709 if(!(dpy
= XOpenDisplay(0)))
1710 die("dwm: cannot open display\n");