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 an array of Bools of the same size as the
20 * global tags array to indicate the tags of a client. For each client dwm
21 * creates a small title window, which is resized whenever the (_NET_)WM_NAME
22 * properties are updated or the client is moved/resized.
24 * Keys and tagging rules are organized as arrays and defined in config.h.
26 * To understand everything else, start reading main().
35 #include <sys/select.h>
36 #include <sys/types.h>
39 #include <X11/cursorfont.h>
40 #include <X11/keysym.h>
41 #include <X11/Xatom.h>
43 #include <X11/Xproto.h>
44 #include <X11/Xutil.h>
47 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
48 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
49 #define MOUSEMASK (BUTTONMASK | PointerMotionMask)
52 enum { BarTop
, BarBot
, BarOff
}; /* bar position */
53 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
54 enum { ColBorder
, ColFG
, ColBG
, ColLast
}; /* color */
55 enum { NetSupported
, NetWMName
, NetLast
}; /* EWMH atoms */
56 enum { WMProtocols
, WMDelete
, WMName
, WMState
, WMLast
};/* default atoms */
59 typedef struct Client Client
;
63 int rx
, ry
, rw
, rh
; /* revert geometry */
64 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
65 int minax
, maxax
, minay
, maxay
;
67 unsigned int border
, oldborder
;
68 Bool isbanned
, isfixed
, ismax
, isfloating
, wasfloating
;
78 unsigned long norm
[ColLast
];
79 unsigned long sel
[ColLast
];
89 } DC
; /* draw context */
94 void (*func
)(const char *arg
);
100 void (*arrange
)(void);
114 /* function declarations */
115 void applyrules(Client
*c
);
117 void attach(Client
*c
);
118 void attachstack(Client
*c
);
120 void buttonpress(XEvent
*e
);
121 void checkotherwm(void);
123 void compileregs(void);
124 void configure(Client
*c
);
125 void configurenotify(XEvent
*e
);
126 void configurerequest(XEvent
*e
);
127 void destroynotify(XEvent
*e
);
128 void detach(Client
*c
);
129 void detachstack(Client
*c
);
131 void drawsquare(Bool filled
, Bool empty
, unsigned long col
[ColLast
]);
132 void drawtext(const char *text
, unsigned long col
[ColLast
]);
133 void *emallocz(unsigned int size
);
134 void enternotify(XEvent
*e
);
135 void eprint(const char *errstr
, ...);
136 void expose(XEvent
*e
);
137 void floating(void); /* default floating layout */
138 void focus(Client
*c
);
139 void focusnext(const char *arg
);
140 void focusprev(const char *arg
);
141 Client
*getclient(Window w
);
142 unsigned long getcolor(const char *colstr
);
143 long getstate(Window w
);
144 Bool
gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
);
145 void grabbuttons(Client
*c
, Bool focused
);
146 unsigned int idxoftag(const char *tag
);
147 void initfont(const char *fontstr
);
148 Bool
isoccupied(unsigned int t
);
149 Bool
isprotodel(Client
*c
);
150 Bool
isvisible(Client
*c
);
151 void keypress(XEvent
*e
);
152 void killclient(const char *arg
);
153 void leavenotify(XEvent
*e
);
154 void manage(Window w
, XWindowAttributes
*wa
);
155 void mappingnotify(XEvent
*e
);
156 void maprequest(XEvent
*e
);
157 void movemouse(Client
*c
);
158 Client
*nexttiled(Client
*c
);
159 void propertynotify(XEvent
*e
);
160 void quit(const char *arg
);
161 void resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
);
162 void resizemouse(Client
*c
);
166 void setclientstate(Client
*c
, long state
);
167 void setlayout(const char *arg
);
168 void setmwfact(const char *arg
);
170 void spawn(const char *arg
);
171 void tag(const char *arg
);
172 unsigned int textnw(const char *text
, unsigned int len
);
173 unsigned int textw(const char *text
);
175 void togglebar(const char *arg
);
176 void togglefloating(const char *arg
);
177 void togglemax(const char *arg
);
178 void toggletag(const char *arg
);
179 void toggleview(const char *arg
);
180 void unban(Client
*c
);
181 void unmanage(Client
*c
);
182 void unmapnotify(XEvent
*e
);
183 void updatebarpos(void);
184 void updatesizehints(Client
*c
);
185 void updatetitle(Client
*c
);
186 void view(const char *arg
);
187 void viewprevtag(const char *arg
); /* views previous selected tags */
188 int xerror(Display
*dpy
, XErrorEvent
*ee
);
189 int xerrordummy(Display
*dsply
, XErrorEvent
*ee
);
190 int xerrorstart(Display
*dsply
, XErrorEvent
*ee
);
191 void zoom(const char *arg
);
196 int screen
, sx
, sy
, sw
, sh
, wax
, way
, waw
, wah
;
197 int (*xerrorxlib
)(Display
*, XErrorEvent
*);
198 unsigned int bh
, bpos
;
199 unsigned int blw
= 0;
200 unsigned int numlockmask
= 0;
201 void (*handler
[LASTEvent
]) (XEvent
*) = {
202 [ButtonPress
] = buttonpress
,
203 [ConfigureRequest
] = configurerequest
,
204 [ConfigureNotify
] = configurenotify
,
205 [DestroyNotify
] = destroynotify
,
206 [EnterNotify
] = enternotify
,
207 [LeaveNotify
] = leavenotify
,
209 [KeyPress
] = keypress
,
210 [MappingNotify
] = mappingnotify
,
211 [MapRequest
] = maprequest
,
212 [PropertyNotify
] = propertynotify
,
213 [UnmapNotify
] = unmapnotify
215 Atom wmatom
[WMLast
], netatom
[NetLast
];
216 Bool domwfact
= True
;
218 Bool otherwm
, readin
;
220 Bool selscreen
= True
;
221 Client
*clients
= NULL
;
223 Client
*stack
= NULL
;
224 Cursor cursor
[CurLast
];
227 Layout
*layout
= NULL
;
231 /* configuration, allows nested code to access above variables */
234 /* function implementations */
236 applyrules(Client
*c
) {
237 static char buf
[512];
240 Bool matched
= False
;
241 XClassHint ch
= { 0 };
244 XGetClassHint(dpy
, c
->win
, &ch
);
245 snprintf(buf
, sizeof buf
, "%s:%s:%s",
246 ch
.res_class
? ch
.res_class
: "",
247 ch
.res_name
? ch
.res_name
: "", c
->name
);
248 for(i
= 0; i
< LENGTH(rules
); i
++)
249 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, buf
, 1, &tmp
, 0)) {
250 c
->isfloating
= rules
[i
].isfloating
;
251 for(j
= 0; regs
[i
].tagregex
&& j
< LENGTH(tags
); j
++) {
252 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
263 memcpy(c
->tags
, seltags
, sizeof seltags
);
270 for(c
= clients
; c
; c
= c
->next
)
289 attachstack(Client
*c
) {
298 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
303 buttonpress(XEvent
*e
) {
306 XButtonPressedEvent
*ev
= &e
->xbutton
;
308 if(barwin
== ev
->window
) {
310 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
)
328 if((ev
->x
< x
+ blw
) && ev
->button
== Button1
)
331 else if((c
= getclient(ev
->window
))) {
333 if(CLEANMASK(ev
->state
) != MODKEY
)
335 if(ev
->button
== Button1
) {
336 if((floating
== layout
->arrange
) || c
->isfloating
)
339 togglefloating(NULL
);
342 else if(ev
->button
== Button2
) {
343 if((floating
!= layout
->arrange
) && !c
->isfixed
&& c
->isfloating
)
344 togglefloating(NULL
);
348 else if(ev
->button
== Button3
&& !c
->isfixed
) {
349 if((floating
== layout
->arrange
) || c
->isfloating
)
352 togglefloating(NULL
);
361 XSetErrorHandler(xerrorstart
);
363 /* this causes an error if some other window manager is running */
364 XSelectInput(dpy
, root
, SubstructureRedirectMask
);
367 eprint("dwm: another window manager is already running\n");
369 XSetErrorHandler(NULL
);
370 xerrorxlib
= XSetErrorHandler(xerror
);
382 XFreeFontSet(dpy
, dc
.font
.set
);
384 XFreeFont(dpy
, dc
.font
.xfont
);
385 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
386 XFreePixmap(dpy
, dc
.drawable
);
388 XDestroyWindow(dpy
, barwin
);
389 XFreeCursor(dpy
, cursor
[CurNormal
]);
390 XFreeCursor(dpy
, cursor
[CurResize
]);
391 XFreeCursor(dpy
, cursor
[CurMove
]);
392 XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
403 regs
= emallocz(LENGTH(rules
) * sizeof(Regs
));
404 for(i
= 0; i
< LENGTH(rules
); i
++) {
406 reg
= emallocz(sizeof(regex_t
));
407 if(regcomp(reg
, rules
[i
].prop
, REG_EXTENDED
))
410 regs
[i
].propregex
= reg
;
413 reg
= emallocz(sizeof(regex_t
));
414 if(regcomp(reg
, rules
[i
].tags
, REG_EXTENDED
))
417 regs
[i
].tagregex
= reg
;
423 configure(Client
*c
) {
426 ce
.type
= ConfigureNotify
;
434 ce
.border_width
= c
->border
;
436 ce
.override_redirect
= False
;
437 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
441 configurenotify(XEvent
*e
) {
442 XConfigureEvent
*ev
= &e
->xconfigure
;
444 if(ev
->window
== root
&& (ev
->width
!= sw
|| ev
->height
!= sh
)) {
447 XFreePixmap(dpy
, dc
.drawable
);
448 dc
.drawable
= XCreatePixmap(dpy
, root
, sw
, bh
, DefaultDepth(dpy
, screen
));
449 XResizeWindow(dpy
, barwin
, sw
, bh
);
456 configurerequest(XEvent
*e
) {
458 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
461 if((c
= getclient(ev
->window
))) {
463 if(ev
->value_mask
& CWBorderWidth
)
464 c
->border
= ev
->border_width
;
465 if(c
->isfixed
|| c
->isfloating
|| (floating
== layout
->arrange
)) {
466 if(ev
->value_mask
& CWX
)
468 if(ev
->value_mask
& CWY
)
470 if(ev
->value_mask
& CWWidth
)
472 if(ev
->value_mask
& CWHeight
)
474 if((c
->x
+ c
->w
) > sw
&& c
->isfloating
)
475 c
->x
= sw
/ 2 - c
->w
/ 2; /* center in x direction */
476 if((c
->y
+ c
->h
) > sh
&& c
->isfloating
)
477 c
->y
= sh
/ 2 - c
->h
/ 2; /* center in y direction */
478 if((ev
->value_mask
& (CWX
| CWY
))
479 && !(ev
->value_mask
& (CWWidth
| CWHeight
)))
482 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
490 wc
.width
= ev
->width
;
491 wc
.height
= ev
->height
;
492 wc
.border_width
= ev
->border_width
;
493 wc
.sibling
= ev
->above
;
494 wc
.stack_mode
= ev
->detail
;
495 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
501 destroynotify(XEvent
*e
) {
503 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
505 if((c
= getclient(ev
->window
)))
512 c
->prev
->next
= c
->next
;
514 c
->next
->prev
= c
->prev
;
517 c
->next
= c
->prev
= NULL
;
521 detachstack(Client
*c
) {
524 for(tc
=&stack
; *tc
&& *tc
!= c
; tc
=&(*tc
)->snext
);
533 for(i
= 0; i
< LENGTH(tags
); i
++) {
534 dc
.w
= textw(tags
[i
]);
536 drawtext(tags
[i
], dc
.sel
);
537 drawsquare(sel
&& sel
->tags
[i
], isoccupied(i
), dc
.sel
);
540 drawtext(tags
[i
], dc
.norm
);
541 drawsquare(sel
&& sel
->tags
[i
], isoccupied(i
), dc
.norm
);
546 drawtext(layout
->symbol
, dc
.norm
);
554 drawtext(stext
, dc
.norm
);
555 if((dc
.w
= dc
.x
- x
) > bh
) {
558 drawtext(sel
->name
, dc
.sel
);
559 drawsquare(sel
->ismax
, sel
->isfloating
, dc
.sel
);
562 drawtext(NULL
, dc
.norm
);
564 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, sw
, bh
, 0, 0);
569 drawsquare(Bool filled
, Bool empty
, unsigned long col
[ColLast
]) {
572 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
574 gcv
.foreground
= col
[ColFG
];
575 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
576 x
= (dc
.font
.ascent
+ dc
.font
.descent
+ 2) / 4;
580 r
.width
= r
.height
= x
+ 1;
581 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
584 r
.width
= r
.height
= x
;
585 XDrawRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
590 drawtext(const char *text
, unsigned long col
[ColLast
]) {
592 static char buf
[256];
593 unsigned int len
, olen
;
594 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
596 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
597 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
601 olen
= len
= strlen(text
);
602 if(len
>= sizeof buf
)
603 len
= sizeof buf
- 1;
604 memcpy(buf
, text
, len
);
606 h
= dc
.font
.ascent
+ dc
.font
.descent
;
607 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
609 /* shorten text if necessary */
610 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
621 return; /* too long */
622 XSetForeground(dpy
, dc
.gc
, col
[ColFG
]);
624 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
626 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
630 emallocz(unsigned int size
) {
631 void *res
= calloc(1, size
);
634 eprint("fatal: could not malloc() %u bytes\n", size
);
639 enternotify(XEvent
*e
) {
641 XCrossingEvent
*ev
= &e
->xcrossing
;
643 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
645 if((c
= getclient(ev
->window
)))
647 else if(ev
->window
== root
) {
654 eprint(const char *errstr
, ...) {
657 va_start(ap
, errstr
);
658 vfprintf(stderr
, errstr
, ap
);
665 XExposeEvent
*ev
= &e
->xexpose
;
668 if(barwin
== ev
->window
)
674 floating(void) { /* default floating layout */
677 domwfact
= dozoom
= False
;
678 for(c
= clients
; c
; c
= c
->next
)
680 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, True
);
685 if((!c
&& selscreen
) || (c
&& !isvisible(c
)))
686 for(c
= stack
; c
&& !isvisible(c
); c
= c
->snext
);
687 if(sel
&& sel
!= c
) {
688 grabbuttons(sel
, False
);
689 XSetWindowBorder(dpy
, sel
->win
, dc
.norm
[ColBorder
]);
694 grabbuttons(c
, True
);
701 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBorder
]);
702 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
705 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
709 focusnext(const char *arg
) {
714 for(c
= sel
->next
; c
&& !isvisible(c
); c
= c
->next
);
716 for(c
= clients
; c
&& !isvisible(c
); c
= c
->next
);
724 focusprev(const char *arg
) {
729 for(c
= sel
->prev
; c
&& !isvisible(c
); c
= c
->prev
);
731 for(c
= clients
; c
&& c
->next
; c
= c
->next
);
732 for(; c
&& !isvisible(c
); c
= c
->prev
);
741 getclient(Window w
) {
744 for(c
= clients
; c
&& c
->win
!= w
; c
= c
->next
);
749 getcolor(const char *colstr
) {
750 Colormap cmap
= DefaultColormap(dpy
, screen
);
753 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
754 eprint("error, cannot allocate color '%s'\n", colstr
);
762 unsigned char *p
= NULL
;
763 unsigned long n
, extra
;
766 status
= XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
767 &real
, &format
, &n
, &extra
, (unsigned char **)&p
);
768 if(status
!= Success
)
777 gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
) {
782 if(!text
|| 0 == size
)
785 XGetTextProperty(dpy
, w
, &name
, atom
);
788 if(name
.encoding
== XA_STRING
)
789 strncpy(text
, (char *)name
.value
, size
- 1);
791 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
794 strncpy(text
, *list
, size
- 1);
795 XFreeStringList(list
);
798 text
[size
- 1] = '\0';
804 grabbuttons(Client
*c
, Bool focused
) {
805 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
808 XGrabButton(dpy
, Button1
, MODKEY
, c
->win
, False
, BUTTONMASK
,
809 GrabModeAsync
, GrabModeSync
, None
, None
);
810 XGrabButton(dpy
, Button1
, MODKEY
| LockMask
, c
->win
, False
, BUTTONMASK
,
811 GrabModeAsync
, GrabModeSync
, None
, None
);
812 XGrabButton(dpy
, Button1
, MODKEY
| numlockmask
, c
->win
, False
, BUTTONMASK
,
813 GrabModeAsync
, GrabModeSync
, None
, None
);
814 XGrabButton(dpy
, Button1
, MODKEY
| numlockmask
| LockMask
, c
->win
, False
, BUTTONMASK
,
815 GrabModeAsync
, GrabModeSync
, None
, None
);
817 XGrabButton(dpy
, Button2
, MODKEY
, c
->win
, False
, BUTTONMASK
,
818 GrabModeAsync
, GrabModeSync
, None
, None
);
819 XGrabButton(dpy
, Button2
, MODKEY
| LockMask
, c
->win
, False
, BUTTONMASK
,
820 GrabModeAsync
, GrabModeSync
, None
, None
);
821 XGrabButton(dpy
, Button2
, MODKEY
| numlockmask
, c
->win
, False
, BUTTONMASK
,
822 GrabModeAsync
, GrabModeSync
, None
, None
);
823 XGrabButton(dpy
, Button2
, MODKEY
| numlockmask
| LockMask
, c
->win
, False
, BUTTONMASK
,
824 GrabModeAsync
, GrabModeSync
, None
, None
);
826 XGrabButton(dpy
, Button3
, MODKEY
, c
->win
, False
, BUTTONMASK
,
827 GrabModeAsync
, GrabModeSync
, None
, None
);
828 XGrabButton(dpy
, Button3
, MODKEY
| LockMask
, c
->win
, False
, BUTTONMASK
,
829 GrabModeAsync
, GrabModeSync
, None
, None
);
830 XGrabButton(dpy
, Button3
, MODKEY
| numlockmask
, c
->win
, False
, BUTTONMASK
,
831 GrabModeAsync
, GrabModeSync
, None
, None
);
832 XGrabButton(dpy
, Button3
, MODKEY
| numlockmask
| LockMask
, c
->win
, False
, BUTTONMASK
,
833 GrabModeAsync
, GrabModeSync
, None
, None
);
836 XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
, BUTTONMASK
,
837 GrabModeAsync
, GrabModeSync
, None
, None
);
841 idxoftag(const char *tag
) {
844 for(i
= 0; (i
< LENGTH(tags
)) && (tags
[i
] != tag
); i
++);
845 return (i
< LENGTH(tags
)) ? i
: 0;
849 initfont(const char *fontstr
) {
850 char *def
, **missing
;
855 XFreeFontSet(dpy
, dc
.font
.set
);
856 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
859 fprintf(stderr
, "dwm: missing fontset: %s\n", missing
[n
]);
860 XFreeStringList(missing
);
863 XFontSetExtents
*font_extents
;
864 XFontStruct
**xfonts
;
866 dc
.font
.ascent
= dc
.font
.descent
= 0;
867 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
868 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
869 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
870 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
871 dc
.font
.ascent
= (*xfonts
)->ascent
;
872 if(dc
.font
.descent
< (*xfonts
)->descent
)
873 dc
.font
.descent
= (*xfonts
)->descent
;
879 XFreeFont(dpy
, dc
.font
.xfont
);
880 dc
.font
.xfont
= NULL
;
881 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
))
882 && !(dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed")))
883 eprint("error, cannot load font: '%s'\n", fontstr
);
884 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
885 dc
.font
.descent
= dc
.font
.xfont
->descent
;
887 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
891 isoccupied(unsigned int t
) {
894 for(c
= clients
; c
; c
= c
->next
)
901 isprotodel(Client
*c
) {
906 if(XGetWMProtocols(dpy
, c
->win
, &protocols
, &n
)) {
907 for(i
= 0; !ret
&& i
< n
; i
++)
908 if(protocols
[i
] == wmatom
[WMDelete
])
916 isvisible(Client
*c
) {
919 for(i
= 0; i
< LENGTH(tags
); i
++)
920 if(c
->tags
[i
] && seltags
[i
])
926 keypress(XEvent
*e
) {
933 if(!e
) { /* grabkeys */
934 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
935 for(i
= 0; i
< LENGTH(keys
); i
++) {
936 code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
);
937 XGrabKey(dpy
, code
, keys
[i
].mod
, root
, True
,
938 GrabModeAsync
, GrabModeAsync
);
939 XGrabKey(dpy
, code
, keys
[i
].mod
| LockMask
, root
, True
,
940 GrabModeAsync
, GrabModeAsync
);
941 XGrabKey(dpy
, code
, keys
[i
].mod
| numlockmask
, root
, True
,
942 GrabModeAsync
, GrabModeAsync
);
943 XGrabKey(dpy
, code
, keys
[i
].mod
| numlockmask
| LockMask
, root
, True
,
944 GrabModeAsync
, GrabModeAsync
);
949 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
950 for(i
= 0; i
< LENGTH(keys
); i
++)
951 if(keysym
== keys
[i
].keysym
952 && CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
))
955 keys
[i
].func(keys
[i
].arg
);
960 killclient(const char *arg
) {
965 if(isprotodel(sel
)) {
966 ev
.type
= ClientMessage
;
967 ev
.xclient
.window
= sel
->win
;
968 ev
.xclient
.message_type
= wmatom
[WMProtocols
];
969 ev
.xclient
.format
= 32;
970 ev
.xclient
.data
.l
[0] = wmatom
[WMDelete
];
971 ev
.xclient
.data
.l
[1] = CurrentTime
;
972 XSendEvent(dpy
, sel
->win
, False
, NoEventMask
, &ev
);
975 XKillClient(dpy
, sel
->win
);
979 leavenotify(XEvent
*e
) {
980 XCrossingEvent
*ev
= &e
->xcrossing
;
982 if((ev
->window
== root
) && !ev
->same_screen
) {
989 manage(Window w
, XWindowAttributes
*wa
) {
990 Client
*c
, *t
= NULL
;
995 c
= emallocz(sizeof(Client
));
996 c
->tags
= emallocz(sizeof seltags
);
1002 c
->oldborder
= wa
->border_width
;
1003 if(c
->w
== sw
&& c
->h
== sh
) {
1006 c
->border
= wa
->border_width
;
1009 if(c
->x
+ c
->w
+ 2 * c
->border
> wax
+ waw
)
1010 c
->x
= wax
+ waw
- c
->w
- 2 * c
->border
;
1011 if(c
->y
+ c
->h
+ 2 * c
->border
> way
+ wah
)
1012 c
->y
= way
+ wah
- c
->h
- 2 * c
->border
;
1017 c
->border
= BORDERPX
;
1019 wc
.border_width
= c
->border
;
1020 XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
1021 XSetWindowBorder(dpy
, w
, dc
.norm
[ColBorder
]);
1022 configure(c
); /* propagates border_width, if size doesn't change */
1024 XSelectInput(dpy
, w
,
1025 StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
1026 grabbuttons(c
, False
);
1028 if((rettrans
= XGetTransientForHint(dpy
, w
, &trans
) == Success
))
1029 for(t
= clients
; t
&& t
->win
!= trans
; t
= t
->next
);
1031 memcpy(c
->tags
, t
->tags
, sizeof seltags
);
1034 c
->isfloating
= (rettrans
== Success
) || c
->isfixed
;
1037 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
); /* some windows require this */
1039 XMapWindow(dpy
, c
->win
);
1040 setclientstate(c
, NormalState
);
1045 mappingnotify(XEvent
*e
) {
1046 XMappingEvent
*ev
= &e
->xmapping
;
1048 XRefreshKeyboardMapping(ev
);
1049 if(ev
->request
== MappingKeyboard
)
1054 maprequest(XEvent
*e
) {
1055 static XWindowAttributes wa
;
1056 XMapRequestEvent
*ev
= &e
->xmaprequest
;
1058 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
1060 if(wa
.override_redirect
)
1062 if(!getclient(ev
->window
))
1063 manage(ev
->window
, &wa
);
1067 movemouse(Client
*c
) {
1068 int x1
, y1
, ocx
, ocy
, di
, nx
, ny
;
1075 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1076 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
1079 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
1081 XMaskEvent(dpy
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
1084 XUngrabPointer(dpy
, CurrentTime
);
1086 case ConfigureRequest
:
1089 handler
[ev
.type
](&ev
);
1093 nx
= ocx
+ (ev
.xmotion
.x
- x1
);
1094 ny
= ocy
+ (ev
.xmotion
.y
- y1
);
1095 if(abs(wax
+ nx
) < SNAP
)
1097 else if(abs((wax
+ waw
) - (nx
+ c
->w
+ 2 * c
->border
)) < SNAP
)
1098 nx
= wax
+ waw
- c
->w
- 2 * c
->border
;
1099 if(abs(way
- ny
) < SNAP
)
1101 else if(abs((way
+ wah
) - (ny
+ c
->h
+ 2 * c
->border
)) < SNAP
)
1102 ny
= way
+ wah
- c
->h
- 2 * c
->border
;
1103 resize(c
, nx
, ny
, c
->w
, c
->h
, False
);
1110 nexttiled(Client
*c
) {
1111 for(; c
&& (c
->isfloating
|| !isvisible(c
)); c
= c
->next
);
1116 propertynotify(XEvent
*e
) {
1119 XPropertyEvent
*ev
= &e
->xproperty
;
1121 if(ev
->state
== PropertyDelete
)
1122 return; /* ignore */
1123 if((c
= getclient(ev
->window
))) {
1126 case XA_WM_TRANSIENT_FOR
:
1127 XGetTransientForHint(dpy
, c
->win
, &trans
);
1128 if(!c
->isfloating
&& (c
->isfloating
= (NULL
!= getclient(trans
))))
1131 case XA_WM_NORMAL_HINTS
:
1135 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
1144 quit(const char *arg
) {
1145 readin
= running
= False
;
1149 resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
) {
1153 /* set minimum possible */
1159 /* temporarily remove base dimensions */
1163 /* adjust for aspect limits */
1164 if (c
->minay
> 0 && c
->maxay
> 0 && c
->minax
> 0 && c
->maxax
> 0) {
1165 if (w
* c
->maxay
> h
* c
->maxax
)
1166 w
= h
* c
->maxax
/ c
->maxay
;
1167 else if (w
* c
->minay
< h
* c
->minax
)
1168 h
= w
* c
->minay
/ c
->minax
;
1171 /* adjust for increment value */
1177 /* restore base dimensions */
1181 if(c
->minw
> 0 && w
< c
->minw
)
1183 if(c
->minh
> 0 && h
< c
->minh
)
1185 if(c
->maxw
> 0 && w
> c
->maxw
)
1187 if(c
->maxh
> 0 && h
> c
->maxh
)
1190 if(w
<= 0 || h
<= 0)
1192 /* offscreen appearance fixes */
1194 x
= sw
- w
- 2 * c
->border
;
1196 y
= sh
- h
- 2 * c
->border
;
1197 if(x
+ w
+ 2 * c
->border
< sx
)
1199 if(y
+ h
+ 2 * c
->border
< sy
)
1201 if(c
->x
!= x
|| c
->y
!= y
|| c
->w
!= w
|| c
->h
!= h
) {
1204 c
->w
= wc
.width
= w
;
1205 c
->h
= wc
.height
= h
;
1206 wc
.border_width
= c
->border
;
1207 XConfigureWindow(dpy
, c
->win
, CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
1214 resizemouse(Client
*c
) {
1221 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1222 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
1225 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
1227 XMaskEvent(dpy
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
1230 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0,
1231 c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
1232 XUngrabPointer(dpy
, CurrentTime
);
1233 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1235 case ConfigureRequest
:
1238 handler
[ev
.type
](&ev
);
1242 if((nw
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
1244 if((nh
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
1246 resize(c
, c
->x
, c
->y
, nw
, nh
, True
);
1261 if(sel
->isfloating
|| (floating
== layout
->arrange
))
1262 XRaiseWindow(dpy
, sel
->win
);
1263 if(floating
!= layout
->arrange
) {
1264 wc
.stack_mode
= Below
;
1265 wc
.sibling
= barwin
;
1266 if(!sel
->isfloating
) {
1267 XConfigureWindow(dpy
, sel
->win
, CWSibling
| CWStackMode
, &wc
);
1268 wc
.sibling
= sel
->win
;
1270 for(c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
)) {
1273 XConfigureWindow(dpy
, c
->win
, CWSibling
| CWStackMode
, &wc
);
1274 wc
.sibling
= c
->win
;
1278 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1288 /* main event loop, also reads status text from stdin */
1290 xfd
= ConnectionNumber(dpy
);
1295 FD_SET(STDIN_FILENO
, &rd
);
1297 if(select(xfd
+ 1, &rd
, NULL
, NULL
, NULL
) == -1) {
1300 eprint("select failed\n");
1302 if(FD_ISSET(STDIN_FILENO
, &rd
)) {
1303 switch(r
= read(STDIN_FILENO
, stext
, sizeof stext
- 1)) {
1305 strncpy(stext
, strerror(errno
), sizeof stext
- 1);
1306 stext
[sizeof stext
- 1] = '\0';
1310 strncpy(stext
, "EOF", 4);
1314 for(stext
[r
] = '\0', p
= stext
+ strlen(stext
) - 1; p
>= stext
&& *p
== '\n'; *p
-- = '\0');
1315 for(; p
>= stext
&& *p
!= '\n'; --p
);
1317 strncpy(stext
, p
+ 1, sizeof stext
);
1321 while(XPending(dpy
)) {
1322 XNextEvent(dpy
, &ev
);
1323 if(handler
[ev
.type
])
1324 (handler
[ev
.type
])(&ev
); /* call handler */
1331 unsigned int i
, num
;
1332 Window
*wins
, d1
, d2
;
1333 XWindowAttributes wa
;
1336 if(XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
1337 for(i
= 0; i
< num
; i
++) {
1338 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
1339 || wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
1341 if(wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
1342 manage(wins
[i
], &wa
);
1344 for(i
= 0; i
< num
; i
++) { /* now the transients */
1345 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
1347 if(XGetTransientForHint(dpy
, wins
[i
], &d1
)
1348 && (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
1349 manage(wins
[i
], &wa
);
1357 setclientstate(Client
*c
, long state
) {
1358 long data
[] = {state
, None
};
1360 XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
1361 PropModeReplace
, (unsigned char *)data
, 2);
1365 setlayout(const char *arg
) {
1369 if(++layout
== &layouts
[LENGTH(layouts
)])
1370 layout
= &layouts
[0];
1373 for(i
= 0; i
< LENGTH(layouts
); i
++)
1374 if(!strcmp(arg
, layouts
[i
].symbol
))
1376 if(i
== LENGTH(layouts
))
1378 layout
= &layouts
[i
];
1387 setmwfact(const char *arg
) {
1392 /* arg handling, manipulate mwfact */
1395 else if(1 == sscanf(arg
, "%lf", &delta
)) {
1396 if(arg
[0] == '+' || arg
[0] == '-')
1402 else if(mwfact
> 0.9)
1411 unsigned int i
, j
, mask
;
1413 XModifierKeymap
*modmap
;
1414 XSetWindowAttributes wa
;
1417 wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
1418 wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
1419 wmatom
[WMName
] = XInternAtom(dpy
, "WM_NAME", False
);
1420 wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
1421 netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
1422 netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
1423 XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
1424 PropModeReplace
, (unsigned char *) netatom
, NetLast
);
1427 cursor
[CurNormal
] = XCreateFontCursor(dpy
, XC_left_ptr
);
1428 cursor
[CurResize
] = XCreateFontCursor(dpy
, XC_sizing
);
1429 cursor
[CurMove
] = XCreateFontCursor(dpy
, XC_fleur
);
1433 sw
= DisplayWidth(dpy
, screen
);
1434 sh
= DisplayHeight(dpy
, screen
);
1436 /* init modifier map */
1437 modmap
= XGetModifierMapping(dpy
);
1438 for(i
= 0; i
< 8; i
++)
1439 for(j
= 0; j
< modmap
->max_keypermod
; j
++) {
1440 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
]
1441 == XKeysymToKeycode(dpy
, XK_Num_Lock
))
1442 numlockmask
= (1 << i
);
1444 XFreeModifiermap(modmap
);
1446 /* select for events */
1447 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
1448 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
1449 wa
.cursor
= cursor
[CurNormal
];
1450 XChangeWindowAttributes(dpy
, root
, CWEventMask
| CWCursor
, &wa
);
1451 XSelectInput(dpy
, root
, wa
.event_mask
);
1459 /* init appearance */
1460 dc
.norm
[ColBorder
] = getcolor(NORMBORDERCOLOR
);
1461 dc
.norm
[ColBG
] = getcolor(NORMBGCOLOR
);
1462 dc
.norm
[ColFG
] = getcolor(NORMFGCOLOR
);
1463 dc
.sel
[ColBorder
] = getcolor(SELBORDERCOLOR
);
1464 dc
.sel
[ColBG
] = getcolor(SELBGCOLOR
);
1465 dc
.sel
[ColFG
] = getcolor(SELFGCOLOR
);
1467 dc
.h
= bh
= dc
.font
.height
+ 2;
1471 layout
= &layouts
[0];
1472 for(blw
= i
= 0; i
< LENGTH(layouts
); i
++) {
1473 j
= textw(layouts
[i
].symbol
);
1480 wa
.override_redirect
= 1;
1481 wa
.background_pixmap
= ParentRelative
;
1482 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
1483 barwin
= XCreateWindow(dpy
, root
, sx
, sy
, sw
, bh
, 0,
1484 DefaultDepth(dpy
, screen
), CopyFromParent
, DefaultVisual(dpy
, screen
),
1485 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
1486 XDefineCursor(dpy
, barwin
, cursor
[CurNormal
]);
1488 XMapRaised(dpy
, barwin
);
1489 strcpy(stext
, "dwm-"VERSION
);
1490 dc
.drawable
= XCreatePixmap(dpy
, root
, sw
, bh
, DefaultDepth(dpy
, screen
));
1491 dc
.gc
= XCreateGC(dpy
, root
, 0, 0);
1492 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
1494 XSetFont(dpy
, dc
.gc
, dc
.font
.xfont
->fid
);
1496 /* multihead support */
1497 selscreen
= XQueryPointer(dpy
, root
, &w
, &w
, &d
, &d
, &d
, &d
, &mask
);
1501 spawn(const char *arg
) {
1502 static char *shell
= NULL
;
1504 if(!shell
&& !(shell
= getenv("SHELL")))
1508 /* The double-fork construct avoids zombie processes and keeps the code
1509 * clean from stupid signal handlers. */
1513 close(ConnectionNumber(dpy
));
1515 execl(shell
, shell
, "-c", arg
, (char *)NULL
);
1516 fprintf(stderr
, "dwm: execl '%s -c %s'", shell
, arg
);
1525 tag(const char *arg
) {
1530 for(i
= 0; i
< LENGTH(tags
); i
++)
1531 sel
->tags
[i
] = (NULL
== arg
);
1532 sel
->tags
[idxoftag(arg
)] = True
;
1537 textnw(const char *text
, unsigned int len
) {
1541 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
1544 return XTextWidth(dc
.font
.xfont
, text
, len
);
1548 textw(const char *text
) {
1549 return textnw(text
, strlen(text
)) + dc
.font
.height
;
1554 unsigned int i
, n
, nx
, ny
, nw
, nh
, mw
, th
;
1557 domwfact
= dozoom
= True
;
1558 for(n
= 0, c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
))
1562 mw
= (n
== 1) ? waw
: mwfact
* waw
;
1563 th
= (n
> 1) ? wah
/ (n
- 1) : 0;
1564 if(n
> 1 && th
< bh
)
1569 nw
= 0; /* gcc stupidity requires this */
1570 for(i
= 0, c
= mc
= nexttiled(clients
); c
; c
= nexttiled(c
->next
), i
++) {
1572 if(0 == i
) { /* master */
1573 nw
= mw
- 2 * c
->border
;
1574 nh
= wah
- 2 * c
->border
;
1576 else { /* tile window */
1579 nx
+= mc
->w
+ 2 * mc
->border
;
1580 nw
= waw
- nx
- 2 * c
->border
;
1582 if(i
+ 1 == n
) /* remainder */
1583 nh
= (way
+ wah
) - ny
- 2 * c
->border
;
1585 nh
= th
- 2 * c
->border
;
1587 resize(c
, nx
, ny
, nw
, nh
, True
);
1588 if((c
->h
< bh
) || (c
->h
> nh
) || (c
->w
< bh
) || (c
->w
> nw
))
1589 /* client doesn't accept size constraints */
1590 resize(c
, nx
, ny
, nw
, nh
, False
);
1591 if(n
> 1 && th
!= wah
)
1592 ny
= c
->y
+ c
->h
+ 2 * c
->border
;
1597 togglebar(const char *arg
) {
1599 bpos
= (BARPOS
== BarOff
) ? BarTop
: BARPOS
;
1607 togglefloating(const char *arg
) {
1610 sel
->isfloating
= !sel
->isfloating
;
1612 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
);
1617 togglemax(const char *arg
) {
1620 if(!sel
|| sel
->isfixed
)
1622 if((sel
->ismax
= !sel
->ismax
)) {
1623 if((floating
== layout
->arrange
) || sel
->isfloating
)
1624 sel
->wasfloating
= True
;
1626 togglefloating(NULL
);
1627 sel
->wasfloating
= False
;
1633 resize(sel
, wax
, way
, waw
- 2 * sel
->border
, wah
- 2 * sel
->border
, True
);
1636 resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, True
);
1637 if(!sel
->wasfloating
)
1638 togglefloating(NULL
);
1641 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1645 toggletag(const char *arg
) {
1651 sel
->tags
[i
] = !sel
->tags
[i
];
1652 for(j
= 0; j
< LENGTH(tags
) && !sel
->tags
[j
]; j
++);
1653 if(j
== LENGTH(tags
))
1654 sel
->tags
[i
] = True
; /* at least one tag must be enabled */
1659 toggleview(const char *arg
) {
1663 seltags
[i
] = !seltags
[i
];
1664 for(j
= 0; j
< LENGTH(tags
) && !seltags
[j
]; j
++);
1665 if(j
== LENGTH(tags
))
1666 seltags
[i
] = True
; /* at least one tag must be viewed */
1674 XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
1675 c
->isbanned
= False
;
1679 unmanage(Client
*c
) {
1682 wc
.border_width
= c
->oldborder
;
1683 /* The server grab construct avoids race conditions. */
1685 XSetErrorHandler(xerrordummy
);
1686 XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
1691 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1692 setclientstate(c
, WithdrawnState
);
1696 XSetErrorHandler(xerror
);
1702 unmapnotify(XEvent
*e
) {
1704 XUnmapEvent
*ev
= &e
->xunmap
;
1706 if((c
= getclient(ev
->window
)))
1711 updatebarpos(void) {
1722 XMoveWindow(dpy
, barwin
, sx
, sy
);
1726 XMoveWindow(dpy
, barwin
, sx
, sy
+ wah
);
1729 XMoveWindow(dpy
, barwin
, sx
, sy
- bh
);
1733 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1737 updatesizehints(Client
*c
) {
1741 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
) || !size
.flags
)
1743 c
->flags
= size
.flags
;
1744 if(c
->flags
& PBaseSize
) {
1745 c
->basew
= size
.base_width
;
1746 c
->baseh
= size
.base_height
;
1748 else if(c
->flags
& PMinSize
) {
1749 c
->basew
= size
.min_width
;
1750 c
->baseh
= size
.min_height
;
1753 c
->basew
= c
->baseh
= 0;
1754 if(c
->flags
& PResizeInc
) {
1755 c
->incw
= size
.width_inc
;
1756 c
->inch
= size
.height_inc
;
1759 c
->incw
= c
->inch
= 0;
1760 if(c
->flags
& PMaxSize
) {
1761 c
->maxw
= size
.max_width
;
1762 c
->maxh
= size
.max_height
;
1765 c
->maxw
= c
->maxh
= 0;
1766 if(c
->flags
& PMinSize
) {
1767 c
->minw
= size
.min_width
;
1768 c
->minh
= size
.min_height
;
1770 else if(c
->flags
& PBaseSize
) {
1771 c
->minw
= size
.base_width
;
1772 c
->minh
= size
.base_height
;
1775 c
->minw
= c
->minh
= 0;
1776 if(c
->flags
& PAspect
) {
1777 c
->minax
= size
.min_aspect
.x
;
1778 c
->maxax
= size
.max_aspect
.x
;
1779 c
->minay
= size
.min_aspect
.y
;
1780 c
->maxay
= size
.max_aspect
.y
;
1783 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
1784 c
->isfixed
= (c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
1785 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
1789 updatetitle(Client
*c
) {
1790 if(!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
1791 gettextprop(c
->win
, wmatom
[WMName
], c
->name
, sizeof c
->name
);
1794 /* There's no way to check accesses to destroyed windows, thus those cases are
1795 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1796 * default error handler, which may call exit. */
1798 xerror(Display
*dpy
, XErrorEvent
*ee
) {
1799 if(ee
->error_code
== BadWindow
1800 || (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
1801 || (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
1802 || (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
1803 || (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
1804 || (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
1805 || (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
1806 || (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
1808 fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
1809 ee
->request_code
, ee
->error_code
);
1810 return xerrorxlib(dpy
, ee
); /* may call exit */
1814 xerrordummy(Display
*dsply
, XErrorEvent
*ee
) {
1818 /* Startup Error handler to check if another window manager
1819 * is already running. */
1821 xerrorstart(Display
*dsply
, XErrorEvent
*ee
) {
1827 view(const char *arg
) {
1830 memcpy(prevtags
, seltags
, sizeof seltags
);
1831 for(i
= 0; i
< LENGTH(tags
); i
++)
1832 seltags
[i
] = (NULL
== arg
);
1833 seltags
[idxoftag(arg
)] = True
;
1838 viewprevtag(const char *arg
) {
1839 static Bool tmptags
[sizeof tags
/ sizeof tags
[0]];
1841 memcpy(tmptags
, seltags
, sizeof seltags
);
1842 memcpy(seltags
, prevtags
, sizeof seltags
);
1843 memcpy(prevtags
, tmptags
, sizeof seltags
);
1848 zoom(const char *arg
) {
1851 if(!sel
|| !dozoom
|| sel
->isfloating
)
1853 if((c
= sel
) == nexttiled(clients
))
1854 if(!(c
= nexttiled(c
->next
)))
1863 main(int argc
, char *argv
[]) {
1864 if(argc
== 2 && !strcmp("-v", argv
[1]))
1865 eprint("dwm-"VERSION
", © 2006-2007 A. R. Garbe, S. van Dijk, J. Salmi, P. Hruby, S. Nagy\n");
1867 eprint("usage: dwm [-v]\n");
1869 setlocale(LC_CTYPE
, "");
1870 if(!(dpy
= XOpenDisplay(0)))
1871 eprint("dwm: cannot open display\n");
1872 screen
= DefaultScreen(dpy
);
1873 root
= RootWindow(dpy
, screen
);