Xinqi Bao's Git
897eeb4b86c6c5e60cf3a5ac1838f66263e719ff
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.
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>
37 #include <X11/cursorfont.h>
38 #include <X11/keysym.h>
39 #include <X11/Xatom.h>
41 #include <X11/Xproto.h>
42 #include <X11/Xutil.h>
44 #include <X11/extensions/Xinerama.h>
48 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
49 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
50 #define LENGTH(x) (sizeof x / sizeof x[0])
52 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
56 enum { BarTop
, BarBot
, BarOff
}; /* bar position */
57 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
58 enum { ColBorder
, ColFG
, ColBG
, ColLast
}; /* color */
59 enum { NetSupported
, NetWMName
, NetLast
}; /* EWMH atoms */
60 enum { WMProtocols
, WMDelete
, WMName
, WMState
, WMLast
};/* default atoms */
63 typedef struct Client Client
;
67 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
68 int minax
, maxax
, minay
, maxay
;
70 unsigned int border
, oldborder
;
71 Bool isbanned
, isfixed
, isfloating
, isurgent
;
81 unsigned long norm
[ColLast
];
82 unsigned long sel
[ColLast
];
92 } DC
; /* draw context */
97 void (*func
)(const char *arg
);
103 void (*arrange
)(void);
112 /* function declarations */
113 void applyrules(Client
*c
);
115 void attach(Client
*c
);
116 void attachstack(Client
*c
);
118 void buttonpress(XEvent
*e
);
119 void checkotherwm(void);
121 void configure(Client
*c
);
122 void configurenotify(XEvent
*e
);
123 void configurerequest(XEvent
*e
);
124 void destroynotify(XEvent
*e
);
125 void detach(Client
*c
);
126 void detachstack(Client
*c
);
128 void drawsquare(Bool filled
, Bool empty
, Bool invert
, unsigned long col
[ColLast
]);
129 void drawtext(const char *text
, unsigned long col
[ColLast
], Bool invert
);
130 void *emallocz(unsigned int size
);
131 void enternotify(XEvent
*e
);
132 void eprint(const char *errstr
, ...);
133 void expose(XEvent
*e
);
134 void floating(void); /* default floating layout */
135 void focus(Client
*c
);
136 void focusin(XEvent
*e
);
137 void focusnext(const char *arg
);
138 void focusprev(const char *arg
);
139 Client
*getclient(Window w
);
140 unsigned long getcolor(const char *colstr
);
141 long getstate(Window w
);
142 Bool
gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
);
143 void grabbuttons(Client
*c
, Bool focused
);
145 unsigned int idxoftag(const char *t
);
146 void initfont(const char *fontstr
);
147 Bool
isoccupied(unsigned int t
);
148 Bool
isprotodel(Client
*c
);
149 Bool
isurgent(unsigned int t
);
150 Bool
isvisible(Client
*c
);
151 void keypress(XEvent
*e
);
152 void killclient(const char *arg
);
153 void manage(Window w
, XWindowAttributes
*wa
);
154 void mappingnotify(XEvent
*e
);
155 void maprequest(XEvent
*e
);
156 void movemouse(Client
*c
);
157 Client
*nexttiled(Client
*c
);
158 void propertynotify(XEvent
*e
);
159 void quit(const char *arg
);
160 void reapply(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 toggletag(const char *arg
);
178 void toggleview(const char *arg
);
179 void unban(Client
*c
);
180 void unmanage(Client
*c
);
181 void unmapnotify(XEvent
*e
);
182 void updatebarpos(void);
183 void updatesizehints(Client
*c
);
184 void updatetitle(Client
*c
);
185 void updatewmhints(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
*dpy
, XErrorEvent
*ee
);
190 int xerrorstart(Display
*dpy
, XErrorEvent
*ee
);
191 void zoom(const char *arg
);
192 void selectview(const char *arg
);
195 char stext
[256], buf
[256];
197 int screen
, sx
, sy
, sw
, sh
, wax
, way
, waw
, wah
, xscreens
;
198 int (*xerrorxlib
)(Display
*, XErrorEvent
*);
199 unsigned int bh
, bpos
;
200 unsigned int blw
= 0;
201 unsigned int numlockmask
= 0;
202 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 Atom wmatom
[WMLast
], netatom
[NetLast
];
217 Bool domwfact
= True
;
219 Bool otherwm
, readin
;
223 Client
*clients
= NULL
;
225 Client
*stack
= NULL
;
226 Cursor cursor
[CurLast
];
232 XineramaScreenInfo
*info
= NULL
;
235 /* configuration, allows nested code to access above variables */
237 #define TAGSZ (LENGTH(tags) * sizeof(Bool))
238 static Bool tmp
[LENGTH(tags
)];
240 /* function implementations */
243 applyrules(Client
*c
) {
245 Bool matched
= False
;
247 XClassHint ch
= { 0 };
250 XGetClassHint(dpy
, c
->win
, &ch
);
251 for(i
= 0; i
< LENGTH(rules
); i
++) {
253 if(strstr(c
->name
, r
->prop
)
254 || (ch
.res_class
&& strstr(ch
.res_class
, r
->prop
))
255 || (ch
.res_name
&& strstr(ch
.res_name
, r
->prop
)))
257 c
->isfloating
= r
->isfloating
;
259 c
->tags
[idxoftag(r
->tag
)] = True
;
269 memcpy(c
->tags
, seltags
, TAGSZ
);
276 for(c
= clients
; c
; c
= c
->next
)
296 attachstack(Client
*c
) {
305 XMoveWindow(dpy
, c
->win
, c
->x
+ 3 * sw
, c
->y
);
310 buttonpress(XEvent
*e
) {
313 XButtonPressedEvent
*ev
= &e
->xbutton
;
315 if(ev
->window
== barwin
) {
317 for(i
= 0; i
< LENGTH(tags
); i
++) {
320 if(ev
->button
== Button1
) {
321 if(ev
->state
& MODKEY
)
326 else if(ev
->button
== Button3
) {
327 if(ev
->state
& MODKEY
)
335 if((ev
->x
< x
+ blw
) && ev
->button
== Button1
)
338 else if((c
= getclient(ev
->window
))) {
340 if(CLEANMASK(ev
->state
) != MODKEY
)
342 if(ev
->button
== Button1
) {
346 else if(ev
->button
== Button2
) {
347 if((floating
!= lt
->arrange
) && c
->isfloating
)
348 togglefloating(NULL
);
352 else if(ev
->button
== Button3
&& !c
->isfixed
) {
362 XSetErrorHandler(xerrorstart
);
364 /* this causes an error if some other window manager is running */
365 XSelectInput(dpy
, DefaultRootWindow(dpy
), SubstructureRedirectMask
);
368 eprint("dwm: another window manager is already running\n");
370 XSetErrorHandler(NULL
);
371 xerrorxlib
= XSetErrorHandler(xerror
);
384 XFreeFontSet(dpy
, dc
.font
.set
);
386 XFreeFont(dpy
, dc
.font
.xfont
);
388 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
389 XFreePixmap(dpy
, dc
.drawable
);
391 XFreeCursor(dpy
, cursor
[CurNormal
]);
392 XFreeCursor(dpy
, cursor
[CurResize
]);
393 XFreeCursor(dpy
, cursor
[CurMove
]);
394 XDestroyWindow(dpy
, barwin
);
400 XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
404 configure(Client
*c
) {
407 ce
.type
= ConfigureNotify
;
415 ce
.border_width
= c
->border
;
417 ce
.override_redirect
= False
;
418 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
422 configurenotify(XEvent
*e
) {
423 XConfigureEvent
*ev
= &e
->xconfigure
;
425 if(ev
->window
== root
&& (ev
->width
!= sw
|| ev
->height
!= sh
)) {
426 /* TODO -- use Xinerama dimensions here ? */
429 XFreePixmap(dpy
, dc
.drawable
);
430 dc
.drawable
= XCreatePixmap(dpy
, root
, DisplayWidth(root
, screen
), bh
, DefaultDepth(dpy
, screen
));
431 XResizeWindow(dpy
, barwin
, sw
, bh
);
438 configurerequest(XEvent
*e
) {
440 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
443 /* TODO -- consider Xinerama if necessary when centering */
444 if((c
= getclient(ev
->window
))) {
445 if(ev
->value_mask
& CWBorderWidth
)
446 c
->border
= ev
->border_width
;
447 if(c
->isfixed
|| c
->isfloating
|| (floating
== lt
->arrange
)) {
448 if(ev
->value_mask
& CWX
)
450 if(ev
->value_mask
& CWY
)
452 if(ev
->value_mask
& CWWidth
)
454 if(ev
->value_mask
& CWHeight
)
456 if((c
->x
- sx
+ c
->w
) > sw
&& c
->isfloating
)
457 c
->x
= sx
+ (sw
/ 2 - c
->w
/ 2); /* center in x direction */
458 if((c
->y
- sy
+ c
->h
) > sh
&& c
->isfloating
)
459 c
->y
= sy
+ (sh
/ 2 - c
->h
/ 2); /* center in y direction */
460 if((ev
->value_mask
& (CWX
|CWY
))
461 && !(ev
->value_mask
& (CWWidth
|CWHeight
)))
464 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
472 wc
.width
= ev
->width
;
473 wc
.height
= ev
->height
;
474 wc
.border_width
= ev
->border_width
;
475 wc
.sibling
= ev
->above
;
476 wc
.stack_mode
= ev
->detail
;
477 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
483 conflicts(Client
*c
, unsigned int tidx
) {
486 for(i
= 0; i
< LENGTH(tags
); i
++)
488 return True
; /* conflict */
493 destroynotify(XEvent
*e
) {
495 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
497 if((c
= getclient(ev
->window
)))
504 c
->prev
->next
= c
->next
;
506 c
->next
->prev
= c
->prev
;
509 c
->next
= c
->prev
= NULL
;
513 detachstack(Client
*c
) {
516 for(tc
=&stack
; *tc
&& *tc
!= c
; tc
=&(*tc
)->snext
);
526 for(c
= stack
; c
&& !isvisible(c
); c
= c
->snext
);
527 for(i
= 0; i
< LENGTH(tags
); i
++) {
528 dc
.w
= textw(tags
[i
]);
530 drawtext(tags
[i
], dc
.sel
, isurgent(i
));
531 drawsquare(c
&& c
->tags
[i
], isoccupied(i
), isurgent(i
), dc
.sel
);
534 drawtext(tags
[i
], dc
.norm
, isurgent(i
));
535 drawsquare(c
&& c
->tags
[i
], isoccupied(i
), isurgent(i
), dc
.norm
);
540 drawtext(lt
->symbol
, dc
.norm
, False
);
548 drawtext(stext
, dc
.norm
, False
);
549 if((dc
.w
= dc
.x
- x
) > bh
) {
552 drawtext(c
->name
, dc
.sel
, False
);
553 drawsquare(False
, c
->isfloating
, False
, dc
.sel
);
556 drawtext(NULL
, dc
.norm
, False
);
558 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, sw
, bh
, 0, 0);
563 drawsquare(Bool filled
, Bool empty
, Bool invert
, unsigned long col
[ColLast
]) {
566 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
568 gcv
.foreground
= col
[invert
? ColBG
: ColFG
];
569 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
570 x
= (dc
.font
.ascent
+ dc
.font
.descent
+ 2) / 4;
574 r
.width
= r
.height
= x
+ 1;
575 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
578 r
.width
= r
.height
= x
;
579 XDrawRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
584 drawtext(const char *text
, unsigned long col
[ColLast
], Bool invert
) {
586 unsigned int len
, olen
;
587 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
589 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColFG
: ColBG
]);
590 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
594 olen
= len
= strlen(text
);
595 if(len
>= sizeof buf
)
596 len
= sizeof buf
- 1;
597 memcpy(buf
, text
, len
);
599 h
= dc
.font
.ascent
+ dc
.font
.descent
;
600 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
602 /* shorten text if necessary */
603 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
614 return; /* too long */
615 XSetForeground(dpy
, dc
.gc
, col
[invert
? ColBG
: ColFG
]);
617 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
619 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
623 emallocz(unsigned int size
) {
624 void *res
= calloc(1, size
);
627 eprint("fatal: could not malloc() %u bytes\n", size
);
632 enternotify(XEvent
*e
) {
634 XCrossingEvent
*ev
= &e
->xcrossing
;
636 if((ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
) && ev
->window
!= root
)
638 if((c
= getclient(ev
->window
)))
645 eprint(const char *errstr
, ...) {
648 va_start(ap
, errstr
);
649 vfprintf(stderr
, errstr
, ap
);
656 XExposeEvent
*ev
= &e
->xexpose
;
658 if(ev
->count
== 0 && (ev
->window
== barwin
))
663 floating(void) { /* default floating layout */
666 domwfact
= dozoom
= False
;
667 for(c
= clients
; c
; c
= c
->next
)
669 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, True
);
674 if(!c
|| (c
&& !isvisible(c
)))
675 for(c
= stack
; c
&& !isvisible(c
); c
= c
->snext
);
676 if(sel
&& sel
!= c
) {
677 grabbuttons(sel
, False
);
678 XSetWindowBorder(dpy
, sel
->win
, dc
.norm
[ColBorder
]);
683 grabbuttons(c
, True
);
687 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBorder
]);
688 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
691 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
696 focusin(XEvent
*e
) { /* there are some broken focus acquiring clients */
697 XFocusChangeEvent
*ev
= &e
->xfocus
;
699 if(sel
&& ev
->window
!= sel
->win
)
700 XSetInputFocus(dpy
, sel
->win
, RevertToPointerRoot
, CurrentTime
);
704 focusnext(const char *arg
) {
709 for(c
= sel
->next
; c
&& !isvisible(c
); c
= c
->next
);
711 for(c
= clients
; c
&& !isvisible(c
); c
= c
->next
);
719 focusprev(const char *arg
) {
724 for(c
= sel
->prev
; c
&& !isvisible(c
); c
= c
->prev
);
726 for(c
= clients
; c
&& c
->next
; c
= c
->next
);
727 for(; c
&& !isvisible(c
); c
= c
->prev
);
736 getclient(Window w
) {
739 for(c
= clients
; c
&& c
->win
!= w
; c
= c
->next
);
744 getcolor(const char *colstr
) {
745 Colormap cmap
= DefaultColormap(dpy
, screen
);
748 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
749 eprint("error, cannot allocate color '%s'\n", colstr
);
757 unsigned char *p
= NULL
;
758 unsigned long n
, extra
;
761 status
= XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
762 &real
, &format
, &n
, &extra
, (unsigned char **)&p
);
763 if(status
!= Success
)
772 gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
) {
777 if(!text
|| size
== 0)
780 XGetTextProperty(dpy
, w
, &name
, atom
);
783 if(name
.encoding
== XA_STRING
)
784 strncpy(text
, (char *)name
.value
, size
- 1);
786 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
788 strncpy(text
, *list
, size
- 1);
789 XFreeStringList(list
);
792 text
[size
- 1] = '\0';
798 grabbuttons(Client
*c
, Bool focused
) {
799 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
802 XGrabButton(dpy
, Button1
, MODKEY
, c
->win
, False
, BUTTONMASK
,
803 GrabModeAsync
, GrabModeSync
, None
, None
);
804 XGrabButton(dpy
, Button1
, MODKEY
|LockMask
, c
->win
, False
, BUTTONMASK
,
805 GrabModeAsync
, GrabModeSync
, None
, None
);
806 XGrabButton(dpy
, Button1
, MODKEY
|numlockmask
, c
->win
, False
, BUTTONMASK
,
807 GrabModeAsync
, GrabModeSync
, None
, None
);
808 XGrabButton(dpy
, Button1
, MODKEY
|numlockmask
|LockMask
, c
->win
, False
, BUTTONMASK
,
809 GrabModeAsync
, GrabModeSync
, None
, None
);
811 XGrabButton(dpy
, Button2
, MODKEY
, c
->win
, False
, BUTTONMASK
,
812 GrabModeAsync
, GrabModeSync
, None
, None
);
813 XGrabButton(dpy
, Button2
, MODKEY
|LockMask
, c
->win
, False
, BUTTONMASK
,
814 GrabModeAsync
, GrabModeSync
, None
, None
);
815 XGrabButton(dpy
, Button2
, MODKEY
|numlockmask
, c
->win
, False
, BUTTONMASK
,
816 GrabModeAsync
, GrabModeSync
, None
, None
);
817 XGrabButton(dpy
, Button2
, MODKEY
|numlockmask
|LockMask
, c
->win
, False
, BUTTONMASK
,
818 GrabModeAsync
, GrabModeSync
, None
, None
);
820 XGrabButton(dpy
, Button3
, MODKEY
, c
->win
, False
, BUTTONMASK
,
821 GrabModeAsync
, GrabModeSync
, None
, None
);
822 XGrabButton(dpy
, Button3
, MODKEY
|LockMask
, c
->win
, False
, BUTTONMASK
,
823 GrabModeAsync
, GrabModeSync
, None
, None
);
824 XGrabButton(dpy
, Button3
, MODKEY
|numlockmask
, c
->win
, False
, BUTTONMASK
,
825 GrabModeAsync
, GrabModeSync
, None
, None
);
826 XGrabButton(dpy
, Button3
, MODKEY
|numlockmask
|LockMask
, c
->win
, False
, BUTTONMASK
,
827 GrabModeAsync
, GrabModeSync
, None
, None
);
830 XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
, BUTTONMASK
,
831 GrabModeAsync
, GrabModeSync
, None
, None
);
838 XModifierKeymap
*modmap
;
840 /* init modifier map */
841 modmap
= XGetModifierMapping(dpy
);
842 for(i
= 0; i
< 8; i
++)
843 for(j
= 0; j
< modmap
->max_keypermod
; j
++) {
844 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
] == XKeysymToKeycode(dpy
, XK_Num_Lock
))
845 numlockmask
= (1 << i
);
847 XFreeModifiermap(modmap
);
849 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
850 for(i
= 0; i
< LENGTH(keys
); i
++) {
851 code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
);
852 XGrabKey(dpy
, code
, keys
[i
].mod
, root
, True
,
853 GrabModeAsync
, GrabModeAsync
);
854 XGrabKey(dpy
, code
, keys
[i
].mod
|LockMask
, root
, True
,
855 GrabModeAsync
, GrabModeAsync
);
856 XGrabKey(dpy
, code
, keys
[i
].mod
|numlockmask
, root
, True
,
857 GrabModeAsync
, GrabModeAsync
);
858 XGrabKey(dpy
, code
, keys
[i
].mod
|numlockmask
|LockMask
, root
, True
,
859 GrabModeAsync
, GrabModeAsync
);
864 idxoftag(const char *t
) {
867 for(i
= 0; (i
< LENGTH(tags
)) && (tags
[i
] != t
); i
++);
868 return (i
< LENGTH(tags
)) ? i
: 0;
872 initfont(const char *fontstr
) {
873 char *def
, **missing
;
878 XFreeFontSet(dpy
, dc
.font
.set
);
879 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
882 fprintf(stderr
, "dwm: missing fontset: %s\n", missing
[n
]);
883 XFreeStringList(missing
);
886 XFontSetExtents
*font_extents
;
887 XFontStruct
**xfonts
;
889 dc
.font
.ascent
= dc
.font
.descent
= 0;
890 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
891 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
892 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
893 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
894 dc
.font
.ascent
= (*xfonts
)->ascent
;
895 if(dc
.font
.descent
< (*xfonts
)->descent
)
896 dc
.font
.descent
= (*xfonts
)->descent
;
902 XFreeFont(dpy
, dc
.font
.xfont
);
903 dc
.font
.xfont
= NULL
;
904 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
))
905 && !(dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed")))
906 eprint("error, cannot load font: '%s'\n", fontstr
);
907 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
908 dc
.font
.descent
= dc
.font
.xfont
->descent
;
910 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
914 isoccupied(unsigned int t
) {
917 for(c
= clients
; c
; c
= c
->next
)
924 isprotodel(Client
*c
) {
929 if(XGetWMProtocols(dpy
, c
->win
, &protocols
, &n
)) {
930 for(i
= 0; !ret
&& i
< n
; i
++)
931 if(protocols
[i
] == wmatom
[WMDelete
])
939 isurgent(unsigned int t
) {
942 for(c
= clients
; c
; c
= c
->next
)
943 if(c
->isurgent
&& c
->tags
[t
])
949 isvisible(Client
*c
) {
952 for(i
= 0; i
< LENGTH(tags
); i
++)
953 if(c
->tags
[i
] && seltags
[i
])
959 keypress(XEvent
*e
) {
965 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
966 for(i
= 0; i
< LENGTH(keys
); i
++)
967 if(keysym
== keys
[i
].keysym
968 && CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
))
971 keys
[i
].func(keys
[i
].arg
);
976 killclient(const char *arg
) {
981 if(isprotodel(sel
)) {
982 ev
.type
= ClientMessage
;
983 ev
.xclient
.window
= sel
->win
;
984 ev
.xclient
.message_type
= wmatom
[WMProtocols
];
985 ev
.xclient
.format
= 32;
986 ev
.xclient
.data
.l
[0] = wmatom
[WMDelete
];
987 ev
.xclient
.data
.l
[1] = CurrentTime
;
988 XSendEvent(dpy
, sel
->win
, False
, NoEventMask
, &ev
);
991 XKillClient(dpy
, sel
->win
);
995 manage(Window w
, XWindowAttributes
*wa
) {
996 Client
*c
, *t
= NULL
;
1001 c
= emallocz(sizeof(Client
));
1002 c
->tags
= emallocz(TAGSZ
);
1009 c
->oldborder
= wa
->border_width
;
1011 if(c
->w
== sw
&& c
->h
== sh
) {
1014 c
->border
= wa
->border_width
;
1017 if(c
->x
+ c
->w
+ 2 * c
->border
> wax
+ waw
)
1018 c
->x
= wax
+ waw
- c
->w
- 2 * c
->border
;
1019 if(c
->y
+ c
->h
+ 2 * c
->border
> way
+ wah
)
1020 c
->y
= way
+ wah
- c
->h
- 2 * c
->border
;
1025 c
->border
= BORDERPX
;
1027 wc
.border_width
= c
->border
;
1028 XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
1029 XSetWindowBorder(dpy
, w
, dc
.norm
[ColBorder
]);
1030 configure(c
); /* propagates border_width, if size doesn't change */
1032 XSelectInput(dpy
, w
, EnterWindowMask
|FocusChangeMask
|PropertyChangeMask
|StructureNotifyMask
);
1033 grabbuttons(c
, False
);
1035 if((rettrans
= XGetTransientForHint(dpy
, w
, &trans
) == Success
))
1036 for(t
= clients
; t
&& t
->win
!= trans
; t
= t
->next
);
1038 memcpy(c
->tags
, t
->tags
, TAGSZ
);
1042 c
->isfloating
= (rettrans
== Success
) || c
->isfixed
;
1045 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
); /* some windows require this */
1047 XMapWindow(dpy
, c
->win
);
1048 setclientstate(c
, NormalState
);
1053 mappingnotify(XEvent
*e
) {
1054 XMappingEvent
*ev
= &e
->xmapping
;
1056 XRefreshKeyboardMapping(ev
);
1057 if(ev
->request
== MappingKeyboard
)
1062 maprequest(XEvent
*e
) {
1063 static XWindowAttributes wa
;
1064 XMapRequestEvent
*ev
= &e
->xmaprequest
;
1066 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
1068 if(wa
.override_redirect
)
1070 if(!getclient(ev
->window
))
1071 manage(ev
->window
, &wa
);
1075 movemouse(Client
*c
) {
1076 int x1
, y1
, ocx
, ocy
, di
, nx
, ny
;
1083 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1084 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
1086 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
1088 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1091 XUngrabPointer(dpy
, CurrentTime
);
1093 case ConfigureRequest
:
1096 handler
[ev
.type
](&ev
);
1100 nx
= ocx
+ (ev
.xmotion
.x
- x1
);
1101 ny
= ocy
+ (ev
.xmotion
.y
- y1
);
1102 if(abs(wax
- nx
) < SNAP
)
1104 else if(abs((wax
+ waw
) - (nx
+ c
->w
+ 2 * c
->border
)) < SNAP
)
1105 nx
= wax
+ waw
- c
->w
- 2 * c
->border
;
1106 if(abs(way
- ny
) < SNAP
)
1108 else if(abs((way
+ wah
) - (ny
+ c
->h
+ 2 * c
->border
)) < SNAP
)
1109 ny
= way
+ wah
- c
->h
- 2 * c
->border
;
1110 if(!c
->isfloating
&& (lt
->arrange
!= floating
) && (abs(nx
- c
->x
) > SNAP
|| abs(ny
- c
->y
) > SNAP
))
1111 togglefloating(NULL
);
1112 if((lt
->arrange
== floating
) || c
->isfloating
)
1113 resize(c
, nx
, ny
, c
->w
, c
->h
, False
);
1120 nexttiled(Client
*c
) {
1121 for(; c
&& (c
->isfloating
|| !isvisible(c
)); c
= c
->next
);
1126 propertynotify(XEvent
*e
) {
1129 XPropertyEvent
*ev
= &e
->xproperty
;
1131 if(ev
->state
== PropertyDelete
)
1132 return; /* ignore */
1133 if((c
= getclient(ev
->window
))) {
1136 case XA_WM_TRANSIENT_FOR
:
1137 XGetTransientForHint(dpy
, c
->win
, &trans
);
1138 if(!c
->isfloating
&& (c
->isfloating
= (getclient(trans
) != NULL
)))
1141 case XA_WM_NORMAL_HINTS
:
1149 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
1158 quit(const char *arg
) {
1159 readin
= running
= False
;
1163 reapply(const char *arg
) {
1164 static Bool zerotags
[LENGTH(tags
)] = { 0 };
1167 for(c
= clients
; c
; c
= c
->next
) {
1168 memcpy(c
->tags
, zerotags
, sizeof zerotags
);
1175 resize(Client
*c
, int x
, int y
, int w
, int h
, Bool sizehints
) {
1179 /* set minimum possible */
1185 /* temporarily remove base dimensions */
1189 /* adjust for aspect limits */
1190 if (c
->minay
> 0 && c
->maxay
> 0 && c
->minax
> 0 && c
->maxax
> 0) {
1191 if (w
* c
->maxay
> h
* c
->maxax
)
1192 w
= h
* c
->maxax
/ c
->maxay
;
1193 else if (w
* c
->minay
< h
* c
->minax
)
1194 h
= w
* c
->minay
/ c
->minax
;
1197 /* adjust for increment value */
1203 /* restore base dimensions */
1207 if(c
->minw
> 0 && w
< c
->minw
)
1209 if(c
->minh
> 0 && h
< c
->minh
)
1211 if(c
->maxw
> 0 && w
> c
->maxw
)
1213 if(c
->maxh
> 0 && h
> c
->maxh
)
1216 if(w
<= 0 || h
<= 0)
1219 x
= sw
- w
- 2 * c
->border
;
1221 y
= sh
- h
- 2 * c
->border
;
1222 if(x
+ w
+ 2 * c
->border
< sx
)
1224 if(y
+ h
+ 2 * c
->border
< sy
)
1226 if(c
->x
!= x
|| c
->y
!= y
|| c
->w
!= w
|| c
->h
!= h
) {
1229 c
->w
= wc
.width
= w
;
1230 c
->h
= wc
.height
= h
;
1231 wc
.border_width
= c
->border
;
1232 XConfigureWindow(dpy
, c
->win
,
1233 CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
, &wc
);
1240 resizemouse(Client
*c
) {
1247 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1248 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
1250 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
1252 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1255 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0,
1256 c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
1257 XUngrabPointer(dpy
, CurrentTime
);
1258 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1260 case ConfigureRequest
:
1263 handler
[ev
.type
](&ev
);
1267 if((nw
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
1269 if((nh
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
1271 if(!c
->isfloating
&& (lt
->arrange
!= floating
) && (abs(nw
- c
->w
) > SNAP
|| abs(nh
- c
->h
) > SNAP
))
1272 togglefloating(NULL
);
1273 if((lt
->arrange
== floating
) || c
->isfloating
)
1274 resize(c
, c
->x
, c
->y
, nw
, nh
, True
);
1289 if(sel
->isfloating
|| (lt
->arrange
== floating
))
1290 XRaiseWindow(dpy
, sel
->win
);
1291 if(lt
->arrange
!= floating
) {
1292 wc
.stack_mode
= Below
;
1293 wc
.sibling
= barwin
;
1294 if(!sel
->isfloating
) {
1295 XConfigureWindow(dpy
, sel
->win
, CWSibling
|CWStackMode
, &wc
);
1296 wc
.sibling
= sel
->win
;
1298 for(c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
)) {
1301 XConfigureWindow(dpy
, c
->win
, CWSibling
|CWStackMode
, &wc
);
1302 wc
.sibling
= c
->win
;
1306 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1312 char sbuf
[sizeof stext
];
1315 unsigned int len
, offset
;
1318 /* main event loop, also reads status text from stdin */
1320 xfd
= ConnectionNumber(dpy
);
1323 len
= sizeof stext
- 1;
1324 sbuf
[len
] = stext
[len
] = '\0'; /* 0-terminator is never touched */
1328 FD_SET(STDIN_FILENO
, &rd
);
1330 if(select(xfd
+ 1, &rd
, NULL
, NULL
, NULL
) == -1) {
1333 eprint("select failed\n");
1335 if(FD_ISSET(STDIN_FILENO
, &rd
)) {
1336 switch((r
= read(STDIN_FILENO
, sbuf
+ offset
, len
- offset
))) {
1338 strncpy(stext
, strerror(errno
), len
);
1342 strncpy(stext
, "EOF", 4);
1346 for(p
= sbuf
+ offset
; r
> 0; p
++, r
--, offset
++)
1347 if(*p
== '\n' || *p
== '\0') {
1349 strncpy(stext
, sbuf
, len
);
1350 p
+= r
- 1; /* p is sbuf + offset + r - 1 */
1351 for(r
= 0; *(p
- r
) && *(p
- r
) != '\n'; r
++);
1354 memmove(sbuf
, p
- r
+ 1, r
);
1361 while(XPending(dpy
)) {
1362 XNextEvent(dpy
, &ev
);
1363 if(handler
[ev
.type
])
1364 (handler
[ev
.type
])(&ev
); /* call handler */
1371 unsigned int i
, num
;
1372 Window
*wins
, d1
, d2
;
1373 XWindowAttributes wa
;
1376 if(XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
1377 for(i
= 0; i
< num
; i
++) {
1378 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
1379 || wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
1381 if(wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
1382 manage(wins
[i
], &wa
);
1384 for(i
= 0; i
< num
; i
++) { /* now the transients */
1385 if(!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
1387 if(XGetTransientForHint(dpy
, wins
[i
], &d1
)
1388 && (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
1389 manage(wins
[i
], &wa
);
1397 setclientstate(Client
*c
, long state
) {
1398 long data
[] = {state
, None
};
1400 XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
1401 PropModeReplace
, (unsigned char *)data
, 2);
1405 setlayout(const char *arg
) {
1410 if(lt
== &layouts
[LENGTH(layouts
)])
1414 for(i
= 0; i
< LENGTH(layouts
); i
++)
1415 if(arg
== layouts
[i
].symbol
)
1417 if(i
== LENGTH(layouts
))
1428 setmwfact(const char *arg
) {
1433 /* arg handling, manipulate mwfact */
1436 else if(sscanf(arg
, "%lf", &delta
) == 1) {
1437 if(arg
[0] == '+' || arg
[0] == '-')
1443 else if(mwfact
> 0.9)
1452 XSetWindowAttributes wa
;
1455 screen
= DefaultScreen(dpy
);
1456 root
= RootWindow(dpy
, screen
);
1459 sw
= DisplayWidth(dpy
, screen
);
1460 sh
= DisplayHeight(dpy
, screen
);
1463 wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
1464 wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
1465 wmatom
[WMName
] = XInternAtom(dpy
, "WM_NAME", False
);
1466 wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
1467 netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
1468 netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
1471 wa
.cursor
= cursor
[CurNormal
] = XCreateFontCursor(dpy
, XC_left_ptr
);
1472 cursor
[CurResize
] = XCreateFontCursor(dpy
, XC_sizing
);
1473 cursor
[CurMove
] = XCreateFontCursor(dpy
, XC_fleur
);
1476 if(XineramaIsActive(dpy
))
1477 info
= XineramaQueryScreens(dpy
, &xscreens
);
1480 /* init appearance */
1481 dc
.norm
[ColBorder
] = getcolor(NORMBORDERCOLOR
);
1482 dc
.norm
[ColBG
] = getcolor(NORMBGCOLOR
);
1483 dc
.norm
[ColFG
] = getcolor(NORMFGCOLOR
);
1484 dc
.sel
[ColBorder
] = getcolor(SELBORDERCOLOR
);
1485 dc
.sel
[ColBG
] = getcolor(SELBGCOLOR
);
1486 dc
.sel
[ColFG
] = getcolor(SELFGCOLOR
);
1488 dc
.h
= bh
= dc
.font
.height
+ 2;
1489 dc
.drawable
= XCreatePixmap(dpy
, root
, DisplayWidth(dpy
, screen
), bh
, DefaultDepth(dpy
, screen
));
1490 dc
.gc
= XCreateGC(dpy
, root
, 0, 0);
1491 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
1493 XSetFont(dpy
, dc
.gc
, dc
.font
.xfont
->fid
);
1496 seltags
= emallocz(TAGSZ
);
1497 prevtags
= emallocz(TAGSZ
);
1498 seltags
[0] = prevtags
[0] = True
;
1504 /* TODO: Xinerama hints ? */
1506 for(blw
= i
= 0; i
< LENGTH(layouts
); i
++) {
1507 i
= textw(layouts
[i
].symbol
);
1513 wa
.override_redirect
= 1;
1514 wa
.background_pixmap
= ParentRelative
;
1515 wa
.event_mask
= ButtonPressMask
|ExposureMask
;
1517 barwin
= XCreateWindow(dpy
, root
, sx
, sy
, sw
, bh
, 0, DefaultDepth(dpy
, screen
),
1518 CopyFromParent
, DefaultVisual(dpy
, screen
),
1519 CWOverrideRedirect
|CWBackPixmap
|CWEventMask
, &wa
);
1520 XDefineCursor(dpy
, barwin
, cursor
[CurNormal
]);
1522 XMapRaised(dpy
, barwin
);
1523 strcpy(stext
, "dwm-"VERSION
);
1526 /* EWMH support per view */
1527 XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
1528 PropModeReplace
, (unsigned char *) netatom
, NetLast
);
1530 /* select for events */
1531 wa
.event_mask
= SubstructureRedirectMask
|SubstructureNotifyMask
1532 |EnterWindowMask
|LeaveWindowMask
|StructureNotifyMask
;
1533 XChangeWindowAttributes(dpy
, root
, CWEventMask
|CWCursor
, &wa
);
1534 XSelectInput(dpy
, root
, wa
.event_mask
);
1542 spawn(const char *arg
) {
1543 static char *shell
= NULL
;
1545 if(!shell
&& !(shell
= getenv("SHELL")))
1549 /* The double-fork construct avoids zombie processes and keeps the code
1550 * clean from stupid signal handlers. */
1554 close(ConnectionNumber(dpy
));
1556 execl(shell
, shell
, "-c", arg
, (char *)NULL
);
1557 fprintf(stderr
, "dwm: execl '%s -c %s'", shell
, arg
);
1566 tag(const char *arg
) {
1571 for(i
= 0; i
< LENGTH(tags
); i
++)
1572 sel
->tags
[i
] = (NULL
== arg
);
1573 sel
->tags
[idxoftag(arg
)] = True
;
1578 textnw(const char *text
, unsigned int len
) {
1582 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
1585 return XTextWidth(dc
.font
.xfont
, text
, len
);
1589 textw(const char *text
) {
1590 return textnw(text
, strlen(text
)) + dc
.font
.height
;
1595 unsigned int i
, n
, nx
, ny
, nw
, nh
, mw
, th
;
1598 domwfact
= dozoom
= True
;
1602 for(n
= 0, c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
))
1606 mw
= (n
== 1) ? waw
: mwfact
* waw
;
1607 th
= (n
> 1) ? wah
/ (n
- 1) : 0;
1608 if(n
> 1 && th
< bh
)
1611 for(i
= 0, c
= mc
= nexttiled(clients
); c
; c
= nexttiled(c
->next
)) {
1612 if(i
== 0) { /* master */
1613 nw
= mw
- 2 * c
->border
;
1614 nh
= wah
- 2 * c
->border
;
1616 else { /* tile window */
1619 nx
+= mc
->w
+ 2 * mc
->border
;
1620 nw
= waw
- mw
- 2 * c
->border
;
1622 if(i
+ 1 == n
) /* remainder */
1623 nh
= (way
+ wah
) - ny
- 2 * c
->border
;
1625 nh
= th
- 2 * c
->border
;
1627 resize(c
, nx
, ny
, nw
, nh
, RESIZEHINTS
);
1628 if((RESIZEHINTS
) && ((c
->h
< bh
) || (c
->h
> nh
) || (c
->w
< bh
) || (c
->w
> nw
)))
1629 /* client doesn't accept size constraints */
1630 resize(c
, nx
, ny
, nw
, nh
, False
);
1631 if(n
> 1 && th
!= wah
)
1632 ny
= c
->y
+ c
->h
+ 2 * c
->border
;
1638 togglebar(const char *arg
) {
1640 bpos
= (BARPOS
== BarOff
) ? BarTop
: BARPOS
;
1648 togglefloating(const char *arg
) {
1651 sel
->isfloating
= !sel
->isfloating
;
1653 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
);
1658 toggletag(const char *arg
) {
1664 if(conflicts(sel
, i
))
1666 sel
->tags
[i
] = !sel
->tags
[i
];
1667 for(j
= 0; j
< LENGTH(tags
) && !sel
->tags
[j
]; j
++);
1668 if(j
== LENGTH(tags
))
1669 sel
->tags
[i
] = True
; /* at least one tag must be enabled */
1674 toggleview(const char *arg
) {
1678 seltags
[i
] = !seltags
[i
];
1679 for(j
= 0; j
< LENGTH(tags
) && !seltags
[j
]; j
++);
1680 if(j
== LENGTH(tags
))
1681 seltags
[i
] = True
; /* at least one tag must be viewed */
1689 XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
1690 c
->isbanned
= False
;
1694 unmanage(Client
*c
) {
1697 wc
.border_width
= c
->oldborder
;
1698 /* The server grab construct avoids race conditions. */
1700 XSetErrorHandler(xerrordummy
);
1701 XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
1706 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1707 setclientstate(c
, WithdrawnState
);
1711 XSetErrorHandler(xerror
);
1717 unmapnotify(XEvent
*e
) {
1719 XUnmapEvent
*ev
= &e
->xunmap
;
1721 if((c
= getclient(ev
->window
)))
1726 updatebarpos(void) {
1737 XMoveWindow(dpy
, barwin
, sx
, sy
);
1741 XMoveWindow(dpy
, barwin
, sx
, sy
+ wah
);
1744 XMoveWindow(dpy
, barwin
, sx
, sy
- bh
);
1748 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1752 updatesizehints(Client
*c
) {
1756 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
) || !size
.flags
)
1758 c
->flags
= size
.flags
;
1759 if(c
->flags
& PBaseSize
) {
1760 c
->basew
= size
.base_width
;
1761 c
->baseh
= size
.base_height
;
1763 else if(c
->flags
& PMinSize
) {
1764 c
->basew
= size
.min_width
;
1765 c
->baseh
= size
.min_height
;
1768 c
->basew
= c
->baseh
= 0;
1769 if(c
->flags
& PResizeInc
) {
1770 c
->incw
= size
.width_inc
;
1771 c
->inch
= size
.height_inc
;
1774 c
->incw
= c
->inch
= 0;
1775 if(c
->flags
& PMaxSize
) {
1776 c
->maxw
= size
.max_width
;
1777 c
->maxh
= size
.max_height
;
1780 c
->maxw
= c
->maxh
= 0;
1781 if(c
->flags
& PMinSize
) {
1782 c
->minw
= size
.min_width
;
1783 c
->minh
= size
.min_height
;
1785 else if(c
->flags
& PBaseSize
) {
1786 c
->minw
= size
.base_width
;
1787 c
->minh
= size
.base_height
;
1790 c
->minw
= c
->minh
= 0;
1791 if(c
->flags
& PAspect
) {
1792 c
->minax
= size
.min_aspect
.x
;
1793 c
->maxax
= size
.max_aspect
.x
;
1794 c
->minay
= size
.min_aspect
.y
;
1795 c
->maxay
= size
.max_aspect
.y
;
1798 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
1799 c
->isfixed
= (c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
1800 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
1804 updatetitle(Client
*c
) {
1805 if(!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
1806 gettextprop(c
->win
, wmatom
[WMName
], c
->name
, sizeof c
->name
);
1810 updatewmhints(Client
*c
) {
1813 if((wmh
= XGetWMHints(dpy
, c
->win
))) {
1814 c
->isurgent
= (wmh
->flags
& XUrgencyHint
) ? True
: False
;
1821 view(const char *arg
) {
1824 for(i
= 0; i
< LENGTH(tags
); i
++)
1825 tmp
[i
] = (NULL
== arg
);
1826 tmp
[idxoftag(arg
)] = True
;
1828 if(memcmp(seltags
, tmp
, TAGSZ
) != 0) {
1829 memcpy(prevtags
, seltags
, TAGSZ
);
1830 memcpy(seltags
, tmp
, TAGSZ
);
1836 viewprevtag(const char *arg
) {
1838 memcpy(tmp
, seltags
, TAGSZ
);
1839 memcpy(seltags
, prevtags
, TAGSZ
);
1840 memcpy(prevtags
, tmp
, TAGSZ
);
1844 /* There's no way to check accesses to destroyed windows, thus those cases are
1845 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1846 * default error handler, which may call exit. */
1848 xerror(Display
*dpy
, XErrorEvent
*ee
) {
1849 if(ee
->error_code
== BadWindow
1850 || (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
1851 || (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
1852 || (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
1853 || (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
1854 || (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
1855 || (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
1856 || (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
1858 fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
1859 ee
->request_code
, ee
->error_code
);
1860 return xerrorxlib(dpy
, ee
); /* may call exit */
1864 xerrordummy(Display
*dpy
, XErrorEvent
*ee
) {
1868 /* Startup Error handler to check if another window manager
1869 * is already running. */
1871 xerrorstart(Display
*dpy
, XErrorEvent
*ee
) {
1877 zoom(const char *arg
) {
1880 if(!sel
|| !dozoom
|| sel
->isfloating
)
1882 if(c
== nexttiled(clients
))
1883 if(!(c
= nexttiled(c
->next
)))
1892 main(int argc
, char *argv
[]) {
1893 if(argc
== 2 && !strcmp("-v", argv
[1]))
1894 eprint("dwm-"VERSION
", © 2006-2008 dwm engineers, see LICENSE for details\n");
1896 eprint("usage: dwm [-v]\n");
1898 setlocale(LC_CTYPE
, "");
1899 if(!(dpy
= XOpenDisplay(0)))
1900 eprint("dwm: cannot open display\n");