+381
config/river/init.roc
+381
config/river/init.roc
···
1
+
#!/usr/bin/env roc
2
+
app [main!] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" }
3
+
4
+
# TODO: Create a platform that interfaces directly with the river wayland protocol
5
+
# TODO: Check for a cli argument to determine if the autostart commands should be run
6
+
7
+
import pf.Cmd
8
+
import pf.Env
9
+
import pf.Stdout
10
+
import pf.Stderr
11
+
12
+
named_tag_to_rtag = |tag_name|
13
+
when tag_name is
14
+
One -> tag_to_rtag 1
15
+
Two -> tag_to_rtag 2
16
+
Three -> tag_to_rtag 3
17
+
Four -> tag_to_rtag 4
18
+
Five -> tag_to_rtag 5
19
+
Six -> tag_to_rtag 6
20
+
Seven -> tag_to_rtag 7
21
+
Eight -> tag_to_rtag 8
22
+
Nine -> tag_to_rtag 9
23
+
KeePassXC -> tag_to_rtag 10
24
+
Nautilus -> tag_to_rtag 11
25
+
Thunderbird -> tag_to_rtag 12
26
+
All -> (Num.shift_left_by 1 32) - 1
27
+
28
+
autostart! = |{}|
29
+
home = Env.decode! "HOME" ?? "/"
30
+
31
+
[
32
+
"systemctl --user start river-session-pre.target",
33
+
"update-session-vars",
34
+
"systemctl --user start river-session.target",
35
+
"kanshi",
36
+
"rivertile -outer-padding 0 -view-padding 0 -main-ratio 0.5",
37
+
Str.replace_each "swaybg -i $HOME/pic/wallpapers/dark/evie-s-Pb1KFv4tauY-unsplash.jpg -m fill" "$HOME" home,
38
+
]
39
+
40
+
configurations = [
41
+
{ option: "border-color-focused", args: ["0x93a1a1"] },
42
+
{ option: "border-color-unfocused", args: ["0x586e75"] },
43
+
{ option: "focus-follows-cursor", args: ["normal"] },
44
+
{ option: "set-cursor-warp", args: ["on-output-change"] },
45
+
{ option: "xcursor-theme", args: ["Adwaita", "24"] },
46
+
{
47
+
option: "input",
48
+
args: [
49
+
"pointer-1356-3570-Sony_Interactive_Entertainment_DualSense_Edge_Wireless_Controller_Touchpad",
50
+
"events",
51
+
"disabled",
52
+
],
53
+
},
54
+
]
55
+
56
+
rules = [
57
+
{ id: "org.gnome.Nautilus", title: "", action: "float", args: [] },
58
+
{ id: "org.gnome.Nautilus", title: "", action: "tags", args: [Num.to_str (named_tag_to_rtag Nautilus)] },
59
+
{ id: "org.gnome.Nautilus", title: "", action: "float", args: [] },
60
+
{ id: "org.keepassxc.KeePassXC", title: "", action: "float", args: [] },
61
+
{
62
+
id: "org.keepassxc.KeePassXC",
63
+
title: "KeyChain.kdbx [Locked] - KeePassXC",
64
+
action: "tags",
65
+
args: [Num.to_str (named_tag_to_rtag KeePassXC)],
66
+
},
67
+
{ id: "org.mozilla.Thunderbird", title: "", action: "tags", args: [Num.to_str (named_tag_to_rtag Thunderbird)] },
68
+
]
69
+
70
+
modes = [
71
+
"passthrough",
72
+
"special-tags",
73
+
]
74
+
75
+
pointer_binds = [
76
+
{ mode: "normal", mods: [Super], btn: "BTN_LEFT", cmd: "move-view" },
77
+
{ mode: "normal", mods: [Super], btn: "BTN_RIGHT", cmd: "resize-view" },
78
+
]
79
+
80
+
tag_binds =
81
+
List.range { start: At(1), end: At(9) }
82
+
|> List.map(
83
+
|tag_num| [
84
+
{
85
+
mode: "normal",
86
+
mods: [Super],
87
+
key: Num.to_str tag_num,
88
+
cmd: "toggle-focused-tags",
89
+
args: [Num.to_str (tag_to_rtag tag_num)],
90
+
},
91
+
{
92
+
mode: "normal",
93
+
mods: [Super, Shift],
94
+
key: Num.to_str tag_num,
95
+
cmd: "toggle-view-tags",
96
+
args: [Num.to_str (tag_to_rtag tag_num)],
97
+
},
98
+
{
99
+
mode: "normal",
100
+
mods: [Super, Control],
101
+
key: Num.to_str tag_num,
102
+
cmd: "set-focused-tags",
103
+
args: [Num.to_str (tag_to_rtag tag_num)],
104
+
},
105
+
{
106
+
mode: "normal",
107
+
mods: [Super, Shift, Control],
108
+
key: Num.to_str tag_num,
109
+
cmd: "set-view-tags",
110
+
args: [Num.to_str (tag_to_rtag tag_num)],
111
+
},
112
+
],
113
+
)
114
+
|> List.join
115
+
|> List.concat [
116
+
# Show all tags
117
+
{
118
+
mode: "normal",
119
+
mods: [Super],
120
+
key: "0",
121
+
cmd: "set-focused-tags",
122
+
args: [Num.to_str (named_tag_to_rtag All)],
123
+
},
124
+
{
125
+
mode: "normal",
126
+
mods: [Super, Shift],
127
+
key: "0",
128
+
cmd: "set-view-tags",
129
+
args: [Num.to_str (named_tag_to_rtag All)],
130
+
},
131
+
]
132
+
133
+
keybinds = [
134
+
# Launch Applications
135
+
{ mode: "normal", mods: [Super], key: "Return", cmd: "spawn", args: ["foot"] },
136
+
{ mode: "normal", mods: [Super], key: "R", cmd: "spawn", args: ["bemenu-run.sh"] },
137
+
138
+
# Audio
139
+
{ mode: "normal", mods: [Super], key: "E", cmd: "spawn", args: ["wpctl set-mute @DEFAULT_SOURCE@ toggle"] },
140
+
141
+
# Screen capture
142
+
{ mode: "normal", mods: [None], key: "Print", cmd: "spawn", args: ["scr pic -c"] },
143
+
{ mode: "normal", mods: [Super], key: "Print", cmd: "spawn", args: ["scr pic -cd"] },
144
+
145
+
# Output Control
146
+
{ mode: "normal", mods: [Super], key: "X", cmd: "focus-output", args: ["next"] },
147
+
{ mode: "normal", mods: [Super, Alt], key: "X", cmd: "focus-output", args: ["previous"] },
148
+
{ mode: "normal", mods: [Super, Control], key: "X", cmd: "send-to-output", args: ["next"] },
149
+
{ mode: "normal", mods: [Super, Control, Alt], key: "X", cmd: "send-to-output", args: ["previous"] },
150
+
{
151
+
mode: "normal",
152
+
mods: [Super, Shift, Control],
153
+
key: "X",
154
+
cmd: "send-to-output",
155
+
args: ["-current-tags", "next"],
156
+
},
157
+
{
158
+
mode: "normal",
159
+
mods: [Super, Shift, Control, Alt],
160
+
key: "X",
161
+
cmd: "send-to-output",
162
+
args: ["-current-tags", "previous"],
163
+
},
164
+
165
+
# Exit River
166
+
{ mode: "normal", mods: [Super, Control], key: "Escape", cmd: "exit", args: [] },
167
+
168
+
# Window Management
169
+
{ mode: "normal", mods: [Super], key: "Q", cmd: "close", args: [] },
170
+
{ mode: "normal", mods: [Super], key: "F", cmd: "toggle-float", args: [] },
171
+
{ mode: "normal", mods: [Super, Control], key: "F", cmd: "toggle-fullscreen", args: [] },
172
+
{ mode: "normal", mods: [Super], key: "T", cmd: "output-layout", args: ["rivertile"] },
173
+
{ mode: "normal", mods: [Super, Control], key: "T", cmd: "output-layout", args: ["none"] },
174
+
{ mode: "normal", mods: [Super], key: "Z", cmd: "focus-view", args: ["next"] },
175
+
{ mode: "normal", mods: [Super, Control], key: "Z", cmd: "focus-view", args: ["previous"] },
176
+
{ mode: "normal", mods: [Super], key: "Up", cmd: "send-layout-cmd", args: ["rivertile", "main-location top"] },
177
+
{ mode: "normal", mods: [Super], key: "Left", cmd: "send-layout-cmd", args: ["rivertile", "main-location left"] },
178
+
{ mode: "normal", mods: [Super], key: "Down", cmd: "send-layout-cmd", args: ["rivertile", "main-location bottom"] },
179
+
{ mode: "normal", mods: [Super], key: "Right", cmd: "send-layout-cmd", args: ["rivertile", "main-location right"] },
180
+
{ mode: "normal", mods: [Super], key: "Bracketleft", cmd: "send-layout-cmd", args: ["rivertile", "main-count -1"] },
181
+
{
182
+
mode: "normal",
183
+
mods: [Super],
184
+
key: "Bracketright",
185
+
cmd: "send-layout-cmd",
186
+
args: ["rivertile", "main-count +1"],
187
+
},
188
+
{
189
+
mode: "normal",
190
+
mods: [Super, Control],
191
+
key: "Bracketleft",
192
+
cmd: "send-layout-cmd",
193
+
args: ["rivertile", "main-ratio -0.05"],
194
+
},
195
+
{
196
+
mode: "normal",
197
+
mods: [Super, Control],
198
+
key: "Bracketright",
199
+
cmd: "send-layout-cmd",
200
+
args: ["rivertile", "main-ratio +0.05"],
201
+
},
202
+
{ mode: "normal", mods: [Super], key: "Space", cmd: "zoom", args: [] },
203
+
{ mode: "normal", mods: [Super], key: "Comma", cmd: "focus-view", args: ["previous"] },
204
+
{ mode: "normal", mods: [Super], key: "Period", cmd: "focus-view", args: ["next"] },
205
+
{ mode: "normal", mods: [Super, Control], key: "Comma", cmd: "swap", args: ["previous"] },
206
+
{ mode: "normal", mods: [Super, Control], key: "Period", cmd: "swap", args: ["next"] },
207
+
208
+
# Passthrough mode
209
+
{ mode: "normal", mods: [Super], key: "F12", cmd: "enter-mode", args: ["passthrough"] },
210
+
{ mode: "passthrough", mods: [Super], key: "F12", cmd: "enter-mode", args: ["normal"] },
211
+
212
+
# Special Tags Mode
213
+
{ mode: "normal", mods: [Super], key: "G", cmd: "enter-mode", args: ["special-tags"] },
214
+
{ mode: "special-tags", mods: [None], key: "Escape", cmd: "enter-mode", args: ["normal"] },
215
+
216
+
# KeePassXC Tag
217
+
{
218
+
mode: "special-tags",
219
+
mods: [None],
220
+
key: "K",
221
+
cmd: "toggle-focused-tags",
222
+
args: [Num.to_str (named_tag_to_rtag KeePassXC)],
223
+
},
224
+
{
225
+
mode: "special-tags",
226
+
mods: [Shift],
227
+
key: "K",
228
+
cmd: "toggle-view-tags",
229
+
args: [Num.to_str (named_tag_to_rtag KeePassXC)],
230
+
},
231
+
{
232
+
mode: "special-tags",
233
+
mods: [Control],
234
+
key: "K",
235
+
cmd: "set-focused-tags",
236
+
args: [Num.to_str (named_tag_to_rtag KeePassXC)],
237
+
},
238
+
{
239
+
mode: "special-tags",
240
+
mods: [Shift, Control],
241
+
key: "K",
242
+
cmd: "set-view-tags",
243
+
args: [Num.to_str (named_tag_to_rtag KeePassXC)],
244
+
},
245
+
246
+
# Thunderbird Tag
247
+
{
248
+
mode: "special-tags",
249
+
mods: [None],
250
+
key: "T",
251
+
cmd: "toggle-focused-tags",
252
+
args: [Num.to_str (named_tag_to_rtag Thunderbird)],
253
+
},
254
+
{
255
+
mode: "special-tags",
256
+
mods: [Shift],
257
+
key: "T",
258
+
cmd: "toggle-view-tags",
259
+
args: [Num.to_str (named_tag_to_rtag Thunderbird)],
260
+
},
261
+
{
262
+
mode: "special-tags",
263
+
mods: [Control],
264
+
key: "T",
265
+
cmd: "set-focused-tags",
266
+
args: [Num.to_str (named_tag_to_rtag Thunderbird)],
267
+
},
268
+
{
269
+
mode: "special-tags",
270
+
mods: [Shift, Control],
271
+
key: "T",
272
+
cmd: "set-view-tags",
273
+
args: [Num.to_str (named_tag_to_rtag Thunderbird)],
274
+
},
275
+
276
+
# Nautilus Tag
277
+
{
278
+
mode: "special-tags",
279
+
mods: [None],
280
+
key: "N",
281
+
cmd: "toggle-focused-tags",
282
+
args: [Num.to_str (named_tag_to_rtag Nautilus)],
283
+
},
284
+
{
285
+
mode: "special-tags",
286
+
mods: [Shift],
287
+
key: "N",
288
+
cmd: "toggle-view-tags",
289
+
args: [Num.to_str (named_tag_to_rtag Nautilus)],
290
+
},
291
+
{
292
+
mode: "special-tags",
293
+
mods: [Control],
294
+
key: "N",
295
+
cmd: "set-focused-tags",
296
+
args: [Num.to_str (named_tag_to_rtag Nautilus)],
297
+
},
298
+
{
299
+
mode: "special-tags",
300
+
mods: [Shift, Control],
301
+
key: "N",
302
+
cmd: "set-view-tags",
303
+
args: [Num.to_str (named_tag_to_rtag Nautilus)],
304
+
},
305
+
]
306
+
307
+
tag_to_rtag = |num|
308
+
Num.shift_left_by 1 (num - 1)
309
+
310
+
mod_str = |mod|
311
+
when mod is
312
+
Control -> "Control"
313
+
Mod1 | Alt -> "Mod1"
314
+
Mod3 -> "Mod3"
315
+
Mod4 | Super -> "Mod4"
316
+
Mod5 -> "Mod3"
317
+
None -> "None"
318
+
Shift -> "Shift"
319
+
320
+
riverctl_runner! = |list_of_args|
321
+
list_of_args
322
+
|> List.for_each_try! |elem|
323
+
_ = Stdout.line! "Running riverctl with arguments: `${Str.join_with elem ", "}`"
324
+
325
+
result =
326
+
Cmd.new "riverctl"
327
+
|> Cmd.args elem
328
+
|> Cmd.status!
329
+
330
+
when result is
331
+
Ok exit_code if exit_code == 0 -> Ok {}
332
+
Ok exit_code -> Stderr.line! "Command exited with non-zero code: ${Num.to_str exit_code}"
333
+
Err err -> Stderr.line! "Error executing command: ${Inspect.to_str err}"
334
+
335
+
main! = |_args|
336
+
autostart_cmds! =
337
+
autostart! {}
338
+
|> List.map |cmd|
339
+
["spawn", cmd]
340
+
341
+
configuration_cmds =
342
+
configurations
343
+
|> List.map |{ option, args }|
344
+
args
345
+
|> List.prepend option
346
+
347
+
rule_cmds =
348
+
rules
349
+
|> List.map |{ id, title, action, args }|
350
+
id_part = if Str.is_empty id == Bool.false then ["-app-id", id] else []
351
+
full_ident = if Str.is_empty title == Bool.false then List.concat id_part ["-title", title] else id_part
352
+
353
+
["rule-add"]
354
+
|> List.concat full_ident
355
+
|> List.append action
356
+
|> List.concat args
357
+
358
+
mode_cmds =
359
+
modes
360
+
|> List.map |mode|
361
+
["declare-mode", mode]
362
+
363
+
pointer_bind_cmds =
364
+
pointer_binds
365
+
|> List.map |{ mode, mods, btn, cmd }|
366
+
["map-pointer", mode, Str.join_with (List.map mods mod_str) "+", btn, cmd]
367
+
368
+
keybind_cmds =
369
+
tag_binds
370
+
|> List.concat keybinds
371
+
|> List.map |{ mode, mods, key, cmd, args }|
372
+
["map", mode, Str.join_with (List.map mods mod_str) "+", key, cmd]
373
+
|> List.concat args
374
+
375
+
autostart_cmds!
376
+
|> List.concat configuration_cmds
377
+
|> List.concat rule_cmds
378
+
|> List.concat mode_cmds
379
+
|> List.concat pointer_bind_cmds
380
+
|> List.concat keybind_cmds
381
+
|> riverctl_runner!
+145
config/river/init.sh.bak
+145
config/river/init.sh.bak
···
1
+
#!/bin/sh
2
+
riverctl spawn "systemctl --user start river-session-pre.target"
3
+
riverctl spawn update-session-vars
4
+
riverctl spawn "systemctl --user start river-session.target"
5
+
riverctl spawn "swaybg -i ${HOME}/pic/wallpapers/dark/evie-s-Pb1KFv4tauY-unsplash.jpg -m fill"
6
+
riverctl spawn kanshi
7
+
riverctl spawn 'rivertile -outer-padding 0 -view-padding 0 -main-ratio 0.5'
8
+
9
+
riverctl xcursor-theme Adwaita 24
10
+
11
+
riverctl input pointer-1356-3570-Sony_Interactive_Entertainment_DualSense_Edge_Wireless_Controller_Touchpad events disabled
12
+
13
+
riverctl focus-follows-cursor normal
14
+
15
+
riverctl map normal Super Return spawn foot
16
+
riverctl map normal Super R spawn bemenu-run.sh
17
+
riverctl map normal Super E spawn 'wpctl set-mute @DEFAULT_SOURCE@ toggle'
18
+
19
+
riverctl map normal None Print spawn 'scr pic -c'
20
+
riverctl map normal Super Print spawn 'scr pic -cd'
21
+
22
+
# riverctl map normal Super Space 'makoctl dismiss -a'
23
+
24
+
# riverctl map normal Super H focus-view left
25
+
# riverctl map normal Super J focus-view down
26
+
# riverctl map normal Super K focus-view up
27
+
# riverctl map normal Super L focus-view right
28
+
riverctl map normal Super Z focus-view next
29
+
riverctl map normal Super+Control Z focus-view previous
30
+
31
+
riverctl map-pointer normal Super BTN_LEFT move-view
32
+
riverctl map-pointer normal Super BTN_RIGHT resize-view
33
+
34
+
riverctl set-cursor-warp on-output-change
35
+
36
+
riverctl map normal Super X focus-output next
37
+
riverctl map normal Super+Alt X focus-output previous
38
+
riverctl map normal Super+Control X send-to-output next
39
+
riverctl map normal Super+Control+Alt X send-to-output previous
40
+
riverctl map normal Super+Shift+Control X send-to-output -current-tags next
41
+
riverctl map normal Super+Shift+Control+Alt X send-to-output -current-tags previous
42
+
43
+
# This doesn't seem to work with these output names
44
+
# riverctl declare-mode output-ops
45
+
# riverctl map normal Super X enter-mode output-ops
46
+
# riverctl map output-ops None 1 focus-output "LG Electronics LG HDR WFHD 0x0000B11B"
47
+
# riverctl map output-ops None 2 focus-output "BNQ BenQ PD2700U ET87K04288SL0"
48
+
# riverctl map output-ops None 3 focus-output "AOC 2460G4 0x0000075E"
49
+
# riverctl map output-ops Shift 1 send-to-output "LG Electronics LG HDR WFHD 0x0000B11B"
50
+
# riverctl map output-ops Shift 2 send-to-output "BNQ BenQ PD2700U ET87K04288SL0"
51
+
# riverctl map output-ops Shift 3 send-to-output "AOC 2460G4 0x0000075E"
52
+
# riverctl map output-ops None Escape enter-mode normal
53
+
54
+
for i in $(seq 1 9)
55
+
do
56
+
tags=$((1 << ($i - 1)))
57
+
58
+
# Super+Control+[1-9] to toggle focus of tag [0-8]
59
+
riverctl map normal Super $i toggle-focused-tags $tags
60
+
61
+
# Super+Shift+Control+[1-9] to toggle tag [0-8] of focused view
62
+
riverctl map normal Super+Shift $i toggle-view-tags $tags
63
+
64
+
# Super+[1-9] to focus tag [0-8]
65
+
riverctl map normal Super+Control $i set-focused-tags $tags
66
+
67
+
# Super+Shift+[1-9] to tag focused view with tag [0-8]
68
+
riverctl map normal Super+Shift+Control $i set-view-tags $tags
69
+
done
70
+
71
+
# Super+0 to focus all tags
72
+
# Super+Shift+0 to tag focused view with all tags
73
+
all_tags=$(((1 << 32) - 1))
74
+
riverctl map normal Super 0 set-focused-tags $all_tags
75
+
riverctl map normal Super+Shift 0 set-view-tags $all_tags
76
+
77
+
riverctl declare-mode special-tags
78
+
riverctl map normal Super G enter-mode special-tags
79
+
riverctl map special-tags None Escape enter-mode normal
80
+
81
+
keepassxc_tag=$((1 << (10 - 1)))
82
+
riverctl map special-tags None k toggle-focused-tags $keepassxc_tag
83
+
riverctl map special-tags Shift k toggle-view-tags $keepassxc_tag
84
+
riverctl map special-tags Control k set-focused-tags $keepassxc_tag
85
+
riverctl map special-tags Shift+Control k set-view-tags $keepassxc_tag
86
+
87
+
riverctl rule-add -app-id org.keepassxc.KeePassXC float
88
+
riverctl rule-add -app-id org.keepassxc.KeePassXC -title "KeyChain.kdbx [Locked] - KeePassXC" tags $keepassxc_tag
89
+
90
+
thunderbird_tag=$((1 << (11 - 1)))
91
+
riverctl map special-tags None t toggle-focused-tags $thunderbird_tag
92
+
riverctl map special-tags Shift t toggle-view-tags $thunderbird_tag
93
+
riverctl map special-tags Control t set-focused-tags $thunderbird_tag
94
+
riverctl map special-tags Shift+Control t set-view-tags $thunderbird_tag
95
+
96
+
riverctl rule-add -app-id org.mozilla.Thunderbird tags $thunderbird_tag
97
+
98
+
for i in $(seq 1 9)
99
+
do
100
+
tags=$((1 << ($i - 1)))
101
+
102
+
riverctl map special-tags None $i toggle-focused-tags $tags
103
+
riverctl map special-tags Shift $i toggle-view-tags $tags
104
+
riverctl map special-tags Control $i set-focused-tags $tags
105
+
riverctl map special-tags Shift+Control $i set-view-tags $tags
106
+
done
107
+
108
+
riverctl map normal Super+Control Escape exit
109
+
riverctl map normal Super Q close
110
+
111
+
riverctl map normal Super F toggle-float
112
+
riverctl map normal Super+Control F toggle-fullscreen
113
+
114
+
riverctl declare-mode passthrough
115
+
riverctl map normal Super F12 enter-mode passthrough
116
+
riverctl map passthrough Super F12 enter-mode normal
117
+
118
+
# Set background and border color
119
+
# riverctl background-color 0x002b36
120
+
riverctl border-color-focused 0x93a1a1
121
+
riverctl border-color-unfocused 0x586e75
122
+
123
+
# # Set keyboard repeat rate
124
+
# riverctl set-repeat 50 300
125
+
126
+
riverctl map normal Super T output-layout rivertile
127
+
riverctl map normal Super+Control T output-layout none
128
+
129
+
riverctl map normal Super Up send-layout-cmd rivertile "main-location top"
130
+
riverctl map normal Super Left send-layout-cmd rivertile "main-location left"
131
+
riverctl map normal Super Down send-layout-cmd rivertile "main-location bottom"
132
+
riverctl map normal Super Right send-layout-cmd rivertile "main-location right"
133
+
134
+
riverctl map normal Super Bracketleft send-layout-cmd rivertile "main-count -1"
135
+
riverctl map normal Super Bracketright send-layout-cmd rivertile "main-count +1"
136
+
riverctl map normal Super+Control Bracketleft send-layout-cmd rivertile "main-ratio -0.05"
137
+
riverctl map normal Super+Control Bracketright send-layout-cmd rivertile "main-ratio +0.05"
138
+
139
+
riverctl map normal Super Space zoom
140
+
riverctl map normal Super Comma focus-view previous
141
+
riverctl map normal Super Period focus-view next
142
+
riverctl map normal Super+Control Comma swap previous
143
+
riverctl map normal Super+Control Period swap next
144
+
145
+
riverctl rule-add -app-id org.gnome.Nautilus float