Files
Arch-R/scripts/archr-suspend-mode
Douglas Teles 06dc2d16f3 Add system scripts, services, and boot splash
System daemons: hotkeys (volume/brightness), automount, bluetooth agent,
memory manager, sleep/suspend, USB gadget mode, save-config persistence.

Boot splash: initramfs SVG renderer (fbsplash + svg_parser) for 0.7s splash.

Panel tools: generate-panel-dtbos.sh rewrite, convert-panel.py for ROCKNIX
panel data extraction, archr-dtbo.py for runtime overlay management.

Input: archr-gptokeyb.c gamepad-to-keyboard mapper via uinput.

Launch wrappers: emulationstation.sh and retroarch-launch.sh updated for
KMS/DRM + Mesa 26 Panfrost environment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 17:22:30 -03:00

75 lines
2.3 KiB
Bash

#!/bin/bash
# Arch R — Suspend Mode Control
# Sets the system suspend mode and handles power button behavior.
#
# Usage:
# archr-suspend-mode mem — Deep sleep (S3, lowest power, full RAM retention)
# archr-suspend-mode freeze — S2idle (CPU idle, faster wake, higher power)
# archr-suspend-mode off — Disable suspend (power button = power off)
# archr-suspend-mode status — Show current mode
SLEEP_CONF="/etc/systemd/sleep.conf.d/archr.conf"
LOGIND_CONF="/etc/systemd/logind.conf.d/fast.conf"
log() { logger -t archr-suspend "$1"; }
set_mode() {
local mode="$1"
mkdir -p "$(dirname "$SLEEP_CONF")"
mkdir -p "$(dirname "$LOGIND_CONF")"
case "$mode" in
mem|standby|freeze)
# Enable suspend with specified mode
cat > "$SLEEP_CONF" << EOF
[Sleep]
AllowSuspend=yes
SuspendState=$mode
AllowHibernation=no
EOF
# Update logind to handle power button as suspend
sed -i 's/^HandlePowerKey=.*/HandlePowerKey=suspend/' "$LOGIND_CONF" 2>/dev/null
# Write state to sysfs
echo "$mode" > /sys/power/state 2>/dev/null || true
log "Suspend mode set to: $mode"
;;
off)
# Disable suspend
cat > "$SLEEP_CONF" << EOF
[Sleep]
AllowSuspend=no
AllowHibernation=no
EOF
# Power button = ignore (use PMIC power-off via long press)
sed -i 's/^HandlePowerKey=.*/HandlePowerKey=ignore/' "$LOGIND_CONF" 2>/dev/null
log "Suspend disabled"
;;
*)
echo "Usage: archr-suspend-mode {mem|freeze|off|status}"
return 1
;;
esac
# Reload systemd to pick up config changes
systemctl daemon-reload 2>/dev/null
systemctl restart systemd-logind 2>/dev/null
}
show_status() {
echo "Available states: $(cat /sys/power/state 2>/dev/null)"
if [ -f "$SLEEP_CONF" ]; then
echo "Config: $(cat "$SLEEP_CONF")"
else
echo "Config: not set (default)"
fi
POWER_KEY=$(grep "^HandlePowerKey=" "$LOGIND_CONF" 2>/dev/null | cut -d= -f2)
echo "Power button: ${POWER_KEY:-ignore}"
}
case "${1:-status}" in
mem|standby|freeze|off) set_mode "$1" ;;
status) show_status ;;
*) echo "Usage: archr-suspend-mode {mem|freeze|off|status}" ;;
esac