From c38f6b3410fa12d00dcdcbcb5d6dc7d533aea201 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 27 Feb 2025 19:52:15 +0800 Subject: hyprsunset: use IPC instead of kill/restarting hyprsunset --- hyprsunset.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'hyprsunset.sh') diff --git a/hyprsunset.sh b/hyprsunset.sh index 680e9cb..d6fb13a 100755 --- a/hyprsunset.sh +++ b/hyprsunset.sh @@ -1,9 +1,57 @@ #!/bin/bash -time=$(date +%H) +renice -n 19 $$ +ionice -c 3 -p $$ -if [ $time -ge 6 -a $time -lt 20 ]; then - killall hyprsunset -else - hyprsunset & -fi +NIGHT_GAMMA=95 +NIGHT_TEMP=5000 +SUNRISE_HOUR=6 +SUNSET_HOUR=20 + +apply_settings() { + current_hour=$(date +%H | sed 's/^0//') + + if [ $current_hour -ge $SUNRISE_HOUR -a $current_hour -lt $SUNSET_HOUR ]; then + echo "Applying day settings" + hyprctl hyprsunset identity + else + echo "Applying night settings" + hyprctl hyprsunset temperature $NIGHT_TEMP + hyprctl hyprsunset gamma $NIGHT_GAMMA + fi +} + +calculate_sleep_time() { + current_hour=$(date +%H | sed 's/^0//') + current_min=$(date +%M | sed 's/^0//') + + if [ $current_hour -ge $SUNRISE_HOUR -a $current_hour -lt $SUNSET_HOUR ]; then + hours_until_sunset=$((SUNSET_HOUR - current_hour - 1)) + mins_until_sunset=$((60 - current_min)) + sleep_seconds=$(( (hours_until_sunset * 3600) + (mins_until_sunset * 60) )) + else + if [ $current_hour -lt $SUNRISE_HOUR ]; then + hours_until_sunrise=$(($SUNRISE_HOUR - $current_hour - 1)) + mins_until_sunrise=$((60 - $current_min)) + else + hours_until_sunrise=$(($SUNRISE_HOUR + 24 - $current_hour - 1)) + mins_until_sunrise=$((60 - $current_min)) + fi + sleep_seconds=$(( (hours_until_sunrise * 3600) + (mins_until_sunrise * 60) )) + fi + + echo $sleep_seconds +} + +while true; do + if [ ! -d /run/user/$UID/hypr/hyprsunset ]; then + echo "Hyprsunset not running, running it via hyprctl dispatch" + hyprctl dispatch execr hyprsunset + fi + apply_settings + sleep_time=$(calculate_sleep_time) + + printf "Sleeping for %d hours and %d minutes (%d seconds)\n" $((sleep_time / 3600)) $(((sleep_time % 3600) / 60)) $sleep_time + + sleep $sleep_time +done -- cgit v1.2.3