add simple patches
This commit is contained in:
parent
2b6aad54c3
commit
29597ef4b6
203
dwm.c
203
dwm.c
|
@ -47,19 +47,26 @@
|
|||
/* macros */
|
||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
||||
#define GETINC(X) ((X) - 2000)
|
||||
#define INC(X) ((X) + 2000)
|
||||
#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 ISINC(X) ((X) > 1000 && (X) < 3000)
|
||||
#define ISVISIBLEONTAG(C, T) ((C->tags & T))
|
||||
#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags])
|
||||
#define PREVSEL 3000
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define MOD(N,M) ((N)%(M) < 0 ? (N)%(M) + (M) : (N)%(M))
|
||||
#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)
|
||||
#define TRUNC(X,A,B) (MAX((A), MIN((X), (B))))
|
||||
|
||||
/* enums */
|
||||
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||
enum { SchemeNorm, SchemeSel }; /* color schemes */
|
||||
enum { SchemeNorm, SchemeSel, SchemeStatus, SchemeTagsSel, SchemeTagsNorm, SchemeInfoSel, SchemeInfoNorm }; /* color schemes */
|
||||
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
||||
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
||||
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
||||
|
@ -147,6 +154,7 @@ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interac
|
|||
static void arrange(Monitor *m);
|
||||
static void arrangemon(Monitor *m);
|
||||
static void attach(Client *c);
|
||||
static void attachtop(Client *c);
|
||||
static void attachstack(Client *c);
|
||||
static void bstack(Monitor *m);
|
||||
static void bstackhoriz(Monitor *m);
|
||||
|
@ -192,6 +200,7 @@ static void movemouse(const Arg *arg);
|
|||
static Client *nexttiled(Client *c);
|
||||
static void pop(Client *c);
|
||||
static void propertynotify(XEvent *e);
|
||||
static void pushstack(const Arg *arg);
|
||||
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);
|
||||
|
@ -210,12 +219,16 @@ static void setmfact(const Arg *arg);
|
|||
static void setup(void);
|
||||
static void seturgent(Client *c, int urg);
|
||||
static void showhide(Client *c);
|
||||
static void sighup(int unused);
|
||||
static void sigterm(int unused);
|
||||
static void spawn(const Arg *arg);
|
||||
static int stackpos(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 togglefullscr(const Arg *arg);
|
||||
static void toggletag(const Arg *arg);
|
||||
static void toggleview(const Arg *arg);
|
||||
static void unfocus(Client *c, int setfocus);
|
||||
|
@ -265,6 +278,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
|
|||
[UnmapNotify] = unmapnotify
|
||||
};
|
||||
static Atom wmatom[WMLast], netatom[NetLast];
|
||||
static int restart = 0;
|
||||
static int running = 1;
|
||||
static Cur *cursor[CurLast];
|
||||
static Clr **scheme;
|
||||
|
@ -413,6 +427,25 @@ attach(Client *c)
|
|||
c->mon->clients = c;
|
||||
}
|
||||
|
||||
void
|
||||
attachtop(Client *c)
|
||||
{
|
||||
int n;
|
||||
Monitor *m = selmon;
|
||||
Client *below;
|
||||
|
||||
for (n = 1, below = c->mon->clients;
|
||||
below && below->next && (below->isfloating || !ISVISIBLEONTAG(below, c->tags) || n != m->nmaster);
|
||||
n = below->isfloating || !ISVISIBLEONTAG(below, c->tags) ? n + 0 : n + 1, below = below->next);
|
||||
c->next = NULL;
|
||||
if (below) {
|
||||
c->next = below->next;
|
||||
below->next = c;
|
||||
}
|
||||
else
|
||||
c->mon->clients = c;
|
||||
}
|
||||
|
||||
void
|
||||
attachstack(Client *c)
|
||||
{
|
||||
|
@ -500,9 +533,15 @@ buttonpress(XEvent *e)
|
|||
}
|
||||
if (ev->window == selmon->barwin) {
|
||||
i = x = 0;
|
||||
do
|
||||
unsigned int occ = 0;
|
||||
for(c = m->clients; c; c=c->next)
|
||||
occ |= c->tags;
|
||||
do {
|
||||
/* Do not reserve space for vacant tags */
|
||||
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||
continue;
|
||||
x += TEXTW(tags[i]);
|
||||
while (ev->x >= x && ++i < LENGTH(tags));
|
||||
} while (ev->x >= x && ++i < LENGTH(tags));
|
||||
if (i < LENGTH(tags)) {
|
||||
click = ClkTagBar;
|
||||
arg.ui = 1 << i;
|
||||
|
@ -879,7 +918,7 @@ drawbar(Monitor *m)
|
|||
|
||||
/* 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]);
|
||||
drw_setscheme(drw, scheme[SchemeStatus]);
|
||||
tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
|
||||
drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
|
||||
}
|
||||
|
@ -891,22 +930,21 @@ drawbar(Monitor *m)
|
|||
}
|
||||
x = 0;
|
||||
for (i = 0; i < LENGTH(tags); i++) {
|
||||
/* Do not draw vacant tags */
|
||||
if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||
continue;
|
||||
w = TEXTW(tags[i]);
|
||||
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
|
||||
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeTagsSel : SchemeTagsNorm]);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
|
||||
if (occ & 1 << i)
|
||||
drw_rect(drw, x + boxs, boxs, boxw, boxw,
|
||||
m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
||||
urg & 1 << i);
|
||||
x += w;
|
||||
}
|
||||
w = TEXTW(m->ltsymbol);
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_setscheme(drw, scheme[SchemeTagsNorm]);
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
|
||||
|
||||
if ((w = m->ww - tw - x) > bh) {
|
||||
if (m->sel) {
|
||||
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||||
drw_setscheme(drw, scheme[m == selmon ? SchemeInfoSel : SchemeInfoNorm]);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
|
||||
if (m->sel->isfloating)
|
||||
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
|
||||
|
@ -1008,27 +1046,17 @@ focusmon(const Arg *arg)
|
|||
void
|
||||
focusstack(const Arg *arg)
|
||||
{
|
||||
Client *c = NULL, *i;
|
||||
// Client *c = NULL, *i;
|
||||
int i = stackpos(arg);
|
||||
Client *c, *p;
|
||||
|
||||
if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
|
||||
if (i < 0 || (selmon->sel->isfullscreen && lockfullscreen))
|
||||
return;
|
||||
if (arg->i > 0) {
|
||||
for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
|
||||
if (!c)
|
||||
for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
|
||||
} else {
|
||||
for (i = selmon->clients; i != selmon->sel; i = i->next)
|
||||
if (ISVISIBLE(i))
|
||||
c = i;
|
||||
if (!c)
|
||||
for (; i; i = i->next)
|
||||
if (ISVISIBLE(i))
|
||||
c = i;
|
||||
}
|
||||
if (c) {
|
||||
focus(c);
|
||||
restack(selmon);
|
||||
}
|
||||
|
||||
for(p = NULL, c = selmon->clients; c && (i || !ISVISIBLE(c));
|
||||
i -= ISVISIBLE(c) ? 1 : 0, p = c, c = c->next);
|
||||
focus(c ? c : p);
|
||||
restack(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1280,7 +1308,7 @@ manage(Window w, XWindowAttributes *wa)
|
|||
c->isfloating = c->oldstate = trans != None || c->isfixed;
|
||||
if (c->isfloating)
|
||||
XRaiseWindow(dpy, c->win);
|
||||
attach(c);
|
||||
attachtop(c);
|
||||
attachstack(c);
|
||||
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||||
(unsigned char *) &(c->win), 1);
|
||||
|
@ -1461,9 +1489,33 @@ propertynotify(XEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
pushstack(const Arg *arg) {
|
||||
int i = stackpos(arg);
|
||||
Client *sel = selmon->sel, *c, *p;
|
||||
|
||||
if(i < 0)
|
||||
return;
|
||||
else if(i == 0) {
|
||||
detach(sel);
|
||||
attach(sel);
|
||||
}
|
||||
else {
|
||||
for(p = NULL, c = selmon->clients; c; p = c, c = c->next)
|
||||
if(!(i -= (ISVISIBLE(c) && c != sel)))
|
||||
break;
|
||||
c = c ? c : p;
|
||||
detach(sel);
|
||||
sel->next = c->next;
|
||||
c->next = sel;
|
||||
}
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
quit(const Arg *arg)
|
||||
{
|
||||
if(arg->i) restart = 1;
|
||||
running = 0;
|
||||
}
|
||||
|
||||
|
@ -1507,9 +1559,14 @@ void
|
|||
resizemouse(const Arg *arg)
|
||||
{
|
||||
int ocx, ocy, nw, nh;
|
||||
int ocx2, ocy2, nx, ny;
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
XEvent ev;
|
||||
int horizcorner, vertcorner;
|
||||
int di;
|
||||
unsigned int dui;
|
||||
Window dummy;
|
||||
Time lasttime = 0;
|
||||
|
||||
if (!(c = selmon->sel))
|
||||
|
@ -1519,10 +1576,18 @@ resizemouse(const Arg *arg)
|
|||
restack(selmon);
|
||||
ocx = c->x;
|
||||
ocy = c->y;
|
||||
ocx2 = c->x + c->w;
|
||||
ocy2 = c->y + c->h;
|
||||
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||||
None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
|
||||
return;
|
||||
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
|
||||
if (!XQueryPointer (dpy, c->win, &dummy, &dummy, &di, &di, &nx, &ny, &dui))
|
||||
return;
|
||||
horizcorner = nx < c->w / 2;
|
||||
vertcorner = ny < c->h / 2;
|
||||
XWarpPointer (dpy, None, c->win, 0, 0, 0, 0,
|
||||
horizcorner ? (-c->bw) : (c->w + c->bw -1),
|
||||
vertcorner ? (-c->bw) : (c->h + c->bw -1));
|
||||
do {
|
||||
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
|
||||
switch(ev.type) {
|
||||
|
@ -1536,8 +1601,11 @@ resizemouse(const Arg *arg)
|
|||
continue;
|
||||
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);
|
||||
nx = horizcorner ? ev.xmotion.x : c->x;
|
||||
ny = vertcorner ? ev.xmotion.y : c->y;
|
||||
nw = MAX(horizcorner ? (ocx2 - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1);
|
||||
nh = MAX(vertcorner ? (ocy2 - ny) : (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)
|
||||
{
|
||||
|
@ -1546,11 +1614,13 @@ resizemouse(const Arg *arg)
|
|||
togglefloating(NULL);
|
||||
}
|
||||
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
|
||||
resize(c, c->x, c->y, nw, nh, 1);
|
||||
resize(c, nx, ny, nw, nh, 1);
|
||||
break;
|
||||
}
|
||||
} while (ev.type != ButtonRelease);
|
||||
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
|
||||
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
|
||||
horizcorner ? (-c->bw) : (c->w + c->bw - 1),
|
||||
vertcorner ? (-c->bw) : (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) {
|
||||
|
@ -1633,7 +1703,7 @@ sendmon(Client *c, Monitor *m)
|
|||
detachstack(c);
|
||||
c->mon = m;
|
||||
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
|
||||
attach(c);
|
||||
attachtop(c);
|
||||
attachstack(c);
|
||||
focus(NULL);
|
||||
arrange(NULL);
|
||||
|
@ -1759,6 +1829,9 @@ setup(void)
|
|||
/* clean up any zombies (inherited from .xinitrc etc) immediately */
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||
|
||||
signal(SIGHUP, sighup);
|
||||
signal(SIGTERM, sigterm);
|
||||
|
||||
/* init screen */
|
||||
screen = DefaultScreen(dpy);
|
||||
sw = DisplayWidth(dpy, screen);
|
||||
|
@ -1850,6 +1923,20 @@ showhide(Client *c)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
sighup(int unused)
|
||||
{
|
||||
Arg a = {.i = 1};
|
||||
quit(&a);
|
||||
}
|
||||
|
||||
void
|
||||
sigterm(int unused)
|
||||
{
|
||||
Arg a = {.i = 0};
|
||||
quit(&a);
|
||||
}
|
||||
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
|
@ -1864,6 +1951,36 @@ spawn(const Arg *arg)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
stackpos(const Arg *arg) {
|
||||
int n, i;
|
||||
Client *c, *l;
|
||||
|
||||
if(!selmon->clients)
|
||||
return -1;
|
||||
|
||||
if(arg->i == PREVSEL) {
|
||||
for(l = selmon->stack; l && (!ISVISIBLE(l) || l == selmon->sel); l = l->snext);
|
||||
if(!l)
|
||||
return -1;
|
||||
for(i = 0, c = selmon->clients; c != l; i += ISVISIBLE(c) ? 1 : 0, c = c->next);
|
||||
return i;
|
||||
}
|
||||
else if(ISINC(arg->i)) {
|
||||
if(!selmon->sel)
|
||||
return -1;
|
||||
for(i = 0, c = selmon->clients; c != selmon->sel; i += ISVISIBLE(c) ? 1 : 0, c = c->next);
|
||||
for(n = i; c; n += ISVISIBLE(c) ? 1 : 0, c = c->next);
|
||||
return MOD(i + GETINC(arg->i), n);
|
||||
}
|
||||
else if(arg->i < 0) {
|
||||
for(i = 0, c = selmon->clients; c; i += ISVISIBLE(c) ? 1 : 0, c = c->next);
|
||||
return MAX(i + arg->i, 0);
|
||||
}
|
||||
else
|
||||
return arg->i;
|
||||
}
|
||||
|
||||
void
|
||||
tag(const Arg *arg)
|
||||
{
|
||||
|
@ -1933,6 +2050,13 @@ togglefloating(const Arg *arg)
|
|||
arrange(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
togglefullscr(const Arg *arg)
|
||||
{
|
||||
if(selmon->sel)
|
||||
setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
|
||||
}
|
||||
|
||||
void
|
||||
toggletag(const Arg *arg)
|
||||
{
|
||||
|
@ -2113,7 +2237,7 @@ updategeom(void)
|
|||
m->clients = c->next;
|
||||
detachstack(c);
|
||||
c->mon = mons;
|
||||
attach(c);
|
||||
attachtop(c);
|
||||
attachstack(c);
|
||||
}
|
||||
if (m == selmon)
|
||||
|
@ -2357,6 +2481,7 @@ main(int argc, char *argv[])
|
|||
#endif /* __OpenBSD__ */
|
||||
scan();
|
||||
run();
|
||||
if(restart) execvp(argv[0], argv);
|
||||
cleanup();
|
||||
XCloseDisplay(dpy);
|
||||
return EXIT_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue