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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
From b8f39c0710eb3cfdf4c619f532222d356ec58140 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me?= <git@jeromecst.com>
Date: Fri, 17 May 2024 23:06:19 +0200
Subject: [PATCH] stacker
---
config.def.h | 10 +++++
dwl.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+)
diff --git a/config.def.h b/config.def.h
index 8f498d2..44cbcd8 100644
--- a/config.def.h
+++ b/config.def.h
@@ -120,10 +120,20 @@ static const char *menucmd[] = { "wmenu-run", NULL };
static const Key keys[] = {
/* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
/* modifier key function argument */
+ { MODKEY, XKB_KEY_q, focusto, {.i = 0} },
+ { MODKEY, XKB_KEY_w, focusto, {.i = 1} },
+ { MODKEY, XKB_KEY_e, focusto, {.i = 2} },
+ { MODKEY, XKB_KEY_r, focusto, {.i = -1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, swapstack, {.i = 0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_W, swapstack, {.i = 1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_E, swapstack, {.i = 2} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_R, swapstack, {.i = -1} },
{ MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
{ MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, relativeswap, {.i = +1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, relativeswap, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
{ MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
{ MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
diff --git a/dwl.c b/dwl.c
index bf763df..be88c6d 100644
--- a/dwl.c
+++ b/dwl.c
@@ -279,6 +279,7 @@ static void destroysessionlock(struct wl_listener *listener, void *data);
static void destroysessionmgr(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
static void focusclient(Client *c, int lift);
+static void focusto(const Arg *arg);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
@@ -308,6 +309,7 @@ static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
static void printstatus(void);
static void quit(const Arg *arg);
+static void relativeswap(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
@@ -327,6 +329,8 @@ static void setsel(struct wl_listener *listener, void *data);
static void setup(void);
static void spawn(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data);
+static void swapstack(const Arg *arg);
+static void relativeswap(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
@@ -343,9 +347,11 @@ static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data);
static void virtualpointer(struct wl_listener *listener, void *data);
+static Client *nextvisible(int i, struct wl_list *from, Monitor *m);
static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
+static void wl_list_swap(struct wl_list *a, struct wl_list *b);
static void zoom(const Arg *arg);
/* variables */
@@ -1308,6 +1314,21 @@ focusclient(Client *c, int lift)
client_activate_surface(client_surface(c), 1);
}
+void
+focusto(const Arg *arg)
+{
+ Client *c, *sel = focustop(selmon);
+ int i;
+ if (!sel || (sel->isfullscreen && !client_has_children(sel)))
+ return;
+
+ i = arg->i > -1 ? arg->i + 1 : arg->i;
+
+ c = nextvisible(i, &clients, selmon);
+ if (c)
+ focusclient(c , 1);
+}
+
void
focusmon(const Arg *arg)
{
@@ -1951,6 +1972,24 @@ quit(const Arg *arg)
wl_display_terminate(dpy);
}
+void
+relativeswap(const Arg *arg)
+{
+ Client *trgt, *sel = focustop(selmon);
+
+ if (!sel || !selmon)
+ return;
+
+ trgt = nextvisible(arg->i, &sel->link, selmon);
+ if (!trgt || trgt == sel)
+ return;
+
+ wl_list_swap(&sel->link, &trgt->link);
+
+ focusclient(sel, 1);
+ arrange(selmon);
+}
+
void
rendermon(struct wl_listener *listener, void *data)
{
@@ -2548,6 +2587,26 @@ startdrag(struct wl_listener *listener, void *data)
LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
}
+void
+swapstack(const Arg *arg)
+{
+ Client *trgt, *sel = focustop(selmon);
+ int i;
+
+ if (!sel || !selmon)
+ return;
+
+ i = arg->i > -1 ? arg->i + 1 : arg->i;
+ trgt = nextvisible(i, &clients, selmon);
+ if (!trgt || trgt == sel)
+ return;
+
+ wl_list_swap(&sel->link, &trgt->link);
+
+ focusclient(sel, 1);
+ arrange(selmon);
+}
+
void
tag(const Arg *arg)
{
@@ -2858,6 +2917,28 @@ virtualpointer(struct wl_listener *listener, void *data)
wlr_cursor_map_input_to_output(cursor, &pointer.base, event->suggested_output);
}
+Client *
+nextvisible(int i, struct wl_list *from, Monitor *m)
+{
+ Client *c;
+ if (i >= 0){
+ wl_list_for_each(c, from, link) {
+ // if (VISIBLEON(c , m) && &c->link != from && i--)
+ if (VISIBLEON(c , m)) {
+ if (--i == 0)
+ return c;
+ }
+ }
+ } else if (i < 0) {
+ wl_list_for_each_reverse(c, from, link) {
+ if (VISIBLEON(c , m))
+ if (++i == 0)
+ return c;
+ }
+ }
+ return NULL;
+}
+
Monitor *
xytomon(double x, double y)
{
@@ -2865,6 +2946,29 @@ xytomon(double x, double y)
return o ? o->data : NULL;
}
+void
+wl_list_swap(struct wl_list *a, struct wl_list *b)
+{
+ struct wl_list *prev_a = a->prev;
+ struct wl_list *prev_b = b->prev;
+
+ if (prev_b == a) {
+ wl_list_remove(a);
+ wl_list_insert(b, a);
+ return;
+ }
+ if (prev_a == b) {
+ wl_list_remove(b);
+ wl_list_insert(a, b);
+ return;
+ }
+ wl_list_remove(a);
+ wl_list_insert(prev_b, a);
+
+ wl_list_remove(b);
+ wl_list_insert(prev_a, b);
+}
+
void
xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny)
--
2.45.1
|