-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_mons_layout.py
More file actions
executable file
Β·127 lines (110 loc) Β· 2.48 KB
/
switch_mons_layout.py
File metadata and controls
executable file
Β·127 lines (110 loc) Β· 2.48 KB
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
#!/usr/bin/env bash
set -euo pipefail
FIFO="/tmp/kanshi_rofi.fifo"
KONFIG="$HOME/.config/kanshi/config"
SLEEP_SEC=2
# -----------------------------
# HELP
# -----------------------------
show_help() {
cat <<EOF
Usage: $(basename "$0") [options]
Options:
-d, --daemon Start daemon (keeps FIFO updated)
-s, --switch Open rofi menu (client)
-c, --config NAME Switch directly to kanshi profile NAME
-h, --help Show this help and exit
EOF
}
# -----------------------------
# VALIDATION
# -----------------------------
[[ -f "$KONFIG" ]] || { echo "kanshi config not found: $KONFIG" >&2; exit 1; }
# -----------------------------
# GET LAYOUTS (no cache)
# -----------------------------
read_layouts() {
grep -E '^profile "' "$KONFIG" | awk '{print $2}' | tr -d '"'
}
# -----------------------------
# DAEMON
# -----------------------------
run_daemon() {
rm -f "$FIFO"
mkfifo "$FIFO"
trap 'rm -f "$FIFO"; exit 0' INT TERM EXIT
while true; do
{
echo "π dpms on"
echo "π¬ dpms off"
echo "π reload kanshi"
read_layouts
} > "$FIFO"
sleep "$SLEEP_SEC"
done
}
# -----------------------------
# ACTIONS
# -----------------------------
do_dpms_on() {
hyprctl dispatch dpms on
}
do_dpms_off() {
hyprctl dispatch dpms off
}
reload_kanshi() {
pkill kanshi || true
kanshi &
}
switch_layout() {
local name="$1"
if ! grep -qE "^profile \"$name\"" "$KONFIG"; then
echo "Profile '$name' not found" >&2
exit 1
fi
kanshictl switch "$name"
}
# -----------------------------
# CLIENT (ROFI)
# -----------------------------
run_rofi() {
local selected
selected=$(cat "$FIFO" | rofi -dmenu -p "Display manager")
[[ -z "$selected" ]] && exit 0
case "$selected" in
"π dpms on")
do_dpms_on
;;
"π¬ dpms off")
do_dpms_off
;;
"π reload kanshi")
reload_kanshi
;;
*)
switch_layout "$selected"
;;
esac
}
# -----------------------------
# CLI
# -----------------------------
case "${1:-}" in
-d|--daemon)
run_daemon
;;
-s|--switch)
run_rofi
;;
-c|--config)
[[ -n "${2:-}" ]] || { echo "Profile name required"; exit 1; }
switch_layout "$2"
;;
-h|--help)
show_help
;;
*)
show_help
exit 1
;;
esac