-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkillswitch-switcher
More file actions
executable file
·66 lines (54 loc) · 1.83 KB
/
killswitch-switcher
File metadata and controls
executable file
·66 lines (54 loc) · 1.83 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
#!/bin/bash
CONFIG_DIR="$HOME/.config/killswitch"
CONFIG_FILE="$CONFIG_DIR/config.sh"
STATE_DIR="$HOME/.local/state/killswitch"
NEXT_SESSION_FILE="$STATE_DIR/next-session"
CURRENT_SESSION_FILE="$STATE_DIR/current-session"
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
else
notify-send "Killswitch" "Config not found: $CONFIG_FILE"
exit 1
fi
mkdir -p "$STATE_DIR"
export DISPLAY="${DISPLAY:-:0}"
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
declare -A name_to_id
menu_items=""
for var in $(compgen -v | grep '^session_.*_name$'); do
id=$(echo "$var" | sed -e 's/^session_//' -e 's/_name$//')
name="${!var}"
name_to_id["$name"]="$id"
if [ -n "$menu_items" ]; then
menu_items="$menu_items\n$name"
else
menu_items="$name"
fi
done
if [ -n "$ROFI_THEME" ]; then
choice=$(echo -e "$menu_items" | rofi -dmenu -p "Switch Mode:" -theme "$ROFI_THEME" -no-custom)
else
choice=$(echo -e "$menu_items" | rofi -dmenu -p "Switch Mode:" -no-custom)
fi
if [ -n "$choice" ] && [ -n "${name_to_id["$choice"]}" ]; then
target_id="${name_to_id["$choice"]}"
echo "$target_id" > "$NEXT_SESSION_FILE"
notify-send "Session Switcher" "Switching to $choice..." -t 2000
if [ -f "$CURRENT_SESSION_FILE" ]; then
CURRENT_SESSION=$(cat "$CURRENT_SESSION_FILE")
kill_func="session_${CURRENT_SESSION}_kill"
if type "$kill_func" >/dev/null 2>&1; then
$kill_func
exit 0
fi
fi
if pgrep -x "gamescope" > /dev/null; then
pkill -TERM gamescope
systemctl --user stop gamescope-session-plus@steam 2>/dev/null || true
elif [ -n "$HYPRLAND_INSTANCE_SIGNATURE" ]; then
hyprctl dispatch exit
else
pkill -u $USER niri 2>/dev/null || true
pkill -u $USER gamescope 2>/dev/null || true
fi
fi