removed VRATIO, NMASTER, inc*(), renamed HRATIO into MASTER, see mailinglist for details

new_dwm
Anselm R. Garbe 18 years ago
parent 4216bf801f
commit aa53e39ec0

@ -230,7 +230,7 @@ manage(Window w, XWindowAttributes *wa) {
setclientstate(c, IconicState); setclientstate(c, IconicState);
c->isbanned = True; c->isbanned = True;
focus(c); focus(c);
lt->arrange(); lt->arrange(NULL);
} }
void void
@ -305,7 +305,7 @@ togglefloating(const char *arg) {
sel->isfloating = !sel->isfloating; sel->isfloating = !sel->isfloating;
if(sel->isfloating) if(sel->isfloating)
resize(sel, sel->x, sel->y, sel->w, sel->h, True); resize(sel, sel->x, sel->y, sel->w, sel->h, True);
lt->arrange(); lt->arrange(NULL);
} }
void void
@ -337,7 +337,7 @@ unmanage(Client *c) {
XSync(dpy, False); XSync(dpy, False);
XSetErrorHandler(xerror); XSetErrorHandler(xerror);
XUngrabServer(dpy); XUngrabServer(dpy);
lt->arrange(); lt->arrange(NULL);
} }
void void

@ -24,15 +24,14 @@ static Rule rule[] = { \
}; };
/* layout(s) */ /* layout(s) */
void tile(const char *arg); /* arranges all windows tiled */
#define LAYOUTS \ #define LAYOUTS \
static Layout layout[] = { \ static Layout layout[] = { \
/* symbol function */ \ /* symbol function */ \
{ "[]=", tile }, /* first entry is default */ \ { "[]=", tile }, /* first entry is default */ \
{ "><>", floating }, \ { "><>", floating }, \
}; };
#define NMASTER 1 /* clients in master area */ #define MASTER 0.6 /* 0.1 .. 0.9 */
#define HRATIO .8 /* horizontal ratio of tile */
#define VRATIO .9 /* vertical ratio of tile */
#define SNAP 32 /* snap pixel */ #define SNAP 32 /* snap pixel */
/* key definitions */ /* key definitions */
@ -47,14 +46,10 @@ static Key key[] = { \
"exec urxvtcd -tr -bg '#111' -fg '#eee' -cr '#eee' +sb -fn '"FONT"'" }, \ "exec urxvtcd -tr -bg '#111' -fg '#eee' -cr '#eee' +sb -fn '"FONT"'" }, \
{ MODKEY, XK_space, setlayout, NULL }, \ { MODKEY, XK_space, setlayout, NULL }, \
{ MODKEY, XK_b, togglebar, NULL }, \ { MODKEY, XK_b, togglebar, NULL }, \
{ MODKEY, XK_h, incnmaster, "1" }, \ { MODKEY, XK_h, tile, "-0.05" }, \
{ MODKEY, XK_l, incnmaster, "-1" }, \
{ MODKEY, XK_j, focusclient, "1" }, \ { MODKEY, XK_j, focusclient, "1" }, \
{ MODKEY, XK_k, focusclient, "-1" }, \ { MODKEY, XK_k, focusclient, "-1" }, \
{ MODKEY|ShiftMask, XK_h, inchratio, ".1" }, \ { MODKEY, XK_l, tile, "0.05" }, \
{ MODKEY|ShiftMask, XK_l, inchratio, "-.1" }, \
{ MODKEY|ShiftMask, XK_j, incvratio, "-.1" }, \
{ MODKEY|ShiftMask, XK_k, incvratio, ".1" }, \
{ MODKEY, XK_m, togglemax, NULL }, \ { MODKEY, XK_m, togglemax, NULL }, \
{ MODKEY, XK_Return, zoom, NULL }, \ { MODKEY, XK_Return, zoom, NULL }, \
{ MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \ { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \

@ -25,15 +25,14 @@ static Rule rule[] = { \
}; };
/* layout(s) */ /* layout(s) */
void tile(const char *arg); /* arranges all windows tiled */
#define LAYOUTS \ #define LAYOUTS \
static Layout layout[] = { \ static Layout layout[] = { \
/* symbol function */ \ /* symbol function */ \
{ "[]=", tile }, /* first entry is default */ \ { "[]=", tile }, /* first entry is default */ \
{ "><>", floating }, \ { "><>", floating }, \
}; };
#define NMASTER 1 /* clients in master area */ #define MASTER 0.6 /* 0.1 .. 0.9 */
#define HRATIO .8 /* horizontal ratio of tile */
#define VRATIO 1 /* vertical ratio of tile */
#define SNAP 32 /* snap pixel */ #define SNAP 32 /* snap pixel */
/* key definitions */ /* key definitions */
@ -45,14 +44,10 @@ static Key key[] = { \
{ MODKEY, XK_p, spawn, "exe=`dmenu_path | dmenu` && exec $exe" }, \ { MODKEY, XK_p, spawn, "exe=`dmenu_path | dmenu` && exec $exe" }, \
{ MODKEY, XK_space, setlayout, NULL }, \ { MODKEY, XK_space, setlayout, NULL }, \
{ MODKEY, XK_b, togglebar, NULL }, \ { MODKEY, XK_b, togglebar, NULL }, \
{ MODKEY, XK_h, incnmaster, "1" }, \ { MODKEY, XK_h, tile, "-0.05" }, \
{ MODKEY, XK_l, incnmaster, "-1" }, \
{ MODKEY, XK_j, focusclient, "1" }, \ { MODKEY, XK_j, focusclient, "1" }, \
{ MODKEY, XK_k, focusclient, "-1" }, \ { MODKEY, XK_k, focusclient, "-1" }, \
{ MODKEY|ShiftMask, XK_h, inchratio, ".1" }, \ { MODKEY, XK_l, tile, "0.05" }, \
{ MODKEY|ShiftMask, XK_l, inchratio, "-.1" }, \
{ MODKEY|ShiftMask, XK_j, incvratio, "-.1" }, \
{ MODKEY|ShiftMask, XK_k, incvratio, ".1" }, \
{ MODKEY, XK_m, togglemax, NULL }, \ { MODKEY, XK_m, togglemax, NULL }, \
{ MODKEY, XK_Return, zoom, NULL }, \ { MODKEY, XK_Return, zoom, NULL }, \
{ MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \ { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \

22
dwm.1

@ -10,7 +10,7 @@ floating layouts. Either layout can be applied dynamically, optimizing the
environment for the application in use and the task performed. environment for the application in use and the task performed.
.P .P
In tiled layout windows are managed in a master and stacking area. The master In tiled layout windows are managed in a master and stacking area. The master
area contains the windows which currently need most attention, whereas the area contains the window which currently needs most attention, whereas the
stacking area contains all other windows. In floating layout windows can be stacking area contains all other windows. In floating layout windows can be
resized and moved freely. Dialog windows are always managed floating, resized and moved freely. Dialog windows are always managed floating,
regardless of the layout applied. regardless of the layout applied.
@ -62,29 +62,17 @@ Zooms/cycles current window to/from master area (tiled layout only).
.B Mod1\-b .B Mod1\-b
Shows/hides the status bar. Shows/hides the status bar.
.TP .TP
.B Mod1\-h
Decreases the master area width about 5% (tiled layout only).
.TP
.B Mod1\-j .B Mod1\-j
Focus next window. Focus next window.
.TP .TP
.B Mod1\-k .B Mod1\-k
Focus previous window. Focus previous window.
.TP .TP
.B Mod1\-h
Increase the number of windows in the master area (tiled layout only).
.TP
.B Mod1\-l .B Mod1\-l
Decrease the number of windows in the master area (tiled layout only). Increases the master area width about 5% (tiled layout only).
.TP
.B Mod1\-Shift\-k
Increase vertical tile ratio, effects tile heights (tiled layout only).
.TP
.B Mod1\-Shift\-j
Decrease vertical tile ratio, effects tile heights (tiled layout only).
.TP
.B Mod1\-Shift\-h
Increase horizontal tile ratio, effects master area width (tiled layout only).
.TP
.B Mod1\-Shift\-l
Decrease horizontal tile ratio, effects master area width (tiled layout only).
.TP .TP
.B Mod1\-m .B Mod1\-m
Toggles maximization of current window (floating layout only). Toggles maximization of current window (floating layout only).

@ -76,7 +76,7 @@ typedef struct {
typedef struct { typedef struct {
const char *symbol; const char *symbol;
void (*arrange)(void); void (*arrange)(const char *);
} Layout; } Layout;
extern const char *tags[]; /* all tags */ extern const char *tags[]; /* all tags */
@ -120,11 +120,8 @@ unsigned int textw(const char *text); /* return the width of text in px*/
void grabkeys(void); /* grab all keys defined in config.h */ void grabkeys(void); /* grab all keys defined in config.h */
/* layout.c */ /* layout.c */
void floating(void); /* arranges all windows floating */ void floating(const char *arg); /* arranges all windows floating */
void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */ void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */
void inchratio(const char *arg); /* increments the horizontal tile ratio with arg's value */
void incvratio(const char *arg); /* increments the vertical tile ratio with arg's value */
void incnmaster(const char *arg); /* increments nmaster with arg's index value */
void initlayouts(void); /* initialize layout array */ void initlayouts(void); /* initialize layout array */
Client *nexttiled(Client *c); /* returns tiled successor of c */ Client *nexttiled(Client *c); /* returns tiled successor of c */
void restack(void); /* restores z layers of all clients */ void restack(void); /* restores z layers of all clients */

@ -216,7 +216,7 @@ configurenotify(XEvent *e) {
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
XResizeWindow(dpy, barwin, sw, bh); XResizeWindow(dpy, barwin, sw, bh);
updatebarpos(); updatebarpos();
lt->arrange(); lt->arrange(NULL);
} }
} }
@ -317,7 +317,7 @@ propertynotify(XEvent *e) {
case XA_WM_TRANSIENT_FOR: case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans); XGetTransientForHint(dpy, c->win, &trans);
if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
lt->arrange(); lt->arrange(NULL);
break; break;
case XA_WM_NORMAL_HINTS: case XA_WM_NORMAL_HINTS:
updatesizehints(c); updatesizehints(c);

@ -8,131 +8,19 @@ Layout *lt = NULL;
/* static */ /* static */
static double hratio = HRATIO;
static double vratio = VRATIO;
static unsigned int nlayouts = 0; static unsigned int nlayouts = 0;
static unsigned int nmaster = NMASTER;
static double /* simple pow() */
spow(double x, double y)
{
if(y == 0)
return 1;
while(--y)
x *= x;
return x;
}
static void
tile(void) {
Bool mmaxtile = False, smaxtile = False; /* fallback tiling */
double mscale = 0, sscale = 0, sum = 0;
unsigned int i, n, nx, ny, nw, nh, mw, tw;
Client *c;
/* preparation */
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
n++;
nx = wax;
ny = way;
mw = (n <= nmaster) ? waw : waw / (1 + hratio);
tw = waw - mw;
if(n > 0) {
if(n <= nmaster) {
for(i = 0; i < n; i++)
sum += spow(vratio, i);
mscale = wah / sum;
if(vratio >= 1)
mmaxtile = bh > mscale;
else
mmaxtile = bh > (mscale * spow(vratio, n - 1));
}
else {
for(i = 0; i < nmaster; i++)
sum += spow(vratio, i);
mscale = wah / sum;
for(sum = 0, i = 0; i < (n - nmaster); i++)
sum += spow(vratio, i);
sscale = wah / sum;
if(vratio >= 1) {
mmaxtile = bh > mscale;
smaxtile = bh > sscale;
}
else {
mmaxtile = bh > (mscale * spow(vratio, nmaster - 1));
smaxtile = bh > (sscale * spow(vratio, n - nmaster - 1));
}
}
}
/* tiling */
for(i = 0, c = clients; c; c = c->next)
if(isvisible(c)) {
unban(c);
if(c->isfloating)
continue;
c->ismax = False;
if(i < nmaster) { /* master window */
nw = mw - 2 * c->border;
if(mmaxtile) {
ny = way;
nh = wah - 2 * c->border;
}
else if(i + 1 == (n < nmaster ? n : nmaster))
nh = (way + wah) - ny - 2 * c->border;
else
nh = (mscale * spow(vratio, i)) - 2 * c->border;
}
else { /* tile window */
nw = tw - 2 * c->border;
if(i == nmaster) {
ny = way;
nx = wax + mw;
}
if(smaxtile) {
ny = way;
nh = wah - 2 * c->border;
}
else if(i + 1 == n)
nh = (way + wah) - ny - 2 * c->border;
else
nh = (sscale * spow(vratio, i - nmaster)) - 2 * c->border;
}
resize(c, nx, ny, nw, nh, False);
ny += nh;
i++;
}
else
ban(c);
focus(NULL);
restack();
}
LAYOUTS LAYOUTS
static void
incratio(const char *arg, double *ratio, double def) {
double delta;
if(lt->arrange != tile)
return;
if(!arg)
*ratio = def;
else {
if(1 == sscanf(arg, "%lf", &delta)) {
if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9)
return;
*ratio += delta;
}
}
lt->arrange();
}
/* extern */ /* extern */
void void
floating(void) { floating(const char *arg) {
Client *c; Client *c;
if(lt->arrange != floating)
return;
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
if(isvisible(c)) { if(isvisible(c)) {
unban(c); unban(c);
@ -168,35 +56,6 @@ focusclient(const char *arg) {
} }
} }
void
inchratio(const char *arg) {
incratio(arg, &hratio, HRATIO);
}
void
incvratio(const char *arg) {
incratio(arg, &vratio, VRATIO);
}
void
incnmaster(const char *arg) {
int i;
if(!arg)
nmaster = NMASTER;
else {
i = atoi(arg);
if((lt->arrange != tile) || (nmaster + i < 1)
|| (wah / (nmaster + i) <= 2 * BORDERPX))
return;
nmaster += i;
}
if(sel)
lt->arrange();
else
drawstatus();
}
void void
initlayouts(void) { initlayouts(void) {
unsigned int i, w; unsigned int i, w;
@ -261,11 +120,70 @@ setlayout(const char *arg) {
lt = &layout[i]; lt = &layout[i];
} }
if(sel) if(sel)
lt->arrange(); lt->arrange(NULL);
else else
drawstatus(); drawstatus();
} }
void
tile(const char *arg) {
static double master = MASTER;
double delta;
unsigned int i, n, nx, ny, nw, nh, mw, th;
Client *c;
if(lt->arrange != tile)
return;
/* arg handling, manipulate master */
if(arg && (1 == sscanf(arg, "%lf", &delta))) {
if(delta + master > 0.1 && delta + master < 0.9)
master += delta;
}
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
n++;
/* window geoms */
mw = (n == 1) ? waw : master * waw;
th = (n > 1) ? wah / (n - 1) : 0;
if(n > 1 && th < bh)
th = wah;
nx = wax;
ny = way;
for(i = 0, c = clients; c; c = c->next)
if(isvisible(c)) {
unban(c);
if(c->isfloating)
continue;
c->ismax = False;
if(i == 0) { /* master */
nw = mw - 2 * c->border;
nh = wah - 2 * c->border;
}
else { /* tile window */
if(i == 1) {
ny = way;
nx += mw;
}
nw = waw - mw - 2 * c->border;
if(i + 1 == n) /* remainder */
nh = (way + wah) - ny - 2 * c->border;
else
nh = th - 2 * c->border;
}
resize(c, nx, ny, nw, nh, False);
if(n > 1 && th != wah)
ny += nh;
i++;
}
else
ban(c);
focus(NULL);
restack();
}
void void
togglebar(const char *arg) { togglebar(const char *arg) {
if(bpos == BarOff) if(bpos == BarOff)
@ -273,7 +191,7 @@ togglebar(const char *arg) {
else else
bpos = BarOff; bpos = BarOff;
updatebarpos(); updatebarpos();
lt->arrange(); lt->arrange(NULL);
} }
void void
@ -307,5 +225,5 @@ zoom(const char *arg) {
detach(c); detach(c);
attach(c); attach(c);
focus(c); focus(c);
lt->arrange(); lt->arrange(NULL);
} }

@ -110,7 +110,7 @@ tag(const char *arg) {
i = arg ? atoi(arg) : 0; i = arg ? atoi(arg) : 0;
if(i >= 0 && i < ntags) if(i >= 0 && i < ntags)
sel->tags[i] = True; sel->tags[i] = True;
lt->arrange(); lt->arrange(NULL);
} }
void void
@ -124,7 +124,7 @@ toggletag(const char *arg) {
for(j = 0; j < ntags && !sel->tags[j]; j++); for(j = 0; j < ntags && !sel->tags[j]; j++);
if(j == ntags) if(j == ntags)
sel->tags[i] = True; sel->tags[i] = True;
lt->arrange(); lt->arrange(NULL);
} }
void void
@ -136,7 +136,7 @@ toggleview(const char *arg) {
for(j = 0; j < ntags && !seltag[j]; j++); for(j = 0; j < ntags && !seltag[j]; j++);
if(j == ntags) if(j == ntags)
seltag[i] = True; /* cannot toggle last view */ seltag[i] = True; /* cannot toggle last view */
lt->arrange(); lt->arrange(NULL);
} }
void void
@ -148,5 +148,5 @@ view(const char *arg) {
i = arg ? atoi(arg) : 0; i = arg ? atoi(arg) : 0;
if(i >= 0 && i < ntags) if(i >= 0 && i < ntags)
seltag[i] = True; seltag[i] = True;
lt->arrange(); lt->arrange(NULL);
} }

Loading…
Cancel
Save