sites

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

dwm-ru_centeredmaster-6.2.diff (5453B)


      1 diff -up a/config.def.h b/config.def.h
      2 --- a/config.def.h	2019-07-24 08:59:14.429282151 +0200
      3 +++ b/config.def.h	2019-07-24 09:30:18.841019314 +0200
      4 @@ -42,6 +42,8 @@ static const Layout layouts[] = {
      5  	{ "[]=",      tile },    /* first entry is default */
      6  	{ "><>",      NULL },    /* no layout function means floating behavior */
      7  	{ "[M]",      monocle },
      8 +	{ "|M|",      centeredmaster },
      9 +	{ ">M>",      centeredfloatingmaster },
     10  };
     11  
     12  /* key definitions */
     13 @@ -77,6 +79,8 @@ static Key keys[] = {
     14  	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
     15  	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
     16  	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     17 +	{ MODKEY,                       XK_u,      setlayout,      {.v = &layouts[3]} },
     18 +	{ MODKEY|ShiftMask,             XK_u,      setlayout,      {.v = &layouts[4]} },
     19  	{ MODKEY,                       XK_space,  setlayout,      {0} },
     20  	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
     21  	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
     22 diff -up a/dwm.c b/dwm.c
     23 --- a/dwm.c	2019-07-24 08:59:14.432615503 +0200
     24 +++ b/dwm.c	2019-07-24 09:24:16.192110897 +0200
     25 @@ -235,6 +235,8 @@ static int xerror(Display *dpy, XErrorEv
     26  static int xerrordummy(Display *dpy, XErrorEvent *ee);
     27  static int xerrorstart(Display *dpy, XErrorEvent *ee);
     28  static void zoom(const Arg *arg);
     29 +static void centeredmaster(Monitor *m);
     30 +static void centeredfloatingmaster(Monitor *m);
     31  
     32  /* variables */
     33  static const char broken[] = "broken";
     34 @@ -2176,3 +2178,127 @@ main(int argc, char *argv[])
     35  	XCloseDisplay(dpy);
     36  	return EXIT_SUCCESS;
     37  }
     38 +
     39 +void
     40 +centeredmaster(Monitor *m)
     41 +{
     42 +	unsigned int i, n, h, mw, mx, my, oty, ety, tw;
     43 +	Client *c;
     44 +	
     45 +	/* count number of clients in the selected monitor */
     46 +	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
     47 +	
     48 +	if (n == 0)
     49 +		return;
     50 +	if(n == 1){
     51 +		c = nexttiled(m->clients);
     52 +		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
     53 +		return;
     54 +	}
     55 +
     56 +	/* initialize areas */
     57 +	mw = m->ww;
     58 +	mx = 0;
     59 +	my = m->gappx;
     60 +	tw = mw;
     61 +
     62 +	if (n > m->nmaster) {
     63 +		/* go mfact box in the center if more than nmaster clients */
     64 +		mw = m->nmaster ? m->ww * m->mfact : 0;
     65 +		tw = m->ww - mw;
     66 +
     67 +		if (n - m->nmaster > 1) {
     68 +			/* only one client */
     69 +			mx = (m->ww - mw) / 2;
     70 +			tw = (m->ww - mw) / 2;
     71 +		}
     72 +	}
     73 +
     74 +	oty = m->gappx;
     75 +	ety = m->gappx;
     76 +	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
     77 +	if (i < m->nmaster) {
     78 +		/* nmaster clients are stacked vertically, in the center
     79 +		 * of the screen */
     80 +		h = (m->wh - my) / (MIN(n, m->nmaster) - i);
     81 +		if(m->nmaster >= n)
     82 +			resize(c, m->wx + mx + m->gappx, m->wy + my, mw - 2*(c->bw + m->gappx),
     83 +		       h - (2*c->bw) - m->gappx, 0);
     84 +		else if(m->nmaster + 1 < n)
     85 +			resize(c, m->wx + mx + m->gappx/2, m->wy + my, mw - 2*c->bw - m->gappx, h - 2*c->bw - m->gappx, 0);
     86 +		else
     87 +			resize(c, m->wx + mx + m->gappx, m->wy + my, mw - 2*c->bw - m->gappx*3/2, h - 2*c->bw - m->gappx, 0);
     88 +		if(my + HEIGHT(c) + m->gappx < m->mh)
     89 +			my += HEIGHT(c) + m->gappx;
     90 +	} else {
     91 +		/* stack clients are stacked vertically */
     92 +		if ((i - m->nmaster) % 2) {
     93 +			h = (m->wh - ety) / ( (1 + n - i) / 2);
     94 +			resize(c, m->wx + m->gappx, m->wy + ety, tw - (2*c->bw) - m->gappx*3/2, h - 2*c->bw - m->gappx, 0);
     95 +			if(ety + HEIGHT(c) + m->gappx < m->mh)
     96 +				ety += HEIGHT(c) + m->gappx;
     97 +		} else {
     98 +			h = (m->wh - oty) / ((1 + n - i) / 2);
     99 +			resize(c, m->wx + mx + mw + m->gappx/2, m->wy + oty, tw - (2*c->bw) - m->gappx*3/2, h - 2*c->bw - m->gappx, 0);
    100 +			if(oty + HEIGHT(c) + m->gappx < m->mh)
    101 +				oty += HEIGHT(c) + m->gappx;
    102 +		}
    103 +	}
    104 +}
    105 +
    106 +void
    107 +centeredfloatingmaster(Monitor *m)
    108 +{
    109 +	unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx;
    110 +	Client *c;
    111 +
    112 +	/* count number of clients in the selected monitor */
    113 +	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
    114 +	if (n == 0)
    115 +		return;
    116 +	if(n == 1){
    117 +		c = nexttiled(m->clients);
    118 +		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
    119 +		return;
    120 +	}
    121 +
    122 +	/* initialize nmaster area */
    123 +	if (n > m->nmaster) {
    124 +		/* go mfact box in the center if more than nmaster clients */
    125 +		if (m->ww > m->wh) {
    126 +			mw = m->nmaster ? m->ww * m->mfact : 0;
    127 +			mh = m->nmaster ? m->wh * 0.9 : 0;
    128 +		} else {
    129 +			mh = m->nmaster ? m->wh * m->mfact : 0;
    130 +			mw = m->nmaster ? m->ww * 0.9 : 0;
    131 +		}
    132 +		mx = mxo = (m->ww - mw + m->gappx) / 2;
    133 +		my = myo = (m->wh - mh) / 2;
    134 +	} else {
    135 +		/* go fullscreen if all clients are in the master area */
    136 +		mh = m->wh;
    137 +		mw = m->ww;
    138 +		mx = m->gappx;
    139 +		mxo = 0;
    140 +		my = myo = 0;
    141 +	}
    142 +	
    143 +	tx = m->gappx;
    144 +	for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
    145 +	if (i < m->nmaster) {
    146 +		/* nmaster clients are stacked horizontally, in the center
    147 +		 * of the screen */
    148 +		w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i) + m->gappx;
    149 +		resize(c, m->wx + mx, m->wy + my + m->gappx, w - 2*(c->bw + m->gappx),
    150 +		       mh - 2*(c->bw + m->gappx), 0);
    151 +		if(mx + WIDTH(c) + m->gappx < m->mw)
    152 +			mx += WIDTH(c) + m->gappx;
    153 +	} else {
    154 +		/* stack clients are stacked horizontally */
    155 +		w = (m->ww - tx) / (n - i) + m->gappx;
    156 +		resize(c, m->wx + tx, m->wy + m->gappx, w - 2*(c->bw + m->gappx),
    157 +		       m->wh - 2*(c->bw + m->gappx), 0);
    158 +		if(tx + WIDTH(c) + m->gappx < m->mw)
    159 +			tx += WIDTH(c) + m->gappx;
    160 +	}
    161 +}