dwm

dwm

https://git.tonybtw.com/dwm.git git://git.tonybtw.com/dwm.git
3,505 bytes raw
1
From 9cd160c4ba9c345c24644a7da77cc4f04fc93c4e Mon Sep 17 00:00:00 2001
2
From: Rob Pilling <robpilling@gmail.com>
3
Date: Mon, 27 Jul 2020 20:11:08 +0100
4
Subject: [PATCH] alwaysontop
5
6
---
7
 config.def.h |  1 +
8
 dwm.c        | 45 +++++++++++++++++++++++++++++++++++++++++++--
9
 2 files changed, 44 insertions(+), 2 deletions(-)
10
11
diff --git a/config.def.h b/config.def.h
12
index 1c0b587..c3c7edd 100644
13
--- a/config.def.h
14
+++ b/config.def.h
15
@@ -78,6 +78,7 @@ static Key keys[] = {
16
 	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
17
 	{ MODKEY,                       XK_space,  setlayout,      {0} },
18
 	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
19
+	{ MODKEY|ShiftMask,             XK_space,  togglealwaysontop, {0} },
20
 	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
21
 	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
22
 	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
23
diff --git a/dwm.c b/dwm.c
24
index 4465af1..8d54b26 100644
25
--- a/dwm.c
26
+++ b/dwm.c
27
@@ -92,7 +92,7 @@ struct Client {
28
 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
29
 	int bw, oldbw;
30
 	unsigned int tags;
31
-	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
32
+	int isfixed, iscentered, isfloating, isalwaysontop, isurgent, neverfocus, oldstate, isfullscreen;
33
 	Client *next;
34
 	Client *snext;
35
 	Monitor *mon;
36
@@ -211,6 +211,7 @@ static void tagmon(const Arg *arg);
37
 static void tile(Monitor *);
38
 static void togglebar(const Arg *arg);
39
 static void togglefloating(const Arg *arg);
40
+static void togglealwaysontop(const Arg *arg);
41
 static void toggletag(const Arg *arg);
42
 static void toggleview(const Arg *arg);
43
 static void unfocus(Client *c, int setfocus);
44
@@ -732,8 +733,11 @@ drawbar(Monitor *m)
45
 		if (m->sel) {
46
 			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
47
 			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
48
-			if (m->sel->isfloating)
49
+			if (m->sel->isfloating) {
50
 				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
51
+				if (m->sel->isalwaysontop)
52
+					drw_rect(drw, x + boxs, bh - boxw, boxw, boxw, 0, 0);
53
+			}
54
 		} else {
55
 			drw_setscheme(drw, scheme[SchemeNorm]);
56
 			drw_rect(drw, x, 0, w, bh, 1, 1);
57
@@ -1356,6 +1360,17 @@ restack(Monitor *m)
58
 		return;
59
 	if (m->sel->isfloating || !m->lt[m->sellt]->arrange)
60
 		XRaiseWindow(dpy, m->sel->win);
61
+
62
+	/* raise the aot window */
63
+	for(Monitor *m_search = mons; m_search; m_search = m_search->next){
64
+		for(c = m_search->clients; c; c = c->next){
65
+			if(c->isalwaysontop){
66
+				XRaiseWindow(dpy, c->win);
67
+				break;
68
+			}
69
+		}
70
+	}
71
+
72
 	if (m->lt[m->sellt]->arrange) {
73
 		wc.stack_mode = Below;
74
 		wc.sibling = m->barwin;
75
@@ -1716,6 +1731,32 @@ togglefloating(const Arg *arg)
76
 	if (selmon->sel->isfloating)
77
 		resize(selmon->sel, selmon->sel->x, selmon->sel->y,
78
 			selmon->sel->w, selmon->sel->h, 0);
79
+	else
80
+		selmon->sel->isalwaysontop = 0; /* disabled, turn this off too */
81
+	arrange(selmon);
82
+}
83
+
84
+void
85
+togglealwaysontop(const Arg *arg)
86
+{
87
+	if (!selmon->sel)
88
+		return;
89
+	if (selmon->sel->isfullscreen)
90
+		return;
91
+
92
+	if(selmon->sel->isalwaysontop){
93
+		selmon->sel->isalwaysontop = 0;
94
+	}else{
95
+		/* disable others */
96
+		for(Monitor *m = mons; m; m = m->next)
97
+			for(Client *c = m->clients; c; c = c->next)
98
+				c->isalwaysontop = 0;
99
+
100
+		/* turn on, make it float too */
101
+		selmon->sel->isfloating = 1;
102
+		selmon->sel->isalwaysontop = 1;
103
+	}
104
+
105
 	arrange(selmon);
106
 }
107
 
108
-- 
109
2.31.1