Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Last active November 29, 2023 20:31
Show Gist options
  • Save sebastiancarlos/04a15bfd21cbdf9b46d596a3207916bd to your computer and use it in GitHub Desktop.
Save sebastiancarlos/04a15bfd21cbdf9b46d596a3207916bd to your computer and use it in GitHub Desktop.
sway-toggle-casual-mode
#!/usr/bin/env bash
# sway-toggle-casual-mode
green='\033[0;32m'
red='\033[0;31m'
bold='\033[1m'
reset='\033[0m'
shopt -s xpg_echo
# print usage on -h or --help
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "${bold}Usage:${reset} ${green}sway-toggle-casual-mode${reset}"
echo " Toggle a \"Casual Mode\" in Sway. When active, the Sway"
echo " configuration is adjusted to facilitate usage scenarios where"
echo " the user may not have two-handed keyboard access or prefers a"
echo " more relaxed computer interaction, such as when reclining or"
echo " lying down."
exit 0
fi
# define state file
if [ -z "$XDG_RUNTIME_DIR" ]; then
state_file="/tmp/sway-toggle-casual-mode.${USER}"
else
state_file="$XDG_RUNTIME_DIR/sway-toggle-casual-mode"
fi
# get new state
if [[ -f "$state_file" ]]; then
if [[ "$(cat "$state_file")" == "true" ]]; then
state="false"
else
state="true"
fi
else
state="true"
fi
# update sway
if [[ $state == "true" ]]; then
swaymsg "bar mode dock"
else
swaymsg "bar mode hide"
fi
# persist state
echo "$state" >| "$state_file"
# print message
if [[ "$state" == "true" ]]; then
echo "Casual Mode ${green}enabled${reset}."
else
echo "Casual Mode ${red}disabled${reset}."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment