dwm-foreground-20240220-9f88553.diff - sites - public wiki contents of suckless… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dwm-foreground-20240220-9f88553.diff (5117B) | |
--- | |
1 From 507895940574e77386d53f81df541e3903bf1ba3 Mon Sep 17 00:00:00 2001 | |
2 From: espro1 <[email protected]> | |
3 Date: Tue, 20 Feb 2024 16:11:05 -0500 | |
4 Subject: [PATCH] Essentially a layout for a special class of floating wi… | |
5 When a window is foregrounded, it is floated, resized, and moved to a | |
6 predictable location | |
7 | |
8 --- | |
9 config.def.h | 3 ++ | |
10 dwm.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++- | |
11 2 files changed, 84 insertions(+), 1 deletion(-) | |
12 | |
13 diff --git a/config.def.h b/config.def.h | |
14 index 9efa774..718e7c3 100644 | |
15 --- a/config.def.h | |
16 +++ b/config.def.h | |
17 @@ -37,6 +37,8 @@ static const int nmaster = 1; /* number of clie… | |
18 static const int resizehints = 1; /* 1 means respect size hints in t… | |
19 static const int lockfullscreen = 1; /* 1 will force focus on the fulls… | |
20 | |
21 +static const float fgw = .6,fgh = .6; | |
22 + | |
23 static const Layout layouts[] = { | |
24 /* symbol arrange function */ | |
25 { "[]=", tile }, /* first entry is default */ | |
26 @@ -78,6 +80,7 @@ static const Key keys[] = { | |
27 { MODKEY, XK_f, setlayout, {.v … | |
28 { MODKEY, XK_m, setlayout, {.v … | |
29 { MODKEY, XK_space, setlayout, {0} … | |
30 + { MODKEY|Mod4Mask, XK_space, toggleforegrounded, … | |
31 { MODKEY|ShiftMask, XK_space, togglefloating, {0} … | |
32 { MODKEY, XK_0, view, {.ui… | |
33 { MODKEY|ShiftMask, XK_0, tag, {.ui… | |
34 diff --git a/dwm.c b/dwm.c | |
35 index f1d86b2..12b037d 100644 | |
36 --- a/dwm.c | |
37 +++ b/dwm.c | |
38 @@ -92,9 +92,10 @@ struct Client { | |
39 int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvali… | |
40 int bw, oldbw; | |
41 unsigned int tags; | |
42 - int isfixed, isfloating, isurgent, neverfocus, oldstate, isfull… | |
43 + int isfixed, isfloating, isurgent, neverfocus, oldstate, isfull… | |
44 Client *next; | |
45 Client *snext; | |
46 + Client *tnext; | |
47 Monitor *mon; | |
48 Window win; | |
49 }; | |
50 @@ -127,6 +128,7 @@ struct Monitor { | |
51 Client *clients; | |
52 Client *sel; | |
53 Client *stack; | |
54 + Client *foregrounded; | |
55 Monitor *next; | |
56 Window barwin; | |
57 const Layout *lt[2]; | |
58 @@ -210,6 +212,7 @@ static void tag(const Arg *arg); | |
59 static void tagmon(const Arg *arg); | |
60 static void tile(Monitor *m); | |
61 static void togglebar(const Arg *arg); | |
62 +static void toggleforegrounded(const Arg *arg); | |
63 static void togglefloating(const Arg *arg); | |
64 static void toggletag(const Arg *arg); | |
65 static void toggleview(const Arg *arg); | |
66 @@ -415,6 +418,21 @@ attachstack(Client *c) | |
67 c->mon->stack = c; | |
68 } | |
69 | |
70 +void | |
71 +attachforegrounded (Client *c) | |
72 +{ | |
73 + c->tnext = c->mon->foregrounded; | |
74 + c->mon->foregrounded = c; | |
75 +} | |
76 + | |
77 +void | |
78 +detachforegrounded (Client *c) | |
79 +{ | |
80 + Client **tc; | |
81 + for (tc = &c->mon->foregrounded; *tc && *tc != c; tc = &(*tc)->… | |
82 + *tc = c->tnext; | |
83 +} | |
84 + | |
85 void | |
86 buttonpress(XEvent *e) | |
87 { | |
88 @@ -1209,6 +1227,39 @@ nexttiled(Client *c) | |
89 return c; | |
90 } | |
91 | |
92 +Client * | |
93 +nextforegrounded(Client *c) | |
94 +{ | |
95 + for (; c && (!c->isforegrounded || !ISVISIBLE(c)); c = c->tnext… | |
96 + return c; | |
97 +} | |
98 + | |
99 +void | |
100 +arrangeforegrounded (Monitor *m) | |
101 +{ | |
102 + unsigned int n,i,x,y,w,h; | |
103 + Client *c; | |
104 + | |
105 + for (n = 0, c = nextforegrounded(m->foregrounded); c; c = nextf… | |
106 + if (n == 0) | |
107 + return; | |
108 + | |
109 + for (i = 0, c = nextforegrounded(m->foregrounded); c; c = nextf… | |
110 + if (n == 1) { | |
111 + x = m->mx + (m->mw - m->mw * fgw) / 2; | |
112 + y = m->my + (m->mh - m->mh * fgh) / 2; | |
113 + w = (m->mw * fgw) - (2 * (m->foregrounded->bw)); | |
114 + h = (m->mh * fgh) - (2 * (m->foregrounded->bw)); | |
115 + } else { | |
116 + x = (n - 1 - i) * (m->mw / n); | |
117 + y = m->my + (m->mh - m->mh * fgh) / 2; | |
118 + w = (m->mw * (1 / (float)n)) - (2 * (m->foregro… | |
119 + h = (m->mh * fgh) - (2 * (m->foregrounded->bw)); | |
120 + } | |
121 + resize(c,x,y,w,h,0); | |
122 + } | |
123 +} | |
124 + | |
125 void | |
126 pop(Client *c) | |
127 { | |
128 @@ -1721,6 +1772,24 @@ togglebar(const Arg *arg) | |
129 arrange(selmon); | |
130 } | |
131 | |
132 +void | |
133 +toggleforegrounded(const Arg *arg) | |
134 +{ | |
135 + if (!selmon->sel) | |
136 + return; | |
137 + if (selmon->sel->isfullscreen) /* no support for fullscreen win… | |
138 + return; | |
139 + | |
140 + selmon->sel->isforegrounded || selmon->sel->isfloating ? | |
141 + detachforegrounded(selmon->sel) : attachforegrounded(se… | |
142 + | |
143 + selmon->sel->isforegrounded = selmon->sel->isfloating = | |
144 + !selmon->sel->isfloating && !selmon->sel->isforegrounde… | |
145 + | |
146 + arrangeforegrounded(selmon); | |
147 + arrange(selmon); | |
148 +} | |
149 + | |
150 void | |
151 togglefloating(const Arg *arg) | |
152 { | |
153 @@ -1732,6 +1801,11 @@ togglefloating(const Arg *arg) | |
154 if (selmon->sel->isfloating) | |
155 resize(selmon->sel, selmon->sel->x, selmon->sel->y, | |
156 selmon->sel->w, selmon->sel->h, 0); | |
157 + if (selmon->sel->isforegrounded) { | |
158 + selmon->sel->isforegrounded = 0; | |
159 + detachforegrounded(selmon->sel); | |
160 + arrangeforegrounded(selmon); | |
161 + } | |
162 arrange(selmon); | |
163 } | |
164 | |
165 @@ -1783,6 +1857,12 @@ unmanage(Client *c, int destroyed) | |
166 | |
167 detach(c); | |
168 detachstack(c); | |
169 + | |
170 + if (c->isforegrounded){ | |
171 + detachforegrounded(c); | |
172 + arrangeforegrounded(m); | |
173 + } | |
174 + | |
175 if (!destroyed) { | |
176 wc.border_width = c->oldbw; | |
177 XGrabServer(dpy); /* avoid race conditions */ | |
178 -- | |
179 2.43.0 | |
180 |