Optimize kernel-to-userspace battery life across CAMSS, SPI runtime PM, dwm, NeoUI, and plugins

This commit is contained in:
Luxferre committed 2026-11-01 11:56:28 +02:00
1 parent f112b6ae72
commit 456d3fbc42
61 files changed
+466 -148

No files matched your search

@@ -115,7 +115,7 @@ trap 'rm -f "$SESSION_PID_FILE"; pkill -P $$ >/dev/null 2>&1 || true; exit 0' IN
pkill -9 -x conky >/dev/null 2>&1 || true
rm -rf /tmp/sxmo_conky_time_state /tmp/sxmo_conky_restart.lock
DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
sxmo_hook_start.sh >/tmp/sxmo_hook_start.log 2>&1 </dev/null &
( sxmo_hook_start.sh >/tmp/sxmo_hook_start.log 2>&1 </dev/null & )
first_iter=1
while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do
@@ -140,14 +140,14 @@ while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do
*) WP_FLAG="--bg-fill" ;;
esac
fi
feh --no-fehbg "$WP_FLAG" "$WP_FILE" >/dev/null 2>&1 </dev/null &
( feh --no-fehbg "$WP_FLAG" "$WP_FILE" >/dev/null 2>&1 </dev/null & )
if [ "$first_iter" = "0" ]; then
pkill -x conky >/dev/null 2>&1 || true
sleep 0.05
pkill -9 -x conky >/dev/null 2>&1 || true
rm -rf /tmp/sxmo_conky_time_state /tmp/sxmo_conky_restart.lock
DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
pidof -s fcitx5 >/dev/null 2>&1 || superctl start fcitx5 >/dev/null 2>&1 || /usr/bin/bananarchy-fcitx5.sh </dev/null &
pidof -s fcitx5 >/dev/null 2>&1 || superctl start fcitx5 >/dev/null 2>&1 || ( /usr/bin/bananarchy-fcitx5.sh </dev/null & )
fi
first_iter=0
dwm >/tmp/dwm.log 2>&1 || true
Binary file not shown.
+13 -11
View File
@@ -93,36 +93,38 @@ mainloop() {
while read -r line; do
case "$line" in
signal*"interface=org.freedesktop.ModemManager1.Modem.Voice"*"member=CallAdded"*)
sxmo_modem.sh checkforincomingcalls &
( sxmo_modem.sh checkforincomingcalls & )
;;
signal*"interface=org.freedesktop.ModemManager1.Modem.Messaging"*"member=Added"*)
sxmo_modem.sh checkfornewtexts &
( sxmo_modem.sh checkfornewtexts & )
;;
signal*"path=/org/freedesktop/ModemManager1/SMS/"*"member=PropertiesChanged"*)
sxmo_modem.sh checkfornewtexts &
( sxmo_modem.sh checkfornewtexts & )
;;
signal*"path=/org/freedesktop/ModemManager1/Call/"*"member=PropertiesChanged"*)
sxmo_modem.sh checkforfinishedcalls &
( sxmo_modem.sh checkforfinishedcalls & )
;;
signal*"interface=org.freedesktop.ModemManager1.Modem;"*"member=StateChanged"*)
read -r oldstate || true
read -r newstate || true
read -r reason || true
(
sxmo_hook_modem.sh "$(statenumtoname "$oldstate")" \
"$(statenumtoname "$newstate")" \
"$(echo "$reason" | sed 's/uint32 //')"
sxmo_hook_statusbar.sh modem
) &
(
sxmo_hook_modem.sh "$(statenumtoname "$oldstate")" \
"$(statenumtoname "$newstate")" \
"$(echo "$reason" | sed 's/uint32 //')"
sxmo_hook_statusbar.sh modem
) &
)
;;
signal*"path=/org/freedesktop/ModemManager1/Modem/"*"member=PropertiesChanged"*)
MODEM="$(echo "$line" | awk -F'[;=]' '{print $6}')"
;;
*"string \"NetworkNotification\""*)
[ -n "${MODEM:-}" ] && sxmo_ussd.sh "$MODEM" "NetworkNotification" "" &
[ -n "${MODEM:-}" ] && ( sxmo_ussd.sh "$MODEM" "NetworkNotification" "" & )
;;
*"string \"NetworkRequest\""*)
[ -n "${MODEM:-}" ] && sxmo_ussd.sh "$MODEM" "NetworkRequest" "" &
[ -n "${MODEM:-}" ] && ( sxmo_ussd.sh "$MODEM" "NetworkRequest" "" & )
;;
esac
done &
+3
View File
@@ -46,6 +46,9 @@ xorgdisplay() {
if [ -w /sys/class/backlight/backlight/brightness ]; then
printf '0\n' > /sys/class/backlight/backlight/brightness 2>/dev/null || true
fi
if [ -w /sys/class/backlight/backlight/bl_power ]; then
printf '4\n' > /sys/class/backlight/backlight/bl_power 2>/dev/null || true
fi
xset s off s noblank >/dev/null 2>&1 || true
;;
on)
+1
View File
@@ -281,6 +281,7 @@ int neoui_clear_toast(void);
// 5. Event Loop, Keypad & Multi-Tap Input Management
// ---------------------------------------------------------------------------
int neoui_poll_event(int timeout_ms);
int neoui_next_timeout_ms(int default_timeout_ms);
int neoui_event_key(void);
int neoui_event_keycode(void);
int neoui_event_keysym(void);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2052,6 +2052,12 @@ PY
exec python3 - << 'PY'
import datetime, os, select, socket, struct, subprocess, sys, time
try:
while os.waitpid(-1, os.WNOHANG)[0] > 0:
pass
except Exception:
pass
AF_QIPCRTR = 42
QRTR_PORT_CTRL = 0xfffffffe
QRTR_TYPE_NEW_SERVER = 4
@@ -2187,12 +2193,16 @@ def run_user_cmd(cmd_str, extra_env=None):
env["PATH"] = "/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin"
if extra_env:
env.update(extra_env)
subprocess.Popen(
["su", "-m", "user", "-c", f"export DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 HOME=/home/user PATH=/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin; {cmd_str}"],
env=env,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
try:
p = subprocess.Popen(
["su", "-m", "user", "-c", f"export DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 HOME=/home/user PATH=/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin; ({cmd_str}) >/dev/null 2>&1 &"],
env=env,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
p.wait(timeout=2.0)
except Exception:
pass
def send_fifo(fifo_path, line):
try:
@@ -2795,8 +2805,10 @@ while True:
poll_timeout = 1.0
elif multipart_buf:
poll_timeout = 2.0
elif os.path.exists("/tmp/bananarchy_screen_locked"):
poll_timeout = None
else:
poll_timeout = 300.0
poll_timeout = 600.0
r, _, _ = select.select([ws, vs], [], [], poll_timeout)
got_voice_ind = False
events = []
@@ -8,11 +8,11 @@
. sxmo_common.sh
if [ -z "$SXMO_NO_MODEM" ]; then
MMCLI="$(mmcli -m any -J 2>/dev/null)"
if [ -z "$MMCLI" ]; then
sxmo_notify_user.sh "Modem crashed! 30s recovery."
sxmo_wakelock.sh lock sxmo_modem_crashed 30s
fi
MMCLI="$(mmcli -m any -J 2>/dev/null)"
if [ -z "$MMCLI" ]; then
sxmo_notify_user.sh "Modem crashed! 30s recovery."
sxmo_wakelock.sh lock sxmo_modem_crashed 30s
fi
fi
# Add here whatever you want to do
@@ -15,6 +15,7 @@ cur_state=""
[ "$cur_state" = "unlock" ] && exit 0
printf '1\n' > /tmp/bananarchy_screen_locked
pkill -STOP -x conky 2>/dev/null || true
if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_led.sh blink red blue &
@@ -10,52 +10,54 @@
. sxmo_common.sh
# Create xdg user directories, such as ~/Pictures
[ -d "$HOME/Pictures" ] || xdg-user-dirs-update &
[ -d "$HOME/Pictures" ] || ( xdg-user-dirs-update & )
# Ensure fontconfig cache is valid without forcing a full rescan on every boot
if command -v fc-cache > /dev/null && [ -z "$(ls -A /var/cache/fontconfig 2>/dev/null)" ]; then
fc-cache >/dev/null 2>&1 &
( fc-cache >/dev/null 2>&1 & )
fi
if ! superctl status > /dev/null 2>&1; then
pkill -9 -x superd > /dev/null 2>&1 || true
rm -f "$XDG_RUNTIME_DIR/superd.lock" "$XDG_RUNTIME_DIR/superd.sock"
sxmo_jobs.sh start daemon_manager superd
while ! superctl status > /dev/null 2>&1; do
sleep 0.05
done
pkill -9 -x superd > /dev/null 2>&1 || true
rm -f "$XDG_RUNTIME_DIR/superd.lock" "$XDG_RUNTIME_DIR/superd.sock"
sxmo_jobs.sh start daemon_manager superd
while ! superctl status > /dev/null 2>&1; do
sleep 0.05
done
fi
if [ -n "$SXMO_ROTATE_START" ]; then
sxmo_rotate.sh
sxmo_rotate.sh
fi
# Load our sound daemons
if [ -z "$SXMO_NO_AUDIO" ]; then
if ! [ -d /run/systemd/system ]; then
if [ "$(command -v pulseaudio)" ]; then
superctl start pulseaudio
elif [ "$(command -v pipewire)" ]; then
# pipewire-pulse will start pipewire
pidof -s pipewire >/dev/null 2>&1 || superctl start pipewire-pulse
pidof -s wireplumber >/dev/null 2>&1 || superctl start wireplumber
fi
fi
if ! [ -d /run/systemd/system ]; then
if [ "$(command -v pulseaudio)" ]; then
superctl start pulseaudio
elif [ "$(command -v pipewire)" ]; then
# pipewire-pulse will start pipewire
pidof -s pipewire >/dev/null 2>&1 || superctl start pipewire-pulse
pidof -s wireplumber >/dev/null 2>&1 || superctl start wireplumber
fi
fi
# monitor for headphone for statusbar
superctl start sxmo_soundmonitor
(
sleep 1
sxmo_audio.sh device apply >/dev/null 2>&1 || true
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
) &
# monitor for headphone for statusbar
superctl start sxmo_soundmonitor
(
(
sleep 1
sxmo_audio.sh device apply >/dev/null 2>&1 || true
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
) &
)
fi
# Periodically update some status bar components
sxmo_hook_statusbar.sh all
sxmo_jobs.sh start statusbar_periodics sxmo_run_aligned.sh 60 \
sxmo_hook_statusbar.sh periodics
sxmo_hook_statusbar.sh periodics
# dunst is required for warnings.
/usr/bin/bananarchy-sync-dunst-theme --no-restart >/dev/null 2>&1 || true
@@ -68,7 +70,7 @@ superctl start dunst
[ "$(command -v sxmo_xob)" ] && superctl start sxmo_xob
[ "$(command -v bonsaid)" ] && superctl start bonsaid
if [ "$(command -v fcitx5)" ]; then
superctl start fcitx5
superctl start fcitx5
fi
[ -n "$SXMO_MONITOR" ] && xrandr --output "$SXMO_MONITOR" --primary
@@ -76,7 +78,7 @@ fi
mkdir -p "$XDG_CACHE_HOME/sxmo"
touch "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
if sxmo_wakelock.sh isenabled; then
sxmo_wakelock.sh lock sxmo_not_suspendable infinite
sxmo_wakelock.sh lock sxmo_not_suspendable infinite
fi
# Activate lockscreen upon GUI startup
@@ -85,23 +87,23 @@ sxmo_state.sh set lock
# Turn on lisgd only on touch devices
if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ] && [ ! -e "$XDG_CACHE_HOME"/sxmo/sxmo.nogesture ]; then
superctl start sxmo_hook_lisgd
superctl start sxmo_hook_lisgd
fi
if [ -z "$SXMO_NO_MODEM" ] && command -v ModemManager > /dev/null; then
# Turn on the dbus-monitors for modem-related tasks
superctl start sxmo_modemmonitor
# Turn on the dbus-monitors for modem-related tasks
superctl start sxmo_modemmonitor
# place a wakelock for 120s to allow the modem to fully warm up (eg25 +
# elogind/systemd would do this for us, but we don't use those.)
sxmo_wakelock.sh lock sxmo_modem_warming_up 120s
# place a wakelock for 120s to allow the modem to fully warm up (eg25 +
# elogind/systemd would do this for us, but we don't use those.)
sxmo_wakelock.sh lock sxmo_modem_warming_up 120s
fi
# Start the desktop widget (e.g. clock)
pidof -s conky >/dev/null 2>&1 || DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
if [ -f /tmp/bananarchy_screen_locked ]; then
pkill -STOP -x conky 2>/dev/null || true
xlocker wake >/dev/null 2>&1 &
pkill -STOP -x conky 2>/dev/null || true
( xlocker wake >/dev/null 2>&1 & )
fi
# It watch network changes and update the status bar icon by example
@@ -112,6 +114,8 @@ superctl start sxmo_notificationmonitor
# Pre-warm app and script menu caches in background
(
sxmo_hook_apps.sh >/dev/null 2>&1 || true
sxmo_hook_scripts.sh >/dev/null 2>&1 || true
) &
(
sxmo_hook_apps.sh >/dev/null 2>&1 || true
sxmo_hook_scripts.sh >/dev/null 2>&1 || true
) &
)
@@ -501,27 +501,43 @@ set_inputmethod() {
sxmobar -a input-method 5 "$im_mode"
}
is_screen_dark() {
_st=""
[ -r "$SXMO_STATE" ] && { read -r _st < "$SXMO_STATE" 2>/dev/null || true; }
_bl=1
[ -r /sys/class/backlight/backlight/brightness ] && { read -r _bl < /sys/class/backlight/backlight/brightness 2>/dev/null || _bl=1; }
if [ "$_st" = "screenoff" ] || [ "${_bl:-1}" -le 0 ] 2>/dev/null; then
return 0
fi
return 1
}
sxmo_debug "$@"
case "$1" in
network)
is_screen_dark && exit 0
shift
set_network "$@"
;;
battery)
is_screen_dark && exit 0
shift
set_battery "$@"
;;
time)
is_screen_dark && exit 0
set_time 1
;;
modem|volume|state|notifications|notch|inputmethod)
modem|volume)
is_screen_dark && exit 0
set_"$1"
;;
state|notifications|notch|inputmethod)
set_"$1"
;;
state_change)
set_state
cur_st=""
[ -r "$SXMO_STATE" ] && { read -r cur_st < "$SXMO_STATE" 2>/dev/null || true; }
if [ "$cur_st" != "screenoff" ]; then
if ! is_screen_dark; then
set_time
set_inputmethod
if [ -z "$SXMO_NO_MODEM" ]; then
@@ -532,10 +548,7 @@ case "$1" in
fi
;;
periodics) # 60 s loop
cur_st=""
[ -r "$SXMO_STATE" ] && { read -r cur_st < "$SXMO_STATE" 2>/dev/null || true; }
cur_bl="$(cat /sys/class/backlight/backlight/brightness 2>/dev/null || echo 1)"
if [ "$cur_st" = "screenoff" ] || [ "${cur_bl:-1}" -le 0 ] 2>/dev/null || [ -f /tmp/bananarchy_screen_locked ]; then
if is_screen_dark || [ -f /tmp/bananarchy_screen_locked ]; then
exit 0
fi
set_time
@@ -569,6 +582,6 @@ case "$1" in
;;
esac
if [ "${SXMO_WM:-dwm}" = "dwm" ] && command -v xsetroot >/dev/null 2>&1; then
if ! is_screen_dark && [ "${SXMO_WM:-dwm}" = "dwm" ] && command -v xsetroot >/dev/null 2>&1; then
DISPLAY="${DISPLAY:-:0}" xsetroot -name "$(sxmo_status.sh)" 2>/dev/null || true
fi
@@ -10,27 +10,28 @@
# This hook is called when the system becomes unlocked again
if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_led.sh blink red green &
sxmo_led.sh blink red green &
fi
sxmo_wm.sh display on
pkill -CONT -x conky 2>/dev/null || true
( sxmo_hook_statusbar.sh state_change >/dev/null 2>&1 & )
if [ -z "$SXMO_NO_VIRTUAL_KEYBOARD" ]; then
sxmo_wm.sh inputevent touchscreen on
sxmo_wm.sh inputevent touchscreen on
fi
if [ -z "$SXMO_DISABLE_LEDS" ]; then
sxmo_jobs.sh stop periodic_blink
sxmo_jobs.sh stop periodic_blink
fi
sxmo_jobs.sh stop periodic_wakelock_check
# Re-enable automatic screen-off on idle to save battery. Locking stays
# explicit (the user locks only on request); we only blank the display.
if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then
sxmo_jobs.sh stop idle_locker
sxmo_jobs.sh stop idle_locker
else
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_UNLOCK_IDLE_TIME:-30}" 'sh -c "sxmo_state.sh set screenoff"'
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_UNLOCK_IDLE_TIME:-30}" 'sh -c "sxmo_state.sh set screenoff"'
fi
wait