Skip to content

Commit 5bb5879

Browse files
committed
Add cfacts patch
1 parent 146afbc commit 5bb5879

File tree

4 files changed

+158
-4
lines changed

4 files changed

+158
-4
lines changed

config.def.h

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ static Key keys[] = {
7575
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
7676
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
7777
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
78+
{ MODKEY|ShiftMask, XK_i, setcfact, {.f = +0.25} },
79+
{ MODKEY|ShiftMask, XK_d, setcfact, {.f = -0.25} },
80+
{ MODKEY|ShiftMask, XK_r, setcfact, {.f = 0.00} },
7881
{ MODKEY, XK_Return, zoom, {0} },
7982
{ MODKEY, XK_Tab, view, {0} },
8083
{ MODKEY|ShiftMask, XK_c, killclient, {0} },

config.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ static Key keys[] = {
117117
{ MODKEY, XK_k, focusstack, {.i = +1 } },
118118
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
119119
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
120+
120121
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
121122
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
123+
{ MODKEY|ShiftMask, XK_i, setcfact, {.f = +0.25} },
124+
{ MODKEY|ShiftMask, XK_d, setcfact, {.f = -0.25} },
125+
{ MODKEY|ShiftMask, XK_r, setcfact, {.f = 0.00} },
126+
122127
{ MODKEY, XK_Return, zoom, {0} },
123128
{ MODKEY, XK_Tab, view, {0} },
124-
// { MODKEY|ShiftMask, XK_c, killclient, {0} },
129+
125130
{ MODKEY, XK_q, killclient, {0} },
126131
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
127132
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },

dwm-cfacts-20200913-61bb8b2.diff

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
From c32a879432573d71dec7fcb4bf68927d2f4cdf10 Mon Sep 17 00:00:00 2001
2+
From: iofq <[email protected]>
3+
Date: Sat, 12 Sep 2020 22:28:09 -0500
4+
Subject: [PATCH] Fixed 'cfacts' patch failure due to upstream commit
5+
'f09418bbb...'
6+
7+
---
8+
config.def.h | 3 +++
9+
dwm.c | 34 +++++++++++++++++++++++++++++++---
10+
2 files changed, 34 insertions(+), 3 deletions(-)
11+
12+
diff --git a/config.def.h b/config.def.h
13+
index 1c0b587..83910c1 100644
14+
--- a/config.def.h
15+
+++ b/config.def.h
16+
@@ -70,6 +70,9 @@ static Key keys[] = {
17+
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
18+
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
19+
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
20+
+ { MODKEY|ShiftMask, XK_h, setcfact, {.f = +0.25} },
21+
+ { MODKEY|ShiftMask, XK_l, setcfact, {.f = -0.25} },
22+
+ { MODKEY|ShiftMask, XK_o, setcfact, {.f = 0.00} },
23+
{ MODKEY, XK_Return, zoom, {0} },
24+
{ MODKEY, XK_Tab, view, {0} },
25+
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
26+
diff --git a/dwm.c b/dwm.c
27+
index 664c527..5233229 100644
28+
--- a/dwm.c
29+
+++ b/dwm.c
30+
@@ -87,6 +87,7 @@ typedef struct Client Client;
31+
struct Client {
32+
char name[256];
33+
float mina, maxa;
34+
+ float cfact;
35+
int x, y, w, h;
36+
int oldx, oldy, oldw, oldh;
37+
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
38+
@@ -201,6 +202,7 @@ static void setclientstate(Client *c, long state);
39+
static void setfocus(Client *c);
40+
static void setfullscreen(Client *c, int fullscreen);
41+
static void setlayout(const Arg *arg);
42+
+static void setcfact(const Arg *arg);
43+
static void setmfact(const Arg *arg);
44+
static void setup(void);
45+
static void seturgent(Client *c, int urg);
46+
@@ -1030,6 +1032,7 @@ manage(Window w, XWindowAttributes *wa)
47+
c->w = c->oldw = wa->width;
48+
c->h = c->oldh = wa->height;
49+
c->oldbw = wa->border_width;
50+
+ c->cfact = 1.0;
51+
52+
updatetitle(c);
53+
if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
54+
@@ -1512,6 +1515,23 @@ setlayout(const Arg *arg)
55+
drawbar(selmon);
56+
}
57+
58+
+void setcfact(const Arg *arg) {
59+
+ float f;
60+
+ Client *c;
61+
+
62+
+ c = selmon->sel;
63+
+
64+
+ if(!arg || !c || !selmon->lt[selmon->sellt]->arrange)
65+
+ return;
66+
+ f = arg->f + c->cfact;
67+
+ if(arg->f == 0.0)
68+
+ f = 1.0;
69+
+ else if(f < 0.25 || f > 4.0)
70+
+ return;
71+
+ c->cfact = f;
72+
+ arrange(selmon);
73+
+}
74+
+
75+
/* arg > 1.0 will set mfact absolutely */
76+
void
77+
setmfact(const Arg *arg)
78+
@@ -1675,9 +1695,15 @@ void
79+
tile(Monitor *m)
80+
{
81+
unsigned int i, n, h, mw, my, ty;
82+
+ float mfacts = 0, sfacts = 0;
83+
Client *c;
84+
85+
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
86+
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
87+
+ if (n < m->nmaster)
88+
+ mfacts += c->cfact;
89+
+ else
90+
+ sfacts += c->cfact;
91+
+ }
92+
if (n == 0)
93+
return;
94+
95+
@@ -1687,15 +1713,17 @@ tile(Monitor *m)
96+
mw = m->ww;
97+
for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
98+
if (i < m->nmaster) {
99+
- h = (m->wh - my) / (MIN(n, m->nmaster) - i);
100+
+ h = (m->wh - my) * (c->cfact / mfacts);
101+
resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
102+
if (my + HEIGHT(c) < m->wh)
103+
my += HEIGHT(c);
104+
+ mfacts -= c->cfact;
105+
} else {
106+
- h = (m->wh - ty) / (n - i);
107+
+ h = (m->wh - ty) * (c->cfact / sfacts);
108+
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
109+
if (ty + HEIGHT(c) < m->wh)
110+
ty += HEIGHT(c);
111+
+ sfacts -= c->cfact;
112+
}
113+
}
114+
115+
--
116+
2.28.0
117+

dwm.c

+32-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef struct Client Client;
8888
struct Client {
8989
char name[256];
9090
float mina, maxa;
91+
float cfact;
9192
int x, y, w, h;
9293
int oldx, oldy, oldw, oldh;
9394
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
@@ -203,6 +204,7 @@ static void setclientstate(Client *c, long state);
203204
static void setfocus(Client *c);
204205
static void setfullscreen(Client *c, int fullscreen);
205206
static void setlayout(const Arg *arg);
207+
static void setcfact(const Arg *arg);
206208
static void setmfact(const Arg *arg);
207209
static void setup(void);
208210
static void seturgent(Client *c, int urg);
@@ -1041,6 +1043,7 @@ manage(Window w, XWindowAttributes *wa)
10411043
c->w = c->oldw = wa->width;
10421044
c->h = c->oldh = wa->height;
10431045
c->oldbw = wa->border_width;
1046+
c->cfact = 1.0;
10441047

10451048
updatetitle(c);
10461049
if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
@@ -1624,6 +1627,23 @@ setlayout(const Arg *arg)
16241627
drawbar(selmon);
16251628
}
16261629

1630+
void setcfact(const Arg *arg) {
1631+
float f;
1632+
Client *c;
1633+
1634+
c = selmon->sel;
1635+
1636+
if(!arg || !c || !selmon->lt[selmon->sellt]->arrange)
1637+
return;
1638+
f = arg->f + c->cfact;
1639+
if(arg->f == 0.0)
1640+
f = 1.0;
1641+
else if(f < 0.25 || f > 4.0)
1642+
return;
1643+
c->cfact = f;
1644+
arrange(selmon);
1645+
}
1646+
16271647
/* arg > 1.0 will set mfact absolutely */
16281648
void
16291649
setmfact(const Arg *arg)
@@ -1787,9 +1807,15 @@ void
17871807
tile(Monitor *m)
17881808
{
17891809
unsigned int i, n, h, mw, my, ty;
1810+
float mfacts = 0, sfacts = 0;
17901811
Client *c;
17911812

1792-
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
1813+
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
1814+
if (n < m->nmaster)
1815+
mfacts += c->cfact;
1816+
else
1817+
sfacts += c->cfact;
1818+
}
17931819
if (n == 0)
17941820
return;
17951821

@@ -1799,15 +1825,18 @@ tile(Monitor *m)
17991825
mw = m->ww;
18001826
for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
18011827
if (i < m->nmaster) {
1802-
h = (m->wh - my) / (MIN(n, m->nmaster) - i);
1828+
h = (m->wh - my) *(c->cfact / mfacts);
18031829
resize(c, m->wx, m->wy + my, mw - (2*c->bw) + (n > 1 ? gappx : 0), h - (2*c->bw), 0);
18041830
if (my + HEIGHT(c) < m->wh)
18051831
my += HEIGHT(c);
1832+
1833+
mfacts -= c->cfact;
18061834
} else {
1807-
h = (m->wh - ty) / (n - i);
1835+
h = (m->wh - ty) * (c->cfact / sfacts);
18081836
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
18091837
if (ty + HEIGHT(c) < m->wh)
18101838
ty += HEIGHT(c);
1839+
sfacts -= c->cfact;
18111840
}
18121841
}
18131842

0 commit comments

Comments
 (0)