summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c88
1 files changed, 69 insertions, 19 deletions
diff --git a/dwm.c b/dwm.c
index c1e7f8f..780be02 100644
--- a/dwm.c
+++ b/dwm.c
@@ -53,15 +53,21 @@
/* 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 ISINC(X) ((X) > 1000 && (X) < 3000)
#define ISVISIBLE(C) ((C->tags & 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 */
@@ -204,6 +210,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);
@@ -224,6 +231,7 @@ static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void sigchld(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 togglebar(const Arg *arg);
@@ -1049,27 +1057,16 @@ focusmon(const Arg *arg)
void
focusstack(const Arg *arg)
{
- 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);
}
Atom
@@ -1467,6 +1464,29 @@ 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)
{
running = 0;
@@ -1874,6 +1894,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)
{