smfact patch

This commit is contained in:
Jakub 2024-05-14 22:18:49 -04:00
parent f533b4ed35
commit 8b5f4911c1
3 changed files with 159 additions and 5 deletions

View File

@ -4,6 +4,7 @@
static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */ static const unsigned int snap = 32; /* snap pixel */
static const int swallowfloating = 0; /* 1 means swallow floating windows by default */ static const int swallowfloating = 0; /* 1 means swallow floating windows by default */
static const unsigned int minwsz = 20; /* Minimal heigt of a client for smfact */
static const int showbar = 1; /* 0 means no standard bar */ static const int showbar = 1; /* 0 means no standard bar */
static const int topbar = 1; /* 0 means standard bar at bottom */ static const int topbar = 1; /* 0 means standard bar at bottom */
static const int extrabar = 1; /* 0 means no extra bar */ static const int extrabar = 1; /* 0 means no extra bar */
@ -51,6 +52,7 @@ static const Rule rules[] = {
#define WFDEFAULT WFINACTIVE #define WFDEFAULT WFINACTIVE
/* layout(s) */ /* layout(s) */
static const float smfact = 0.00; /* factor of tiled clients [0.00..0.95] */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */ static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
@ -94,6 +96,8 @@ static const Key keys[] = {
{ MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY|ShiftMask, XK_h, setsmfact, {.f = +0.05} },
{ MODKEY|ShiftMask, XK_l, setsmfact, {.f = -0.05} },
{ MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} }, { MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} }, { MODKEY|ShiftMask, XK_c, killclient, {0} },

37
dwm.c
View File

@ -80,6 +80,7 @@ typedef union {
int i; int i;
unsigned int ui; unsigned int ui;
float f; float f;
float sf;
const void *v; const void *v;
} Arg; } Arg;
@ -128,6 +129,7 @@ struct Monitor {
char ltsymbol[16]; char ltsymbol[16];
char wfsymbol[2]; char wfsymbol[2];
float mfact; float mfact;
float smfact;
int nmaster; int nmaster;
int num; int num;
int by; /* bar geometry */ int by; /* bar geometry */
@ -232,6 +234,7 @@ static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen); static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg); static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg); static void setmfact(const Arg *arg);
static void setsmfact(const Arg *arg);
static void setup(void); static void setup(void);
static void seturgent(Client *c, int urg); static void seturgent(Client *c, int urg);
static void show(const Arg *arg); static void show(const Arg *arg);
@ -783,6 +786,7 @@ createmon(void)
m = ecalloc(1, sizeof(Monitor)); m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1; m->tagset[0] = m->tagset[1] = 1;
m->mfact = mfact; m->mfact = mfact;
m->smfact = smfact;
m->nmaster = nmaster; m->nmaster = nmaster;
m->showbar = showbar; m->showbar = showbar;
m->topbar = topbar; m->topbar = topbar;
@ -1948,6 +1952,19 @@ setmfact(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
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 void
setup(void) setup(void)
{ {
@ -2170,7 +2187,7 @@ tagmon(const Arg *arg)
void void
tile(Monitor *m) tile(Monitor *m)
{ {
unsigned int i, n, h, mw, my, ty; unsigned int i, n, h, smh, mw, my, ty;
Client *c; Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
@ -2188,9 +2205,25 @@ tile(Monitor *m)
if (my + HEIGHT(c) < m->wh) if (my + HEIGHT(c) < m->wh)
my += HEIGHT(c); my += HEIGHT(c);
} else { } else {
smh = m->mh * m->smfact;
if(!(nexttiled(c->next)))
h = (m->wh - ty) / (n - i); 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); 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), False);
ty -= HEIGHT(c);
}
else
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), False);
if(!(nexttiled(c->next))) {
if (ty + HEIGHT(c) < m->wh) if (ty + HEIGHT(c) < m->wh)
ty += HEIGHT(c) + smh;
}
else if (ty + HEIGHT(c) < m->wh)
ty += HEIGHT(c); ty += HEIGHT(c);
} }
} }

View File

@ -0,0 +1,117 @@
--- config.def.h 2013-04-06 21:01:27.750829760 +0200
+++ config.def.h 2013-04-06 21:02:19.557495556 +0200
@@ -10,6 +10,7 @@ static const char selbgcolor[] = "#
static const char selfgcolor[] = "#eeeeee";
static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
+static const unsigned int minwsz = 20; /* Minimal heigt of a client for smfact */
static const Bool showbar = True; /* False means no bar */
static const Bool topbar = True; /* False means bottom bar */
@@ -24,6 +25,7 @@ static const Rule rules[] = {
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static const float smfact = 0.00; /* factor of tiled clients [0.00..0.95] */
static const int nmaster = 1; /* number of clients in master area */
static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
@@ -60,6 +62,8 @@ static Key keys[] = {
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
+ { MODKEY|ShiftMask, XK_h, setsmfact, {.f = +0.05} },
+ { MODKEY|ShiftMask, XK_l, setsmfact, {.f = -0.05} },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
--- dwm.c 2011-12-19 16:02:46.000000000 +0100
+++ dwm.c 2013-04-06 21:00:46.620830452 +0200
@@ -69,6 +69,7 @@ typedef union {
int i;
unsigned int ui;
float f;
+ float sf;
const void *v;
} Arg;
@@ -127,6 +128,7 @@ typedef struct {
struct Monitor {
char ltsymbol[16];
float mfact;
+ float smfact;
int nmaster;
int num;
int by; /* bar geometry */
@@ -220,6 +222,7 @@ static void setfocus(Client *c);
static void setfullscreen(Client *c, Bool 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 showhide(Client *c);
static void sigchld(int unused);
@@ -651,6 +654,7 @@ createmon(void) {
die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1;
m->mfact = mfact;
+ m->smfact = smfact;
m->nmaster = nmaster;
m->showbar = showbar;
m->topbar = topbar;
@@ -1581,6 +1585,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) {
XSetWindowAttributes wa;
@@ -1703,7 +1720,7 @@ textnw(const char *text, unsigned int le
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++);
@@ -1721,9 +1738,23 @@ tile(Monitor *m) {
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), False);
- 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), False);
+ ty -= HEIGHT(c);
+ }
+ else
+ resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), False);
+ if(!(nexttiled(c->next)))
+ ty += HEIGHT(c) + smh;
+ else
+ ty += HEIGHT(c);
}
}