summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c116
1 files changed, 109 insertions, 7 deletions
diff --git a/dwm.c b/dwm.c
index bd3a526..f58d146 100644
--- a/dwm.c
+++ b/dwm.c
@@ -76,6 +76,7 @@ typedef union {
int i;
unsigned int ui;
float f;
+ float sf;
const void *v;
} Arg;
@@ -121,6 +122,7 @@ typedef struct {
struct Monitor {
char ltsymbol[16];
float mfact;
+ float smfact;
int nmaster;
int num;
int by; /* bar geometry */
@@ -192,6 +194,7 @@ static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
+static void moveresize(const Arg *arg);
static void movemouse(const Arg *arg);
static unsigned int nexttag(void);
static unsigned int prevtag(void);
@@ -217,6 +220,7 @@ 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 setsmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
@@ -228,6 +232,7 @@ 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);
@@ -714,6 +719,7 @@ createmon(void)
m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1;
m->mfact = mfact;
+ m->smfact = smfact;
m->nmaster = nmaster;
m->showbar = showbar;
m->topbar = topbar;
@@ -1309,6 +1315,71 @@ movemouse(const Arg *arg)
}
}
+void
+moveresize(const Arg *arg) {
+ Client *c;
+ c = selmon->sel;
+ int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh;
+ char xAbs, yAbs, wAbs, hAbs;
+ int msx, msy, dx, dy, nmx, nmy;
+ unsigned int dui;
+ Window dummy;
+
+ if (!c || !arg)
+ return;
+ if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
+ return;
+ if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8)
+ return;
+
+ nw = c->w + w;
+ if (wAbs == 'W')
+ nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw;
+
+ nh = c->h + h;
+ if (hAbs == 'H')
+ nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * c->bw;
+
+ nx = c->x + x;
+ if (xAbs == 'X') {
+ if (x < selmon->mx)
+ nx = selmon->mx;
+ else if (x > selmon->mx + selmon->mw)
+ nx = selmon->mx + selmon->mw - nw - 2 * c->bw;
+ else
+ nx = x;
+ }
+
+ ny = c->y + y;
+ if (yAbs == 'Y') {
+ if (y < selmon->my)
+ ny = selmon->my;
+ else if (y > selmon->my + selmon->mh)
+ ny = selmon->my + selmon->mh - nh - 2 * c->bw;
+ else
+ ny = y;
+ }
+
+ ox = c->x;
+ oy = c->y;
+ ow = c->w;
+ oh = c->h;
+
+ XRaiseWindow(dpy, c->win);
+ Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui);
+ resize(c, nx, ny, nw, nh, True);
+
+ /* move cursor along with the window to avoid problems */
+ if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy)
+ {
+ nmx = c->x - ox + c->w - ow;
+ nmy = c->y - oy + c->h - oh;
+ /* make sure the cursor stays inside the window */
+ if ((msx + nmx) > c->x && (msy + nmy) > c->y)
+ XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy);
+ }
+}
+
unsigned int
nexttag(void)
{
@@ -1502,8 +1573,6 @@ resizemouse(const Arg *arg)
handler[ev.type](&ev);
break;
case MotionNotify:
-// nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
-// nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
nw = MAX(ocw + (ev.xmotion.x - x), 1);
nh = MAX(och + (ev.xmotion.y - y), 1);
if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
@@ -1710,6 +1779,19 @@ setmfact(const Arg *arg)
}
void
+setsmfact(const Arg *arg) {
+ float sf;
+
+ if(!arg || !selmon->lt[selmon->sellt]->arrange)
+ return;
+ sf = arg->sf < 1.0 ? arg->sf + selmon->smfact : arg->sf - 1.0;
+ if(sf < 0 || sf > 0.9)
+ return;
+ selmon->smfact = sf;
+ arrange(selmon);
+}
+
+void
setup(void)
{
int i;
@@ -1879,7 +1961,7 @@ tagmon(const Arg *arg)
void
tile(Monitor *m)
{
- unsigned int i, n, h, mw, my, ty;
+ unsigned int i, n, h, smh, mw, my, ty;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
@@ -1897,10 +1979,23 @@ tile(Monitor *m)
if (my + HEIGHT(c) < m->wh)
my += HEIGHT(c);
} else {
- 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)
- ty += HEIGHT(c);
+ smh = m->mh * m->smfact;
+ if(!(nexttiled(c->next)))
+ h = (m->wh - ty) / (n - i);
+ else
+ h = (m->wh - smh - ty) / (n - i);
+ if(h < minwsz) {
+ c->isfloating = True;
+ XRaiseWindow(dpy, c->win);
+ resize(c, m->mx + (m->mw / 2 - WIDTH(c) / 2), m->my + (m->mh / 2 - HEIGHT(c) / 2), m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
+ ty -= HEIGHT(c);
+ }
+ else
+ resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
+ if(!(nexttiled(c->next)))
+ ty += HEIGHT(c) + smh;
+ else
+ ty += HEIGHT(c);
}
}
@@ -1928,6 +2023,13 @@ togglefloating(const Arg *arg)
}
void
+togglefullscr(const Arg *arg)
+{
+ if(selmon->sel)
+ setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
+}
+
+void
toggletag(const Arg *arg)
{
unsigned int newtags;