sites

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

dwm-ru_centeredmaster-6.2.diff (5241B)


      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,122 @@ 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 +		my += HEIGHT(c) + m->gappx;
     89 +	} else {
     90 +		/* stack clients are stacked vertically */
     91 +		if ((i - m->nmaster) % 2) {
     92 +			h = (m->wh - ety) / ( (1 + n - i) / 2);
     93 +			resize(c, m->wx + m->gappx, m->wy + ety, tw - (2*c->bw) - m->gappx*3/2, h - 2*c->bw - m->gappx, 0);
     94 +			ety += HEIGHT(c) + m->gappx;
     95 +		} else {
     96 +			h = (m->wh - oty) / ((1 + n - i) / 2);
     97 +			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);
     98 +			oty += HEIGHT(c) + m->gappx;
     99 +		}
    100 +	}
    101 +}
    102 +
    103 +void
    104 +centeredfloatingmaster(Monitor *m)
    105 +{
    106 +	unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx;
    107 +	Client *c;
    108 +
    109 +	/* count number of clients in the selected monitor */
    110 +	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
    111 +	if (n == 0)
    112 +		return;
    113 +	if(n == 1){
    114 +		c = nexttiled(m->clients);
    115 +		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
    116 +		return;
    117 +	}
    118 +
    119 +	/* initialize nmaster area */
    120 +	if (n > m->nmaster) {
    121 +		/* go mfact box in the center if more than nmaster clients */
    122 +		if (m->ww > m->wh) {
    123 +			mw = m->nmaster ? m->ww * m->mfact : 0;
    124 +			mh = m->nmaster ? m->wh * 0.9 : 0;
    125 +		} else {
    126 +			mh = m->nmaster ? m->wh * m->mfact : 0;
    127 +			mw = m->nmaster ? m->ww * 0.9 : 0;
    128 +		}
    129 +		mx = mxo = (m->ww - mw + m->gappx) / 2;
    130 +		my = myo = (m->wh - mh) / 2;
    131 +	} else {
    132 +		/* go fullscreen if all clients are in the master area */
    133 +		mh = m->wh;
    134 +		mw = m->ww;
    135 +		mx = m->gappx;
    136 +		mxo = 0;
    137 +		my = myo = 0;
    138 +	}
    139 +	
    140 +	tx = m->gappx;
    141 +	for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
    142 +	if (i < m->nmaster) {
    143 +		/* nmaster clients are stacked horizontally, in the center
    144 +		 * of the screen */
    145 +		w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i) + m->gappx;
    146 +		resize(c, m->wx + mx, m->wy + my + m->gappx, w - 2*(c->bw + m->gappx),
    147 +		       mh - 2*(c->bw + m->gappx), 0);
    148 +		mx += WIDTH(c) + m->gappx;
    149 +	} else {
    150 +		/* stack clients are stacked horizontally */
    151 +		w = (m->ww - tx) / (n - i) + m->gappx;
    152 +		resize(c, m->wx + tx, m->wy + m->gappx, w - 2*(c->bw + m->gappx),
    153 +		       m->wh - 2*(c->bw + m->gappx), 0);
    154 +		tx += WIDTH(c) + m->gappx;
    155 +	}
    156 +}