From d03b0963d0939a6df862d02085dca3ddca4c2abf Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sat, 23 Dec 2023 20:13:54 -0700 Subject: [PATCH] Add mouse-free exit to sway --- sway/config | 4 ++-- sway/sway_exit.sh | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 sway/sway_exit.sh diff --git a/sway/config b/sway/config index 5a5b30d..6eb684d 100644 --- a/sway/config +++ b/sway/config @@ -294,8 +294,8 @@ exec sudo ~/.configs_pointer/bin/switch_keyboard.sh pc bindsym $mod1+i exec ~/.config/sway/toggle_fcitx.sh # Mako notifications exec mako - # Exit sway (logs you out of your Wayland session) -bindsym $mod2+Escape exec swaynag -t warning -m 'Are you sure you want to exit sway?' -b 'Yes, exit sway' 'swaymsg exit' + # Exit sway (hit 3 times repeatedly to force exit) +bindsym $mod2+Escape exec ~/.config/sway/sway_exit.sh # Screenshots ==== bindsym $mod2+6 mode "screenshots" diff --git a/sway/sway_exit.sh b/sway/sway_exit.sh new file mode 100755 index 0000000..3c5c762 --- /dev/null +++ b/sway/sway_exit.sh @@ -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