summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-02-27 19:52:15 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-02-27 19:52:15 +0800
commitc38f6b3410fa12d00dcdcbcb5d6dc7d533aea201 (patch)
tree8454ccf2b32c36a0508561e23f606b5d03af552a
parent61717d2e10478750a6b9ad8bf12eb994b8d1bb60 (diff)
hyprsunset: use IPC instead of kill/restarting hyprsunset
-rwxr-xr-xhyprsunset.sh60
1 files changed, 54 insertions, 6 deletions
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