'mode' command didn't actually work until now.

Also rotate mode if no argument is provided. This makes the rotate behaviour of waybar-idle.sh unnecessary.
This commit is contained in:
John Mertz 2024-08-16 11:09:00 -06:00
parent 60344ec940
commit b32759643a
2 changed files with 26 additions and 23 deletions

View File

@ -10,9 +10,12 @@ BLFILE="$HOME/.local/state/idle.dim"
OPFILE="$HOME/.local/state/active_outputs" OPFILE="$HOME/.local/state/active_outputs"
STATEFILE="$HOME/.local/state/idle.state" STATEFILE="$HOME/.local/state/idle.state"
IDLEMODE=$(cat $HOME/.local/state/idle_mode) IDLEMODE=$(cat $HOME/.local/state/idle_mode)
if [[ -n $2 ]]; then if [[ -n $2 ]]; then
if [[ $2 == '--ignore_mode' ]]; then if [[ $2 == '--ignore_mode' ]]; then
IDLEMODE='hibernate' IDLEMODE='hibernate'
elif [[ $1 == "mode" ]]; then
IDLEMODE=$2
else else
echo "Unknown mode $IDLEMODE" echo "Unknown mode $IDLEMODE"
exit exit
@ -76,6 +79,23 @@ function usage() {
if [[ -z $1 ]]; then if [[ -z $1 ]]; then
echo "Missing argument" echo "Missing argument"
usage usage
elif [[ $1 == "mode" ]]; then
if [[ -n $2 ]]; then
echo -n $2 > $HOME/.local/state/idle_mode
elif [[ $IDLEMODE == 0 ]]; then
echo -n 'fade' > $HOME/.local/state/idle_mode
elif [[ $IDLEMODE == 1 ]]; then
echo -n 'dim' > $HOME/.local/state/idle_mode
elif [[ $IDLEMODE == 2 ]]; then
echo -n 'lock' > $HOME/.local/state/idle_mode
elif [[ $IDLEMODE == 3 ]]; then
echo -n 'sleep' > $HOME/.local/state/idle_mode
elif [[ $IDLEMODE == 4 ]]; then
echo -n 'hibernate' > $HOME/.local/state/idle_mode
elif [[ $IDLEMODE == 5 ]]; then
echo -n 'none' > $HOME/.local/state/idle_mode
fi
cat $HOME/.local/state/idle_mode
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]] || [[ $1 == "help" ]]; then elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]] || [[ $1 == "help" ]]; then
usage usage
elif [[ $1 == "start" ]]; then elif [[ $1 == "start" ]]; then

View File

@ -1,45 +1,28 @@
#!/bin/bash #!/bin/bash
FILE="$HOME/.local/state/idle_mode" FILE="$HOME/.local/state/idle_mode"
if [[ -z $1 ]] || [[ "$1" == 'rotate' ]] || [[ "$1" == 'bar' ]]; then
if [[ -e $FILE ]]; then if [[ -e $FILE ]]; then
MODE=$(cat $FILE) MODE=$(cat $FILE)
else else
MODE="fade" MODE="fade"
fi fi
else
MODE="$1"
fi
if [[ $MODE == "none" ]]; then if [[ $MODE == "none" ]]; then
NEXT="fade"
ICON="☕" ICON="☕"
elif [[ $MODE == "fade" ]]; then elif [[ $MODE == "fade" ]]; then
ICON="🌌" ICON="🌌"
NEXT="dim"
elif [[ $MODE == "dim" ]]; then elif [[ $MODE == "dim" ]]; then
ICON="⬛" ICON="⬛"
NEXT="lock"
elif [[ $MODE == "lock" ]]; then elif [[ $MODE == "lock" ]]; then
ICON="🔒" ICON="🔒"
NEXT="sleep"
elif [[ $MODE == "sleep" ]]; then elif [[ $MODE == "sleep" ]]; then
ICON="💤" ICON="💤"
NEXT="hibernate"
elif [[ $MODE == "hibernate" ]]; then elif [[ $MODE == "hibernate" ]]; then
ICON="↯ " ICON="↯ "
NEXT="none"
else else
echo "Invalid mode: $MODE" ICON="? "
echo '{"text":"'$ICON'","icon":"'$ICON'","tooltip":"Error: Invalid mode ('$MODE')","class":"'$MODE'"}'
exit exit
fi fi
if [[ -z $1 ]] || [[ "$1" == "bar" ]]; then
echo '{"text":"'$ICON'","icon":"'$ICON'","tooltip":"Change sleep mode ('$MODE')","class":"'$MODE'"}' echo '{"text":"'$ICON'","icon":"'$ICON'","tooltip":"Change sleep mode ('$MODE')","class":"'$MODE'"}'
elif [ "$1" == "rotate" ]; then
echo -n $NEXT >$FILE
$0 bar
else
echo -n $MODE >$FILE
$0 bar
fi