From 081a2e517acc34e4fc77ebb3fb862609517f614b Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Sun, 31 Mar 2024 00:56:22 +0300 Subject: [PATCH] Util : Add _twice. --- module/common/bash/module/Util.sh | 15 +++++++++++++++ module/sway/module/20-Keybind | 7 ++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/module/common/bash/module/Util.sh b/module/common/bash/module/Util.sh index 8b71aef..d045790 100644 --- a/module/common/bash/module/Util.sh +++ b/module/common/bash/module/Util.sh @@ -132,7 +132,22 @@ function _bell() { echo -e '\a' } +# Get users. function _get_users() { local users=("voronind" "dasha") echo ${users[@]} } + +# Force the command to be called twice within the specified period in seconds. Used primarily in important keyboard shortcuts like poweroff. +# Usage: _twice +function _twice() { + local IFS=$'\n' + local file="/tmp/.twice" + local period=${1} + local command="${@:2}" + + [[ "$(cat ${file} 2> /dev/null)" = "${command}" ]] && ${command} + echo "${command}" > "${file}" + sleep ${period} + rm "${file}" 2> /dev/null +} diff --git a/module/sway/module/20-Keybind b/module/sway/module/20-Keybind index cf1f3f7..e133e26 100644 --- a/module/sway/module/20-Keybind +++ b/module/sway/module/20-Keybind @@ -18,8 +18,8 @@ floating_modifier $mod normal bindsym $mod+Shift+c reload # Exit sway (logs you out of your Wayland session). -bindsym $mod+z exec 'swaylock -F -c 000000 -k --font "SF Pro Display Medium" --font-size 14' -bindsym $mod+Shift+z exec 'swaymsg exit' +bindsym $mod+z exec '_twice 1 swaylock -F -c 000000 -k --font "SF Pro Display Medium" --font-size 14' +bindsym $mod+Shift+z exec '_twice 1 swaymsg exit' # Show last notification. bindsym $mod+n exec makoctl restore @@ -33,6 +33,3 @@ bindsym XF86MonBrightnessUp exec light -A 10 bindsym XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +1%' bindsym XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -1%' bindsym XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle' - -# Lock screen -bindsym $mod+z exec 'swaylock -k -c 000000'