diff --git a/Makefile b/Makefile index cbcb0eb..50d0c1c 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ OPENRC:=1 CC ?= $(CROSS_COMPILE)gcc PROGRAMS = \ + programs/sxmo_aligned_sleep \ programs/sxmo_vibrate \ programs/sxmo_splitchar @@ -20,14 +21,11 @@ test: shellcheck shellcheck: find . -type f -name '*.sh' -print0 | xargs -0 shellcheck -x --shell=sh -programs/sxmo_vibrate: programs/sxmo_vibrate.c - $(CC) -o programs/sxmo_vibrate programs/sxmo_vibrate.c - -programs/sxmo_splitchar: programs/sxmo_splitchar.c - $(CC) -o programs/sxmo_splitchar programs/sxmo_splitchar.c +programs/%: programs/%.c + gcc -o $@ $< clean: - rm -f programs/sxmo_vibrate programs/sxmo_splitchar + rm -f programs/sxmo_aligned_sleep programs/sxmo_vibrate programs/sxmo_splitchar install: $(PROGRAMS) cd configs && find . -type f -not -name sxmo-setpermissions -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd .. @@ -68,6 +66,7 @@ install: $(PROGRAMS) # Bin install -D -t $(DESTDIR)$(PREFIX)/bin scripts/*/*.sh + install -D programs/sxmo_aligned_sleep $(DESTDIR)$(PREFIX)/bin/ install -D programs/sxmo_vibrate $(DESTDIR)$(PREFIX)/bin/ install -D programs/sxmo_splitchar $(DESTDIR)$(PREFIX)/bin/ diff --git a/configs/default_hooks/one_button_e_reader/sxmo_hook_postwake.sh b/configs/default_hooks/one_button_e_reader/sxmo_hook_postwake.sh index a82c0c8..28ec72a 100755 --- a/configs/default_hooks/one_button_e_reader/sxmo_hook_postwake.sh +++ b/configs/default_hooks/one_button_e_reader/sxmo_hook_postwake.sh @@ -14,7 +14,6 @@ light -S "$(cat "$XDG_RUNTIME_DIR"/sxmo.brightness.presuspend.state)" -sxmo_hook_statusbar.sh time sxmo_hook_unlock.sh # Add here whatever you want to do diff --git a/configs/default_hooks/one_button_e_reader/sxmo_hook_unlock.sh b/configs/default_hooks/one_button_e_reader/sxmo_hook_unlock.sh index f56e737..2c4f801 100755 --- a/configs/default_hooks/one_button_e_reader/sxmo_hook_unlock.sh +++ b/configs/default_hooks/one_button_e_reader/sxmo_hook_unlock.sh @@ -27,5 +27,3 @@ if ! [ -e "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend" ]; then timeout "$((${SXMO_UNLOCK_IDLE_TIME:-120}+10))" 'sxmo_daemons.sh start periodic_state_mutex_check sxmo_run_periodically.sh 10 sxmo_hook_check_state_mutexes.sh' \ resume 'sxmo_daemons.sh stop periodic_state_mutex_check' fi - -sxmo_superd_signal.sh sxmo_desktop_widget -USR2 diff --git a/configs/default_hooks/sxmo_hook_desktop_widget.sh b/configs/default_hooks/sxmo_hook_desktop_widget.sh index c9dc032..8edc154 100644 --- a/configs/default_hooks/sxmo_hook_desktop_widget.sh +++ b/configs/default_hooks/sxmo_hook_desktop_widget.sh @@ -19,40 +19,23 @@ pangodraw() { } if [ -n "$WAYLAND_DISPLAY" ] && command -v wayout > /dev/null; then + trap 'kill -- $WAYOUT' TERM INT EXIT + # For wayland we use wayout: - tmp="$(mktemp)" ( - pangodraw - pangodraw + sleep 1 # wayout misses output sent to it as it's starting while : ; do - sleep 60 pangodraw + sxmo_aligned_sleep 60 done - ) >> "$tmp" & - PIDS="$!" - - forceredraw() { - pangodraw >> "$tmp" - for PID in $PIDS; do - wait "$PID" - done - } - trap 'forceredraw' USR2 - - tail -f "$tmp" | wayout --font "FiraMono Nerd Font" --foreground-color "#ffffff" --fontsize "80" --height 200 --textalign center --feed-par & - PIDS="$! $PIDS" - - finish() { - for PID in $PIDS; do - kill "$PID" - done - rm "$tmp" - } - trap 'finish' TERM INT EXIT - - for PID in $PIDS; do - wait "$PID" - done + ) | wayout --font "FiraMono Nerd Font" \ + --foreground-color "#ffffff" \ + --fontsize "80" \ + --height 200 \ + --textalign center \ + --feed-par & + WAYOUT="$!" + wait elif [ -n "$DISPLAY" ] && command -v conky > /dev/null; then # For X we use conky (if not already running): exec conky -c "$(xdg_data_path sxmo/appcfg/conky24h.conf)" #24 hour clock diff --git a/configs/default_hooks/sxmo_hook_start.sh b/configs/default_hooks/sxmo_hook_start.sh index 00e605f..ff4bcd2 100644 --- a/configs/default_hooks/sxmo_hook_start.sh +++ b/configs/default_hooks/sxmo_hook_start.sh @@ -60,7 +60,7 @@ superctl start sxmo_desktop_widget # Periodically update some status bar components sxmo_hook_statusbar.sh all -sxmo_daemons.sh start statusbar_periodics sxmo_run_periodically.sh 55 \ +sxmo_daemons.sh start statusbar_periodics sxmo_run_aligned.sh 60 \ sxmo_hook_statusbar.sh periodics # Monitor the battery diff --git a/configs/default_hooks/three_button_touchscreen/sxmo_hook_lock.sh b/configs/default_hooks/three_button_touchscreen/sxmo_hook_lock.sh index 5750d29..688cac3 100644 --- a/configs/default_hooks/three_button_touchscreen/sxmo_hook_lock.sh +++ b/configs/default_hooks/three_button_touchscreen/sxmo_hook_lock.sh @@ -29,5 +29,3 @@ if ! [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then sxmo_daemons.sh start idle_locker sxmo_idle.sh -w \ timeout 8 "sxmo_hook_screenoff.sh" fi - -sxmo_superd_signal.sh sxmo_desktop_widget -USR2 diff --git a/configs/default_hooks/three_button_touchscreen/sxmo_hook_postwake.sh b/configs/default_hooks/three_button_touchscreen/sxmo_hook_postwake.sh index b3c904d..5b42aa8 100644 --- a/configs/default_hooks/three_button_touchscreen/sxmo_hook_postwake.sh +++ b/configs/default_hooks/three_button_touchscreen/sxmo_hook_postwake.sh @@ -19,8 +19,6 @@ if [ "$UNSUSPENDREASON" != "modem" ]; then fi fi -sxmo_hook_statusbar.sh time - if [ "$UNSUSPENDREASON" = "rtc" ] || [ "$UNSUSPENDREASON" = "usb power" ]; then if grep -q screenoff "$XDG_RUNTIME_DIR/sxmo.state"; then # We stopped it in presuspend diff --git a/configs/default_hooks/three_button_touchscreen/sxmo_hook_unlock.sh b/configs/default_hooks/three_button_touchscreen/sxmo_hook_unlock.sh index a8d10c9..351ae36 100644 --- a/configs/default_hooks/three_button_touchscreen/sxmo_hook_unlock.sh +++ b/configs/default_hooks/three_button_touchscreen/sxmo_hook_unlock.sh @@ -44,5 +44,3 @@ else ;; esac fi - -sxmo_superd_signal.sh sxmo_desktop_widget -USR2 diff --git a/programs/sxmo_aligned_sleep.c b/programs/sxmo_aligned_sleep.c new file mode 100644 index 0000000..d383a95 --- /dev/null +++ b/programs/sxmo_aligned_sleep.c @@ -0,0 +1,48 @@ +#include // error handling +#include // uint64_t type +#include // dprintf +#include // strtol, exit +#include // strerror, strcmp +#include // timers +#include // read + +static void error(char *message, int err) { + dprintf(2, "%s: %s\n", message, strerror(err)); + exit(1); +} + +int main(int argc, char **argv) { + uint64_t buf; + long duration = -1; + int time_fd; + + struct timespec now; + struct itimerspec time = { + .it_value = { .tv_sec = 0, .tv_nsec = 0 }, + .it_interval = { .tv_sec = 0, .tv_nsec = 0 } + }; + + // Process arguments + if (argc >= 2) duration = strtol(argv[1], NULL, 0); + if (duration <= 0) { + dprintf(2, "Usage: %s \n", argv[0]); + dprintf(2, "ERROR: duration must be a positive integer\n"); + return 1; + } + + // Setup timer + if ((time_fd = timerfd_create(CLOCK_REALTIME, 0)) == -1) + error("Failed to create timerfd", errno); + if (clock_gettime(CLOCK_REALTIME, &now) == -1) + error("Failed to get current time", errno); + + // find the next time that's divisable by the provided number of seconds + time.it_value.tv_sec = now.tv_sec + duration - (now.tv_sec % duration); + + if (timerfd_settime(time_fd, TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &time, NULL) == -1) + error("Failed to set timer",errno); + + // Wait for timer + read(time_fd, &buf, sizeof(uint64_t)); +} + diff --git a/scripts/core/sxmo_run_aligned.sh b/scripts/core/sxmo_run_aligned.sh new file mode 100644 index 0000000..71dc058 --- /dev/null +++ b/scripts/core/sxmo_run_aligned.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SPDX-License-Identifier: AGPL-3.0-only +# Copyright 2022 Sxmo Contributors + +timeout="$1" +shift + +finish() { + kill "$CMDPID" + kill "$SLEEPPID" + exit 0 +} + +trap 'finish' TERM INT + +while : ; do + "$@" & + CMDPID="$!" + wait "$CMDPID" + + sxmo_aligned_sleep "$timeout" & + SLEEPPID="$!" + wait "$SLEEPPID" +done