227 lines
6.1 KiB
Plaintext
227 lines
6.1 KiB
Plaintext
--- dwm.c
|
|
+++ dwm.c
|
|
@@ -50,6 +50,7 @@
|
|
#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 HIDDEN(C) ((getstate(C->win) == IconicState))
|
|
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
|
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
|
|
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
|
|
@@ -170,13 +174,17 @@ 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 void focusstackvis(const Arg *arg);
|
|
+static void focusstackhid(const Arg *arg);
|
|
+static void focusstack(int inc, int vis);
|
|
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 hide(const Arg *arg);
|
|
+static void hidewin(Client *c);
|
|
static void incnmaster(const Arg *arg);
|
|
static void keypress(XEvent *e);
|
|
static void killclient(const Arg *arg);
|
|
@@ -447,10 +459,25 @@ buttonpress(XEvent *e)
|
|
arg.ui = 1 << i;
|
|
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
|
|
click = ClkLtSymbol;
|
|
- else if (ev->x > selmon->ww - (int)TEXTW(stext))
|
|
+ /* 2px right padding */
|
|
+ else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
|
|
click = ClkStatusText;
|
|
- else
|
|
- click = ClkWinTitle;
|
|
+ else {
|
|
+ x += TEXTW(selmon->ltsymbol);
|
|
+ c = m->clients;
|
|
+
|
|
+ if (c) {
|
|
+ do {
|
|
+ if (!ISVISIBLE(c))
|
|
+ continue;
|
|
+ else
|
|
+ x +=(1.0 / (double)m->bt) * m->btw;
|
|
+ } while (ev->x > x && (c = c->next));
|
|
+
|
|
+ click = ClkWinTitle;
|
|
+ arg.v = c;
|
|
+ }
|
|
+ }
|
|
} else if ((c = wintoclient(ev->window))) {
|
|
focus(c);
|
|
restack(selmon);
|
|
@@ -704,7 +731,7 @@ dirtomon(int dir)
|
|
void
|
|
drawbar(Monitor *m)
|
|
{
|
|
- int x, w, tw = 0;
|
|
+ int x, w, tw = 0, n = 0, scm;
|
|
int boxs = drw->fonts->h / 9;
|
|
int boxw = drw->fonts->h / 6 + 2;
|
|
unsigned int i, occ = 0, urg = 0;
|
|
@@ -743,16 +772,36 @@ drawbar(Monitor *m)
|
|
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_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);
|
|
+ if (n > 0) {
|
|
+ int remainder = w % n;
|
|
+ int tabw = (1.0 / (double)n) * w + 1;
|
|
+ for (c = m->clients; c; c = c->next) {
|
|
+ if (!ISVISIBLE(c))
|
|
+ continue;
|
|
+ if (m->sel == c)
|
|
+ scm = SchemeSel;
|
|
+ else if (HIDDEN(c))
|
|
+ scm = SchemeHid;
|
|
+ else
|
|
+ scm = SchemeNorm;
|
|
+ drw_setscheme(drw, scheme[scm]);
|
|
+
|
|
+ if (remainder >= 0) {
|
|
+ if (remainder == 0) {
|
|
+ tabw--;
|
|
+ }
|
|
+ remainder--;
|
|
+ }
|
|
+ drw_text(drw, x, 0, tabw, bh, lrpad / 2, c->name, 0);
|
|
+ x += tabw;
|
|
+ }
|
|
} else {
|
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
|
drw_rect(drw, x, 0, w, bh, 1, 1);
|
|
}
|
|
}
|
|
+ m->bt = n;
|
|
+ m->btw = w;
|
|
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
|
|
}
|
|
|
|
@@ -798,9 +847,17 @@ void
|
|
focus(Client *c)
|
|
{
|
|
if (!c || !ISVISIBLE(c))
|
|
- for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
|
|
- if (selmon->sel && selmon->sel != c)
|
|
+ for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext);
|
|
+ if (selmon->sel && selmon->sel != c) {
|
|
unfocus(selmon->sel, 0);
|
|
+
|
|
+ if (selmon->hidsel) {
|
|
+ hidewin(selmon->sel);
|
|
+ if (c)
|
|
+ arrange(c->mon);
|
|
+ selmon->hidsel = 0;
|
|
+ }
|
|
+ }
|
|
if (c) {
|
|
if (c->mon != selmon)
|
|
selmon = c->mon;
|
|
@@ -844,28 +901,52 @@ focusmon(const Arg *arg)
|
|
}
|
|
|
|
void
|
|
-focusstack(const Arg *arg)
|
|
+focusstackvis(const Arg *arg) {
|
|
+ focusstack(arg->i, 0);
|
|
+}
|
|
+
|
|
+void
|
|
+focusstackhid(const Arg *arg) {
|
|
+ focusstack(arg->i, 1);
|
|
+}
|
|
+
|
|
+void
|
|
+focusstack(int inc, int hid)
|
|
{
|
|
Client *c = NULL, *i;
|
|
-
|
|
- if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
|
|
+ // if no client selected AND exclude hidden client; if client selected but fullscreened
|
|
+ if ((!selmon->sel && !hid) || (selmon->sel && selmon->sel->isfullscreen && lockfullscreen))
|
|
return;
|
|
- if (arg->i > 0) {
|
|
- for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
|
|
+ if (!selmon->clients)
|
|
+ return;
|
|
+ if (inc > 0) {
|
|
+ if (selmon->sel)
|
|
+ for (c = selmon->sel->next;
|
|
+ c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
|
|
+ c = c->next);
|
|
if (!c)
|
|
- for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
|
|
+ for (c = selmon->clients;
|
|
+ c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
|
|
+ c = c->next);
|
|
} else {
|
|
- for (i = selmon->clients; i != selmon->sel; i = i->next)
|
|
- if (ISVISIBLE(i))
|
|
- c = i;
|
|
+ if (selmon->sel) {
|
|
+ for (i = selmon->clients; i != selmon->sel; i = i->next)
|
|
+ if (ISVISIBLE(i) && !(!hid && HIDDEN(i)))
|
|
+ c = i;
|
|
+ } else
|
|
+ c = selmon->clients;
|
|
if (!c)
|
|
for (; i; i = i->next)
|
|
- if (ISVISIBLE(i))
|
|
+ if (ISVISIBLE(i) && !(!hid && HIDDEN(i)))
|
|
c = i;
|
|
}
|
|
if (c) {
|
|
focus(c);
|
|
restack(selmon);
|
|
+ if (HIDDEN(c)) {
|
|
+ showwin(c);
|
|
+ c->mon->hidsel = 1;
|
|
+ }
|
|
}
|
|
}
|
|
|
|
@@ -1117,12 +1228,14 @@ manage(Window w, XWindowAttributes *wa)
|
|
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);
|
|
+ if (!HIDDEN(c))
|
|
+ setclientstate(c, NormalState);
|
|
if (c->mon == selmon)
|
|
unfocus(selmon->sel, 0);
|
|
c->mon->sel = c;
|
|
arrange(c->mon);
|
|
- XMapWindow(dpy, c->win);
|
|
+ if (!HIDDEN(c))
|
|
+ XMapWindow(dpy, c->win);
|
|
focus(NULL);
|
|
}
|
|
|
|
@@ -1296,6 +1409,16 @@ propertynotify(XEvent *e)
|
|
void
|
|
quit(const Arg *arg)
|
|
{
|
|
+ // fix: reloading dwm keeps all the hidden clients hidden
|
|
+ Monitor *m;
|
|
+ Client *c;
|
|
+ for (m = mons; m; m = m->next) {
|
|
+ if (m) {
|
|
+ for (c = m->stack; c; c = c->next)
|
|
+ if (c && HIDDEN(c)) showwin(c);
|
|
+ }
|
|
+ }
|
|
+
|
|
running = 0;
|
|
}
|
|
|