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 * The event handlers of dwm are organized in an array which is accessed
10 * whenever a new event has been fetched. This allows event dispatching
13 * Each child of the root window is called a client, except windows which have
14 * set the override_redirect flag. Clients are organized in a linked client
15 * list on each monitor, the focus history is remembered through a stack list
16 * on each monitor. Each client contains a bit array to indicate the tags of a
19 * Keys and tagging rules are organized as arrays and defined in config.h.
21 * To understand everything else, start reading main().
31 #include <sys/types.h>
33 #include <X11/cursorfont.h>
34 #include <X11/keysym.h>
35 #include <X11/Xatom.h>
37 #include <X11/Xproto.h>
38 #include <X11/Xutil.h>
40 #include <X11/extensions/Xinerama.h>
42 #include <X11/Xft/Xft.h>
48 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
49 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
50 #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
51 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
52 #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
53 #define LENGTH(X) (sizeof X / sizeof X[0])
54 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
55 #define WIDTH(X) ((X)->w + 2 * (X)->bw)
56 #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
57 #define TAGMASK ((1 << LENGTH(tags)) - 1)
58 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
60 #define SYSTEM_TRAY_REQUEST_DOCK 0
63 #define XEMBED_EMBEDDED_NOTIFY 0
64 #define XEMBED_WINDOW_ACTIVATE 1
65 #define XEMBED_FOCUS_IN 4
66 #define XEMBED_MODALITY_ON 10
68 #define XEMBED_MAPPED (1 << 0)
69 #define XEMBED_WINDOW_ACTIVATE 1
70 #define XEMBED_WINDOW_DEACTIVATE 2
72 #define VERSION_MAJOR 0
73 #define VERSION_MINOR 0
74 #define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
77 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
78 enum { SchemeNorm
, SchemeSel
}; /* color schemes */
79 enum { NetSupported
, NetWMName
, NetWMState
, NetWMCheck
,
80 NetSystemTray
, NetSystemTrayOP
, NetSystemTrayOrientation
, NetSystemTrayOrientationHorz
,
81 NetWMFullscreen
, NetActiveWindow
, NetWMWindowType
,
82 NetWMWindowTypeDialog
, NetClientList
, NetLast
}; /* EWMH atoms */
83 enum { Manager
, Xembed
, XembedInfo
, XLast
}; /* Xembed atoms */
84 enum { WMProtocols
, WMDelete
, WMState
, WMTakeFocus
, WMLast
}; /* default atoms */
85 enum { ClkTagBar
, ClkLtSymbol
, ClkStatusText
, ClkWinTitle
,
86 ClkClientWin
, ClkRootWin
, ClkLast
}; /* clicks */
99 void (*func
)(const Arg
*arg
);
103 typedef struct Monitor Monitor
;
104 typedef struct Client Client
;
109 int sfx
, sfy
, sfw
, sfh
; /* stored float geometry, used on mode revert */
110 int oldx
, oldy
, oldw
, oldh
;
111 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
114 int isfixed
, isfloating
, isurgent
, neverfocus
, oldstate
, isfullscreen
;
124 void (*func
)(const Arg
*);
130 void (*arrange
)(Monitor
*);
138 int by
; /* bar geometry */
139 int mx
, my
, mw
, mh
; /* screen size */
140 int wx
, wy
, ww
, wh
; /* window area */
141 unsigned int seltags
;
143 unsigned int tagset
[2];
156 const char *instance
;
163 typedef struct Systray Systray
;
169 /* function declarations */
170 static void applyrules(Client
*c
);
171 static int applysizehints(Client
*c
, int *x
, int *y
, int *w
, int *h
, int interact
);
172 static void arrange(Monitor
*m
);
173 static void arrangemon(Monitor
*m
);
174 static void attach(Client
*c
);
175 static void attachstack(Client
*c
);
176 static void buttonpress(XEvent
*e
);
177 static void checkotherwm(void);
178 static void cleanup(void);
179 static void cleanupmon(Monitor
*mon
);
180 static void clientmessage(XEvent
*e
);
181 static void configure(Client
*c
);
182 static void configurenotify(XEvent
*e
);
183 static void configurerequest(XEvent
*e
);
184 static Monitor
*createmon(void);
185 static void destroynotify(XEvent
*e
);
186 static void detach(Client
*c
);
187 static void detachstack(Client
*c
);
188 static Monitor
*dirtomon(int dir
);
189 static void drawbar(Monitor
*m
);
190 static void drawbars(void);
191 static void enternotify(XEvent
*e
);
192 static void expose(XEvent
*e
);
193 static void focus(Client
*c
);
194 static void focusin(XEvent
*e
);
195 static void focusmon(const Arg
*arg
);
196 static void focusstack(const Arg
*arg
);
197 static Atom
getatomprop(Client
*c
, Atom prop
);
198 static int getrootptr(int *x
, int *y
);
199 static long getstate(Window w
);
200 static unsigned int getsystraywidth();
201 static int gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
);
202 static void grabbuttons(Client
*c
, int focused
);
203 static void grabkeys(void);
204 static void incnmaster(const Arg
*arg
);
205 static void keypress(XEvent
*e
);
206 static void killclient(const Arg
*arg
);
207 static void manage(Window w
, XWindowAttributes
*wa
);
208 static void mappingnotify(XEvent
*e
);
209 static void maprequest(XEvent
*e
);
210 static void monocle(Monitor
*m
);
211 static void motionnotify(XEvent
*e
);
212 static void movemouse(const Arg
*arg
);
213 static Client
*nexttiled(Client
*c
);
214 static void pop(Client
*);
215 static void propertynotify(XEvent
*e
);
216 static void quit(const Arg
*arg
);
217 static Monitor
*recttomon(int x
, int y
, int w
, int h
);
218 static void removesystrayicon(Client
*i
);
219 static void resize(Client
*c
, int x
, int y
, int w
, int h
, int interact
);
220 static void resizebarwin(Monitor
*m
);
221 static void resizeclient(Client
*c
, int x
, int y
, int w
, int h
);
222 static void resizemouse(const Arg
*arg
);
223 static void resizerequest(XEvent
*e
);
224 static void restack(Monitor
*m
);
225 static void run(void);
226 static void scan(void);
227 static int sendevent(Window w
, Atom proto
, int m
, long d0
, long d1
, long d2
, long d3
, long d4
);
228 static void sendmon(Client
*c
, Monitor
*m
);
229 static void setclientstate(Client
*c
, long state
);
230 static void setfocus(Client
*c
);
231 static void setfullscreen(Client
*c
, int fullscreen
);
232 static void setlayout(const Arg
*arg
);
233 static void setmfact(const Arg
*arg
);
234 static void setup(void);
235 static void seturgent(Client
*c
, int urg
);
236 static void showhide(Client
*c
);
237 static void sigchld(int unused
);
238 static void spawn(const Arg
*arg
);
239 static Monitor
*systraytomon(Monitor
*m
);
240 static void tag(const Arg
*arg
);
241 static void tagmon(const Arg
*arg
);
242 static void tile(Monitor
*);
243 static void togglebar(const Arg
*arg
);
244 static void togglefloating(const Arg
*arg
);
245 static void toggletag(const Arg
*arg
);
246 static void toggleview(const Arg
*arg
);
247 static void unfocus(Client
*c
, int setfocus
);
248 static void unmanage(Client
*c
, int destroyed
);
249 static void unmapnotify(XEvent
*e
);
250 static void updatebarpos(Monitor
*m
);
251 static void updatebars(void);
252 static void updateclientlist(void);
253 static int updategeom(void);
254 static void updatenumlockmask(void);
255 static void updatesizehints(Client
*c
);
256 static void updatestatus(void);
257 static void updatesystray(void);
258 static void updatesystrayicongeom(Client
*i
, int w
, int h
);
259 static void updatesystrayiconstate(Client
*i
, XPropertyEvent
*ev
);
260 static void updatetitle(Client
*c
);
261 static void updatewindowtype(Client
*c
);
262 static void updatewmhints(Client
*c
);
263 static void view(const Arg
*arg
);
264 static Client
*wintoclient(Window w
);
265 static Monitor
*wintomon(Window w
);
266 static Client
*wintosystrayicon(Window w
);
267 static int xerror(Display
*dpy
, XErrorEvent
*ee
);
268 static int xerrordummy(Display
*dpy
, XErrorEvent
*ee
);
269 static int xerrorstart(Display
*dpy
, XErrorEvent
*ee
);
270 static void zoom(const Arg
*arg
);
273 static Systray
*systray
= NULL
;
274 static const char broken
[] = "broken";
275 static char stext
[256];
277 static int sw
, sh
; /* X display screen geometry width, height */
278 static int bh
, blw
= 0; /* bar geometry */
279 static int lrpad
; /* sum of left and right padding for text */
280 static int (*xerrorxlib
)(Display
*, XErrorEvent
*);
281 static unsigned int numlockmask
= 0;
282 static void (*handler
[LASTEvent
]) (XEvent
*) = {
283 [ButtonPress
] = buttonpress
,
284 [ClientMessage
] = clientmessage
,
285 [ConfigureRequest
] = configurerequest
,
286 [ConfigureNotify
] = configurenotify
,
287 [DestroyNotify
] = destroynotify
,
288 [EnterNotify
] = enternotify
,
291 [KeyPress
] = keypress
,
292 [MappingNotify
] = mappingnotify
,
293 [MapRequest
] = maprequest
,
294 [MotionNotify
] = motionnotify
,
295 [PropertyNotify
] = propertynotify
,
296 [ResizeRequest
] = resizerequest
,
297 [UnmapNotify
] = unmapnotify
299 static Atom wmatom
[WMLast
], netatom
[NetLast
], xatom
[XLast
];
300 static int running
= 1;
301 static Cur
*cursor
[CurLast
];
305 static Monitor
*mons
, *selmon
;
306 static Window root
, wmcheckwin
;
308 /* configuration, allows nested code to access above variables */
311 /* compile-time check if all tags fit into an unsigned int bit array. */
312 struct NumTags
{ char limitexceeded
[LENGTH(tags
) > 31 ? -1 : 1]; };
314 /* function implementations */
316 applyrules(Client
*c
)
318 const char *class, *instance
;
322 XClassHint ch
= { NULL
, NULL
};
327 XGetClassHint(dpy
, c
->win
, &ch
);
328 class = ch
.res_class
? ch
.res_class
: broken
;
329 instance
= ch
.res_name
? ch
.res_name
: broken
;
331 for (i
= 0; i
< LENGTH(rules
); i
++) {
333 if ((!r
->title
|| strstr(c
->name
, r
->title
))
334 && (!r
->class || strstr(class, r
->class))
335 && (!r
->instance
|| strstr(instance
, r
->instance
)))
337 c
->isfloating
= r
->isfloating
;
339 for (m
= mons
; m
&& m
->num
!= r
->monitor
; m
= m
->next
);
348 c
->tags
= c
->tags
& TAGMASK
? c
->tags
& TAGMASK
: c
->mon
->tagset
[c
->mon
->seltags
];
352 applysizehints(Client
*c
, int *x
, int *y
, int *w
, int *h
, int interact
)
357 /* set minimum possible */
365 if (*x
+ *w
+ 2 * c
->bw
< 0)
367 if (*y
+ *h
+ 2 * c
->bw
< 0)
370 if (*x
>= m
->wx
+ m
->ww
)
371 *x
= m
->wx
+ m
->ww
- WIDTH(c
);
372 if (*y
>= m
->wy
+ m
->wh
)
373 *y
= m
->wy
+ m
->wh
- HEIGHT(c
);
374 if (*x
+ *w
+ 2 * c
->bw
<= m
->wx
)
376 if (*y
+ *h
+ 2 * c
->bw
<= m
->wy
)
383 if (resizehints
|| c
->isfloating
|| !c
->mon
->lt
[c
->mon
->sellt
]->arrange
) {
384 /* see last two sentences in ICCCM 4.1.2.3 */
385 baseismin
= c
->basew
== c
->minw
&& c
->baseh
== c
->minh
;
386 if (!baseismin
) { /* temporarily remove base dimensions */
390 /* adjust for aspect limits */
391 if (c
->mina
> 0 && c
->maxa
> 0) {
392 if (c
->maxa
< (float)*w
/ *h
)
393 *w
= *h
* c
->maxa
+ 0.5;
394 else if (c
->mina
< (float)*h
/ *w
)
395 *h
= *w
* c
->mina
+ 0.5;
397 if (baseismin
) { /* increment calculation requires this */
401 /* adjust for increment value */
406 /* restore base dimensions */
407 *w
= MAX(*w
+ c
->basew
, c
->minw
);
408 *h
= MAX(*h
+ c
->baseh
, c
->minh
);
410 *w
= MIN(*w
, c
->maxw
);
412 *h
= MIN(*h
, c
->maxh
);
414 return *x
!= c
->x
|| *y
!= c
->y
|| *w
!= c
->w
|| *h
!= c
->h
;
422 else for (m
= mons
; m
; m
= m
->next
)
427 } else for (m
= mons
; m
; m
= m
->next
)
432 arrangemon(Monitor
*m
)
434 strncpy(m
->ltsymbol
, m
->lt
[m
->sellt
]->symbol
, sizeof m
->ltsymbol
);
435 if (m
->lt
[m
->sellt
]->arrange
)
436 m
->lt
[m
->sellt
]->arrange(m
);
442 c
->next
= c
->mon
->clients
;
447 attachstack(Client
*c
)
449 c
->snext
= c
->mon
->stack
;
454 buttonpress(XEvent
*e
)
456 unsigned int i
, x
, click
;
460 XButtonPressedEvent
*ev
= &e
->xbutton
;
463 /* focus monitor if necessary */
464 if ((m
= wintomon(ev
->window
)) && m
!= selmon
) {
465 unfocus(selmon
->sel
, 1);
469 if (ev
->window
== selmon
->barwin
) {
473 while (ev
->x
>= x
&& ++i
< LENGTH(tags
));
474 if (i
< LENGTH(tags
)) {
477 } else if (ev
->x
< x
+ blw
)
479 else if (ev
->x
> selmon
->ww
- TEXTW(stext
))
480 click
= ClkStatusText
;
483 } else if ((c
= wintoclient(ev
->window
))) {
486 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
487 click
= ClkClientWin
;
489 for (i
= 0; i
< LENGTH(buttons
); i
++)
490 if (click
== buttons
[i
].click
&& buttons
[i
].func
&& buttons
[i
].button
== ev
->button
491 && CLEANMASK(buttons
[i
].mask
) == CLEANMASK(ev
->state
))
492 buttons
[i
].func(click
== ClkTagBar
&& buttons
[i
].arg
.i
== 0 ? &arg
: &buttons
[i
].arg
);
498 xerrorxlib
= XSetErrorHandler(xerrorstart
);
499 /* this causes an error if some other window manager is running */
500 XSelectInput(dpy
, DefaultRootWindow(dpy
), SubstructureRedirectMask
);
502 XSetErrorHandler(xerror
);
510 Layout foo
= { "", NULL
};
515 selmon
->lt
[selmon
->sellt
] = &foo
;
516 for (m
= mons
; m
; m
= m
->next
)
518 unmanage(m
->stack
, 0);
519 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
523 XUnmapWindow(dpy
, systray
->win
);
524 XDestroyWindow(dpy
, systray
->win
);
527 for (i
= 0; i
< CurLast
; i
++)
528 drw_cur_free(drw
, cursor
[i
]);
529 for (i
= 0; i
< LENGTH(colors
); i
++)
531 XDestroyWindow(dpy
, wmcheckwin
);
534 XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
535 XDeleteProperty(dpy
, root
, netatom
[NetActiveWindow
]);
539 cleanupmon(Monitor
*mon
)
546 for (m
= mons
; m
&& m
->next
!= mon
; m
= m
->next
);
549 XUnmapWindow(dpy
, mon
->barwin
);
550 XDestroyWindow(dpy
, mon
->barwin
);
555 clientmessage(XEvent
*e
)
557 XWindowAttributes wa
;
558 XSetWindowAttributes swa
;
559 XClientMessageEvent
*cme
= &e
->xclient
;
560 Client
*c
= wintoclient(cme
->window
);
562 if (showsystray
&& cme
->window
== systray
->win
&& cme
->message_type
== netatom
[NetSystemTrayOP
]) {
563 /* add systray icons */
564 if (cme
->data
.l
[1] == SYSTEM_TRAY_REQUEST_DOCK
) {
565 if (!(c
= (Client
*)calloc(1, sizeof(Client
))))
566 die("fatal: could not malloc() %u bytes\n", sizeof(Client
));
567 if (!(c
->win
= cme
->data
.l
[2])) {
572 c
->next
= systray
->icons
;
574 XGetWindowAttributes(dpy
, c
->win
, &wa
);
575 c
->x
= c
->oldx
= c
->y
= c
->oldy
= 0;
576 c
->w
= c
->oldw
= wa
.width
;
577 c
->h
= c
->oldh
= wa
.height
;
578 c
->oldbw
= wa
.border_width
;
580 c
->isfloating
= True
;
581 /* reuse tags field as mapped status */
584 updatesystrayicongeom(c
, wa
.width
, wa
.height
);
585 XAddToSaveSet(dpy
, c
->win
);
586 XSelectInput(dpy
, c
->win
, StructureNotifyMask
| PropertyChangeMask
| ResizeRedirectMask
);
587 XReparentWindow(dpy
, c
->win
, systray
->win
, 0, 0);
588 /* use parents background color */
589 swa
.background_pixel
= scheme
[SchemeNorm
][ColBg
].pixel
;
590 XChangeWindowAttributes(dpy
, c
->win
, CWBackPixel
, &swa
);
591 sendevent(c
->win
, netatom
[Xembed
], StructureNotifyMask
, CurrentTime
, XEMBED_EMBEDDED_NOTIFY
, 0 , systray
->win
, XEMBED_EMBEDDED_VERSION
);
592 /* FIXME not sure if I have to send these events, too */
593 sendevent(c
->win
, netatom
[Xembed
], StructureNotifyMask
, CurrentTime
, XEMBED_FOCUS_IN
, 0 , systray
->win
, XEMBED_EMBEDDED_VERSION
);
594 sendevent(c
->win
, netatom
[Xembed
], StructureNotifyMask
, CurrentTime
, XEMBED_WINDOW_ACTIVATE
, 0 , systray
->win
, XEMBED_EMBEDDED_VERSION
);
595 sendevent(c
->win
, netatom
[Xembed
], StructureNotifyMask
, CurrentTime
, XEMBED_MODALITY_ON
, 0 , systray
->win
, XEMBED_EMBEDDED_VERSION
);
597 resizebarwin(selmon
);
599 setclientstate(c
, NormalState
);
605 if (cme
->message_type
== netatom
[NetWMState
]) {
606 if (cme
->data
.l
[1] == netatom
[NetWMFullscreen
]
607 || cme
->data
.l
[2] == netatom
[NetWMFullscreen
])
608 setfullscreen(c
, (cme
->data
.l
[0] == 1 /* _NET_WM_STATE_ADD */
609 || (cme
->data
.l
[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c
->isfullscreen
)));
610 } else if (cme
->message_type
== netatom
[NetActiveWindow
]) {
611 if (c
!= selmon
->sel
&& !c
->isurgent
)
621 ce
.type
= ConfigureNotify
;
629 ce
.border_width
= c
->bw
;
631 ce
.override_redirect
= False
;
632 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
636 configurenotify(XEvent
*e
)
640 XConfigureEvent
*ev
= &e
->xconfigure
;
643 /* TODO: updategeom handling sucks, needs to be simplified */
644 if (ev
->window
== root
) {
645 dirty
= (sw
!= ev
->width
|| sh
!= ev
->height
);
648 if (updategeom() || dirty
) {
649 drw_resize(drw
, sw
, bh
);
651 for (m
= mons
; m
; m
= m
->next
) {
652 for (c
= m
->clients
; c
; c
= c
->next
)
654 resizeclient(c
, m
->mx
, m
->my
, m
->mw
, m
->mh
);
664 configurerequest(XEvent
*e
)
668 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
671 if ((c
= wintoclient(ev
->window
))) {
672 if (ev
->value_mask
& CWBorderWidth
)
673 c
->bw
= ev
->border_width
;
674 else if (c
->isfloating
|| !selmon
->lt
[selmon
->sellt
]->arrange
) {
676 if (ev
->value_mask
& CWX
) {
678 c
->x
= m
->mx
+ ev
->x
;
680 if (ev
->value_mask
& CWY
) {
682 c
->y
= m
->my
+ ev
->y
;
684 if (ev
->value_mask
& CWWidth
) {
688 if (ev
->value_mask
& CWHeight
) {
692 if ((c
->x
+ c
->w
) > m
->mx
+ m
->mw
&& c
->isfloating
)
693 c
->x
= m
->mx
+ (m
->mw
/ 2 - WIDTH(c
) / 2); /* center in x direction */
694 if ((c
->y
+ c
->h
) > m
->my
+ m
->mh
&& c
->isfloating
)
695 c
->y
= m
->my
+ (m
->mh
/ 2 - HEIGHT(c
) / 2); /* center in y direction */
696 if ((ev
->value_mask
& (CWX
|CWY
)) && !(ev
->value_mask
& (CWWidth
|CWHeight
)))
699 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
705 wc
.width
= ev
->width
;
706 wc
.height
= ev
->height
;
707 wc
.border_width
= ev
->border_width
;
708 wc
.sibling
= ev
->above
;
709 wc
.stack_mode
= ev
->detail
;
710 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
720 m
= ecalloc(1, sizeof(Monitor
));
721 m
->tagset
[0] = m
->tagset
[1] = 1;
723 m
->nmaster
= nmaster
;
724 m
->showbar
= showbar
;
726 m
->lt
[0] = &layouts
[0];
727 m
->lt
[1] = &layouts
[1 % LENGTH(layouts
)];
728 strncpy(m
->ltsymbol
, layouts
[0].symbol
, sizeof m
->ltsymbol
);
733 destroynotify(XEvent
*e
)
736 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
738 if ((c
= wintoclient(ev
->window
)))
740 else if ((c
= wintosystrayicon(ev
->window
))) {
741 removesystrayicon(c
);
742 resizebarwin(selmon
);
752 for (tc
= &c
->mon
->clients
; *tc
&& *tc
!= c
; tc
= &(*tc
)->next
);
757 detachstack(Client
*c
)
761 for (tc
= &c
->mon
->stack
; *tc
&& *tc
!= c
; tc
= &(*tc
)->snext
);
764 if (c
== c
->mon
->sel
) {
765 for (t
= c
->mon
->stack
; t
&& !ISVISIBLE(t
); t
= t
->snext
);
776 if (!(m
= selmon
->next
))
778 } else if (selmon
== mons
)
779 for (m
= mons
; m
->next
; m
= m
->next
);
781 for (m
= mons
; m
->next
!= selmon
; m
= m
->next
);
788 int x
, w
, sw
= 0, stw
= 0;
789 int boxs
= drw
->fonts
->h
/ 9;
790 int boxw
= drw
->fonts
->h
/ 6 + 2;
791 unsigned int i
, occ
= 0, urg
= 0;
794 if(showsystray
&& m
== systraytomon(m
))
795 stw
= getsystraywidth();
797 /* draw status first so it can be overdrawn by tags later */
798 if (m
== selmon
) { /* status is only drawn on selected monitor */
799 drw_setscheme(drw
, scheme
[SchemeNorm
]);
800 sw
= TEXTW(stext
) - lrpad
/ 2 + 2; /* 2px right padding */
801 drw_text(drw
, m
->ww
- sw
- stw
, 0, sw
, bh
, lrpad
/ 2 - 2, stext
, 0);
805 for (c
= m
->clients
; c
; c
= c
->next
) {
811 for (i
= 0; i
< LENGTH(tags
); i
++) {
813 drw_setscheme(drw
, scheme
[m
->tagset
[m
->seltags
] & 1 << i
? SchemeSel
: SchemeNorm
]);
814 drw_text(drw
, x
, 0, w
, bh
, lrpad
/ 2, tags
[i
], urg
& 1 << i
);
816 drw_rect(drw
, x
+ boxs
, boxs
, boxw
, boxw
,
817 m
== selmon
&& selmon
->sel
&& selmon
->sel
->tags
& 1 << i
,
821 w
= blw
= TEXTW(m
->ltsymbol
);
822 drw_setscheme(drw
, scheme
[SchemeNorm
]);
823 x
= drw_text(drw
, x
, 0, w
, bh
, lrpad
/ 2, m
->ltsymbol
, 0);
825 if ((w
= m
->ww
- sw
- stw
- x
) > bh
) {
827 drw_setscheme(drw
, scheme
[m
== selmon
? SchemeSel
: SchemeNorm
]);
828 drw_text(drw
, x
, 0, w
, bh
, lrpad
/ 2, m
->sel
->name
, 0);
829 if (m
->sel
->isfloating
)
830 drw_rect(drw
, x
+ boxs
, boxs
, boxw
, boxw
, m
->sel
->isfixed
, 0);
832 drw_setscheme(drw
, scheme
[SchemeNorm
]);
833 drw_rect(drw
, x
, 0, w
, bh
, 1, 1);
836 drw_map(drw
, m
->barwin
, 0, 0, m
->ww
- stw
, bh
);
844 for (m
= mons
; m
; m
= m
->next
)
849 enternotify(XEvent
*e
)
853 XCrossingEvent
*ev
= &e
->xcrossing
;
855 if ((ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
) && ev
->window
!= root
)
857 c
= wintoclient(ev
->window
);
858 m
= c
? c
->mon
: wintomon(ev
->window
);
860 unfocus(selmon
->sel
, 1);
862 } else if (!c
|| c
== selmon
->sel
)
871 XExposeEvent
*ev
= &e
->xexpose
;
873 if (ev
->count
== 0 && (m
= wintomon(ev
->window
))) {
883 if (!c
|| !ISVISIBLE(c
))
884 for (c
= selmon
->stack
; c
&& !ISVISIBLE(c
); c
= c
->snext
);
885 if (selmon
->sel
&& selmon
->sel
!= c
)
886 unfocus(selmon
->sel
, 0);
888 if (c
->mon
!= selmon
)
895 XSetWindowBorder(dpy
, c
->win
, scheme
[SchemeSel
][ColBorder
].pixel
);
898 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
899 XDeleteProperty(dpy
, root
, netatom
[NetActiveWindow
]);
905 /* there are some broken focus acquiring clients needing extra handling */
909 XFocusChangeEvent
*ev
= &e
->xfocus
;
911 if (selmon
->sel
&& ev
->window
!= selmon
->sel
->win
)
912 setfocus(selmon
->sel
);
916 focusmon(const Arg
*arg
)
922 if ((m
= dirtomon(arg
->i
)) == selmon
)
924 unfocus(selmon
->sel
, 0);
930 focusstack(const Arg
*arg
)
932 Client
*c
= NULL
, *i
;
937 for (c
= selmon
->sel
->next
; c
&& !ISVISIBLE(c
); c
= c
->next
);
939 for (c
= selmon
->clients
; c
&& !ISVISIBLE(c
); c
= c
->next
);
941 for (i
= selmon
->clients
; i
!= selmon
->sel
; i
= i
->next
)
945 for (; i
; i
= i
->next
)
956 getatomprop(Client
*c
, Atom prop
)
960 unsigned char *p
= NULL
;
961 Atom da
, atom
= None
;
962 /* FIXME getatomprop should return the number of items and a pointer to
963 * the stored data instead of this workaround */
965 if (prop
== xatom
[XembedInfo
])
966 req
= xatom
[XembedInfo
];
968 if (XGetWindowProperty(dpy
, c
->win
, prop
, 0L, sizeof atom
, False
, req
,
969 &da
, &di
, &dl
, &dl
, &p
) == Success
&& p
) {
971 if (da
== xatom
[XembedInfo
] && dl
== 2)
972 atom
= ((Atom
*)p
)[1];
979 getrootptr(int *x
, int *y
)
985 return XQueryPointer(dpy
, root
, &dummy
, &dummy
, x
, y
, &di
, &di
, &dui
);
993 unsigned char *p
= NULL
;
994 unsigned long n
, extra
;
997 if (XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
998 &real
, &format
, &n
, &extra
, (unsigned char **)&p
) != Success
)
1012 for(i
= systray
->icons
; i
; w
+= i
->w
+ systrayspacing
, i
= i
->next
) ;
1013 return w
? w
+ systrayspacing
: 1;
1017 gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
)
1023 if (!text
|| size
== 0)
1026 if (!XGetTextProperty(dpy
, w
, &name
, atom
) || !name
.nitems
)
1028 if (name
.encoding
== XA_STRING
)
1029 strncpy(text
, (char *)name
.value
, size
- 1);
1031 if (XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
&& n
> 0 && *list
) {
1032 strncpy(text
, *list
, size
- 1);
1033 XFreeStringList(list
);
1036 text
[size
- 1] = '\0';
1042 grabbuttons(Client
*c
, int focused
)
1044 updatenumlockmask();
1047 unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
1048 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1050 XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
,
1051 BUTTONMASK
, GrabModeSync
, GrabModeSync
, None
, None
);
1052 for (i
= 0; i
< LENGTH(buttons
); i
++)
1053 if (buttons
[i
].click
== ClkClientWin
)
1054 for (j
= 0; j
< LENGTH(modifiers
); j
++)
1055 XGrabButton(dpy
, buttons
[i
].button
,
1056 buttons
[i
].mask
| modifiers
[j
],
1057 c
->win
, False
, BUTTONMASK
,
1058 GrabModeAsync
, GrabModeSync
, None
, None
);
1065 updatenumlockmask();
1068 unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
1071 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
1072 for (i
= 0; i
< LENGTH(keys
); i
++)
1073 if ((code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
)))
1074 for (j
= 0; j
< LENGTH(modifiers
); j
++)
1075 XGrabKey(dpy
, code
, keys
[i
].mod
| modifiers
[j
], root
,
1076 True
, GrabModeAsync
, GrabModeAsync
);
1081 incnmaster(const Arg
*arg
)
1083 selmon
->nmaster
= MAX(selmon
->nmaster
+ arg
->i
, 0);
1089 isuniquegeom(XineramaScreenInfo
*unique
, size_t n
, XineramaScreenInfo
*info
)
1092 if (unique
[n
].x_org
== info
->x_org
&& unique
[n
].y_org
== info
->y_org
1093 && unique
[n
].width
== info
->width
&& unique
[n
].height
== info
->height
)
1097 #endif /* XINERAMA */
1107 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
1108 for (i
= 0; i
< LENGTH(keys
); i
++)
1109 if (keysym
== keys
[i
].keysym
1110 && CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
)
1112 keys
[i
].func(&(keys
[i
].arg
));
1116 killclient(const Arg
*arg
)
1120 if (!sendevent(selmon
->sel
->win
, wmatom
[WMDelete
], NoEventMask
, wmatom
[WMDelete
], CurrentTime
, 0 , 0, 0)) {
1122 XSetErrorHandler(xerrordummy
);
1123 XSetCloseDownMode(dpy
, DestroyAll
);
1124 XKillClient(dpy
, selmon
->sel
->win
);
1126 XSetErrorHandler(xerror
);
1132 manage(Window w
, XWindowAttributes
*wa
)
1134 Client
*c
, *t
= NULL
;
1135 Window trans
= None
;
1138 c
= ecalloc(1, sizeof(Client
));
1141 c
->x
= c
->oldx
= wa
->x
;
1142 c
->y
= c
->oldy
= wa
->y
;
1143 c
->w
= c
->oldw
= wa
->width
;
1144 c
->h
= c
->oldh
= wa
->height
;
1145 c
->oldbw
= wa
->border_width
;
1148 if (XGetTransientForHint(dpy
, w
, &trans
) && (t
= wintoclient(trans
))) {
1156 if (c
->x
+ WIDTH(c
) > c
->mon
->mx
+ c
->mon
->mw
)
1157 c
->x
= c
->mon
->mx
+ c
->mon
->mw
- WIDTH(c
);
1158 if (c
->y
+ HEIGHT(c
) > c
->mon
->my
+ c
->mon
->mh
)
1159 c
->y
= c
->mon
->my
+ c
->mon
->mh
- HEIGHT(c
);
1160 c
->x
= MAX(c
->x
, c
->mon
->mx
);
1161 /* only fix client y-offset, if the client center might cover the bar */
1162 c
->y
= MAX(c
->y
, ((c
->mon
->by
== c
->mon
->my
) && (c
->x
+ (c
->w
/ 2) >= c
->mon
->wx
)
1163 && (c
->x
+ (c
->w
/ 2) < c
->mon
->wx
+ c
->mon
->ww
)) ? bh
: c
->mon
->my
);
1166 wc
.border_width
= c
->bw
;
1167 XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
1168 XSetWindowBorder(dpy
, w
, scheme
[SchemeNorm
][ColBorder
].pixel
);
1169 configure(c
); /* propagates border_width, if size doesn't change */
1170 updatewindowtype(c
);
1177 XSelectInput(dpy
, w
, EnterWindowMask
|FocusChangeMask
|PropertyChangeMask
|StructureNotifyMask
);
1180 c
->isfloating
= c
->oldstate
= trans
!= None
|| c
->isfixed
;
1182 XRaiseWindow(dpy
, c
->win
);
1185 XChangeProperty(dpy
, root
, netatom
[NetClientList
], XA_WINDOW
, 32, PropModeAppend
,
1186 (unsigned char *) &(c
->win
), 1);
1187 XMoveResizeWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
, c
->w
, c
->h
); /* some windows require this */
1188 setclientstate(c
, NormalState
);
1189 if (c
->mon
== selmon
)
1190 unfocus(selmon
->sel
, 0);
1193 XMapWindow(dpy
, c
->win
);
1198 mappingnotify(XEvent
*e
)
1200 XMappingEvent
*ev
= &e
->xmapping
;
1202 XRefreshKeyboardMapping(ev
);
1203 if (ev
->request
== MappingKeyboard
)
1208 maprequest(XEvent
*e
)
1210 static XWindowAttributes wa
;
1211 XMapRequestEvent
*ev
= &e
->xmaprequest
;
1213 if ((i
= wintosystrayicon(ev
->window
))) {
1214 sendevent(i
->win
, netatom
[Xembed
], StructureNotifyMask
, CurrentTime
, XEMBED_WINDOW_ACTIVATE
, 0, systray
->win
, XEMBED_EMBEDDED_VERSION
);
1215 resizebarwin(selmon
);
1219 if (!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
1221 if (wa
.override_redirect
)
1223 if (!wintoclient(ev
->window
))
1224 manage(ev
->window
, &wa
);
1233 for (c
= m
->clients
; c
; c
= c
->next
)
1236 if (n
> 0) /* override layout symbol */
1237 snprintf(m
->ltsymbol
, sizeof m
->ltsymbol
, "[%d]", n
);
1238 for (c
= nexttiled(m
->clients
); c
; c
= nexttiled(c
->next
))
1239 resize(c
, m
->wx
, m
->wy
, m
->ww
- 2 * c
->bw
, m
->wh
- 2 * c
->bw
, 0);
1243 motionnotify(XEvent
*e
)
1245 static Monitor
*mon
= NULL
;
1247 XMotionEvent
*ev
= &e
->xmotion
;
1249 if (ev
->window
!= root
)
1251 if ((m
= recttomon(ev
->x_root
, ev
->y_root
, 1, 1)) != mon
&& mon
) {
1252 unfocus(selmon
->sel
, 1);
1260 movemouse(const Arg
*arg
)
1262 int x
, y
, ocx
, ocy
, nx
, ny
;
1268 if (!(c
= selmon
->sel
))
1270 if (c
->isfullscreen
) /* no support moving fullscreen windows by mouse */
1275 if (XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1276 None
, cursor
[CurMove
]->cursor
, CurrentTime
) != GrabSuccess
)
1278 if (!getrootptr(&x
, &y
))
1281 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1283 case ConfigureRequest
:
1286 handler
[ev
.type
](&ev
);
1289 if ((ev
.xmotion
.time
- lasttime
) <= (1000 / 60))
1291 lasttime
= ev
.xmotion
.time
;
1293 nx
= ocx
+ (ev
.xmotion
.x
- x
);
1294 ny
= ocy
+ (ev
.xmotion
.y
- y
);
1295 if (abs(selmon
->wx
- nx
) < snap
)
1297 else if (abs((selmon
->wx
+ selmon
->ww
) - (nx
+ WIDTH(c
))) < snap
)
1298 nx
= selmon
->wx
+ selmon
->ww
- WIDTH(c
);
1299 if (abs(selmon
->wy
- ny
) < snap
)
1301 else if (abs((selmon
->wy
+ selmon
->wh
) - (ny
+ HEIGHT(c
))) < snap
)
1302 ny
= selmon
->wy
+ selmon
->wh
- HEIGHT(c
);
1303 if (!c
->isfloating
&& selmon
->lt
[selmon
->sellt
]->arrange
1304 && (abs(nx
- c
->x
) > snap
|| abs(ny
- c
->y
) > snap
))
1305 togglefloating(NULL
);
1306 if (!selmon
->lt
[selmon
->sellt
]->arrange
|| c
->isfloating
)
1307 resize(c
, nx
, ny
, c
->w
, c
->h
, 1);
1310 } while (ev
.type
!= ButtonRelease
);
1311 XUngrabPointer(dpy
, CurrentTime
);
1312 if ((m
= recttomon(c
->x
, c
->y
, c
->w
, c
->h
)) != selmon
) {
1320 nexttiled(Client
*c
)
1322 for (; c
&& (c
->isfloating
|| !ISVISIBLE(c
)); c
= c
->next
);
1336 propertynotify(XEvent
*e
)
1340 XPropertyEvent
*ev
= &e
->xproperty
;
1342 if ((c
= wintosystrayicon(ev
->window
))) {
1343 if (ev
->atom
== XA_WM_NORMAL_HINTS
) {
1345 updatesystrayicongeom(c
, c
->w
, c
->h
);
1348 updatesystrayiconstate(c
, ev
);
1349 resizebarwin(selmon
);
1352 if ((ev
->window
== root
) && (ev
->atom
== XA_WM_NAME
))
1354 else if (ev
->state
== PropertyDelete
)
1355 return; /* ignore */
1356 else if ((c
= wintoclient(ev
->window
))) {
1359 case XA_WM_TRANSIENT_FOR
:
1360 if (!c
->isfloating
&& (XGetTransientForHint(dpy
, c
->win
, &trans
)) &&
1361 (c
->isfloating
= (wintoclient(trans
)) != NULL
))
1364 case XA_WM_NORMAL_HINTS
:
1372 if (ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
1374 if (c
== c
->mon
->sel
)
1377 if (ev
->atom
== netatom
[NetWMWindowType
])
1378 updatewindowtype(c
);
1383 quit(const Arg
*arg
)
1389 recttomon(int x
, int y
, int w
, int h
)
1391 Monitor
*m
, *r
= selmon
;
1394 for (m
= mons
; m
; m
= m
->next
)
1395 if ((a
= INTERSECT(x
, y
, w
, h
, m
)) > area
) {
1403 removesystrayicon(Client
*i
)
1407 if (!showsystray
|| !i
)
1409 for (ii
= &systray
->icons
; *ii
&& *ii
!= i
; ii
= &(*ii
)->next
);
1417 resize(Client
*c
, int x
, int y
, int w
, int h
, int interact
)
1419 if (applysizehints(c
, &x
, &y
, &w
, &h
, interact
))
1420 resizeclient(c
, x
, y
, w
, h
);
1424 resizebarwin(Monitor
*m
) {
1425 unsigned int w
= m
->ww
;
1426 if (showsystray
&& m
== systraytomon(m
))
1427 w
-= getsystraywidth();
1428 XMoveResizeWindow(dpy
, m
->barwin
, m
->wx
, m
->by
, w
, bh
);
1432 resizeclient(Client
*c
, int x
, int y
, int w
, int h
)
1436 c
->oldx
= c
->x
; c
->x
= wc
.x
= x
;
1437 c
->oldy
= c
->y
; c
->y
= wc
.y
= y
;
1438 c
->oldw
= c
->w
; c
->w
= wc
.width
= w
;
1439 c
->oldh
= c
->h
; c
->h
= wc
.height
= h
;
1440 wc
.border_width
= c
->bw
;
1441 XConfigureWindow(dpy
, c
->win
, CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
, &wc
);
1447 resizemouse(const Arg
*arg
)
1449 int ocx
, ocy
, nw
, nh
;
1455 if (!(c
= selmon
->sel
))
1457 if (c
->isfullscreen
) /* no support resizing fullscreen windows by mouse */
1462 if (XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
1463 None
, cursor
[CurResize
]->cursor
, CurrentTime
) != GrabSuccess
)
1465 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1467 XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
1469 case ConfigureRequest
:
1472 handler
[ev
.type
](&ev
);
1475 if ((ev
.xmotion
.time
- lasttime
) <= (1000 / 60))
1477 lasttime
= ev
.xmotion
.time
;
1479 nw
= MAX(ev
.xmotion
.x
- ocx
- 2 * c
->bw
+ 1, 1);
1480 nh
= MAX(ev
.xmotion
.y
- ocy
- 2 * c
->bw
+ 1, 1);
1481 if (c
->mon
->wx
+ nw
>= selmon
->wx
&& c
->mon
->wx
+ nw
<= selmon
->wx
+ selmon
->ww
1482 && c
->mon
->wy
+ nh
>= selmon
->wy
&& c
->mon
->wy
+ nh
<= selmon
->wy
+ selmon
->wh
)
1484 if (!c
->isfloating
&& selmon
->lt
[selmon
->sellt
]->arrange
1485 && (abs(nw
- c
->w
) > snap
|| abs(nh
- c
->h
) > snap
))
1486 togglefloating(NULL
);
1488 if (!selmon
->lt
[selmon
->sellt
]->arrange
|| c
->isfloating
)
1489 resize(c
, c
->x
, c
->y
, nw
, nh
, 1);
1492 } while (ev
.type
!= ButtonRelease
);
1493 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
1494 XUngrabPointer(dpy
, CurrentTime
);
1495 while (XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1496 if ((m
= recttomon(c
->x
, c
->y
, c
->w
, c
->h
)) != selmon
) {
1504 resizerequest(XEvent
*e
)
1506 XResizeRequestEvent
*ev
= &e
->xresizerequest
;
1509 if ((i
= wintosystrayicon(ev
->window
))) {
1510 updatesystrayicongeom(i
, ev
->width
, ev
->height
);
1511 resizebarwin(selmon
);
1526 if (m
->sel
->isfloating
|| !m
->lt
[m
->sellt
]->arrange
)
1527 XRaiseWindow(dpy
, m
->sel
->win
);
1528 if (m
->lt
[m
->sellt
]->arrange
) {
1529 wc
.stack_mode
= Below
;
1530 wc
.sibling
= m
->barwin
;
1531 for (c
= m
->stack
; c
; c
= c
->snext
)
1532 if (!c
->isfloating
&& ISVISIBLE(c
)) {
1533 XConfigureWindow(dpy
, c
->win
, CWSibling
|CWStackMode
, &wc
);
1534 wc
.sibling
= c
->win
;
1538 while (XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
1545 /* main event loop */
1547 while (running
&& !XNextEvent(dpy
, &ev
))
1548 if (handler
[ev
.type
])
1549 handler
[ev
.type
](&ev
); /* call handler */
1555 unsigned int i
, num
;
1556 Window d1
, d2
, *wins
= NULL
;
1557 XWindowAttributes wa
;
1559 if (XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
1560 for (i
= 0; i
< num
; i
++) {
1561 if (!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
1562 || wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
1564 if (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
1565 manage(wins
[i
], &wa
);
1567 for (i
= 0; i
< num
; i
++) { /* now the transients */
1568 if (!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
1570 if (XGetTransientForHint(dpy
, wins
[i
], &d1
)
1571 && (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
1572 manage(wins
[i
], &wa
);
1580 sendmon(Client
*c
, Monitor
*m
)
1588 c
->tags
= m
->tagset
[m
->seltags
]; /* assign tags of target monitor */
1596 setclientstate(Client
*c
, long state
)
1598 long data
[] = { state
, None
};
1600 XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
1601 PropModeReplace
, (unsigned char *)data
, 2);
1605 sendevent(Window w
, Atom proto
, int mask
, long d0
, long d1
, long d2
, long d3
, long d4
)
1608 Atom
*protocols
, mt
;
1612 if (proto
== wmatom
[WMTakeFocus
] || proto
== wmatom
[WMDelete
]) {
1613 mt
= wmatom
[WMProtocols
];
1614 if (XGetWMProtocols(dpy
, w
, &protocols
, &n
)) {
1615 while (!exists
&& n
--)
1616 exists
= protocols
[n
] == proto
;
1625 ev
.type
= ClientMessage
;
1626 ev
.xclient
.window
= w
;
1627 ev
.xclient
.message_type
= mt
;
1628 ev
.xclient
.format
= 32;
1629 ev
.xclient
.data
.l
[0] = d0
;
1630 ev
.xclient
.data
.l
[1] = d1
;
1631 ev
.xclient
.data
.l
[2] = d2
;
1632 ev
.xclient
.data
.l
[3] = d3
;
1633 ev
.xclient
.data
.l
[4] = d4
;
1634 XSendEvent(dpy
, w
, False
, mask
, &ev
);
1642 if (!c
->neverfocus
) {
1643 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
1644 XChangeProperty(dpy
, root
, netatom
[NetActiveWindow
],
1645 XA_WINDOW
, 32, PropModeReplace
,
1646 (unsigned char *) &(c
->win
), 1);
1648 sendevent(c
->win
, wmatom
[WMTakeFocus
], NoEventMask
, wmatom
[WMTakeFocus
], CurrentTime
, 0, 0, 0);
1652 setfullscreen(Client
*c
, int fullscreen
)
1654 if (fullscreen
&& !c
->isfullscreen
) {
1655 XChangeProperty(dpy
, c
->win
, netatom
[NetWMState
], XA_ATOM
, 32,
1656 PropModeReplace
, (unsigned char*)&netatom
[NetWMFullscreen
], 1);
1657 c
->isfullscreen
= 1;
1658 c
->oldstate
= c
->isfloating
;
1662 resizeclient(c
, c
->mon
->mx
, c
->mon
->my
, c
->mon
->mw
, c
->mon
->mh
);
1663 XRaiseWindow(dpy
, c
->win
);
1664 } else if (!fullscreen
&& c
->isfullscreen
){
1665 XChangeProperty(dpy
, c
->win
, netatom
[NetWMState
], XA_ATOM
, 32,
1666 PropModeReplace
, (unsigned char*)0, 0);
1667 c
->isfullscreen
= 0;
1668 c
->isfloating
= c
->oldstate
;
1674 resizeclient(c
, c
->x
, c
->y
, c
->w
, c
->h
);
1680 setlayout(const Arg
*arg
)
1682 if (!arg
|| !arg
->v
|| arg
->v
!= selmon
->lt
[selmon
->sellt
])
1685 selmon
->lt
[selmon
->sellt
] = (Layout
*)arg
->v
;
1686 strncpy(selmon
->ltsymbol
, selmon
->lt
[selmon
->sellt
]->symbol
, sizeof selmon
->ltsymbol
);
1693 /* arg > 1.0 will set mfact absolutely */
1695 setmfact(const Arg
*arg
)
1699 if (!arg
|| !selmon
->lt
[selmon
->sellt
]->arrange
)
1701 f
= arg
->f
< 1.0 ? arg
->f
+ selmon
->mfact
: arg
->f
- 1.0;
1702 if (f
< 0.1 || f
> 0.9)
1712 XSetWindowAttributes wa
;
1715 /* clean up any zombies immediately */
1719 screen
= DefaultScreen(dpy
);
1720 sw
= DisplayWidth(dpy
, screen
);
1721 sh
= DisplayHeight(dpy
, screen
);
1722 root
= RootWindow(dpy
, screen
);
1723 drw
= drw_create(dpy
, screen
, root
, sw
, sh
);
1724 if (!drw_fontset_create(drw
, fonts
, LENGTH(fonts
)))
1725 die("no fonts could be loaded.");
1726 lrpad
= drw
->fonts
->h
;
1727 bh
= drw
->fonts
->h
+ 2;
1730 utf8string
= XInternAtom(dpy
, "UTF8_STRING", False
);
1731 wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
1732 wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
1733 wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
1734 wmatom
[WMTakeFocus
] = XInternAtom(dpy
, "WM_TAKE_FOCUS", False
);
1735 netatom
[NetActiveWindow
] = XInternAtom(dpy
, "_NET_ACTIVE_WINDOW", False
);
1736 netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
1737 netatom
[NetSystemTray
] = XInternAtom(dpy
, "_NET_SYSTEM_TRAY_S0", False
);
1738 netatom
[NetSystemTrayOP
] = XInternAtom(dpy
, "_NET_SYSTEM_TRAY_OPCODE", False
);
1739 netatom
[NetSystemTrayOrientation
] = XInternAtom(dpy
, "_NET_SYSTEM_TRAY_ORIENTATION", False
);
1740 netatom
[NetSystemTrayOrientationHorz
] = XInternAtom(dpy
, "_NET_SYSTEM_TRAY_ORIENTATION_HORZ", False
);
1741 netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
1742 netatom
[NetWMState
] = XInternAtom(dpy
, "_NET_WM_STATE", False
);
1743 netatom
[NetWMCheck
] = XInternAtom(dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
1744 netatom
[NetWMFullscreen
] = XInternAtom(dpy
, "_NET_WM_STATE_FULLSCREEN", False
);
1745 netatom
[NetWMWindowType
] = XInternAtom(dpy
, "_NET_WM_WINDOW_TYPE", False
);
1746 netatom
[NetWMWindowTypeDialog
] = XInternAtom(dpy
, "_NET_WM_WINDOW_TYPE_DIALOG", False
);
1747 netatom
[NetClientList
] = XInternAtom(dpy
, "_NET_CLIENT_LIST", False
);
1748 xatom
[Manager
] = XInternAtom(dpy
, "MANAGER", False
);
1749 xatom
[Xembed
] = XInternAtom(dpy
, "_XEMBED", False
);
1750 xatom
[XembedInfo
] = XInternAtom(dpy
, "_XEMBED_INFO", False
);
1752 cursor
[CurNormal
] = drw_cur_create(drw
, XC_left_ptr
);
1753 cursor
[CurResize
] = drw_cur_create(drw
, XC_sizing
);
1754 cursor
[CurMove
] = drw_cur_create(drw
, XC_fleur
);
1755 /* init appearance */
1756 scheme
= ecalloc(LENGTH(colors
), sizeof(Clr
*));
1757 for (i
= 0; i
< LENGTH(colors
); i
++)
1758 scheme
[i
] = drw_scm_create(drw
, colors
[i
], 3);
1759 /* init system tray */
1764 /* supporting window for NetWMCheck */
1765 wmcheckwin
= XCreateSimpleWindow(dpy
, root
, 0, 0, 1, 1, 0, 0, 0);
1766 XChangeProperty(dpy
, wmcheckwin
, netatom
[NetWMCheck
], XA_WINDOW
, 32,
1767 PropModeReplace
, (unsigned char *) &wmcheckwin
, 1);
1768 XChangeProperty(dpy
, wmcheckwin
, netatom
[NetWMName
], utf8string
, 8,
1769 PropModeReplace
, (unsigned char *) "dwm", 3);
1770 XChangeProperty(dpy
, root
, netatom
[NetWMCheck
], XA_WINDOW
, 32,
1771 PropModeReplace
, (unsigned char *) &wmcheckwin
, 1);
1772 /* EWMH support per view */
1773 XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
1774 PropModeReplace
, (unsigned char *) netatom
, NetLast
);
1775 XDeleteProperty(dpy
, root
, netatom
[NetClientList
]);
1777 wa
.cursor
= cursor
[CurNormal
]->cursor
;
1778 wa
.event_mask
= SubstructureRedirectMask
|SubstructureNotifyMask
1779 |ButtonPressMask
|PointerMotionMask
|EnterWindowMask
1780 |LeaveWindowMask
|StructureNotifyMask
|PropertyChangeMask
;
1781 XChangeWindowAttributes(dpy
, root
, CWEventMask
|CWCursor
, &wa
);
1782 XSelectInput(dpy
, root
, wa
.event_mask
);
1789 seturgent(Client
*c
, int urg
)
1794 if (!(wmh
= XGetWMHints(dpy
, c
->win
)))
1796 wmh
->flags
= urg
? (wmh
->flags
| XUrgencyHint
) : (wmh
->flags
& ~XUrgencyHint
);
1797 XSetWMHints(dpy
, c
->win
, wmh
);
1807 /* show clients top down */
1808 XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
1809 if ((!c
->mon
->lt
[c
->mon
->sellt
]->arrange
|| c
->isfloating
) && !c
->isfullscreen
)
1810 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, 0);
1813 /* hide clients bottom up */
1815 XMoveWindow(dpy
, c
->win
, WIDTH(c
) * -2, c
->y
);
1822 if (signal(SIGCHLD
, sigchld
) == SIG_ERR
)
1823 die("can't install SIGCHLD handler:");
1824 while (0 < waitpid(-1, NULL
, WNOHANG
));
1828 spawn(const Arg
*arg
)
1830 if (arg
->v
== dmenucmd
)
1831 dmenumon
[0] = '0' + selmon
->num
;
1834 close(ConnectionNumber(dpy
));
1836 execvp(((char **)arg
->v
)[0], (char **)arg
->v
);
1837 fprintf(stderr
, "dwm: execvp %s", ((char **)arg
->v
)[0]);
1846 if (selmon
->sel
&& arg
->ui
& TAGMASK
) {
1847 selmon
->sel
->tags
= arg
->ui
& TAGMASK
;
1854 tagmon(const Arg
*arg
)
1856 if (!selmon
->sel
|| !mons
->next
)
1858 sendmon(selmon
->sel
, dirtomon(arg
->i
));
1864 unsigned int i
, n
, h
, mw
, my
, ty
;
1867 for (n
= 0, c
= nexttiled(m
->clients
); c
; c
= nexttiled(c
->next
), n
++);
1872 mw
= m
->nmaster
? m
->ww
* m
->mfact
: 0;
1875 for (i
= my
= ty
= 0, c
= nexttiled(m
->clients
); c
; c
= nexttiled(c
->next
), i
++)
1876 if (i
< m
->nmaster
) {
1877 h
= (m
->wh
- my
) / (MIN(n
, m
->nmaster
) - i
);
1878 resize(c
, m
->wx
, m
->wy
+ my
, mw
- (2*c
->bw
), h
- (2*c
->bw
), 0);
1881 h
= (m
->wh
- ty
) / (n
- i
);
1882 resize(c
, m
->wx
+ mw
, m
->wy
+ ty
, m
->ww
- mw
- (2*c
->bw
), h
- (2*c
->bw
), 0);
1888 togglebar(const Arg
*arg
)
1890 selmon
->showbar
= !selmon
->showbar
;
1891 updatebarpos(selmon
);
1892 resizebarwin(selmon
);
1895 if (!selmon
->showbar
)
1897 else if (selmon
->showbar
) {
1899 if (!selmon
->topbar
)
1900 wc
.y
= selmon
->mh
- bh
;
1902 XConfigureWindow(dpy
, systray
->win
, CWY
, &wc
);
1908 togglefloating(const Arg
*arg
)
1912 if (selmon
->sel
->isfullscreen
) /* no support for fullscreen windows */
1914 selmon
->sel
->isfloating
= !selmon
->sel
->isfloating
|| selmon
->sel
->isfixed
;
1915 if (selmon
->sel
->isfloating
)
1916 /* restore last known float dimensions */
1917 resize(selmon
->sel
, selmon
->sel
->sfx
, selmon
->sel
->sfy
,
1918 selmon
->sel
->sfw
, selmon
->sel
->sfh
, False
);
1920 /* save last known float dimensions */
1921 selmon
->sel
->sfx
= selmon
->sel
->x
;
1922 selmon
->sel
->sfy
= selmon
->sel
->y
;
1923 selmon
->sel
->sfw
= selmon
->sel
->w
;
1924 selmon
->sel
->sfh
= selmon
->sel
->h
;
1930 toggletag(const Arg
*arg
)
1932 unsigned int newtags
;
1936 newtags
= selmon
->sel
->tags
^ (arg
->ui
& TAGMASK
);
1938 selmon
->sel
->tags
= newtags
;
1945 toggleview(const Arg
*arg
)
1947 unsigned int newtagset
= selmon
->tagset
[selmon
->seltags
] ^ (arg
->ui
& TAGMASK
);
1950 selmon
->tagset
[selmon
->seltags
] = newtagset
;
1957 unfocus(Client
*c
, int setfocus
)
1962 XSetWindowBorder(dpy
, c
->win
, scheme
[SchemeNorm
][ColBorder
].pixel
);
1964 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
1965 XDeleteProperty(dpy
, root
, netatom
[NetActiveWindow
]);
1970 unmanage(Client
*c
, int destroyed
)
1972 Monitor
*m
= c
->mon
;
1978 wc
.border_width
= c
->oldbw
;
1979 XGrabServer(dpy
); /* avoid race conditions */
1980 XSetErrorHandler(xerrordummy
);
1981 XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
1982 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
1983 setclientstate(c
, WithdrawnState
);
1985 XSetErrorHandler(xerror
);
1995 unmapnotify(XEvent
*e
)
1998 XUnmapEvent
*ev
= &e
->xunmap
;
2000 if ((c
= wintoclient(ev
->window
))) {
2002 setclientstate(c
, WithdrawnState
);
2006 else if ((c
= wintosystrayicon(ev
->window
))) {
2007 /* KLUDGE! sometimes icons occasionally unmap their windows, but do
2008 * _not_ destroy them. We map those windows back */
2009 XMapRaised(dpy
, c
->win
);
2019 XSetWindowAttributes wa
= {
2020 .override_redirect
= True
,
2021 .background_pixmap
= ParentRelative
,
2022 .event_mask
= ButtonPressMask
|ExposureMask
2024 XClassHint ch
= {"dwm", "dwm"};
2025 for (m
= mons
; m
; m
= m
->next
) {
2029 if (showsystray
&& m
== systraytomon(m
))
2030 w
-= getsystraywidth();
2031 m
->barwin
= XCreateWindow(dpy
, root
, m
->wx
, m
->by
, w
, bh
, 0, DefaultDepth(dpy
, screen
),
2032 CopyFromParent
, DefaultVisual(dpy
, screen
),
2033 CWOverrideRedirect
|CWBackPixmap
|CWEventMask
, &wa
);
2034 XDefineCursor(dpy
, m
->barwin
, cursor
[CurNormal
]->cursor
);
2035 if (showsystray
&& m
== systraytomon(m
))
2036 XMapRaised(dpy
, systray
->win
);
2037 XMapRaised(dpy
, m
->barwin
);
2038 XSetClassHint(dpy
, m
->barwin
, &ch
);
2043 updatebarpos(Monitor
*m
)
2049 m
->by
= m
->topbar
? m
->wy
: m
->wy
+ m
->wh
;
2050 m
->wy
= m
->topbar
? m
->wy
+ bh
: m
->wy
;
2061 XDeleteProperty(dpy
, root
, netatom
[NetClientList
]);
2062 for (m
= mons
; m
; m
= m
->next
)
2063 for (c
= m
->clients
; c
; c
= c
->next
)
2064 XChangeProperty(dpy
, root
, netatom
[NetClientList
],
2065 XA_WINDOW
, 32, PropModeAppend
,
2066 (unsigned char *) &(c
->win
), 1);
2075 if (XineramaIsActive(dpy
)) {
2079 XineramaScreenInfo
*info
= XineramaQueryScreens(dpy
, &nn
);
2080 XineramaScreenInfo
*unique
= NULL
;
2082 for (n
= 0, m
= mons
; m
; m
= m
->next
, n
++);
2083 /* only consider unique geometries as separate screens */
2084 unique
= ecalloc(nn
, sizeof(XineramaScreenInfo
));
2085 for (i
= 0, j
= 0; i
< nn
; i
++)
2086 if (isuniquegeom(unique
, j
, &info
[i
]))
2087 memcpy(&unique
[j
++], &info
[i
], sizeof(XineramaScreenInfo
));
2090 if (n
<= nn
) { /* new monitors available */
2091 for (i
= 0; i
< (nn
- n
); i
++) {
2092 for (m
= mons
; m
&& m
->next
; m
= m
->next
);
2094 m
->next
= createmon();
2098 for (i
= 0, m
= mons
; i
< nn
&& m
; m
= m
->next
, i
++)
2100 || unique
[i
].x_org
!= m
->mx
|| unique
[i
].y_org
!= m
->my
2101 || unique
[i
].width
!= m
->mw
|| unique
[i
].height
!= m
->mh
)
2105 m
->mx
= m
->wx
= unique
[i
].x_org
;
2106 m
->my
= m
->wy
= unique
[i
].y_org
;
2107 m
->mw
= m
->ww
= unique
[i
].width
;
2108 m
->mh
= m
->wh
= unique
[i
].height
;
2111 } else { /* less monitors available nn < n */
2112 for (i
= nn
; i
< n
; i
++) {
2113 for (m
= mons
; m
&& m
->next
; m
= m
->next
);
2114 while ((c
= m
->clients
)) {
2116 m
->clients
= c
->next
;
2129 #endif /* XINERAMA */
2130 { /* default monitor setup */
2133 if (mons
->mw
!= sw
|| mons
->mh
!= sh
) {
2135 mons
->mw
= mons
->ww
= sw
;
2136 mons
->mh
= mons
->wh
= sh
;
2142 selmon
= wintomon(root
);
2148 updatenumlockmask(void)
2151 XModifierKeymap
*modmap
;
2154 modmap
= XGetModifierMapping(dpy
);
2155 for (i
= 0; i
< 8; i
++)
2156 for (j
= 0; j
< modmap
->max_keypermod
; j
++)
2157 if (modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
]
2158 == XKeysymToKeycode(dpy
, XK_Num_Lock
))
2159 numlockmask
= (1 << i
);
2160 XFreeModifiermap(modmap
);
2164 updatesizehints(Client
*c
)
2169 if (!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
))
2170 /* size is uninitialized, ensure that size.flags aren't used */
2172 if (size
.flags
& PBaseSize
) {
2173 c
->basew
= size
.base_width
;
2174 c
->baseh
= size
.base_height
;
2175 } else if (size
.flags
& PMinSize
) {
2176 c
->basew
= size
.min_width
;
2177 c
->baseh
= size
.min_height
;
2179 c
->basew
= c
->baseh
= 0;
2180 if (size
.flags
& PResizeInc
) {
2181 c
->incw
= size
.width_inc
;
2182 c
->inch
= size
.height_inc
;
2184 c
->incw
= c
->inch
= 0;
2185 if (size
.flags
& PMaxSize
) {
2186 c
->maxw
= size
.max_width
;
2187 c
->maxh
= size
.max_height
;
2189 c
->maxw
= c
->maxh
= 0;
2190 if (size
.flags
& PMinSize
) {
2191 c
->minw
= size
.min_width
;
2192 c
->minh
= size
.min_height
;
2193 } else if (size
.flags
& PBaseSize
) {
2194 c
->minw
= size
.base_width
;
2195 c
->minh
= size
.base_height
;
2197 c
->minw
= c
->minh
= 0;
2198 if (size
.flags
& PAspect
) {
2199 c
->mina
= (float)size
.min_aspect
.y
/ size
.min_aspect
.x
;
2200 c
->maxa
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
2202 c
->maxa
= c
->mina
= 0.0;
2203 c
->isfixed
= (c
->maxw
&& c
->maxh
&& c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
2209 if (!gettextprop(root
, XA_WM_NAME
, stext
, sizeof(stext
)))
2210 strcpy(stext
, "dwm-"VERSION
);
2216 updatesystrayicongeom(Client
*i
, int w
, int h
)
2225 i
->w
= (int) ((float)bh
* ((float)w
/ (float)h
));
2226 applysizehints(i
, &(i
->x
), &(i
->y
), &(i
->w
), &(i
->h
), False
);
2227 /* force icons into the systray dimenons if they don't want to */
2232 i
->w
= (int) ((float)bh
* ((float)i
->w
/ (float)i
->h
));
2239 updatesystrayiconstate(Client
*i
, XPropertyEvent
*ev
)
2244 if (!showsystray
|| !i
|| ev
->atom
!= xatom
[XembedInfo
] ||
2245 !(flags
= getatomprop(i
, xatom
[XembedInfo
])))
2248 if (flags
& XEMBED_MAPPED
&& !i
->tags
) {
2250 code
= XEMBED_WINDOW_ACTIVATE
;
2251 XMapRaised(dpy
, i
->win
);
2252 setclientstate(i
, NormalState
);
2254 else if (!(flags
& XEMBED_MAPPED
) && i
->tags
) {
2256 code
= XEMBED_WINDOW_DEACTIVATE
;
2257 XUnmapWindow(dpy
, i
->win
);
2258 setclientstate(i
, WithdrawnState
);
2262 sendevent(i
->win
, xatom
[Xembed
], StructureNotifyMask
, CurrentTime
, code
, 0,
2263 systray
->win
, XEMBED_EMBEDDED_VERSION
);
2269 XSetWindowAttributes wa
;
2272 Monitor
*m
= systraytomon(NULL
);
2273 unsigned int x
= m
->mx
+ m
->mw
;
2280 if (!(systray
= (Systray
*)calloc(1, sizeof(Systray
))))
2281 die("fatal: could not malloc() %u bytes\n", sizeof(Systray
));
2282 systray
->win
= XCreateSimpleWindow(dpy
, root
, x
, m
->by
, w
, bh
, 0, 0, scheme
[SchemeSel
][ColBg
].pixel
);
2283 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
2284 wa
.override_redirect
= True
;
2285 wa
.background_pixel
= scheme
[SchemeNorm
][ColBg
].pixel
;
2286 XSelectInput(dpy
, systray
->win
, SubstructureNotifyMask
);
2287 XChangeProperty(dpy
, systray
->win
, netatom
[NetSystemTrayOrientation
], XA_CARDINAL
, 32,
2288 PropModeReplace
, (unsigned char *)&netatom
[NetSystemTrayOrientationHorz
], 1);
2289 XChangeWindowAttributes(dpy
, systray
->win
, CWEventMask
|CWOverrideRedirect
|CWBackPixel
, &wa
);
2290 XMapRaised(dpy
, systray
->win
);
2291 XSetSelectionOwner(dpy
, netatom
[NetSystemTray
], systray
->win
, CurrentTime
);
2292 if (XGetSelectionOwner(dpy
, netatom
[NetSystemTray
]) == systray
->win
) {
2293 sendevent(root
, xatom
[Manager
], StructureNotifyMask
, CurrentTime
, netatom
[NetSystemTray
], systray
->win
, 0, 0);
2297 fprintf(stderr
, "dwm: unable to obtain system tray.\n");
2303 for (w
= 0, i
= systray
->icons
; i
; i
= i
->next
) {
2304 /* make sure the background color stays the same */
2305 wa
.background_pixel
= scheme
[SchemeNorm
][ColBg
].pixel
;
2306 XChangeWindowAttributes(dpy
, i
->win
, CWBackPixel
, &wa
);
2307 XMapRaised(dpy
, i
->win
);
2308 w
+= systrayspacing
;
2310 XMoveResizeWindow(dpy
, i
->win
, i
->x
, 0, i
->w
, i
->h
);
2315 w
= w
? w
+ systrayspacing
: 1;
2317 XMoveResizeWindow(dpy
, systray
->win
, x
, m
->by
, w
, bh
);
2318 wc
.x
= x
; wc
.y
= m
->by
; wc
.width
= w
; wc
.height
= bh
;
2319 wc
.stack_mode
= Above
; wc
.sibling
= m
->barwin
;
2320 XConfigureWindow(dpy
, systray
->win
, CWX
|CWY
|CWWidth
|CWHeight
|CWSibling
|CWStackMode
, &wc
);
2321 XMapWindow(dpy
, systray
->win
);
2322 XMapSubwindows(dpy
, systray
->win
);
2323 /* redraw background */
2324 XSetForeground(dpy
, drw
->gc
, scheme
[SchemeNorm
][ColBg
].pixel
);
2325 XFillRectangle(dpy
, systray
->win
, drw
->gc
, 0, 0, w
, bh
);
2330 updatetitle(Client
*c
)
2332 if (!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
2333 gettextprop(c
->win
, XA_WM_NAME
, c
->name
, sizeof c
->name
);
2334 if (c
->name
[0] == '\0') /* hack to mark broken clients */
2335 strcpy(c
->name
, broken
);
2339 updatewindowtype(Client
*c
)
2341 Atom state
= getatomprop(c
, netatom
[NetWMState
]);
2342 Atom wtype
= getatomprop(c
, netatom
[NetWMWindowType
]);
2344 if (state
== netatom
[NetWMFullscreen
])
2345 setfullscreen(c
, 1);
2346 if (wtype
== netatom
[NetWMWindowTypeDialog
])
2351 updatewmhints(Client
*c
)
2355 if ((wmh
= XGetWMHints(dpy
, c
->win
))) {
2356 if (c
== selmon
->sel
&& wmh
->flags
& XUrgencyHint
) {
2357 wmh
->flags
&= ~XUrgencyHint
;
2358 XSetWMHints(dpy
, c
->win
, wmh
);
2360 c
->isurgent
= (wmh
->flags
& XUrgencyHint
) ? 1 : 0;
2361 if (wmh
->flags
& InputHint
)
2362 c
->neverfocus
= !wmh
->input
;
2370 view(const Arg
*arg
)
2372 if ((arg
->ui
& TAGMASK
) == selmon
->tagset
[selmon
->seltags
])
2374 selmon
->seltags
^= 1; /* toggle sel tagset */
2375 if (arg
->ui
& TAGMASK
)
2376 selmon
->tagset
[selmon
->seltags
] = arg
->ui
& TAGMASK
;
2382 wintoclient(Window w
)
2387 for (m
= mons
; m
; m
= m
->next
)
2388 for (c
= m
->clients
; c
; c
= c
->next
)
2395 wintosystrayicon(Window w
) {
2398 if (!showsystray
|| !w
)
2400 for (i
= systray
->icons
; i
&& i
->win
!= w
; i
= i
->next
) ;
2411 if (w
== root
&& getrootptr(&x
, &y
))
2412 return recttomon(x
, y
, 1, 1);
2413 for (m
= mons
; m
; m
= m
->next
)
2416 if ((c
= wintoclient(w
)))
2421 /* There's no way to check accesses to destroyed windows, thus those cases are
2422 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
2423 * default error handler, which may call exit. */
2425 xerror(Display
*dpy
, XErrorEvent
*ee
)
2427 if (ee
->error_code
== BadWindow
2428 || (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
2429 || (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
2430 || (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
2431 || (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
2432 || (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
2433 || (ee
->request_code
== X_GrabButton
&& ee
->error_code
== BadAccess
)
2434 || (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
2435 || (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
2437 fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
2438 ee
->request_code
, ee
->error_code
);
2439 return xerrorxlib(dpy
, ee
); /* may call exit */
2443 xerrordummy(Display
*dpy
, XErrorEvent
*ee
)
2448 /* Startup Error handler to check if another window manager
2449 * is already running. */
2451 xerrorstart(Display
*dpy
, XErrorEvent
*ee
)
2453 die("dwm: another window manager is already running");
2458 systraytomon(Monitor
*m
) {
2461 if(!systraypinning
) {
2464 return m
== selmon
? m
: NULL
;
2466 for(n
= 1, t
= mons
; t
&& t
->next
; n
++, t
= t
->next
) ;
2467 for(i
= 1, t
= mons
; t
&& t
->next
&& i
< systraypinning
; i
++, t
= t
->next
) ;
2468 if(systraypinningfailfirst
&& n
< systraypinning
)
2474 zoom(const Arg
*arg
)
2476 Client
*c
= selmon
->sel
;
2478 if (!selmon
->lt
[selmon
->sellt
]->arrange
2479 || (selmon
->sel
&& selmon
->sel
->isfloating
))
2481 if (c
== nexttiled(selmon
->clients
))
2482 if (!c
|| !(c
= nexttiled(c
->next
)))
2488 main(int argc
, char *argv
[])
2490 if (argc
== 2 && !strcmp("-v", argv
[1]))
2493 die("usage: dwm [-v]");
2494 if (!setlocale(LC_CTYPE
, "") || !XSupportsLocale())
2495 fputs("warning: no locale support\n", stderr
);
2496 if (!(dpy
= XOpenDisplay(NULL
)))
2497 die("dwm: cannot open display");
2501 if (pledge("stdio rpath proc exec", NULL
) == -1)
2503 #endif /* __OpenBSD__ */
2508 return EXIT_SUCCESS
;