summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/viewnextocctag/viewnextocctag.patch
blob: f79743115d935ea8338886e0b6d64eb87621a5af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
From 330fa634a83e9b332494fade75552e02583bad6c Mon Sep 17 00:00:00 2001
From: Ben Collerson <benc@benc.cc>
Date: Sat, 30 Dec 2023 13:39:31 +1000
Subject: [PATCH] viewnextocctag

---
 config.def.h |  2 ++
 dwl.c        | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/config.def.h b/config.def.h
index a784eb4f..e1a6a428 100644
--- a/config.def.h
+++ b/config.def.h
@@ -130,6 +130,8 @@ static const Key keys[] = {
 	{ MODKEY,                    XKB_KEY_d,          incnmaster,     {.i = -1} },
 	{ MODKEY,                    XKB_KEY_h,          setmfact,       {.f = -0.05f} },
 	{ MODKEY,                    XKB_KEY_l,          setmfact,       {.f = +0.05f} },
+	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_H,          viewnextocctag, {.i = -1} },
+	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_L,          viewnextocctag, {.i = +1} },
 	{ MODKEY,                    XKB_KEY_Return,     zoom,           {0} },
 	{ MODKEY,                    XKB_KEY_Tab,        view,           {0} },
 	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C,          killclient,     {0} },
diff --git a/dwl.c b/dwl.c
index 6f041a0d..df5461d0 100644
--- a/dwl.c
+++ b/dwl.c
@@ -304,6 +304,7 @@ static void motionnotify(uint32_t time, struct wlr_input_device *device, double
 		double sy, double sx_unaccel, double sy_unaccel);
 static void motionrelative(struct wl_listener *listener, void *data);
 static void moveresize(const Arg *arg);
+unsigned int nextocctag(int);
 static void outputmgrapply(struct wl_listener *listener, void *data);
 static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test);
 static void outputmgrtest(struct wl_listener *listener, void *data);
@@ -344,6 +345,7 @@ static void updatemons(struct wl_listener *listener, void *data);
 static void updatetitle(struct wl_listener *listener, void *data);
 static void urgent(struct wl_listener *listener, void *data);
 static void view(const Arg *arg);
+static void viewnextocctag(const Arg *argint);
 static void virtualkeyboard(struct wl_listener *listener, void *data);
 static void virtualpointer(struct wl_listener *listener, void *data);
 static Monitor *xytomon(double x, double y);
@@ -1868,6 +1870,27 @@ moveresize(const Arg *arg)
 	}
 }
 
+unsigned int
+nextocctag(int direction)
+{
+	unsigned int seltag = selmon->tagset[selmon->seltags];
+	unsigned int occ = 0, i;
+	Client *c;
+
+	wl_list_for_each(c, &clients, link)
+		occ |= c->tags;
+
+	for (i=0; i<TAGCOUNT; i++) {
+		seltag = (direction > 0) ?
+			(seltag == (1u << (TAGCOUNT - 1)) ? 1u : seltag << 1) :
+			(seltag == 1 ? (1u << (TAGCOUNT - 1)) : seltag >> 1);
+		if (seltag & occ)
+			break;
+	}
+
+	return seltag & TAGMASK;
+}
+
 void
 outputmgrapply(struct wl_listener *listener, void *data)
 {
@@ -2852,6 +2875,17 @@ view(const Arg *arg)
 	printstatus();
 }
 
+void
+viewnextocctag(const Arg *arg)
+{
+	unsigned int tmp;
+
+	if ((tmp = nextocctag(arg->i)) == selmon->tagset[selmon->seltags])
+		return;
+
+	view(&(const Arg){.ui = tmp});
+}
+
 void
 virtualkeyboard(struct wl_listener *listener, void *data)
 {
-- 
2.45.1