1
0

first step to a more flexible dotile() algorithm

This commit is contained in:
Anselm R. Garbe 2006-09-29 12:38:27 +02:00
parent a118a57fe3
commit 14d05e7c72
7 changed files with 52 additions and 35 deletions

View File

@ -6,9 +6,11 @@
#define TAGS \ #define TAGS \
const char *tags[] = { "dev", "work", "net", "fnord", NULL }; const char *tags[] = { "dev", "work", "net", "fnord", NULL };
#define DEFMODE dotile /* dofloat */ #define DEFMODE dotile /* dofloat */
#define FLOATSYMBOL "><>" #define FLOATSYMBOL "><>"
#define STACKPOS StackRight /* StackLeft, StackBottom */
#define TILESYMBOL "[]=" #define TILESYMBOL "[]="
#define VERTICALSTACK True /* False == horizontal stack */
#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*" #define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
#define NORMBGCOLOR "#333333" #define NORMBGCOLOR "#333333"
@ -18,7 +20,7 @@ const char *tags[] = { "dev", "work", "net", "fnord", NULL };
#define STATUSBGCOLOR "#222222" #define STATUSBGCOLOR "#222222"
#define STATUSFGCOLOR "#9999cc" #define STATUSFGCOLOR "#9999cc"
#define MASTERW 60 /* percent */ #define MASTER 60 /* percent */
#define MODKEY Mod1Mask #define MODKEY Mod1Mask
#define KEYS \ #define KEYS \

View File

@ -8,7 +8,9 @@ const char *tags[] = { "1", "2", "3", "4", "5", NULL };
#define DEFMODE dotile /* dofloat */ #define DEFMODE dotile /* dofloat */
#define FLOATSYMBOL "><>" #define FLOATSYMBOL "><>"
#define STACKPOS StackRight /* StackLeft, StackBottom */
#define TILESYMBOL "[]=" #define TILESYMBOL "[]="
#define VERTICALSTACK True /* False == horizontal stack */
#define FONT "fixed" #define FONT "fixed"
#define NORMBGCOLOR "#333366" #define NORMBGCOLOR "#333366"
@ -18,7 +20,7 @@ const char *tags[] = { "1", "2", "3", "4", "5", NULL };
#define STATUSBGCOLOR "#dddddd" #define STATUSBGCOLOR "#dddddd"
#define STATUSFGCOLOR "#222222" #define STATUSFGCOLOR "#222222"
#define MASTERW 60 /* percent */ #define MASTER 60 /* percent */
#define MODKEY Mod1Mask #define MODKEY Mod1Mask
#define KEYS \ #define KEYS \

View File

@ -1,5 +1,5 @@
# dwm version # dwm version
VERSION = 1.7.1 VERSION = 1.8
# Customize below to fit your system # Customize below to fit your system

8
dwm.h
View File

@ -47,6 +47,10 @@ enum { WMProtocols, WMDelete, WMLast }; /* default atoms */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { ColFG, ColBG, ColLast }; /* color */ enum { ColFG, ColBG, ColLast }; /* color */
typedef enum {
StackLeft, StackBottom, StackRight
} StackPos; /* stack position*/
typedef enum { typedef enum {
TopLeft, TopRight, BotLeft, BotRight TopLeft, TopRight, BotLeft, BotRight
} Corner; /* window corners */ } Corner; /* window corners */
@ -97,16 +101,18 @@ struct Client {
extern const char *tags[]; /* all tags */ extern const char *tags[]; /* all tags */
extern char stext[1024]; /* status text */ extern char stext[1024]; /* status text */
extern int bx, by, bw, bh, bmw; /* bar geometry, bar mode label width */ extern int bx, by, bw, bh, bmw; /* bar geometry, bar mode label width */
extern int mw, screen, sx, sy, sw, sh; /* screen geometry, master width */ extern int master, screen, sx, sy, sw, sh; /* screen geometry, master width */
extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */ extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */
extern void (*handler[LASTEvent])(XEvent *); /* event handler */ extern void (*handler[LASTEvent])(XEvent *); /* event handler */
extern void (*arrange)(Arg *); /* arrange function, indicates mode */ extern void (*arrange)(Arg *); /* arrange function, indicates mode */
extern Atom wmatom[WMLast], netatom[NetLast]; extern Atom wmatom[WMLast], netatom[NetLast];
extern Bool running, issel, *seltag; /* seltag is array of Bool */ extern Bool running, issel, *seltag; /* seltag is array of Bool */
extern Bool isvertical; /* stack direction */
extern Client *clients, *sel, *stack; /* global client list and stack */ extern Client *clients, *sel, *stack; /* global client list and stack */
extern Cursor cursor[CurLast]; extern Cursor cursor[CurLast];
extern DC dc; /* global draw context */ extern DC dc; /* global draw context */
extern Display *dpy; extern Display *dpy;
extern StackPos stackpos;
extern Window root, barwin; extern Window root, barwin;
/* client.c */ /* client.c */

View File

@ -176,8 +176,11 @@ configurerequest(XEvent *e) {
else else
configure(c); configure(c);
XSync(dpy, False); XSync(dpy, False);
if(c->isfloat) if(c->isfloat) {
resize(c, False, TopLeft); resize(c, False, TopLeft);
if(!isvisible(c))
ban(c);
}
else else
arrange(NULL); arrange(NULL);
} }

4
main.c
View File

@ -19,7 +19,7 @@
char stext[1024]; char stext[1024];
Bool *seltag; Bool *seltag;
int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh; int bx, by, bw, bh, bmw, master, screen, sx, sy, sw, sh;
unsigned int ntags, numlockmask; unsigned int ntags, numlockmask;
Atom wmatom[WMLast], netatom[NetLast]; Atom wmatom[WMLast], netatom[NetLast];
Bool running = True; Bool running = True;
@ -133,7 +133,7 @@ setup(void) {
sx = sy = 0; sx = sy = 0;
sw = DisplayWidth(dpy, screen); sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen); sh = DisplayHeight(dpy, screen);
mw = (sw * MASTERW) / 100; master = ((stackpos == StackBottom ? sh - bh : sw) * MASTER) / 100;
bx = by = 0; bx = by = 0;
bw = sw; bw = sw;

58
view.c
View File

@ -65,6 +65,8 @@ togglemax(Client *c)
/* extern */ /* extern */
void (*arrange)(Arg *) = DEFMODE; void (*arrange)(Arg *) = DEFMODE;
Bool isvertical = VERTICALSTACK;
StackPos stackpos = STACKPOS;
void void
detach(Client *c) { detach(Client *c) {
@ -97,35 +99,37 @@ dofloat(Arg *arg) {
/* This algorithm is based on a (M)aster area and a (S)tacking area. /* This algorithm is based on a (M)aster area and a (S)tacking area.
* It supports following arrangements: * It supports following arrangements:
* * MMMS MMMM SMMM
* MMMS MMMM * MMMS MMMM SMMM
* MMMS MMMM * MMMS SSSS SMMM
* MMMS SSSS
*
* The stacking area can be set to arrange clients vertically or horizontally.
* Through inverting the algorithm it can be used to achieve following setup in
* a dual head environment (due to running two dwm instances concurrently on
* the specific screen):
*
* SMM MMS MMM MMM
* SMM MMS MMM MMM
* SMM MMS SSS SSS
*
* This uses the center of the two screens for master areas.
*/ */
void void
dotile(Arg *arg) { dotile(Arg *arg) {
int h, i, n, w; int h, i, n, w;
Client *c; Client *c;
w = sw - mw;
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
n++; n++;
if(n > 1) if(isvertical) {
h = (sh - bh) / (n - 1); if(stackpos == StackBottom) {
else w = sw;
h = sh - bh; if(n > 1)
h = (sh - bh) / (n - 1);
else
h = sh - bh;
}
else {
w = sw - master;
if(n > 1)
h = (sh - bh) / (n - 1);
else
h = sh - bh;
}
}
else { /* horizontal stack */
}
for(i = 0, c = clients; c; c = c->next) { for(i = 0, c = clients; c; c = c->next) {
if(isvisible(c)) { if(isvisible(c)) {
@ -143,11 +147,11 @@ dotile(Arg *arg) {
else if(i == 0) { else if(i == 0) {
c->x = sx; c->x = sx;
c->y = sy + bh; c->y = sy + bh;
c->w = mw - 2 * BORDERPX; c->w = master - 2 * BORDERPX;
c->h = sh - 2 * BORDERPX - bh; c->h = sh - 2 * BORDERPX - bh;
} }
else if(h > bh) { else if(h > bh) {
c->x = sx + mw; c->x = sx + master;
c->y = sy + (i - 1) * h + bh; c->y = sy + (i - 1) * h + bh;
c->w = w - 2 * BORDERPX; c->w = w - 2 * BORDERPX;
if(i + 1 == n) if(i + 1 == n)
@ -156,7 +160,7 @@ dotile(Arg *arg) {
c->h = h - 2 * BORDERPX; c->h = h - 2 * BORDERPX;
} }
else { /* fallback if h < bh */ else { /* fallback if h < bh */
c->x = sx + mw; c->x = sx + master;
c->y = sy + bh; c->y = sy + bh;
c->w = w - 2 * BORDERPX; c->w = w - 2 * BORDERPX;
c->h = sh - 2 * BORDERPX - bh; c->h = sh - 2 * BORDERPX - bh;
@ -228,14 +232,14 @@ resizecol(Arg *arg) {
return; return;
if(sel == getnext(clients)) { if(sel == getnext(clients)) {
if(mw + arg->i > sw - 100 || mw + arg->i < 100) if(master + arg->i > sw - 100 || master + arg->i < 100)
return; return;
mw += arg->i; master += arg->i;
} }
else { else {
if(mw - arg->i > sw - 100 || mw - arg->i < 100) if(master - arg->i > sw - 100 || master - arg->i < 100)
return; return;
mw -= arg->i; master -= arg->i;
} }
arrange(NULL); arrange(NULL);
} }