sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-flextile-5.8.2.diff (13307B)


      1 diff -up ../dwm-5.8.2-0/config.def.h ./config.def.h
      2 --- ../dwm-5.8.2-0/config.def.h	2010-06-10 22:47:51.660949000 +0200
      3 +++ ./config.def.h	2010-06-10 22:55:53.094322000 +0200
      4 @@ -16,6 +16,9 @@ static const Bool topbar            = Tr
      5  /* tagging */
      6  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
      7  
      8 +/* include(s) depending on the tags array */
      9 +#include "flextile.h"
     10 +
     11  static const Rule rules[] = {
     12  	/* class      instance    title       tags mask     isfloating   monitor */
     13  	{ "Gimp",     NULL,       NULL,       0,            True,        -1 },
     14 @@ -25,6 +28,11 @@ static const Rule rules[] = {
     15  /* layout(s) */
     16  static const float mfact      = 0.55; /* factor of master area size [0.05..0.95] */
     17  static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
     18 +static const int layoutaxis[] = {
     19 +	1,    /* layout axis: 1 = x, 2 = y; negative values mirror the layout, setting the master area to the right / bottom instead of left / top */
     20 +	2,    /* master axis: 1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle) */
     21 +	2,    /* stack axis:  1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle) */
     22 +};
     23  
     24  static const Layout layouts[] = {
     25  	/* symbol     arrange function */
     26 @@ -81,6 +89,12 @@ static Key keys[] = {
     27  	TAGKEYS(                        XK_8,                      7)
     28  	TAGKEYS(                        XK_9,                      8)
     29  	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
     30 +	{ MODKEY|ControlMask,           XK_t,      rotatelayoutaxis, {.i = 0} },    /* 0 = layout axis */
     31 +	{ MODKEY|ControlMask,           XK_Tab,    rotatelayoutaxis, {.i = 1} },    /* 1 = master axis */
     32 +	{ MODKEY|ControlMask|ShiftMask, XK_Tab,    rotatelayoutaxis, {.i = 2} },    /* 2 = stack axis */
     33 +	{ MODKEY|ControlMask,           XK_Return, mirrorlayout,     {0} },
     34 +	{ MODKEY|ControlMask,           XK_h,      shiftmastersplit, {.i = -1} },   /* reduce the number of tiled clients in the master area */
     35 +	{ MODKEY|ControlMask,           XK_l,      shiftmastersplit, {.i = +1} },   /* increase the number of tiled clients in the master area */
     36  };
     37  
     38  /* button definitions */
     39 diff -up ../dwm-5.8.2-0/dwm.c ./dwm.c
     40 --- ../dwm-5.8.2-0/dwm.c	2010-06-10 22:47:51.669677000 +0200
     41 +++ ./dwm.c	2010-06-10 22:55:53.128305000 +0200
     42 @@ -122,26 +122,6 @@ typedef struct {
     43  	void (*arrange)(Monitor *);
     44  } Layout;
     45  
     46 -struct Monitor {
     47 -	char ltsymbol[16];
     48 -	float mfact;
     49 -	int num;
     50 -	int by;               /* bar geometry */
     51 -	int mx, my, mw, mh;   /* screen size */
     52 -	int wx, wy, ww, wh;   /* window area  */
     53 -	unsigned int seltags;
     54 -	unsigned int sellt;
     55 -	unsigned int tagset[2];
     56 -	Bool showbar;
     57 -	Bool topbar;
     58 -	Client *clients;
     59 -	Client *sel;
     60 -	Client *stack;
     61 -	Monitor *next;
     62 -	Window barwin;
     63 -	const Layout *lt[2];
     64 -};
     65 -
     66  typedef struct {
     67  	const char *class;
     68  	const char *instance;
     69 @@ -610,6 +590,7 @@ configurerequest(XEvent *e) {
     70  
     71  Monitor *
     72  createmon(void) {
     73 +  unsigned int i;
     74  	Monitor *m;
     75  
     76  	if(!(m = (Monitor *)calloc(1, sizeof(Monitor))))
     77 @@ -621,6 +602,21 @@ createmon(void) {
     78  	m->lt[0] = &layouts[0];
     79  	m->lt[1] = &layouts[1 % LENGTH(layouts)];
     80  	strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
     81 +	m->ltaxis[0] = layoutaxis[0];
     82 +	m->ltaxis[1] = layoutaxis[1];
     83 +	m->ltaxis[2] = layoutaxis[2];
     84 +	m->msplit = 1;
     85 +	/* init tags, bars, layouts, axes, msplits and mfacts */
     86 +  m->curtag = m->prevtag = 1;
     87 +  for(i = 0; i < LENGTH(tags) + 1; i++){
     88 +    m->showbars[i] = m->showbar;
     89 +    m->lts[i] = &layouts[0];
     90 +    m->mfacts[i] = m->mfact;
     91 +    m->ltaxes[i][0] = m->ltaxis[0];
     92 +    m->ltaxes[i][1] = m->ltaxis[1];
     93 +    m->ltaxes[i][2] = m->ltaxis[2];
     94 +    m->msplits[i] = m->msplit;
     95 +  }
     96  	return m;
     97  }
     98  
     99 @@ -1494,7 +1490,7 @@ setlayout(const Arg *arg) {
    100  	if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
    101  		selmon->sellt ^= 1;
    102  	if(arg && arg->v)
    103 -		selmon->lt[selmon->sellt] = (Layout *)arg->v;
    104 +		selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag] = (Layout *)arg->v;
    105  	strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
    106  	if(selmon->sel)
    107  		arrange(selmon);
    108 @@ -1512,14 +1508,14 @@ setmfact(const Arg *arg) {
    109  	f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
    110  	if(f < 0.1 || f > 0.9)
    111  		return;
    112 -	selmon->mfact = f;
    113 +	selmon->mfact = selmon->mfacts[selmon->curtag] = f;
    114  	arrange(selmon);
    115  }
    116  
    117  void
    118  setup(void) {
    119  	XSetWindowAttributes wa;
    120 -
    121 + 
    122  	/* clean up any zombies immediately */
    123  	sigchld(0);
    124  
    125 @@ -1555,7 +1551,6 @@ setup(void) {
    126  	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
    127  	if(!dc.font.set)
    128  		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
    129 -	/* init bars */
    130  	updatebars();
    131  	updatestatus();
    132  	/* EWMH support per view */
    133 @@ -1635,38 +1631,8 @@ textnw(const char *text, unsigned int le
    134  }
    135  
    136  void
    137 -tile(Monitor *m) {
    138 -	int x, y, h, w, mw;
    139 -	unsigned int i, n;
    140 -	Client *c;
    141 -
    142 -	for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
    143 -	if(n == 0)
    144 -		return;
    145 -	/* master */
    146 -	c = nexttiled(m->clients);
    147 -	mw = m->mfact * m->ww;
    148 -	resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False);
    149 -	if(--n == 0)
    150 -		return;
    151 -	/* tile stack */
    152 -	x = (m->wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : m->wx + mw;
    153 -	y = m->wy;
    154 -	w = (m->wx + mw > c->x + c->w) ? m->wx + m->ww - x : m->ww - mw;
    155 -	h = m->wh / n;
    156 -	if(h < bh)
    157 -		h = m->wh;
    158 -	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
    159 -		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
    160 -		       ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw), False);
    161 -		if(h != m->wh)
    162 -			y = c->y + HEIGHT(c);
    163 -	}
    164 -}
    165 -
    166 -void
    167  togglebar(const Arg *arg) {
    168 -	selmon->showbar = !selmon->showbar;
    169 +	selmon->showbar = selmon->showbars[selmon->curtag] = !selmon->showbar;
    170  	updatebarpos(selmon);
    171  	XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
    172  	arrange(selmon);
    173 @@ -1686,12 +1652,31 @@ togglefloating(const Arg *arg) {
    174  void
    175  toggletag(const Arg *arg) {
    176  	unsigned int newtags;
    177 +	unsigned int i;
    178  
    179  	if(!selmon->sel)
    180  		return;
    181  	newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
    182  	if(newtags) {
    183  		selmon->sel->tags = newtags;
    184 +		if(newtags == ~0) {
    185 +			selmon->prevtag = selmon->curtag;
    186 +			selmon->curtag = 0;
    187 +		}
    188 +		if(!(newtags & 1 << (selmon->curtag - 1))) {
    189 +			selmon->prevtag = selmon->curtag;
    190 +			for (i=0; !(newtags & 1 << i); i++);
    191 +			selmon->curtag = i + 1;
    192 +		}
    193 +		selmon->sel->tags = newtags;
    194 +		selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag];
    195 +		selmon->mfact = selmon->mfacts[selmon->curtag];
    196 +		if (selmon->showbar != selmon->showbars[selmon->curtag])
    197 +			togglebar(NULL);
    198 +		selmon->ltaxis[0] = selmon->ltaxes[selmon->curtag][0];
    199 +		selmon->ltaxis[1] = selmon->ltaxes[selmon->curtag][1];
    200 +		selmon->ltaxis[2] = selmon->ltaxes[selmon->curtag][2];
    201 +		selmon->msplit = selmon->msplits[selmon->curtag];
    202  		arrange(selmon);
    203  	}
    204  }
    205 @@ -1959,11 +1944,33 @@ updatewmhints(Client *c) {
    206  
    207  void
    208  view(const Arg *arg) {
    209 +	unsigned int i;
    210 +
    211  	if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    212  		return;
    213  	selmon->seltags ^= 1; /* toggle sel tagset */
    214 -	if(arg->ui & TAGMASK)
    215 +	if(arg->ui & TAGMASK) {
    216  		selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
    217 +		selmon->prevtag = selmon->curtag;
    218 +		if(arg->ui == ~0)
    219 +			selmon->curtag = 0;
    220 +		else {
    221 +			for (i=0; !(arg->ui & 1 << i); i++);
    222 +			selmon->curtag = i + 1;
    223 +		}
    224 +	} else {
    225 +		selmon->prevtag = selmon->curtag ^ selmon->prevtag;
    226 +		selmon->curtag ^= selmon->prevtag;
    227 +		selmon->prevtag = selmon->curtag ^ selmon->prevtag;
    228 +	}
    229 +	selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag];
    230 +	selmon->mfact = selmon->mfacts[selmon->curtag];
    231 +	if(selmon->showbar != selmon->showbars[selmon->curtag])
    232 +		togglebar(NULL);
    233 +	selmon->ltaxis[0] = selmon->ltaxes[selmon->curtag][0];
    234 +	selmon->ltaxis[1] = selmon->ltaxes[selmon->curtag][1];
    235 +	selmon->ltaxis[2] = selmon->ltaxes[selmon->curtag][2];
    236 +	selmon->msplit = selmon->msplits[selmon->curtag];
    237  	arrange(selmon);
    238  }
    239  
    240  
    241 diff -up ../dwm-5.8.2-0/flextile.h ./flextile.h
    242 --- ../dwm-5.8.2-0/flextile.h	2010-06-10 23:08:24.000000000 +0200
    243 +++ ./flextile.h	2010-06-10 22:59:20.632706000 +0200
    244 @@ -0,0 +1,159 @@
    245 +/* See LICENSE file for copyright and license details. */
    246 +/* © 2010 joten <joten@freenet.de> */
    247 +
    248 +struct Monitor {
    249 +	char ltsymbol[16];
    250 +	float mfact;
    251 +	double mfacts[LENGTH(tags) + 1];
    252 +	int ltaxis[3];
    253 +	int ltaxes[LENGTH(tags) + 1][3];
    254 +	int num;
    255 +	int curtag;
    256 +	int prevtag;
    257 +	int by;               /* bar geometry */
    258 +	int mx, my, mw, mh;   /* screen size */
    259 +	int wx, wy, ww, wh;   /* window area  */
    260 +	unsigned int msplit;
    261 +	unsigned int msplits[LENGTH(tags) + 1];
    262 +	unsigned int seltags;
    263 +	unsigned int sellt;
    264 +	unsigned int tagset[2];
    265 +	Bool showbar;
    266 +	Bool showbars[LENGTH(tags) + 1];
    267 +	Bool topbar;
    268 +	Client *clients;
    269 +	Client *sel;
    270 +	Client *stack;
    271 +	Monitor *next;
    272 +	Window barwin;
    273 +	const Layout *lt[2];
    274 +	const Layout *lts[LENGTH(tags) + 1];
    275 +};
    276 +
    277 +/* function declarations */
    278 +static void mirrorlayout(const Arg *arg);
    279 +static void rotatelayoutaxis(const Arg *arg);
    280 +static void shiftmastersplit(const Arg *arg);
    281 +
    282 +void
    283 +mirrorlayout(const Arg *arg) {
    284 +	if(!selmon->lt[selmon->sellt]->arrange)
    285 +		return;
    286 +	selmon->ltaxis[0] *= -1;
    287 +	selmon->ltaxes[selmon->curtag][0] = selmon->ltaxis[0];
    288 +	arrange(selmon);
    289 +}
    290 +
    291 +void
    292 +rotatelayoutaxis(const Arg *arg) {
    293 +	if(!selmon->lt[selmon->sellt]->arrange)
    294 +		return;
    295 +	if(arg->i == 0) {
    296 +		if(selmon->ltaxis[0] > 0)
    297 +			selmon->ltaxis[0] = selmon->ltaxis[0] + 1 > 2 ? 1 : selmon->ltaxis[0] + 1;
    298 +		else
    299 +			selmon->ltaxis[0] = selmon->ltaxis[0] - 1 < -2 ? -1 : selmon->ltaxis[0] - 1;
    300 +	} else
    301 +		selmon->ltaxis[arg->i] = selmon->ltaxis[arg->i] + 1 > 3 ? 1 : selmon->ltaxis[arg->i] + 1;
    302 +	selmon->ltaxes[selmon->curtag][arg->i] = selmon->ltaxis[arg->i];
    303 +	arrange(selmon);
    304 +}
    305 +
    306 +void
    307 +shiftmastersplit(const Arg *arg) {
    308 +	unsigned int n;
    309 +	Client *c;
    310 +
    311 +	for(n = 0, c = nexttiled(selmon->clients); c; c = nexttiled(c->next), n++);
    312 +	if(!arg || !selmon->lt[selmon->sellt]->arrange || selmon->msplit + arg->i < 1 || selmon->msplit + arg->i > n)
    313 +		return;
    314 +	selmon->msplit += arg->i;
    315 +	selmon->msplits[selmon->curtag] = selmon->msplit;
    316 +	arrange(selmon);
    317 +}
    318 +
    319 +void
    320 +tile(Monitor *m) {
    321 +	char sym1 = 61, sym2 = 93, sym3 = 61, sym;
    322 +	int x1 = m->wx, y1 = m->wy, h1 = m->wh, w1 = m->ww, X1 = x1 + w1, Y1 = y1 + h1;
    323 +	int x2 = m->wx, y2 = m->wy, h2 = m->wh, w2 = m->ww, X2 = x2 + w2, Y2 = y2 + h2;
    324 +	unsigned int i, n, n1, n2;
    325 +	Client *c;
    326 +
    327 +	for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
    328 +	if(m->msplit > n)
    329 +		m->msplit = (n == 0) ? 1 : n;
    330 +	/* layout symbol */
    331 +	if(abs(m->ltaxis[0]) == m->ltaxis[1])    /* explicitly: ((abs(m->ltaxis[0]) == 1 && m->ltaxis[1] == 1) || (abs(m->ltaxis[0]) == 2 && m->ltaxis[1] == 2)) */
    332 +		sym1 = 124;
    333 +	if(abs(m->ltaxis[0]) == m->ltaxis[2])
    334 +		sym3 = 124;
    335 +	if(m->ltaxis[1] == 3)
    336 +		sym1 = (n == 0) ? 0 : m->msplit;
    337 +	if(m->ltaxis[2] == 3)
    338 +		sym3 = (n == 0) ? 0 : n - m->msplit;
    339 +	if(m->ltaxis[0] < 0) {
    340 +		sym = sym1;
    341 +		sym1 = sym3;
    342 +		sym2 = 91;
    343 +		sym3 = sym;
    344 +	}
    345 +	if(m->msplit == 1) {
    346 +		if(m->ltaxis[0] > 0)
    347 +			sym1 = 91;
    348 +		else
    349 +			sym3 = 93;
    350 +	}
    351 +	if(m->msplit > 1 && m->ltaxis[1] == 3 && m->ltaxis[2] == 3)
    352 +		snprintf(m->ltsymbol, sizeof m->ltsymbol, "%d%c%d", sym1, sym2, sym3);
    353 +	else if((m->msplit > 1 && m->ltaxis[1] == 3 && m->ltaxis[0] > 0) || (m->ltaxis[2] == 3 && m->ltaxis[0] < 0))
    354 +		snprintf(m->ltsymbol, sizeof m->ltsymbol, "%d%c%c", sym1, sym2, sym3);
    355 +	else if((m->ltaxis[2] == 3 && m->ltaxis[0] > 0) || (m->msplit > 1 && m->ltaxis[1] == 3 && m->ltaxis[0] < 0))
    356 +		snprintf(m->ltsymbol, sizeof m->ltsymbol, "%c%c%d", sym1, sym2, sym3);
    357 +	else
    358 +		snprintf(m->ltsymbol, sizeof m->ltsymbol, "%c%c%c", sym1, sym2, sym3);
    359 +	if(n == 0)
    360 +		return;
    361 +	/* master and stack area */
    362 +	if(abs(m->ltaxis[0]) == 1 && n > m->msplit) {
    363 +		w1 *= m->mfact;
    364 +		w2 -= w1;
    365 +		x1 += (m->ltaxis[0] < 0) ? w2 : 0;
    366 +		x2 += (m->ltaxis[0] < 0) ? 0 : w1;
    367 +		X1 = x1 + w1;
    368 +		X2 = x2 + w2;
    369 +	} else if(abs(m->ltaxis[0]) == 2 && n > m->msplit) {
    370 +		h1 *= m->mfact;
    371 +		h2 -= h1;
    372 +		y1 += (m->ltaxis[0] < 0) ? h2 : 0;
    373 +		y2 += (m->ltaxis[0] < 0) ? 0 : h1;
    374 +		Y1 = y1 + h1;
    375 +		Y2 = y2 + h2;
    376 +	}
    377 +	/* master */
    378 +	n1 = (m->ltaxis[1] != 1 || w1 / m->msplit < bh) ? 1 : m->msplit;
    379 +	n2 = (m->ltaxis[1] != 2 || h1 / m->msplit < bh) ? 1 : m->msplit;
    380 +	for(i = 0, c = nexttiled(m->clients); i < m->msplit; c = nexttiled(c->next), i++) {
    381 +		resize(c, x1, y1, 
    382 +			(m->ltaxis[1] == 1 && i + 1 == m->msplit) ? X1 - x1 - 2 * c->bw : w1 / n1 - 2 * c->bw, 
    383 +			(m->ltaxis[1] == 2 && i + 1 == m->msplit) ? Y1 - y1 - 2 * c->bw : h1 / n2 - 2 * c->bw, False);
    384 +		if(n1 > 1)
    385 +			x1 = c->x + WIDTH(c);
    386 +		if(n2 > 1)
    387 +			y1 = c->y + HEIGHT(c);
    388 +	}
    389 +	/* stack */
    390 +	if(n > m->msplit) {
    391 +		n1 = (m->ltaxis[2] != 1 || w2 / (n - m->msplit) < bh) ? 1 : n - m->msplit;
    392 +		n2 = (m->ltaxis[2] != 2 || h2 / (n - m->msplit) < bh) ? 1 : n - m->msplit;
    393 +		for(i = 0; c; c = nexttiled(c->next), i++) {
    394 +			resize(c, x2, y2, 
    395 +				(m->ltaxis[2] == 1 && i + 1 == n - m->msplit) ? X2 - x2 - 2 * c->bw : w2 / n1 - 2 * c->bw, 
    396 +				(m->ltaxis[2] == 2 && i + 1 == n - m->msplit) ? Y2 - y2 - 2 * c->bw : h2 / n2 - 2 * c->bw, False);
    397 +			if(n1 > 1)
    398 +				x2 = c->x + WIDTH(c);
    399 +			if(n2 > 1)
    400 +				y2 = c->y + HEIGHT(c);
    401 +		}
    402 +	}
    403 +}