sites

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

dwm-xtile-6.2.diff (12122B)


      1 From 9edd083970e01027483a3b34a3256824668f585a Mon Sep 17 00:00:00 2001
      2 From: MLquest8 <miskuzius@gmail.com>
      3 Date: Fri, 12 Jun 2020 15:31:20 +0400
      4 Subject: [PATCH] xtile updated for version 6.2
      5 
      6 ---
      7  config.def.h |  15 +++++--
      8  dwm.c        | 121 ++++++++++++++++++++++++++++++++++-----------------
      9  2 files changed, 94 insertions(+), 42 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 1c0b587..254e51c 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -32,7 +32,8 @@ static const Rule rules[] = {
     16  };
     17  
     18  /* layout(s) */
     19 -static const float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
     20 +static const int dirs[3]      = { DirHor, DirVer, DirVer }; /* tiling dirs */
     21 +static const float facts[3]   = { 1.1,    1.1,    1.1 };    /* tiling facts */
     22  static const int nmaster     = 1;    /* number of clients in master area */
     23  static const int resizehints = 1;    /* 1 means respect size hints in tiled resizals */
     24  
     25 @@ -50,6 +51,10 @@ static const Layout layouts[] = {
     26  	{ MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
     27  	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
     28  	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },
     29 +#define TILEKEYS(MOD,G,M,S) \
     30 +	{ MOD, XK_r, setdirs,  {.v = (int[])  { INC(G * +1),   INC(M * +1),   INC(S * +1) } } }, \
     31 +	{ MOD, XK_h, setfacts, {.v = (float[]){ INC(G * -0.1), INC(M * -0.1), INC(S * -0.1) } } }, \
     32 +	{ MOD, XK_l, setfacts, {.v = (float[]){ INC(G * +0.1), INC(M * +0.1), INC(S * +0.1) } } },
     33  
     34  /* helper for spawning shell commands in the pre dwm-5.0 fashion */
     35  #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
     36 @@ -68,8 +73,6 @@ static Key keys[] = {
     37  	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     38  	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
     39  	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
     40 -	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
     41 -	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
     42  	{ MODKEY,                       XK_Return, zoom,           {0} },
     43  	{ MODKEY,                       XK_Tab,    view,           {0} },
     44  	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
     45 @@ -77,6 +80,12 @@ static Key keys[] = {
     46  	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
     47  	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     48  	{ MODKEY,                       XK_space,  setlayout,      {0} },
     49 +	TILEKEYS(MODKEY,                                           1, 0, 0)
     50 +	TILEKEYS(MODKEY|ShiftMask,                                 0, 1, 0)
     51 +	TILEKEYS(MODKEY|ControlMask,                               0, 0, 1)
     52 +	TILEKEYS(MODKEY|ShiftMask|ControlMask,                     1, 1, 1)
     53 +	{ MODKEY|ShiftMask,             XK_t,      setdirs,        {.v = (int[]){ DirHor, DirVer, DirVer } } },
     54 +	{ MODKEY|ControlMask,           XK_t,      setdirs,        {.v = (int[]){ DirVer, DirHor, DirHor } } },
     55  	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
     56  	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
     57  	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
     58 diff --git a/dwm.c b/dwm.c
     59 index a2943af..e43fbad 100644
     60 --- a/dwm.c
     61 +++ b/dwm.c
     62 @@ -47,15 +47,20 @@
     63  /* macros */
     64  #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
     65  #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
     66 +#define GETINC(X)               ((X) - 2000)
     67 +#define INC(X)                  ((X) + 2000)
     68  #define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
     69                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
     70 +#define ISINC(X)                ((X) > 1000 && (X) < 3000)
     71  #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
     72  #define LENGTH(X)               (sizeof X / sizeof X[0])
     73 +#define MOD(N,M)                ((N)%(M) < 0 ? (N)%(M) + (M) : (N)%(M))
     74  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
     75  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
     76  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
     77  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
     78  #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
     79 +#define TRUNC(X,A,B)            (MAX((A), MIN((X), (B))))
     80  
     81  /* enums */
     82  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     83 @@ -66,6 +71,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     84  enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
     85  enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
     86         ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
     87 +enum { DirHor, DirVer, DirRotHor, DirRotVer, DirLast }; /* tiling dirs */
     88  
     89  typedef union {
     90  	int i;
     91 @@ -74,6 +80,11 @@ typedef union {
     92  	const void *v;
     93  } Arg;
     94  
     95 +typedef struct {
     96 +	unsigned int x, y, fx, fy, n, dir;
     97 +	float fact;
     98 +} Area;
     99 +
    100  typedef struct {
    101  	unsigned int click;
    102  	unsigned int mask;
    103 @@ -114,7 +125,6 @@ typedef struct {
    104  typedef struct Pertag Pertag;
    105  struct Monitor {
    106  	char ltsymbol[16];
    107 -	float mfact;
    108  	int nmaster;
    109  	int num;
    110  	int by;               /* bar geometry */
    111 @@ -200,10 +210,11 @@ static void scan(void);
    112  static int sendevent(Client *c, Atom proto);
    113  static void sendmon(Client *c, Monitor *m);
    114  static void setclientstate(Client *c, long state);
    115 +static void setdirs(const Arg *arg);
    116 +static void setfacts(const Arg *arg);
    117  static void setfocus(Client *c);
    118  static void setfullscreen(Client *c, int fullscreen);
    119  static void setlayout(const Arg *arg);
    120 -static void setmfact(const Arg *arg);
    121  static void setup(void);
    122  static void seturgent(Client *c, int urg);
    123  static void showhide(Client *c);
    124 @@ -277,7 +288,7 @@ static Window root, wmcheckwin;
    125  struct Pertag {
    126  	unsigned int curtag, prevtag; /* current and previous tag */
    127  	int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
    128 -	float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
    129 +	Area areas[LENGTH(tags) + 1][3]; /* tiling areas */
    130  	unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
    131  	const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes  */
    132  	int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
    133 @@ -526,6 +537,7 @@ clientmessage(XEvent *e)
    134  {
    135  	XClientMessageEvent *cme = &e->xclient;
    136  	Client *c = wintoclient(cme->window);
    137 +	int i;
    138  
    139  	if (!c)
    140  		return;
    141 @@ -535,6 +547,10 @@ clientmessage(XEvent *e)
    142  			setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD    */
    143  				|| (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
    144  	} else if (cme->message_type == netatom[NetActiveWindow]) {
    145 + 		if(!ISVISIBLE(c)) {
    146 +			for(i=0; !(c->tags & 1 << i); i++);
    147 +			view(&(Arg){.ui = 1 << i});
    148 +		}
    149  		if (c != selmon->sel && !c->isurgent)
    150  			seturgent(c, 1);
    151  	}
    152 @@ -643,11 +659,10 @@ Monitor *
    153  createmon(void)
    154  {
    155  	Monitor *m;
    156 -	unsigned int i;
    157 +	unsigned int i, j;
    158  
    159  	m = ecalloc(1, sizeof(Monitor));
    160  	m->tagset[0] = m->tagset[1] = 1;
    161 -	m->mfact = mfact;
    162  	m->nmaster = nmaster;
    163  	m->showbar = showbar;
    164  	m->topbar = topbar;
    165 @@ -659,7 +674,12 @@ createmon(void)
    166  
    167  	for (i = 0; i <= LENGTH(tags); i++) {
    168  		m->pertag->nmasters[i] = m->nmaster;
    169 -		m->pertag->mfacts[i] = m->mfact;
    170 +
    171 +		/* init tiling dirs and facts */
    172 +		for(j = 0; j < 3; j++) {
    173 +			m->pertag->areas[i][j].dir = MIN(dirs[j], ((int[]){ 3, 1, 1 }[j]));
    174 +			m->pertag->areas[i][j].fact = TRUNC(facts[j], 0.1, 10);
    175 +		}
    176  
    177  		m->pertag->ltidxs[i][0] = m->lt[0];
    178  		m->pertag->ltidxs[i][1] = m->lt[1];
    179 @@ -1459,6 +1479,31 @@ setclientstate(Client *c, long state)
    180  		PropModeReplace, (unsigned char *)data, 2);
    181  }
    182  
    183 +void
    184 +setdirs(const Arg *arg) {
    185 +	int *dirs = (int *)arg->v, i, n;
    186 +	Area *areas = selmon->pertag->areas[selmon->pertag->curtag];
    187 +
    188 +	for(i = 0; i < 3; i++) {
    189 +		n = (int[]){ 4, 2, 2 }[i];
    190 +		areas[i].dir = ISINC(dirs[i]) ?
    191 +			MOD((int)areas[i].dir + GETINC(dirs[i]), n) : TRUNC(dirs[i], 0, n - 1);
    192 +	}
    193 +	arrange(selmon);
    194 +}
    195 +
    196 +void
    197 +setfacts(const Arg *arg) {
    198 +	float *facts = (float *)arg->v;
    199 +	Area *areas = selmon->pertag->areas[selmon->pertag->curtag];
    200 +	int i;
    201 +
    202 +	for(i = 0; i < 3; i++)
    203 +		areas[i].fact = TRUNC(ISINC(facts[i]) ?
    204 +			areas[i].fact + GETINC(facts[i]) : facts[i], 0.1, 10);
    205 +	arrange(selmon);
    206 +}
    207 +
    208  int
    209  sendevent(Client *c, Atom proto)
    210  {
    211 @@ -1538,21 +1583,6 @@ setlayout(const Arg *arg)
    212  		drawbar(selmon);
    213  }
    214  
    215 -/* arg > 1.0 will set mfact absolutely */
    216 -void
    217 -setmfact(const Arg *arg)
    218 -{
    219 -	float f;
    220 -
    221 -	if (!arg || !selmon->lt[selmon->sellt]->arrange)
    222 -		return;
    223 -	f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
    224 -	if (f < 0.05 || f > 0.95)
    225 -		return;
    226 -	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
    227 -	arrange(selmon);
    228 -}
    229 -
    230  void
    231  setup(void)
    232  {
    233 @@ -1700,29 +1730,44 @@ tagmon(const Arg *arg)
    234  void
    235  tile(Monitor *m)
    236  {
    237 -	unsigned int i, n, h, mw, my, ty;
    238  	Client *c;
    239  
    240 +	Area *ga = m->pertag->areas[m->pertag->curtag], *ma = ga + 1, *sa = ga + 2, *a;
    241 +	unsigned int n, i, w, h, ms, ss;
    242 +	float f;
    243 + 
    244 +	/* print layout symbols */
    245 +	snprintf(m->ltsymbol, sizeof m->ltsymbol, "%c%c%c",
    246 +		(char[]){ '<', '^', '>', 'v' }[ga->dir],
    247 +		(char[]){ '-', '|' }[ma->dir],
    248 +		(char[]){ '-', '|' }[sa->dir]);
    249 +
    250 +	/* calculate number of clients */
    251  	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
    252  	if (n == 0)
    253  		return;
    254  
    255 -	if (n > m->nmaster)
    256 -		mw = m->nmaster ? m->ww * m->mfact : 0;
    257 +	ma->n = MIN(n, m->nmaster), sa->n = n - ma->n;
    258 +	/* calculate area rectangles */
    259 +	f = ma->n == 0 ? 0 : (sa->n == 0 ? 1 : ga->fact / 2);
    260 +	if(ga->dir == DirHor || ga->dir == DirRotHor)
    261 +		ms = f * m->ww, ss = m->ww - ms,
    262 +		ma->x = ga->dir == DirHor ? 0 : ss, ma->y = 0, ma->fx = ma->x + ms, ma->fy = m->wh,
    263 +		sa->x = ga->dir == DirHor ? ms : 0, sa->y = 0, sa->fx = sa->x + ss, sa->fy = m->wh;
    264  	else
    265 -		mw = m->ww;
    266 -	for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
    267 -		if (i < m->nmaster) {
    268 -			h = (m->wh - my) / (MIN(n, m->nmaster) - i);
    269 -			resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
    270 -			if (my + HEIGHT(c) < m->wh)
    271 -				my += HEIGHT(c);
    272 -		} else {
    273 -			h = (m->wh - ty) / (n - i);
    274 -			resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
    275 -			if (ty + HEIGHT(c) < m->wh)
    276 -				ty += HEIGHT(c);
    277 -		}
    278 +		ms = f * m->wh, ss = m->wh - ms,
    279 +		ma->x = 0, ma->y = ga->dir == DirVer ? 0 : ss, ma->fx = m->ww, ma->fy = ma->y + ms,
    280 +		sa->x = 0, sa->y = ga->dir == DirVer ? ms : 0, sa->fx = m->ww, sa->fy = sa->y + ss;
    281 +	/* tile clients */
    282 +	for(c = nexttiled(m->clients), i = 0; i < n; c = nexttiled(c->next), i++) {
    283 +		a = ma->n > 0 ? ma : sa;
    284 +		f = i == 0 || ma->n == 0 ? a->fact : 1, f /= --a->n + f;
    285 +		w = (a->dir == DirVer ? 1 : f) * (a->fx - a->x);
    286 +		h = (a->dir == DirHor ? 1 : f) * (a->fy - a->y);
    287 +		resize(c, m->wx + a->x, m->wy + a->y, w - 2 * c->bw, h - 2 * c->bw, False);
    288 +		a->x += a->dir == DirHor ? w : 0;
    289 +		a->y += a->dir == DirVer ? h : 0;
    290 +	}
    291  }
    292  
    293  void
    294 @@ -1786,7 +1831,6 @@ toggleview(const Arg *arg)
    295  
    296  		/* apply settings for this view */
    297  		selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    298 -		selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    299  		selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    300  		selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    301  		selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    302 @@ -2111,7 +2155,6 @@ view(const Arg *arg)
    303  	}
    304  
    305  	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    306 -	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    307  	selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    308  	selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    309  	selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    310 -- 
    311 2.26.2
    312