21393d8f72c16bd6b04a928876805372a5f36f44
/* See LICENSE file for copyright and license details.
* dynamic window manager is designed like any other X client as well. It is
* driven through handling X events. In contrast to other X clients, a window
* manager selects for SubstructureRedirectMask on the root window, to receive
* events about window (dis-)appearance. Only one X connection at a time is
* allowed to select for this event mask.
* The event handlers of dwm are organized in an array which is accessed
* whenever a new event has been fetched. This allows event dispatching
* Each child of the root window is called a client, except windows which have
* set the override_redirect flag. Clients are organized in a linked client
* list on each monitor, the focus history is remembered through a stack list
* on each monitor. Each client contains a bit array to indicate the tags of a
* Keys and tagging rules are organized as arrays and defined in config.h.
* To understand everything else, start reading main().
#include <X11/cursorfont.h>
#include <X11/extensions/Xinerama.h>
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
enum { SchemeNorm
, SchemeSel
}; /* color schemes */
enum { NetSupported
, NetWMName
, NetWMState
, NetWMCheck
,
NetWMFullscreen
, NetActiveWindow
, NetWMWindowType
,
NetWMWindowTypeDialog
, NetClientList
, NetLast
}; /* EWMH atoms */
enum { WMProtocols
, WMDelete
, WMState
, WMTakeFocus
, WMLast
}; /* default atoms */
enum { ClkTagBar
, ClkLtSymbol
, ClkStatusText
, ClkWinTitle
,
ClkClientWin
, ClkRootWin
, ClkLast
}; /* clicks */
void (*func
)(const Arg
*arg
);
typedef struct Monitor Monitor
;
typedef struct Client Client
;
int oldx
, oldy
, oldw
, oldh
;
int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
, hintsvalid
;
int isfixed
, isfloating
, isurgent
, neverfocus
, oldstate
, isfullscreen
;
void (*func
)(const Arg
*);
void (*arrange
)(Monitor
*);
int by
; /* bar geometry */
int mx
, my
, mw
, mh
; /* screen size */
int wx
, wy
, ww
, wh
; /* window area */
/* function declarations */
static void applyrules(Client
*c
);
static int applysizehints(Client
*c
, int *x
, int *y
, int *w
, int *h
, int interact
);
static void arrange(Monitor
*m
);
static void arrangemon(Monitor
*m
);
static void attach(Client
*c
);
static void attachstack(Client
*c
);
static void buttonpress(XEvent
*e
);
static void checkotherwm(void);
static void cleanup(void);
static void cleanupmon(Monitor
*mon
);
static void clientmessage(XEvent
*e
);
static void configure(Client
*c
);
static void configurenotify(XEvent
*e
);
static void configurerequest(XEvent
*e
);
static Monitor
*createmon(void);
static void destroynotify(XEvent
*e
);
static void detach(Client
*c
);
static void detachstack(Client
*c
);
static Monitor
*dirtomon(int dir
);
static void drawbar(Monitor
*m
);
static void drawbars(void);
static void enternotify(XEvent
*e
);
static void expose(XEvent
*e
);
static void focus(Client
*c
);
static void focusin(XEvent
*e
);
static void focusmon(const Arg
*arg
);
static void focusstack(const Arg
*arg
);
static Atom
getatomprop(Client
*c
, Atom prop
);
static int getrootptr(int *x
, int *y
);
static long getstate(Window w
);
static int gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
);
static void grabbuttons(Client
*c
, int focused
);
static void grabkeys(void);
static void incnmaster(const Arg
*arg
);
static void keypress(XEvent
*e
);
static void killclient(const Arg
*arg
);
static void layoutmenu(const Arg
*arg
);
static void manage(Window w
, XWindowAttributes
*wa
);
static void mappingnotify(XEvent
*e
);
static void maprequest(XEvent
*e
);
static void monocle(Monitor
*m
);
static void motionnotify(XEvent
*e
);
static void movemouse(const Arg
*arg
);
static void nametag(const Arg
*arg
);
static Client
*nexttiled(Client
*c
);
static void pop(Client
*c
);
static void propertynotify(XEvent
*e
);
static void quit(const Arg
*arg
);
static Monitor
*recttomon(int x
, int y
, int w
, int h
);
static void resize(Client
*c
, int x
, int y
, int w
, int h
, int interact
);
static void resizeclient(Client
*c
, int x
, int y
, int w
, int h
);
static void resizemouse(const Arg
*arg
);
static void restack(Monitor
*m
);
static int sendevent(Client
*c
, Atom proto
);
static void sendmon(Client
*c
, Monitor
*m
);
static void setclientstate(Client
*c
, long state
);
static void setfocus(Client
*c
);
static void setfullscreen(Client
*c
, int fullscreen
);
static void setlayout(const Arg
*arg
);
static void setmfact(const Arg
*arg
);
static void seturgent(Client
*c
, int urg
);
static void showhide(Client
*c
);
static void sigchld(int unused
);
static void spawn(const Arg
*arg
);
static void tag(const Arg
*arg
);
static void tagmon(const Arg
*arg
);
static void tile(Monitor
*m
);
static void togglebar(const Arg
*arg
);
static void togglefloating(const Arg
*arg
);
static void toggletag(const Arg
*arg
);
static void toggleview(const Arg
*arg
);
static void unfocus(Client
*c
, int setfocus
);
static void unmanage(Client
*c
, int destroyed
);
static void unmapnotify(XEvent
*e
);
static void updatebarpos(Monitor
*m
);
static void updatebars(void);
static void updateclientlist(void);
static int updategeom(void);
static void updatenumlockmask(void);
static void updatesizehints(Client
*c
);
static void updatestatus(void);
static void updatetitle(Client
*c
);
static void updatewindowtype(Client
*c
);
static void updatewmhints(Client
*c
);
static void view(const Arg
*arg
);
static Client
*wintoclient(Window w
);
static Monitor
*wintomon(Window w
);
static int xerror(Display
*dpy
, XErrorEvent
*ee
);
static int xerrordummy(Display
*dpy
, XErrorEvent
*ee
);
static int xerrorstart(Display
*dpy
, XErrorEvent
*ee
);
static void zoom(const Arg
*arg
);
static void keyrelease(XEvent
*e
);
static void combotag(const Arg
*arg
);
static void comboview(const Arg
*arg
);
static const char broken
[] = "broken";
static int sw
, sh
; /* X display screen geometry width, height */
static int bh
; /* bar height */
static int lrpad
; /* sum of left and right padding for text */
static int (*xerrorxlib
)(Display
*, XErrorEvent
*);
static unsigned int numlockmask
= 0;
static void (*handler
[LASTEvent
]) (XEvent
*) = {
[ButtonPress
] = buttonpress
,
[ButtonRelease
] = keyrelease
,
[ClientMessage
] = clientmessage
,
[ConfigureRequest
] = configurerequest
,
[ConfigureNotify
] = configurenotify
,
[DestroyNotify
] = destroynotify
,
[EnterNotify
] = enternotify
,
[KeyRelease
] = keyrelease
,
[MappingNotify
] = mappingnotify
,
[MapRequest
] = maprequest
,
[MotionNotify
] = motionnotify
,
[PropertyNotify
] = propertynotify
,
[UnmapNotify
] = unmapnotify
static Atom wmatom
[WMLast
], netatom
[NetLast
];
static Cur
*cursor
[CurLast
];
static Monitor
*mons
, *selmon
;
static Window root
, wmcheckwin
;
/* configuration, allows nested code to access above variables */
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags
{ char limitexceeded
[LENGTH(tags
) > 31 ? -1 : 1]; };
/* function implementations */
combotag(const Arg
*arg
) {
if(selmon
->sel
&& arg
->ui
& TAGMASK
) {
selmon
->sel
->tags
|= arg
->ui
& TAGMASK
;
selmon
->sel
->tags
= arg
->ui
& TAGMASK
;
comboview(const Arg
*arg
) {
unsigned newtags
= arg
->ui
& TAGMASK
;
selmon
->tagset
[selmon
->seltags
] |= newtags
;
selmon
->seltags
^= 1; /*toggle tagset*/
selmon
->tagset
[selmon
->seltags
] = newtags
;
const char *class, *instance
;
XClassHint ch
= { NULL
, NULL
};
XGetClassHint(dpy
, c
->win
, &ch
);
class = ch
.res_class
? ch
.res_class
: broken
;
instance
= ch
.res_name
? ch
.res_name
: broken
;
for (i
= 0; i
< LENGTH(rules
); i
++) {
if ((!r
->title
|| strstr(c
->name
, r
->title
))
&& (!r
->class || strstr(class, r
->class))
&& (!r
->instance
|| strstr(instance
, r
->instance
)))
c
->isfloating
= r
->isfloating
;
for (m
= mons
; m
&& m
->num
!= r
->monitor
; m
= m
->next
);
if(c
->tags
& TAGMASK
) c
->tags
= c
->tags
& TAGMASK
;
else if(c
->mon
->tagset
[c
->mon
->seltags
]) c
->tags
= c
->mon
->tagset
[c
->mon
->seltags
];
applysizehints(Client
*c
, int *x
, int *y
, int *w
, int *h
, int interact
)
/* set minimum possible */
if (*x
+ *w
+ 2 * c
->bw
< 0)
if (*y
+ *h
+ 2 * c
->bw
< 0)
*x
= m
->wx
+ m
->ww
- WIDTH(c
);
*y
= m
->wy
+ m
->wh
- HEIGHT(c
);
if (*x
+ *w
+ 2 * c
->bw
<= m
->wx
)
if (*y
+ *h
+ 2 * c
->bw
<= m
->wy
)
if (resizehints
|| c
->isfloating
|| !c
->mon
->lt
[c
->mon
->sellt
]->arrange
) {
/* see last two sentences in ICCCM 4.1.2.3 */
baseismin
= c
->basew
== c
->minw
&& c
->baseh
== c
->minh
;
if (!baseismin
) { /* temporarily remove base dimensions */
/* adjust for aspect limits */
if (c
->mina
> 0 && c
->maxa
> 0) {
if (c
->maxa
< (float)*w
/ *h
)
else if (c
->mina
< (float)*h
/ *w
)
if (baseismin
) { /* increment calculation requires this */
/* adjust for increment value */
/* restore base dimensions */
*w
= MAX(*w
+ c
->basew
, c
->minw
);
*h
= MAX(*h
+ c
->baseh
, c
->minh
);
return *x
!= c
->x
|| *y
!= c
->y
|| *w
!= c
->w
|| *h
!= c
->h
;
else for (m
= mons
; m
; m
= m
->next
)
} else for (m
= mons
; m
; m
= m
->next
)
strncpy(m
->ltsymbol
, m
->lt
[m
->sellt
]->symbol
, sizeof m
->ltsymbol
);
if (m
->lt
[m
->sellt
]->arrange
)
m
->lt
[m
->sellt
]->arrange(m
);
c
->next
= c
->mon
->clients
;
c
->snext
= c
->mon
->stack
;
unsigned int i
, x
, click
;
XButtonPressedEvent
*ev
= &e
->xbutton
;
/* focus monitor if necessary */
if ((m
= wintomon(ev
->window
)) && m
!= selmon
) {
if (ev
->window
== selmon
->barwin
) {
while (ev
->x
>= x
&& ++i
< LENGTH(tags
));
} else if (ev
->x
< x
+ TEXTW(selmon
->ltsymbol
))
else if (ev
->x
> selmon
->ww
- (int)TEXTW(stext
))
} else if ((c
= wintoclient(ev
->window
))) {
XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
for (i
= 0; i
< LENGTH(buttons
); i
++)
if (click
== buttons
[i
].click
&& buttons
[i
].func
&& buttons
[i
].button
== ev
->button
&& CLEANMASK(buttons
[i
].mask
) == CLEANMASK(ev
->state
))
buttons
[i
].func(click
== ClkTagBar
&& buttons
[i
].arg
.i
== 0 ? &arg
: &buttons
[i
].arg
);
xerrorxlib
= XSetErrorHandler(xerrorstart
);
/* this causes an error if some other window manager is running */
XSelectInput(dpy
, DefaultRootWindow(dpy
), SubstructureRedirectMask
);
XSetErrorHandler(xerror
);
Layout foo
= { "", NULL
};
selmon
->lt
[selmon
->sellt
] = &foo
;
for (m
= mons
; m
; m
= m
->next
)
XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
for (i
= 0; i
< CurLast
; i
++)
drw_cur_free(drw
, cursor
[i
]);
for (i
= 0; i
< LENGTH(colors
); i
++)
XDestroyWindow(dpy
, wmcheckwin
);
XSetInputFocus(dpy
, PointerRoot
, RevertToPointerRoot
, CurrentTime
);
XDeleteProperty(dpy
, root
, netatom
[NetActiveWindow
]);
for (m
= mons
; m
&& m
->next
!= mon
; m
= m
->next
);
XUnmapWindow(dpy
, mon
->barwin
);
XDestroyWindow(dpy
, mon
->barwin
);
XClientMessageEvent
*cme
= &e
->xclient
;
Client
*c
= wintoclient(cme
->window
);
if (cme
->message_type
== netatom
[NetWMState
]) {
if (cme
->data
.l
[1] == netatom
[NetWMFullscreen
]
|| cme
->data
.l
[2] == netatom
[NetWMFullscreen
])
setfullscreen(c
, (cme
->data
.l
[0] == 1 /* _NET_WM_STATE_ADD */
|| (cme
->data
.l
[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c
->isfullscreen
)));
} else if (cme
->message_type
== netatom
[NetActiveWindow
]) {
if (c
!= selmon
->sel
&& !c
->isurgent
)
ce
.type
= ConfigureNotify
;
ce
.override_redirect
= False
;
XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&ce
);
configurenotify(XEvent
*e
)
XConfigureEvent
*ev
= &e
->xconfigure
;
/* TODO: updategeom handling sucks, needs to be simplified */
if (ev
->window
== root
) {
dirty
= (sw
!= ev
->width
|| sh
!= ev
->height
);
if (updategeom() || dirty
) {
for (m
= mons
; m
; m
= m
->next
) {
for (c
= m
->clients
; c
; c
= c
->next
)
resizeclient(c
, m
->mx
, m
->my
, m
->mw
, m
->mh
);
XMoveResizeWindow(dpy
, m
->barwin
, m
->wx
, m
->by
, m
->ww
, bh
);
configurerequest(XEvent
*e
)
XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
if ((c
= wintoclient(ev
->window
))) {
if (ev
->value_mask
& CWBorderWidth
)
c
->bw
= ev
->border_width
;
else if (c
->isfloating
|| !selmon
->lt
[selmon
->sellt
]->arrange
) {
if (ev
->value_mask
& CWX
) {
if (ev
->value_mask
& CWY
) {
if (ev
->value_mask
& CWWidth
) {
if (ev
->value_mask
& CWHeight
) {
if ((c
->x
+ c
->w
) > m
->mx
+ m
->mw
&& c
->isfloating
)
c
->x
= m
->mx
+ (m
->mw
/ 2 - WIDTH(c
) / 2); /* center in x direction */
if ((c
->y
+ c
->h
) > m
->my
+ m
->mh
&& c
->isfloating
)
c
->y
= m
->my
+ (m
->mh
/ 2 - HEIGHT(c
) / 2); /* center in y direction */
if ((ev
->value_mask
& (CWX
|CWY
)) && !(ev
->value_mask
& (CWWidth
|CWHeight
)))
XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
wc
.border_width
= ev
->border_width
;
wc
.stack_mode
= ev
->detail
;
XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
m
= ecalloc(1, sizeof(Monitor
));
m
->tagset
[0] = m
->tagset
[1] = startontag
? 1 : 0;
m
->lt
[1] = &layouts
[1 % LENGTH(layouts
)];
strncpy(m
->ltsymbol
, layouts
[0].symbol
, sizeof m
->ltsymbol
);
XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
if ((c
= wintoclient(ev
->window
)))
for (tc
= &c
->mon
->clients
; *tc
&& *tc
!= c
; tc
= &(*tc
)->next
);
for (tc
= &c
->mon
->stack
; *tc
&& *tc
!= c
; tc
= &(*tc
)->snext
);
for (t
= c
->mon
->stack
; t
&& !ISVISIBLE(t
); t
= t
->snext
);
} else if (selmon
== mons
)
for (m
= mons
; m
->next
; m
= m
->next
);
for (m
= mons
; m
->next
!= selmon
; m
= m
->next
);
int boxs
= drw
->fonts
->h
/ 9;
int boxw
= drw
->fonts
->h
/ 6 + 2;
unsigned int i
, occ
= 0, urg
= 0;
/* draw status first so it can be overdrawn by tags later */
if (m
== selmon
) { /* status is only drawn on selected monitor */
drw_setscheme(drw
, scheme
[SchemeNorm
]);
tw
= TEXTW(stext
) - lrpad
+ 2; /* 2px right padding */
drw_text(drw
, m
->ww
- tw
, 0, tw
, bh
, 0, stext
, 0);
for (c
= m
->clients
; c
; c
= c
->next
) {
for (i
= 0; i
< LENGTH(tags
); i
++) {
drw_setscheme(drw
, scheme
[m
->tagset
[m
->seltags
] & 1 << i
? SchemeSel
: SchemeNorm
]);
drw_text(drw
, x
, 0, w
, bh
, lrpad
/ 2, tags
[i
], urg
& 1 << i
);
drw_rect(drw
, x
+ boxs
, boxs
, boxw
, boxw
,
m
== selmon
&& selmon
->sel
&& selmon
->sel
->tags
& 1 << i
,
drw_setscheme(drw
, scheme
[SchemeNorm
]);
x
= drw_text(drw
, x
, 0, w
, bh
, lrpad
/ 2, m
->ltsymbol
, 0);
if ((w
= m
->ww
- tw
- x
) > bh
) {
/* fix overflow when window name is bigger than window width */
int mid
= (m
->ww
- (int)TEXTW(m
->sel
->name
)) / 2 - x
;
/* make sure name will not overlap on tags even when it is very long */
mid
= mid
>= lrpad
/ 2 ? mid
: lrpad
/ 2;
drw_setscheme(drw
, scheme
[m
== selmon
? SchemeSel
: SchemeNorm
]);
drw_text(drw
, x
, 0, w
, bh
, mid
, m
->sel
->name
, 0);
drw_rect(drw
, x
+ boxs
, boxs
, boxw
, boxw
, m
->sel
->isfixed
, 0);
drw_setscheme(drw
, scheme
[SchemeNorm
]);
drw_rect(drw
, x
, 0, w
, bh
, 1, 1);
drw_map(drw
, m
->barwin
, 0, 0, m
->ww
, bh
);
for (m
= mons
; m
; m
= m
->next
)
XCrossingEvent
*ev
= &e
->xcrossing
;
if ((ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
) && ev
->window
!= root
)
c
= wintoclient(ev
->window
);
m
= c
? c
->mon
: wintomon(ev
->window
);
} else if (!c
|| c
== selmon
->sel
)
XExposeEvent
*ev
= &e
->xexpose
;
if (ev
->count
== 0 && (m
= wintomon(ev
->window
)))
for (c
= selmon
->stack
; c
&& !ISVISIBLE(c
); c
= c
->snext
);
if (selmon
->sel
&& selmon
->sel
!= c
)
XSetWindowBorder(dpy
, c
->win
, scheme
[SchemeSel
][ColBorder
].pixel
);
XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
XDeleteProperty(dpy
, root
, netatom
[NetActiveWindow
]);
/* there are some broken focus acquiring clients needing extra handling */
XFocusChangeEvent
*ev
= &e
->xfocus
;
if (selmon
->sel
&& ev
->window
!= selmon
->sel
->win
)
if ((m
= dirtomon(arg
->i
)) == selmon
)
focusstack(const Arg
*arg
)
if (!selmon
->sel
|| (selmon
->sel
->isfullscreen
&& lockfullscreen
))
for (c
= selmon
->sel
->next
; c
&& !ISVISIBLE(c
); c
= c
->next
);
for (c
= selmon
->clients
; c
&& !ISVISIBLE(c
); c
= c
->next
);
for (i
= selmon
->clients
; i
!= selmon
->sel
; i
= i
->next
)
getatomprop(Client
*c
, Atom prop
)
if (XGetWindowProperty(dpy
, c
->win
, prop
, 0L, sizeof atom
, False
, XA_ATOM
,
&da
, &di
, &dl
, &dl
, &p
) == Success
&& p
) {
getrootptr(int *x
, int *y
)
return XQueryPointer(dpy
, root
, &dummy
, &dummy
, x
, y
, &di
, &di
, &dui
);
if (XGetWindowProperty(dpy
, w
, wmatom
[WMState
], 0L, 2L, False
, wmatom
[WMState
],
&real
, &format
, &n
, &extra
, (unsigned char **)&p
) != Success
)
gettextprop(Window w
, Atom atom
, char *text
, unsigned int size
)
if (!XGetTextProperty(dpy
, w
, &name
, atom
) || !name
.nitems
)
if (name
.encoding
== XA_STRING
) {
strncpy(text
, (char *)name
.value
, size
- 1);
} else if (XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
&& n
> 0 && *list
) {
strncpy(text
, *list
, size
- 1);
grabbuttons(Client
*c
, int focused
)
unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
XGrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
, False
,
BUTTONMASK
, GrabModeSync
, GrabModeSync
, None
, None
);
for (i
= 0; i
< LENGTH(buttons
); i
++)
if (buttons
[i
].click
== ClkClientWin
)
for (j
= 0; j
< LENGTH(modifiers
); j
++)
XGrabButton(dpy
, buttons
[i
].button
,
buttons
[i
].mask
| modifiers
[j
],
c
->win
, False
, BUTTONMASK
,
GrabModeAsync
, GrabModeSync
, None
, None
);
unsigned int modifiers
[] = { 0, LockMask
, numlockmask
, numlockmask
|LockMask
};
XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
for (i
= 0; i
< LENGTH(keys
); i
++)
if ((code
= XKeysymToKeycode(dpy
, keys
[i
].keysym
)))
for (j
= 0; j
< LENGTH(modifiers
); j
++)
XGrabKey(dpy
, code
, keys
[i
].mod
| modifiers
[j
], root
,
True
, GrabModeAsync
, GrabModeAsync
);
incnmaster(const Arg
*arg
)
selmon
->nmaster
= MAX(selmon
->nmaster
+ arg
->i
, 0);
isuniquegeom(XineramaScreenInfo
*unique
, size_t n
, XineramaScreenInfo
*info
)
if (unique
[n
].x_org
== info
->x_org
&& unique
[n
].y_org
== info
->y_org
&& unique
[n
].width
== info
->width
&& unique
[n
].height
== info
->height
)
keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
for (i
= 0; i
< LENGTH(keys
); i
++)
if (keysym
== keys
[i
].keysym
&& CLEANMASK(keys
[i
].mod
) == CLEANMASK(ev
->state
)
keys
[i
].func(&(keys
[i
].arg
));
killclient(const Arg
*arg
)
if (!sendevent(selmon
->sel
, wmatom
[WMDelete
])) {
XSetErrorHandler(xerrordummy
);
XSetCloseDownMode(dpy
, DestroyAll
);
XKillClient(dpy
, selmon
->sel
->win
);
XSetErrorHandler(xerror
);
layoutmenu(const Arg
*arg
) {
if (!(p
= popen(layoutmenu_cmd
, "r")))
s
= fgets(c
, sizeof(c
), p
);
if (!s
|| *s
== '\0' || c
[0] == '\0')
setlayout(&((Arg
) { .v
= &layouts
[i
] }));
manage(Window w
, XWindowAttributes
*wa
)
c
= ecalloc(1, sizeof(Client
));
c
->w
= c
->oldw
= wa
->width
;
c
->h
= c
->oldh
= wa
->height
;
c
->oldbw
= wa
->border_width
;
if (XGetTransientForHint(dpy
, w
, &trans
) && (t
= wintoclient(trans
))) {
if (c
->x
+ WIDTH(c
) > c
->mon
->wx
+ c
->mon
->ww
)
c
->x
= c
->mon
->wx
+ c
->mon
->ww
- WIDTH(c
);
if (c
->y
+ HEIGHT(c
) > c
->mon
->wy
+ c
->mon
->wh
)
c
->y
= c
->mon
->wy
+ c
->mon
->wh
- HEIGHT(c
);
c
->x
= MAX(c
->x
, c
->mon
->wx
);
c
->y
= MAX(c
->y
, c
->mon
->wy
);
XConfigureWindow(dpy
, w
, CWBorderWidth
, &wc
);
XSetWindowBorder(dpy
, w
, scheme
[SchemeNorm
][ColBorder
].pixel
);
configure(c
); /* propagates border_width, if size doesn't change */
XSelectInput(dpy
, w
, EnterWindowMask
|FocusChangeMask
|PropertyChangeMask
|StructureNotifyMask
);
c
->isfloating
= c
->oldstate
= trans
!= None
|| c
->isfixed
;
XRaiseWindow(dpy
, c
->win
);
XChangeProperty(dpy
, root
, netatom
[NetClientList
], XA_WINDOW
, 32, PropModeAppend
,
(unsigned char *) &(c
->win
), 1);
XMoveResizeWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
, c
->w
, c
->h
); /* some windows require this */
setclientstate(c
, NormalState
);
XMappingEvent
*ev
= &e
->xmapping
;
XRefreshKeyboardMapping(ev
);
if (ev
->request
== MappingKeyboard
)
static XWindowAttributes wa
;
XMapRequestEvent
*ev
= &e
->xmaprequest
;
if (!XGetWindowAttributes(dpy
, ev
->window
, &wa
) || wa
.override_redirect
)
if (!wintoclient(ev
->window
))
for (c
= m
->clients
; c
; c
= c
->next
)
if (n
> 0) /* override layout symbol */
snprintf(m
->ltsymbol
, sizeof m
->ltsymbol
, "[%d]", n
);
for (c
= nexttiled(m
->clients
); c
; c
= nexttiled(c
->next
))
resize(c
, m
->wx
, m
->wy
, m
->ww
- 2 * c
->bw
, m
->wh
- 2 * c
->bw
, 0);
static Monitor
*mon
= NULL
;
XMotionEvent
*ev
= &e
->xmotion
;
if ((m
= recttomon(ev
->x_root
, ev
->y_root
, 1, 1)) != mon
&& mon
) {
movemouse(const Arg
*arg
)
int x
, y
, ocx
, ocy
, nx
, ny
;
if (c
->isfullscreen
) /* no support moving fullscreen windows by mouse */
if (XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
None
, cursor
[CurMove
]->cursor
, CurrentTime
) != GrabSuccess
)
XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
if ((ev
.xmotion
.time
- lasttime
) <= (1000 / 60))
lasttime
= ev
.xmotion
.time
;
nx
= ocx
+ (ev
.xmotion
.x
- x
);
ny
= ocy
+ (ev
.xmotion
.y
- y
);
if (abs(selmon
->wx
- nx
) < snap
)
else if (abs((selmon
->wx
+ selmon
->ww
) - (nx
+ WIDTH(c
))) < snap
)
nx
= selmon
->wx
+ selmon
->ww
- WIDTH(c
);
if (abs(selmon
->wy
- ny
) < snap
)
else if (abs((selmon
->wy
+ selmon
->wh
) - (ny
+ HEIGHT(c
))) < snap
)
ny
= selmon
->wy
+ selmon
->wh
- HEIGHT(c
);
if (!c
->isfloating
&& selmon
->lt
[selmon
->sellt
]->arrange
&& (abs(nx
- c
->x
) > snap
|| abs(ny
- c
->y
) > snap
))
if (!selmon
->lt
[selmon
->sellt
]->arrange
|| c
->isfloating
)
resize(c
, nx
, ny
, c
->w
, c
->h
, 1);
} while (ev
.type
!= ButtonRelease
);
XUngrabPointer(dpy
, CurrentTime
);
if ((m
= recttomon(c
->x
, c
->y
, c
->w
, c
->h
)) != selmon
) {
nametag(const Arg
*arg
) {
char *p
, name
[MAX_TAGLEN
];
errno
= 0; // popen(3p) says on failure it "may" set errno
if(!(f
= popen("dmenu < /dev/null", "r"))) {
fprintf(stderr
, "dwm: popen 'dmenu < /dev/null' failed%s%s\n", errno
? ": " : "", errno
? strerror(errno
) : "");
if (!(p
= fgets(name
, MAX_TAGLEN
, f
)) && (i
= errno
) && ferror(f
))
fprintf(stderr
, "dwm: fgets failed: %s\n", strerror(i
));
fprintf(stderr
, "dwm: pclose failed: %s\n", strerror(errno
));
if((p
= strchr(name
, '\n')))
for(i
= 0; i
< LENGTH(tags
); i
++)
if(selmon
->tagset
[selmon
->seltags
] & (1 << i
))
for (; c
&& (c
->isfloating
|| !ISVISIBLE(c
)); c
= c
->next
);
propertynotify(XEvent
*e
)
XPropertyEvent
*ev
= &e
->xproperty
;
if ((ev
->window
== root
) && (ev
->atom
== XA_WM_NAME
))
else if (ev
->state
== PropertyDelete
)
else if ((c
= wintoclient(ev
->window
))) {
case XA_WM_TRANSIENT_FOR
:
if (!c
->isfloating
&& (XGetTransientForHint(dpy
, c
->win
, &trans
)) &&
(c
->isfloating
= (wintoclient(trans
)) != NULL
))
if (ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
if (ev
->atom
== netatom
[NetWMWindowType
])
recttomon(int x
, int y
, int w
, int h
)
for (m
= mons
; m
; m
= m
->next
)
if ((a
= INTERSECT(x
, y
, w
, h
, m
)) > area
) {
resize(Client
*c
, int x
, int y
, int w
, int h
, int interact
)
if (applysizehints(c
, &x
, &y
, &w
, &h
, interact
))
resizeclient(c
, x
, y
, w
, h
);
resizeclient(Client
*c
, int x
, int y
, int w
, int h
)
c
->oldx
= c
->x
; c
->x
= wc
.x
= x
;
c
->oldy
= c
->y
; c
->y
= wc
.y
= y
;
c
->oldw
= c
->w
; c
->w
= wc
.width
= w
;
c
->oldh
= c
->h
; c
->h
= wc
.height
= h
;
XConfigureWindow(dpy
, c
->win
, CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
, &wc
);
resizemouse(const Arg
*arg
)
if (c
->isfullscreen
) /* no support resizing fullscreen windows by mouse */
if (XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
None
, cursor
[CurResize
]->cursor
, CurrentTime
) != GrabSuccess
)
XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
XMaskEvent(dpy
, MOUSEMASK
|ExposureMask
|SubstructureRedirectMask
, &ev
);
if ((ev
.xmotion
.time
- lasttime
) <= (1000 / 60))
lasttime
= ev
.xmotion
.time
;
nw
= MAX(ev
.xmotion
.x
- ocx
- 2 * c
->bw
+ 1, 1);
nh
= MAX(ev
.xmotion
.y
- ocy
- 2 * c
->bw
+ 1, 1);
if (c
->mon
->wx
+ nw
>= selmon
->wx
&& c
->mon
->wx
+ nw
<= selmon
->wx
+ selmon
->ww
&& c
->mon
->wy
+ nh
>= selmon
->wy
&& c
->mon
->wy
+ nh
<= selmon
->wy
+ selmon
->wh
)
if (!c
->isfloating
&& selmon
->lt
[selmon
->sellt
]->arrange
&& (abs(nw
- c
->w
) > snap
|| abs(nh
- c
->h
) > snap
))
if (!selmon
->lt
[selmon
->sellt
]->arrange
|| c
->isfloating
)
resize(c
, c
->x
, c
->y
, nw
, nh
, 1);
} while (ev
.type
!= ButtonRelease
);
XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->bw
- 1, c
->h
+ c
->bw
- 1);
XUngrabPointer(dpy
, CurrentTime
);
while (XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
if ((m
= recttomon(c
->x
, c
->y
, c
->w
, c
->h
)) != selmon
) {
if (m
->sel
->isfloating
|| !m
->lt
[m
->sellt
]->arrange
)
XRaiseWindow(dpy
, m
->sel
->win
);
if (m
->lt
[m
->sellt
]->arrange
) {
for (c
= m
->stack
; c
; c
= c
->snext
)
if (!c
->isfloating
&& ISVISIBLE(c
)) {
XConfigureWindow(dpy
, c
->win
, CWSibling
|CWStackMode
, &wc
);
while (XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
while (running
&& !XNextEvent(dpy
, &ev
))
handler
[ev
.type
](&ev
); /* call handler */
Window d1
, d2
, *wins
= NULL
;
if (XQueryTree(dpy
, root
, &d1
, &d2
, &wins
, &num
)) {
for (i
= 0; i
< num
; i
++) {
if (!XGetWindowAttributes(dpy
, wins
[i
], &wa
)
|| wa
.override_redirect
|| XGetTransientForHint(dpy
, wins
[i
], &d1
))
if (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
)
for (i
= 0; i
< num
; i
++) { /* now the transients */
if (!XGetWindowAttributes(dpy
, wins
[i
], &wa
))
if (XGetTransientForHint(dpy
, wins
[i
], &d1
)
&& (wa
.map_state
== IsViewable
|| getstate(wins
[i
]) == IconicState
))
sendmon(Client
*c
, Monitor
*m
)
c
->tags
= (m
->tagset
[m
->seltags
] ? m
->tagset
[m
->seltags
] : 1);
setclientstate(Client
*c
, long state
)
long data
[] = { state
, None
};
XChangeProperty(dpy
, c
->win
, wmatom
[WMState
], wmatom
[WMState
], 32,
PropModeReplace
, (unsigned char *)data
, 2);
sendevent(Client
*c
, Atom proto
)
if (XGetWMProtocols(dpy
, c
->win
, &protocols
, &n
)) {
exists
= protocols
[n
] == proto
;
ev
.xclient
.window
= c
->win
;
ev
.xclient
.message_type
= wmatom
[WMProtocols
];
ev
.xclient
.data
.l
[0] = proto
;
ev
.xclient
.data
.l
[1] = CurrentTime
;
XSendEvent(dpy
, c
->win
, False
, NoEventMask
, &ev
);
XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
XChangeProperty(dpy
, root
, netatom
[NetActiveWindow
],
XA_WINDOW
, 32, PropModeReplace
,
(unsigned char *) &(c
->win
), 1);
sendevent(c
, wmatom
[WMTakeFocus
]);
setfullscreen(Client
*c
, int fullscreen
)
if (fullscreen
&& !c
->isfullscreen
) {
XChangeProperty(dpy
, c
->win
, netatom
[NetWMState
], XA_ATOM
, 32,
PropModeReplace
, (unsigned char*)&netatom
[NetWMFullscreen
], 1);
c
->oldstate
= c
->isfloating
;
resizeclient(c
, c
->mon
->mx
, c
->mon
->my
, c
->mon
->mw
, c
->mon
->mh
);
XRaiseWindow(dpy
, c
->win
);
} else if (!fullscreen
&& c
->isfullscreen
){
XChangeProperty(dpy
, c
->win
, netatom
[NetWMState
], XA_ATOM
, 32,
PropModeReplace
, (unsigned char*)0, 0);
c
->isfloating
= c
->oldstate
;
resizeclient(c
, c
->x
, c
->y
, c
->w
, c
->h
);
setlayout(const Arg
*arg
)
if (!arg
|| !arg
->v
|| arg
->v
!= selmon
->lt
[selmon
->sellt
])
selmon
->lt
[selmon
->sellt
] = (Layout
*)arg
->v
;
strncpy(selmon
->ltsymbol
, selmon
->lt
[selmon
->sellt
]->symbol
, sizeof selmon
->ltsymbol
);
/* arg > 1.0 will set mfact absolutely */
if (!arg
|| !selmon
->lt
[selmon
->sellt
]->arrange
)
f
= arg
->f
< 1.0 ? arg
->f
+ selmon
->mfact
: arg
->f
- 1.0;
if (f
< 0.05 || f
> 0.95)
/* clean up any zombies immediately */
screen
= DefaultScreen(dpy
);
sw
= DisplayWidth(dpy
, screen
);
sh
= DisplayHeight(dpy
, screen
);
root
= RootWindow(dpy
, screen
);
drw
= drw_create(dpy
, screen
, root
, sw
, sh
);
if (!drw_fontset_create(drw
, fonts
, LENGTH(fonts
)))
die("no fonts could be loaded.");
utf8string
= XInternAtom(dpy
, "UTF8_STRING", False
);
wmatom
[WMProtocols
] = XInternAtom(dpy
, "WM_PROTOCOLS", False
);
wmatom
[WMDelete
] = XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
wmatom
[WMState
] = XInternAtom(dpy
, "WM_STATE", False
);
wmatom
[WMTakeFocus
] = XInternAtom(dpy
, "WM_TAKE_FOCUS", False
);
netatom
[NetActiveWindow
] = XInternAtom(dpy
, "_NET_ACTIVE_WINDOW", False
);
netatom
[NetSupported
] = XInternAtom(dpy
, "_NET_SUPPORTED", False
);
netatom
[NetWMName
] = XInternAtom(dpy
, "_NET_WM_NAME", False
);
netatom
[NetWMState
] = XInternAtom(dpy
, "_NET_WM_STATE", False
);
netatom
[NetWMCheck
] = XInternAtom(dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
netatom
[NetWMFullscreen
] = XInternAtom(dpy
, "_NET_WM_STATE_FULLSCREEN", False
);
netatom
[NetWMWindowType
] = XInternAtom(dpy
, "_NET_WM_WINDOW_TYPE", False
);
netatom
[NetWMWindowTypeDialog
] = XInternAtom(dpy
, "_NET_WM_WINDOW_TYPE_DIALOG", False
);
netatom
[NetClientList
] = XInternAtom(dpy
, "_NET_CLIENT_LIST", False
);
cursor
[CurNormal
] = drw_cur_create(drw
, XC_left_ptr
);
cursor
[CurResize
] = drw_cur_create(drw
, XC_sizing
);
cursor
[CurMove
] = drw_cur_create(drw
, XC_fleur
);
scheme
= ecalloc(LENGTH(colors
), sizeof(Clr
*));
for (i
= 0; i
< LENGTH(colors
); i
++)
scheme
[i
] = drw_scm_create(drw
, colors
[i
], 3);
/* supporting window for NetWMCheck */
wmcheckwin
= XCreateSimpleWindow(dpy
, root
, 0, 0, 1, 1, 0, 0, 0);
XChangeProperty(dpy
, wmcheckwin
, netatom
[NetWMCheck
], XA_WINDOW
, 32,
PropModeReplace
, (unsigned char *) &wmcheckwin
, 1);
XChangeProperty(dpy
, wmcheckwin
, netatom
[NetWMName
], utf8string
, 8,
PropModeReplace
, (unsigned char *) "dwm", 3);
XChangeProperty(dpy
, root
, netatom
[NetWMCheck
], XA_WINDOW
, 32,
PropModeReplace
, (unsigned char *) &wmcheckwin
, 1);
/* EWMH support per view */
XChangeProperty(dpy
, root
, netatom
[NetSupported
], XA_ATOM
, 32,
PropModeReplace
, (unsigned char *) netatom
, NetLast
);
XDeleteProperty(dpy
, root
, netatom
[NetClientList
]);
wa
.cursor
= cursor
[CurNormal
]->cursor
;
wa
.event_mask
= SubstructureRedirectMask
|SubstructureNotifyMask
|ButtonPressMask
|PointerMotionMask
|EnterWindowMask
|LeaveWindowMask
|StructureNotifyMask
|PropertyChangeMask
;
XChangeWindowAttributes(dpy
, root
, CWEventMask
|CWCursor
, &wa
);
XSelectInput(dpy
, root
, wa
.event_mask
);
seturgent(Client
*c
, int urg
)
if (!(wmh
= XGetWMHints(dpy
, c
->win
)))
wmh
->flags
= urg
? (wmh
->flags
| XUrgencyHint
) : (wmh
->flags
& ~XUrgencyHint
);
XSetWMHints(dpy
, c
->win
, wmh
);
/* show clients top down */
XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
if ((!c
->mon
->lt
[c
->mon
->sellt
]->arrange
|| c
->isfloating
) && !c
->isfullscreen
)
resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, 0);
/* hide clients bottom up */
XMoveWindow(dpy
, c
->win
, WIDTH(c
) * -2, c
->y
);
if (signal(SIGCHLD
, sigchld
) == SIG_ERR
)
die("can't install SIGCHLD handler:");
while (0 < waitpid(-1, NULL
, WNOHANG
));
close(ConnectionNumber(dpy
));
execvp(((char **)arg
->v
)[0], (char **)arg
->v
);
die("dwm: execvp '%s' failed:", ((char **)arg
->v
)[0]);
if (selmon
->sel
&& arg
->ui
& TAGMASK
) {
selmon
->sel
->tags
= arg
->ui
& TAGMASK
;
if (!selmon
->sel
|| !mons
->next
)
sendmon(selmon
->sel
, dirtomon(arg
->i
));
unsigned int i
, n
, h
, mw
, my
, ty
;
for (n
= 0, c
= nexttiled(m
->clients
); c
; c
= nexttiled(c
->next
), n
++);
mw
= m
->nmaster
? m
->ww
* m
->mfact
: 0;
for (i
= my
= ty
= 0, c
= nexttiled(m
->clients
); c
; c
= nexttiled(c
->next
), i
++)
h
= (m
->wh
- my
) / (MIN(n
, m
->nmaster
) - i
);
resize(c
, m
->wx
, m
->wy
+ my
, mw
- (2*c
->bw
), h
- (2*c
->bw
), 0);
if (my
+ HEIGHT(c
) < m
->wh
)
h
= (m
->wh
- ty
) / (n
- i
);
resize(c
, m
->wx
+ mw
, m
->wy
+ ty
, m
->ww
- mw
- (2*c
->bw
), h
- (2*c
->bw
), 0);
if (ty
+ HEIGHT(c
) < m
->wh
)
togglebar(const Arg
*arg
)
selmon
->showbar
= !selmon
->showbar
;
XMoveResizeWindow(dpy
, selmon
->barwin
, selmon
->wx
, selmon
->by
, selmon
->ww
, bh
);
togglefloating(const Arg
*arg
)
if (selmon
->sel
->isfullscreen
) /* no support for fullscreen windows */
selmon
->sel
->isfloating
= !selmon
->sel
->isfloating
|| selmon
->sel
->isfixed
;
if (selmon
->sel
->isfloating
)
resize(selmon
->sel
, selmon
->sel
->x
, selmon
->sel
->y
,
selmon
->sel
->w
, selmon
->sel
->h
, 0);
toggletag(const Arg
*arg
)
newtags
= selmon
->sel
->tags
^ (arg
->ui
& TAGMASK
);
selmon
->sel
->tags
= newtags
;
toggleview(const Arg
*arg
)
unsigned int newtagset
= selmon
->tagset
[selmon
->seltags
] ^ (arg
->ui
& TAGMASK
);
selmon
->tagset
[selmon
->seltags
] = newtagset
;
unfocus(Client
*c
, int setfocus
)
XSetWindowBorder(dpy
, c
->win
, scheme
[SchemeNorm
][ColBorder
].pixel
);
XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
XDeleteProperty(dpy
, root
, netatom
[NetActiveWindow
]);
unmanage(Client
*c
, int destroyed
)
wc
.border_width
= c
->oldbw
;
XGrabServer(dpy
); /* avoid race conditions */
XSetErrorHandler(xerrordummy
);
XSelectInput(dpy
, c
->win
, NoEventMask
);
XConfigureWindow(dpy
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
setclientstate(c
, WithdrawnState
);
XSetErrorHandler(xerror
);
XUnmapEvent
*ev
= &e
->xunmap
;
if ((c
= wintoclient(ev
->window
))) {
setclientstate(c
, WithdrawnState
);
XSetWindowAttributes wa
= {
.override_redirect
= True
,
.background_pixmap
= ParentRelative
,
.event_mask
= ButtonPressMask
|ExposureMask
XClassHint ch
= {"dwm", "dwm"};
for (m
= mons
; m
; m
= m
->next
) {
m
->barwin
= XCreateWindow(dpy
, root
, m
->wx
, m
->by
, m
->ww
, bh
, 0, DefaultDepth(dpy
, screen
),
CopyFromParent
, DefaultVisual(dpy
, screen
),
CWOverrideRedirect
|CWBackPixmap
|CWEventMask
, &wa
);
XDefineCursor(dpy
, m
->barwin
, cursor
[CurNormal
]->cursor
);
XMapRaised(dpy
, m
->barwin
);
XSetClassHint(dpy
, m
->barwin
, &ch
);
m
->by
= m
->topbar
? m
->wy
: m
->wy
+ m
->wh
;
m
->wy
= m
->topbar
? m
->wy
+ bh
: m
->wy
;
XDeleteProperty(dpy
, root
, netatom
[NetClientList
]);
for (m
= mons
; m
; m
= m
->next
)
for (c
= m
->clients
; c
; c
= c
->next
)
XChangeProperty(dpy
, root
, netatom
[NetClientList
],
XA_WINDOW
, 32, PropModeAppend
,
(unsigned char *) &(c
->win
), 1);
if (XineramaIsActive(dpy
)) {
XineramaScreenInfo
*info
= XineramaQueryScreens(dpy
, &nn
);
XineramaScreenInfo
*unique
= NULL
;
for (n
= 0, m
= mons
; m
; m
= m
->next
, n
++);
/* only consider unique geometries as separate screens */
unique
= ecalloc(nn
, sizeof(XineramaScreenInfo
));
for (i
= 0, j
= 0; i
< nn
; i
++)
if (isuniquegeom(unique
, j
, &info
[i
]))
memcpy(&unique
[j
++], &info
[i
], sizeof(XineramaScreenInfo
));
/* new monitors if nn > n */
for (i
= n
; i
< nn
; i
++) {
for (m
= mons
; m
&& m
->next
; m
= m
->next
);
for (i
= 0, m
= mons
; i
< nn
&& m
; m
= m
->next
, i
++)
|| unique
[i
].x_org
!= m
->mx
|| unique
[i
].y_org
!= m
->my
|| unique
[i
].width
!= m
->mw
|| unique
[i
].height
!= m
->mh
)
m
->mx
= m
->wx
= unique
[i
].x_org
;
m
->my
= m
->wy
= unique
[i
].y_org
;
m
->mw
= m
->ww
= unique
[i
].width
;
m
->mh
= m
->wh
= unique
[i
].height
;
/* removed monitors if n > nn */
for (i
= nn
; i
< n
; i
++) {
for (m
= mons
; m
&& m
->next
; m
= m
->next
);
while ((c
= m
->clients
)) {
{ /* default monitor setup */
if (mons
->mw
!= sw
|| mons
->mh
!= sh
) {
mons
->mw
= mons
->ww
= sw
;
mons
->mh
= mons
->wh
= sh
;
modmap
= XGetModifierMapping(dpy
);
for (j
= 0; j
< modmap
->max_keypermod
; j
++)
if (modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
]
== XKeysymToKeycode(dpy
, XK_Num_Lock
))
XFreeModifiermap(modmap
);
updatesizehints(Client
*c
)
if (!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
))
/* size is uninitialized, ensure that size.flags aren't used */
if (size
.flags
& PBaseSize
) {
c
->basew
= size
.base_width
;
c
->baseh
= size
.base_height
;
} else if (size
.flags
& PMinSize
) {
c
->basew
= size
.min_width
;
c
->baseh
= size
.min_height
;
if (size
.flags
& PResizeInc
) {
c
->incw
= size
.width_inc
;
c
->inch
= size
.height_inc
;
if (size
.flags
& PMaxSize
) {
c
->maxw
= size
.max_width
;
c
->maxh
= size
.max_height
;
if (size
.flags
& PMinSize
) {
c
->minw
= size
.min_width
;
c
->minh
= size
.min_height
;
} else if (size
.flags
& PBaseSize
) {
c
->minw
= size
.base_width
;
c
->minh
= size
.base_height
;
if (size
.flags
& PAspect
) {
c
->mina
= (float)size
.min_aspect
.y
/ size
.min_aspect
.x
;
c
->maxa
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
c
->isfixed
= (c
->maxw
&& c
->maxh
&& c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
);
if (!gettextprop(root
, XA_WM_NAME
, stext
, sizeof(stext
)))
strcpy(stext
, "dwm-"VERSION
);
if (!gettextprop(c
->win
, netatom
[NetWMName
], c
->name
, sizeof c
->name
))
gettextprop(c
->win
, XA_WM_NAME
, c
->name
, sizeof c
->name
);
if (c
->name
[0] == '\0') /* hack to mark broken clients */
updatewindowtype(Client
*c
)
Atom state
= getatomprop(c
, netatom
[NetWMState
]);
Atom wtype
= getatomprop(c
, netatom
[NetWMWindowType
]);
if (state
== netatom
[NetWMFullscreen
])
if (wtype
== netatom
[NetWMWindowTypeDialog
])
if ((wmh
= XGetWMHints(dpy
, c
->win
))) {
if (c
== selmon
->sel
&& wmh
->flags
& XUrgencyHint
) {
wmh
->flags
&= ~XUrgencyHint
;
XSetWMHints(dpy
, c
->win
, wmh
);
c
->isurgent
= (wmh
->flags
& XUrgencyHint
) ? 1 : 0;
if (wmh
->flags
& InputHint
)
c
->neverfocus
= !wmh
->input
;
if(arg
->ui
&& (arg
->ui
& TAGMASK
) == selmon
->tagset
[selmon
->seltags
])
selmon
->seltags
^= 1; /* toggle sel tagset */
selmon
->tagset
[selmon
->seltags
] = arg
->ui
& TAGMASK
;
for (m
= mons
; m
; m
= m
->next
)
for (c
= m
->clients
; c
; c
= c
->next
)
if (w
== root
&& getrootptr(&x
, &y
))
return recttomon(x
, y
, 1, 1);
for (m
= mons
; m
; m
= m
->next
)
if ((c
= wintoclient(w
)))
/* There's no way to check accesses to destroyed windows, thus those cases are
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
* default error handler, which may call exit. */
xerror(Display
*dpy
, XErrorEvent
*ee
)
if (ee
->error_code
== BadWindow
|| (ee
->request_code
== X_SetInputFocus
&& ee
->error_code
== BadMatch
)
|| (ee
->request_code
== X_PolyText8
&& ee
->error_code
== BadDrawable
)
|| (ee
->request_code
== X_PolyFillRectangle
&& ee
->error_code
== BadDrawable
)
|| (ee
->request_code
== X_PolySegment
&& ee
->error_code
== BadDrawable
)
|| (ee
->request_code
== X_ConfigureWindow
&& ee
->error_code
== BadMatch
)
|| (ee
->request_code
== X_GrabButton
&& ee
->error_code
== BadAccess
)
|| (ee
->request_code
== X_GrabKey
&& ee
->error_code
== BadAccess
)
|| (ee
->request_code
== X_CopyArea
&& ee
->error_code
== BadDrawable
))
fprintf(stderr
, "dwm: fatal error: request code=%d, error code=%d\n",
ee
->request_code
, ee
->error_code
);
return xerrorxlib(dpy
, ee
); /* may call exit */
xerrordummy(Display
*dpy
, XErrorEvent
*ee
)
/* Startup Error handler to check if another window manager
xerrorstart(Display
*dpy
, XErrorEvent
*ee
)
die("dwm: another window manager is already running");
if (!selmon
->lt
[selmon
->sellt
]->arrange
|| !c
|| c
->isfloating
)
if (c
== nexttiled(selmon
->clients
) && !(c
= nexttiled(c
->next
)))
main(int argc
, char *argv
[])
if (argc
== 2 && !strcmp("-v", argv
[1]))
if (!setlocale(LC_CTYPE
, "") || !XSupportsLocale())
fputs("warning: no locale support\n", stderr
);
if (!(dpy
= XOpenDisplay(NULL
)))
die("dwm: cannot open display");
if (pledge("stdio rpath proc exec", NULL
) == -1)