Last active
January 5, 2025 22:42
-
-
Save unennhexium/60a1ff418fa7f4d53d061ec1baab96f3 to your computer and use it in GitHub Desktop.
Presentation mode button for Waybar+Sway+Swayidle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set $CONFIG ~/.config/sway | |
| exec $CONFIG/swayidle.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "modules-center" : [ "custom/presentation_mode" ], | |
| "custom/presentation_mode" : | |
| { | |
| "exec" : "~/.config/sway/presentation_mode.sh", | |
| "on-click" : "~/.config/sway/presentation_mode.sh --toggle", | |
| "return-type" : "json", | |
| "exec-on-event" : true, | |
| "tooltip" : true, | |
| }, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/bash | |
| read -r -d '' ON <<- EOM | |
| { | |
| "text": "⚪", | |
| "alt": "on", | |
| "tooltip": "Swayidle is off", | |
| "class": ["on"] | |
| } | |
| EOM | |
| read -r -d '' OFF <<- EOM | |
| { | |
| "text": "⚫", | |
| "alt": "off", | |
| "tooltip": "Swayidle is on", | |
| "class": ["off"] | |
| } | |
| EOM | |
| SRC_DIR=`dirname "$(readlink -f "${BASH_SOURCE[0]}")"` | |
| SIDLE_STS="$SRC_DIR/swayidle_status" | |
| PMODE_PIPE='/tmp/presentation_mode_pipe' | |
| toggle_state() { | |
| if [[ $1 == '1' ]]; then | |
| pkill swayidle | |
| echo 0 > "$SIDLE_STS" | |
| echo 1 > $PMODE_PIPE | |
| else | |
| swayidle -w -S seat0 &>/dev/null & disown | |
| echo 1 > "$SIDLE_STS" | |
| echo 0 > $PMODE_PIPE | |
| fi | |
| } | |
| send_msg() { | |
| [[ $1 == '1' ]] && MSG="$ON" || MSG="$OFF" | |
| stdbuf -oL -eL \ | |
| echo "$MSG" | \ | |
| jq --unbuffered \ | |
| --compact-output \ | |
| --monochrome-output | |
| } | |
| if [[ $1 == '--toggle' ]]; then | |
| toggle_state `cat "$SIDLE_STS"` | |
| else | |
| send_msg $((`cat "$SIDLE_STS"` ^ 1)) | |
| rm -f $PMODE_PIPE | |
| mkfifo $PMODE_PIPE | |
| while true; do | |
| send_msg `cat $PMODE_PIPE` | |
| done | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/bash | |
| SRC_DIR=`dirname "$(readlink -f "${BASH_SOURCE[0]}")"` | |
| ENABLED=`cat "$SRC_DIR/swayidle_status"` | |
| if [[ $ENABLED == '1' ]]; then | |
| swayidle -w -S seat0 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment