Hi,
While porting Michael Elkins's ntile() implementation to 5.4.1, I noticed
that it is actually shorter than vanilla tile()!
It would however be useless without the setnmaster() function clocking in
at 13 LOC, same as setmfact(). But the two have most of their code in common:
1. Verify layout != floating
2. Verify arg is within bounds
3. Set global variable (relatively or absolutely)
4. Call arrange()
How about:
enum { Abs, Rel };
void
tweak(int *var, const int *val, int min, int max) {
int i;
i = val[1] + (val[0] == Abs ? 0 : *var);
if(!lt[sellt]->arrange || i < min || i > max)
return;
*var = i;
arrange();
}
Previously setmfact():
void
tweakmwp(const Arg *arg) {
tweak(&mwp, arg->v, 5, 95);
}
Previously setnmaster():
void
tweakmn(const Arg *arg) {
tweak(&mn, arg->v, 1, wh / (1 + 2 * borderpx));
}
Configuration example:
static int mwp = 55; /* master area width percentage [5..95] */
static int mn = 1; /* number of clients in master area */
[...]
{ MODKEY, XK_h, tweakmwp, {.v = (int[]){Rel, -10}} },
{ MODKEY|ShiftMask, XK_n, tweakmn, {.v = (int[]){Abs, 2}} },
A complete patch to dwm.c and config.def.h is attached. LOC # (including
the new mn feature) stays about the same if you account for the fact that
more (but much smaller) functions are penalized by whitespace, braces, and
forward declarations.
Note that the patch is on top of my last two patches from the virtual
keyboards thread. It also corrects a discrepancy between documentation and
code: mfact was described as [0.05..0.95], but was actually [0.1..0.9].
Regards,
Peter
This archive was generated by hypermail 2.2.0 : Wed Feb 11 2009 - 02:12:03 UTC