Add mouse-free exit to sway

This commit is contained in:
Akemi Izuko 2023-12-23 20:13:54 -07:00
parent 4ead70bf68
commit d03b0963d0
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 27 additions and 2 deletions

View file

@ -294,8 +294,8 @@ exec sudo ~/.configs_pointer/bin/switch_keyboard.sh pc
bindsym $mod1+i exec ~/.config/sway/toggle_fcitx.sh bindsym $mod1+i exec ~/.config/sway/toggle_fcitx.sh
# Mako notifications # Mako notifications
exec mako exec mako
# Exit sway (logs you out of your Wayland session) # Exit sway (hit 3 times repeatedly to force exit)
bindsym $mod2+Escape exec swaynag -t warning -m 'Are you sure you want to exit sway?' -b 'Yes, exit sway' 'swaymsg exit' bindsym $mod2+Escape exec ~/.config/sway/sway_exit.sh
# Screenshots ==== # Screenshots ====
bindsym $mod2+6 mode "screenshots" bindsym $mod2+6 mode "screenshots"

25
sway/sway_exit.sh Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Prompts for confirmation. 3 consecutive calls force exit without confirmation
declare -r CNT_FILE=~/.config/sway/sway_exit_counter
declare -ri MAX_COUNT=3
if [[ -e "$CNT_FILE" ]]; then
declare -i count="$(cat "$CNT_FILE")"
else
declare -i count=0
fi
(( count++ ))
if [[ $count -ge $MAX_COUNT ]]; then
swaymsg exit
else
echo "$count" > "$CNT_FILE"
swaynag -t warning \
-m 'Are you sure you want to exit sway?' \
-Z 'Yes, exit sway' \
"swaymsg exit; rm $CNT_FILE"
fi
rm ~/.config/sway/sway_exit_counter &>/dev/null