From 978a6aef4b2da28102846697dab7383e454cc6ae Mon Sep 17 00:00:00 2001 From: John Mertz Date: Sun, 17 Jan 2021 21:54:21 -0500 Subject: [PATCH] A simulacrum of a functional swayidle script. Working: A proper countdown to idle works and is cancelled on resume. Displays are dimmed if possible at countdown start and restorted at resume. The screens properly lock. The power to the displays is turned off. The power is restore upon first resume. Layout and brightness restored on unlock. Known issue: Displays are not restored if the system idles again while on lock screen. This shouldn't really happen and is a possible indicator of tampering, which is kind of cool, but it's janky. Power needs to be restored with the toggle_displays hotkey. --- sway/idle.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ sway/idlecountdown.sh | 5 +++++ 2 files changed, 48 insertions(+) create mode 100755 sway/idle.sh create mode 100755 sway/idlecountdown.sh diff --git a/sway/idle.sh b/sway/idle.sh new file mode 100755 index 0000000..5fc8a38 --- /dev/null +++ b/sway/idle.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +BLFILE="/home/jpm/.config/blc.last" +OPFILE="/home/jpm/.config/active_outputs" + +if [ -z $1 ]; then + echo "Missing argument: run, warn, sleep or" \ + " wake" +elif [ $1 == "start" ]; then + swayidle -w timeout 270 "/home/jpm/scripts/sway/idle.sh warn" \ + resume "/home/jpm/scripts/sway/idle.sh resume" \ + timeout 300 "/home/jpm/scripts/sway/idle.sh sleep" \ + resume "/home/jpm/scripts/sway/idle.sh wake" \ + before-sleep "/usr/bin/swaylock -c 323232" +elif [ $1 == "warn" ]; then + # Store current brightness + echo $(/home/jpm/scripts/thinkpad/blc.pl %) > $BLFILE + # Dim display + /home/jpm/scripts/thinkpad/blc.pl = 1 + # Warning notifications + /home/jpm/scripts/sway/idlecountdown.sh +elif [ $1 == "sleep" ]; then + # Change nick to AFK + ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \ + 'screen -S irssi -X stuff "/nick jpmAFK^M"' + # Turn off monitor + for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done +elif [ $1 == "wake" ]; then + # Kill additional counters that might have been started + /home/jpm/scripts/sway/idle.sh resume + # Restore output(s) + /home/jpm/scripts/sway/displays.pl + #for i in `cat $OPFILE`; do swaymsg "output $i dpms on"; done + # Lock screen + swaylock -c 323232 + # Restore brightness level + /home/jpm/scripts/thinkpad/blc.pl = $(cat $BLFILE) +elif [ $1 == "resume" ]; then + # Kill warning + for i in `pgrep idlecountdown`; do kill $i; done +else + echo "Invalid argument: run, sleep or wake" +fi diff --git a/sway/idlecountdown.sh b/sway/idlecountdown.sh new file mode 100755 index 0000000..b2cef69 --- /dev/null +++ b/sway/idlecountdown.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +for i in `seq 0 30`; do + notify-send -t 999 "Sleeping" $(expr 30 - $i); sleep 1 +done