diff --git a/configs/appcfg/xinit_template b/configs/appcfg/xinit_template index 49ff421..e16593c 100644 --- a/configs/appcfg/xinit_template +++ b/configs/appcfg/xinit_template @@ -48,10 +48,6 @@ command -v firefox && export BROWSER=firefox # Prepopulate Subreddits menu with custom subreddits #export SXMO_SUBREDDITS="postmarketos pinephoneOfficial pinephone unixporn" -# Temporarily wake every 5 minutes during sleep -#(useful for getting notifications) -#export SXMO_RTCWAKEINTERVAL=300 - # Change the default terminal command # export TERMCMD="st -e" diff --git a/configs/default_hooks/rtcwake b/configs/default_hooks/rtcwake deleted file mode 100644 index 7c0af62..0000000 --- a/configs/default_hooks/rtcwake +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env sh - -. "$(which sxmo_common.sh)" - -REDLED_PATH="/sys/class/leds/red:indicator/brightness" -BLUELED_PATH="/sys/class/leds/blue:indicator/brightness" - -finish() { - kill $BLINKPID - - echo 0 > "$REDLED_PATH" - echo 0 > "$BLUELED_PATH" - - # Going back to crust - if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then - sxmo_screenlock.sh rtc "$SXMO_RTCWAKEINTERVAL" - fi - - exit 0 -} - -trap 'finish' TERM INT EXIT - -blink() { - while [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; do - echo 1 > "$REDLED_PATH" - echo 0 > "$BLUELED_PATH" - sleep 0.5 - echo 0 > "$REDLED_PATH" - echo 1 > "$BLUELED_PATH" - sleep 0.5 - done -} - -blink & -BLINKPID=$! - -# Replace this by wathever you want to do -sleep 10 diff --git a/scripts/core/sxmo_common.sh b/scripts/core/sxmo_common.sh index c02cf91..2b16b04 100644 --- a/scripts/core/sxmo_common.sh +++ b/scripts/core/sxmo_common.sh @@ -9,6 +9,8 @@ # we disable shellcheck SC2034 (variable not used) # for all the variables we define here +# shellcheck disable=SC2034 +export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$HOME/.local/run}" # shellcheck disable=SC2034 export NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications # shellcheck disable=SC2034 diff --git a/scripts/core/sxmo_inputhandler.sh b/scripts/core/sxmo_inputhandler.sh index 50c1553..786b10e 100755 --- a/scripts/core/sxmo_inputhandler.sh +++ b/scripts/core/sxmo_inputhandler.sh @@ -9,14 +9,6 @@ ACTION="$1" # shellcheck source=scripts/core/sxmo_common.sh . "$(dirname "$0")/sxmo_common.sh" -crust() { - if [ -n "$SXMO_RTCWAKEINTERVAL" ]; then - sxmo_screenlock.sh rtc "$SXMO_RTCWAKEINTERVAL" - else - sxmo_screenlock.sh crust - fi -} - lock_screen() { if [ "$SXMO_LOCK_SCREEN_OFF" = "1" ]; then sxmo_screenlock.sh off @@ -24,7 +16,7 @@ lock_screen() { sxmo_screenlock.sh lock fi if [ "$SXMO_LOCK_SUSPEND" = "1" ]; then - crust + sxmo_screenlock.sh crust fi } @@ -46,7 +38,7 @@ typeenter() { if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then case "$ACTION" in "volup_three") - crust + sxmo_screenlock.sh crust ;; "voldown_three") if [ "$(sxmo_screenlock.sh getCurState)" = "lock" ]; then diff --git a/scripts/core/sxmo_rtcwake.sh b/scripts/core/sxmo_rtcwake.sh old mode 100755 new mode 100644 index efa31a9..df7eebd --- a/scripts/core/sxmo_rtcwake.sh +++ b/scripts/core/sxmo_rtcwake.sh @@ -1,11 +1,40 @@ #!/usr/bin/env sh -# This script (and anything it calls) should return as quickly as possible -# as it blocks the system from suspending (and processing input) until done +# shellcheck disable=SC1090 +. "$(which sxmo_common.sh)" -# If this script returns a non-zero exit code, the system will wake up +REDLED_PATH="/sys/class/leds/red:indicator/brightness" +BLUELED_PATH="/sys/class/leds/blue:indicator/brightness" -if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/rtcwake" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/rtcwake" - exit $? -fi +finish() { + kill $BLINKPID + + sxmo_screenlock.sh updateLed + + if grep -q rtc "$UNSUSPENDREASONFILE"; then + # Going back to crust + if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then + sxmo_screenlock.sh crust + fi + fi + + exit 0 +} + +trap 'finish' TERM INT EXIT + +blink() { + while [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; do + echo 1 > "$REDLED_PATH" + echo 0 > "$BLUELED_PATH" + sleep 0.25 + echo 0 > "$REDLED_PATH" + echo 1 > "$BLUELED_PATH" + sleep 0.25 + done +} + +blink & +BLINKPID=$! + +"$@" diff --git a/scripts/core/sxmo_screenlock.sh b/scripts/core/sxmo_screenlock.sh index cf78750..90f60dc 100755 --- a/scripts/core/sxmo_screenlock.sh +++ b/scripts/core/sxmo_screenlock.sh @@ -100,6 +100,7 @@ elif [ "$1" = "unlock" ] ; then xset dpms force on xinput enable "$TOUCH_POINTER_ID" sxmo_lisgdstart.sh + echo 16000 > "$NETWORKRTCSCAN" updateLed exit 0 @@ -120,41 +121,6 @@ elif [ "$1" = "off" ] ; then exit 0 elif [ "$1" = "crust" ] ; then getCurState > "$LASTSTATE" - - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/presuspend" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/presuspend" - fi - - echo 1 > "$REDLED_PATH" - echo 0 > "$BLUELED_PATH" - xset dpms force off - - # configure crust - # TODO: disable all wakeup sources other than button, rtc, and modem. - # TODO: make sure there is logic in whichWake and saveAllEventCounts functions - # Do I need to unbind? https://git.sr.ht/~mil/sxmo-utils/commit/bcf4f5c24968df0055d15a9fca649f67de9ced6a - echo "deep" > /sys/power/mem_sleep # deep sleep - - echo "mem" > /sys/power/state - - echo "crust" > "$LASTSTATE" - - d=$(date) - echo "sxmo_screenlock: woke up from crust ($d)" >&2 - - updateLed - xset dpms force on - - UNSUSPENDREASON=$(whichWake) - echo "$UNSUSPENDREASON" > "$UNSUSPENDREASONFILE" - - if [ "$UNSUSPENDREASON" = "button" ] && [ -x "$XDG_CONFIG_HOME/sxmo/hooks/postwake" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/postwake" - fi - - exit 0 -elif [ "$1" = "rtc" ] ; then - getCurState > "$LASTSTATE" # USER MUST USE sxmo_screenlock.sh rtc rather than using rtcwake directly. # With this new version of lock, we dont check the exit code of the user hook. User must execute "sxmo_screenlock.sh rtc $TIME" at the end of their hook (depending on whether they want to re-rtc) echo 1 > "$REDLED_PATH" @@ -167,20 +133,19 @@ elif [ "$1" = "rtc" ] ; then fi xset dpms force off - rtcwake -m mem -s "$2" - UNSUSPENDREASON=$(whichWake) + suspend_time="$(($(mnc)-10))" + if [ "$suspend_time" -gt 0 ]; then + rtcwake -m mem -s "$suspend_time" + UNSUSPENDREASON=$(whichWake) + else + UNSUSPENDREASON=rtc # we fake the crust for those seconds + fi echo "$UNSUSPENDREASON" > "$UNSUSPENDREASONFILE" echo "crust" > "$LASTSTATE" updateLed - if [ "$UNSUSPENDREASON" = "rtc" ]; then - WAKEHOOK="$XDG_CONFIG_HOME/sxmo/hooks/rtcwake"; - elif [ "$UNSUSPENDREASON" = "button" ]; then - WAKEHOOK="$XDG_CONFIG_HOME/sxmo/hooks/postwake"; - fi - d=$(date) echo "sxmo_screenlock: woke up from crust (reason=$UNSUSPENDREASON) ($d)" >&2 @@ -188,16 +153,18 @@ elif [ "$1" = "rtc" ] ; then xset dpms force on fi - if [ -x "$WAKEHOOK" ]; then + if [ "$UNSUSPENDREASON" = "button" ] && [ -x "$XDG_CONFIG_HOME/sxmo/hooks/postwake" ]; then echo 1200 > "$NETWORKRTCSCAN" - "$WAKEHOOK" - echo 16000 > "$NETWORKRTCSCAN" + "$XDG_CONFIG_HOME/sxmo/hooks/postwake" fi exit 0 elif [ "$1" = "getCurState" ] ; then getCurState exit 0 +elif [ "$1" = "updateLed" ] ; then + updateLed + exit 0 fi -echo "usage: sxmo_screenlock.sh [lock|unlock|off|crust|rtc|getCurState]">&2 +echo "usage: sxmo_screenlock.sh [lock|unlock|off|crust|rtc|getCurState|updateLed]">&2