dwm-flextile-6.2.diff (13094B)
1 From 63354ec03bb7c1138bac60cec146c29e19230f32 Mon Sep 17 00:00:00 2001 2 From: Max Schillinger <maxschillinger@web.de> 3 Date: Fri, 2 Jul 2021 22:39:37 +0200 4 Subject: [PATCH] apply dwm-flextile-6.2.diff 5 6 --- 7 config.def.h | 14 +++++ 8 dwm.c | 114 +++++++++++++++++++----------------- 9 flextile.h | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++ 10 3 files changed, 235 insertions(+), 53 deletions(-) 11 create mode 100644 flextile.h 12 13 diff --git a/config.def.h b/config.def.h 14 index 1c0b587..0a8c20f 100644 15 --- a/config.def.h 16 +++ b/config.def.h 17 @@ -21,6 +21,9 @@ static const char *colors[][3] = { 18 /* tagging */ 19 static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; 20 21 +/* include(s) depending on the tags array */ 22 +#include "flextile.h" 23 + 24 static const Rule rules[] = { 25 /* xprop(1): 26 * WM_CLASS(STRING) = instance, class 27 @@ -35,6 +38,11 @@ static const Rule rules[] = { 28 static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ 29 static const int nmaster = 1; /* number of clients in master area */ 30 static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ 31 +static const int layoutaxis[] = { 32 + 1, /* layout axis: 1 = x, 2 = y; negative values mirror the layout, setting the master area to the right / bottom instead of left / top */ 33 + 2, /* master axis: 1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle) */ 34 + 2, /* stack axis: 1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle) */ 35 +}; 36 37 static const Layout layouts[] = { 38 /* symbol arrange function */ 39 @@ -94,6 +102,12 @@ static Key keys[] = { 40 TAGKEYS( XK_8, 7) 41 TAGKEYS( XK_9, 8) 42 { MODKEY|ShiftMask, XK_q, quit, {0} }, 43 + { MODKEY|ControlMask, XK_t, rotatelayoutaxis, {.i = 0} }, /* 0 = layout axis */ 44 + { MODKEY|ControlMask, XK_Tab, rotatelayoutaxis, {.i = 1} }, /* 1 = master axis */ 45 + { MODKEY|ControlMask|ShiftMask, XK_Tab, rotatelayoutaxis, {.i = 2} }, /* 2 = stack axis */ 46 + { MODKEY|ControlMask, XK_Return, mirrorlayout, {0} }, 47 + { MODKEY|ControlMask, XK_h, shiftmastersplit, {.i = -1} }, /* reduce the number of tiled clients in the master area */ 48 + { MODKEY|ControlMask, XK_l, shiftmastersplit, {.i = +1} }, /* increase the number of tiled clients in the master area */ 49 }; 50 51 /* button definitions */ 52 diff --git a/dwm.c b/dwm.c 53 index b0b3466..367bf78 100644 54 --- a/dwm.c 55 +++ b/dwm.c 56 @@ -111,27 +111,6 @@ typedef struct { 57 void (*arrange)(Monitor *); 58 } Layout; 59 60 -struct Monitor { 61 - char ltsymbol[16]; 62 - float mfact; 63 - int nmaster; 64 - int num; 65 - int by; /* bar geometry */ 66 - int mx, my, mw, mh; /* screen size */ 67 - int wx, wy, ww, wh; /* window area */ 68 - unsigned int seltags; 69 - unsigned int sellt; 70 - unsigned int tagset[2]; 71 - int showbar; 72 - int topbar; 73 - Client *clients; 74 - Client *sel; 75 - Client *stack; 76 - Monitor *next; 77 - Window barwin; 78 - const Layout *lt[2]; 79 -}; 80 - 81 typedef struct { 82 const char *class; 83 const char *instance; 84 @@ -631,6 +610,7 @@ configurerequest(XEvent *e) 85 Monitor * 86 createmon(void) 87 { 88 + unsigned int i; 89 Monitor *m; 90 91 m = ecalloc(1, sizeof(Monitor)); 92 @@ -642,6 +622,21 @@ createmon(void) 93 m->lt[0] = &layouts[0]; 94 m->lt[1] = &layouts[1 % LENGTH(layouts)]; 95 strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 96 + m->ltaxis[0] = layoutaxis[0]; 97 + m->ltaxis[1] = layoutaxis[1]; 98 + m->ltaxis[2] = layoutaxis[2]; 99 + m->msplit = 1; 100 + /* init tags, bars, layouts, axes, msplits and mfacts */ 101 + m->curtag = m->prevtag = 1; 102 + for(i = 0; i < LENGTH(tags) + 1; i++){ 103 + m->showbars[i] = m->showbar; 104 + m->lts[i] = &layouts[0]; 105 + m->mfacts[i] = m->mfact; 106 + m->ltaxes[i][0] = m->ltaxis[0]; 107 + m->ltaxes[i][1] = m->ltaxis[1]; 108 + m->ltaxes[i][2] = m->ltaxis[2]; 109 + m->msplits[i] = m->msplit; 110 + } 111 return m; 112 } 113 114 @@ -1504,7 +1499,7 @@ setlayout(const Arg *arg) 115 if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) 116 selmon->sellt ^= 1; 117 if (arg && arg->v) 118 - selmon->lt[selmon->sellt] = (Layout *)arg->v; 119 + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag] = (Layout *)arg->v; 120 strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); 121 if (selmon->sel) 122 arrange(selmon); 123 @@ -1523,7 +1518,7 @@ setmfact(const Arg *arg) 124 f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; 125 if (f < 0.05 || f > 0.95) 126 return; 127 - selmon->mfact = f; 128 + selmon->mfact = selmon->mfacts[selmon->curtag] = f; 129 arrange(selmon); 130 } 131 132 @@ -1671,38 +1666,10 @@ tagmon(const Arg *arg) 133 sendmon(selmon->sel, dirtomon(arg->i)); 134 } 135 136 -void 137 -tile(Monitor *m) 138 -{ 139 - unsigned int i, n, h, mw, my, ty; 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 - 146 - if (n > m->nmaster) 147 - mw = m->nmaster ? m->ww * m->mfact : 0; 148 - else 149 - mw = m->ww; 150 - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) 151 - if (i < m->nmaster) { 152 - h = (m->wh - my) / (MIN(n, m->nmaster) - i); 153 - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); 154 - if (my + HEIGHT(c) < m->wh) 155 - my += HEIGHT(c); 156 - } else { 157 - h = (m->wh - ty) / (n - i); 158 - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); 159 - if (ty + HEIGHT(c) < m->wh) 160 - ty += HEIGHT(c); 161 - } 162 -} 163 - 164 void 165 togglebar(const Arg *arg) 166 { 167 - selmon->showbar = !selmon->showbar; 168 + selmon->showbar = selmon->showbars[selmon->curtag] = !selmon->showbar; 169 updatebarpos(selmon); 170 XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); 171 arrange(selmon); 172 @@ -1726,12 +1693,31 @@ void 173 toggletag(const Arg *arg) 174 { 175 unsigned int newtags; 176 + unsigned int i; 177 178 if (!selmon->sel) 179 return; 180 newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); 181 if (newtags) { 182 selmon->sel->tags = newtags; 183 + if(newtags == ~0) { 184 + selmon->prevtag = selmon->curtag; 185 + selmon->curtag = 0; 186 + } 187 + if(!(newtags & 1 << (selmon->curtag - 1))) { 188 + selmon->prevtag = selmon->curtag; 189 + for (i=0; !(newtags & 1 << i); i++); 190 + selmon->curtag = i + 1; 191 + } 192 + selmon->sel->tags = newtags; 193 + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag]; 194 + selmon->mfact = selmon->mfacts[selmon->curtag]; 195 + if (selmon->showbar != selmon->showbars[selmon->curtag]) 196 + togglebar(NULL); 197 + selmon->ltaxis[0] = selmon->ltaxes[selmon->curtag][0]; 198 + selmon->ltaxis[1] = selmon->ltaxes[selmon->curtag][1]; 199 + selmon->ltaxis[2] = selmon->ltaxes[selmon->curtag][2]; 200 + selmon->msplit = selmon->msplits[selmon->curtag]; 201 focus(NULL); 202 arrange(selmon); 203 } 204 @@ -2038,11 +2024,33 @@ updatewmhints(Client *c) 205 void 206 view(const Arg *arg) 207 { 208 + unsigned int i; 209 + 210 if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) 211 return; 212 selmon->seltags ^= 1; /* toggle sel tagset */ 213 - if (arg->ui & TAGMASK) 214 + if (arg->ui & TAGMASK) { 215 selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; 216 + selmon->prevtag = selmon->curtag; 217 + if(arg->ui == ~0) 218 + selmon->curtag = 0; 219 + else { 220 + for (i=0; !(arg->ui & 1 << i); i++); 221 + selmon->curtag = i + 1; 222 + } 223 + } else { 224 + selmon->prevtag = selmon->curtag ^ selmon->prevtag; 225 + selmon->curtag ^= selmon->prevtag; 226 + selmon->prevtag = selmon->curtag ^ selmon->prevtag; 227 + } 228 + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag]; 229 + selmon->mfact = selmon->mfacts[selmon->curtag]; 230 + if(selmon->showbar != selmon->showbars[selmon->curtag]) 231 + togglebar(NULL); 232 + selmon->ltaxis[0] = selmon->ltaxes[selmon->curtag][0]; 233 + selmon->ltaxis[1] = selmon->ltaxes[selmon->curtag][1]; 234 + selmon->ltaxis[2] = selmon->ltaxes[selmon->curtag][2]; 235 + selmon->msplit = selmon->msplits[selmon->curtag]; 236 focus(NULL); 237 arrange(selmon); 238 } 239 diff --git a/flextile.h b/flextile.h 240 new file mode 100644 241 index 0000000..9735cf9 242 --- /dev/null 243 +++ b/flextile.h 244 @@ -0,0 +1,160 @@ 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 + int nmaster; 252 + double mfacts[LENGTH(tags) + 1]; 253 + int ltaxis[3]; 254 + int ltaxes[LENGTH(tags) + 1][3]; 255 + int num; 256 + int curtag; 257 + int prevtag; 258 + int by; /* bar geometry */ 259 + int mx, my, mw, mh; /* screen size */ 260 + int wx, wy, ww, wh; /* window area */ 261 + unsigned int msplit; 262 + unsigned int msplits[LENGTH(tags) + 1]; 263 + unsigned int seltags; 264 + unsigned int sellt; 265 + unsigned int tagset[2]; 266 + Bool showbar; 267 + Bool showbars[LENGTH(tags) + 1]; 268 + Bool topbar; 269 + Client *clients; 270 + Client *sel; 271 + Client *stack; 272 + Monitor *next; 273 + Window barwin; 274 + const Layout *lt[2]; 275 + const Layout *lts[LENGTH(tags) + 1]; 276 +}; 277 + 278 +/* function declarations */ 279 +static void mirrorlayout(const Arg *arg); 280 +static void rotatelayoutaxis(const Arg *arg); 281 +static void shiftmastersplit(const Arg *arg); 282 + 283 +void 284 +mirrorlayout(const Arg *arg) { 285 + if(!selmon->lt[selmon->sellt]->arrange) 286 + return; 287 + selmon->ltaxis[0] *= -1; 288 + selmon->ltaxes[selmon->curtag][0] = selmon->ltaxis[0]; 289 + arrange(selmon); 290 +} 291 + 292 +void 293 +rotatelayoutaxis(const Arg *arg) { 294 + if(!selmon->lt[selmon->sellt]->arrange) 295 + return; 296 + if(arg->i == 0) { 297 + if(selmon->ltaxis[0] > 0) 298 + selmon->ltaxis[0] = selmon->ltaxis[0] + 1 > 2 ? 1 : selmon->ltaxis[0] + 1; 299 + else 300 + selmon->ltaxis[0] = selmon->ltaxis[0] - 1 < -2 ? -1 : selmon->ltaxis[0] - 1; 301 + } else 302 + selmon->ltaxis[arg->i] = selmon->ltaxis[arg->i] + 1 > 3 ? 1 : selmon->ltaxis[arg->i] + 1; 303 + selmon->ltaxes[selmon->curtag][arg->i] = selmon->ltaxis[arg->i]; 304 + arrange(selmon); 305 +} 306 + 307 +void 308 +shiftmastersplit(const Arg *arg) { 309 + unsigned int n; 310 + Client *c; 311 + 312 + for(n = 0, c = nexttiled(selmon->clients); c; c = nexttiled(c->next), n++); 313 + if(!arg || !selmon->lt[selmon->sellt]->arrange || selmon->msplit + arg->i < 1 || selmon->msplit + arg->i > n) 314 + return; 315 + selmon->msplit += arg->i; 316 + selmon->msplits[selmon->curtag] = selmon->msplit; 317 + arrange(selmon); 318 +} 319 + 320 +void 321 +tile(Monitor *m) { 322 + char sym1 = 61, sym2 = 93, sym3 = 61, sym; 323 + int x1 = m->wx, y1 = m->wy, h1 = m->wh, w1 = m->ww, X1 = x1 + w1, Y1 = y1 + h1; 324 + int x2 = m->wx, y2 = m->wy, h2 = m->wh, w2 = m->ww, X2 = x2 + w2, Y2 = y2 + h2; 325 + unsigned int i, n, n1, n2; 326 + Client *c; 327 + 328 + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 329 + if(m->msplit > n) 330 + m->msplit = (n == 0) ? 1 : n; 331 + /* layout symbol */ 332 + 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)) */ 333 + sym1 = 124; 334 + if(abs(m->ltaxis[0]) == m->ltaxis[2]) 335 + sym3 = 124; 336 + if(m->ltaxis[1] == 3) 337 + sym1 = (n == 0) ? 0 : m->msplit; 338 + if(m->ltaxis[2] == 3) 339 + sym3 = (n == 0) ? 0 : n - m->msplit; 340 + if(m->ltaxis[0] < 0) { 341 + sym = sym1; 342 + sym1 = sym3; 343 + sym2 = 91; 344 + sym3 = sym; 345 + } 346 + if(m->msplit == 1) { 347 + if(m->ltaxis[0] > 0) 348 + sym1 = 91; 349 + else 350 + sym3 = 93; 351 + } 352 + if(m->msplit > 1 && m->ltaxis[1] == 3 && m->ltaxis[2] == 3) 353 + snprintf(m->ltsymbol, sizeof m->ltsymbol, "%d%c%d", sym1, sym2, sym3); 354 + else if((m->msplit > 1 && m->ltaxis[1] == 3 && m->ltaxis[0] > 0) || (m->ltaxis[2] == 3 && m->ltaxis[0] < 0)) 355 + snprintf(m->ltsymbol, sizeof m->ltsymbol, "%d%c%c", sym1, sym2, sym3); 356 + else if((m->ltaxis[2] == 3 && m->ltaxis[0] > 0) || (m->msplit > 1 && m->ltaxis[1] == 3 && m->ltaxis[0] < 0)) 357 + snprintf(m->ltsymbol, sizeof m->ltsymbol, "%c%c%d", sym1, sym2, sym3); 358 + else 359 + snprintf(m->ltsymbol, sizeof m->ltsymbol, "%c%c%c", sym1, sym2, sym3); 360 + if(n == 0) 361 + return; 362 + /* master and stack area */ 363 + if(abs(m->ltaxis[0]) == 1 && n > m->msplit) { 364 + w1 *= m->mfact; 365 + w2 -= w1; 366 + x1 += (m->ltaxis[0] < 0) ? w2 : 0; 367 + x2 += (m->ltaxis[0] < 0) ? 0 : w1; 368 + X1 = x1 + w1; 369 + X2 = x2 + w2; 370 + } else if(abs(m->ltaxis[0]) == 2 && n > m->msplit) { 371 + h1 *= m->mfact; 372 + h2 -= h1; 373 + y1 += (m->ltaxis[0] < 0) ? h2 : 0; 374 + y2 += (m->ltaxis[0] < 0) ? 0 : h1; 375 + Y1 = y1 + h1; 376 + Y2 = y2 + h2; 377 + } 378 + /* master */ 379 + n1 = (m->ltaxis[1] != 1 || w1 / m->msplit < bh) ? 1 : m->msplit; 380 + n2 = (m->ltaxis[1] != 2 || h1 / m->msplit < bh) ? 1 : m->msplit; 381 + for(i = 0, c = nexttiled(m->clients); i < m->msplit; c = nexttiled(c->next), i++) { 382 + resize(c, x1, y1, 383 + (m->ltaxis[1] == 1 && i + 1 == m->msplit) ? X1 - x1 - 2 * c->bw : w1 / n1 - 2 * c->bw, 384 + (m->ltaxis[1] == 2 && i + 1 == m->msplit) ? Y1 - y1 - 2 * c->bw : h1 / n2 - 2 * c->bw, False); 385 + if(n1 > 1) 386 + x1 = c->x + WIDTH(c); 387 + if(n2 > 1) 388 + y1 = c->y + HEIGHT(c); 389 + } 390 + /* stack */ 391 + if(n > m->msplit) { 392 + n1 = (m->ltaxis[2] != 1 || w2 / (n - m->msplit) < bh) ? 1 : n - m->msplit; 393 + n2 = (m->ltaxis[2] != 2 || h2 / (n - m->msplit) < bh) ? 1 : n - m->msplit; 394 + for(i = 0; c; c = nexttiled(c->next), i++) { 395 + resize(c, x2, y2, 396 + (m->ltaxis[2] == 1 && i + 1 == n - m->msplit) ? X2 - x2 - 2 * c->bw : w2 / n1 - 2 * c->bw, 397 + (m->ltaxis[2] == 2 && i + 1 == n - m->msplit) ? Y2 - y2 - 2 * c->bw : h2 / n2 - 2 * c->bw, False); 398 + if(n1 > 1) 399 + x2 = c->x + WIDTH(c); 400 + if(n2 > 1) 401 + y2 = c->y + HEIGHT(c); 402 + } 403 + } 404 +} 405 -- 406 2.25.1 407