aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/Hyprsunset.sh
diff options
context:
space:
mode:
authorDonald Williams <129223418+dwilliam62@users.noreply.github.com>2025-10-13 20:31:53 -0400
committerGitHub <noreply@github.com>2025-10-13 20:31:53 -0400
commite4be12e23fa8d6f8a73dde974ea6adf242885bc1 (patch)
treeb879abcf54989120a0931443bfb8203c885c2b20 /config/hypr/scripts/Hyprsunset.sh
parent0e52d19b894e3cfd2c87cfbcc35ae087d48f5485 (diff)
parent9d26c191c1071a542e816d1bc2b0b3f96ebfa74d (diff)
Merge pull request #841 from JaKooLit/ddubs-hyprsunset
Merge ddubs-hyprsunset into main fixes for wallust, sddm and weather
Diffstat (limited to 'config/hypr/scripts/Hyprsunset.sh')
-rwxr-xr-xconfig/hypr/scripts/Hyprsunset.sh99
1 files changed, 99 insertions, 0 deletions
diff --git a/config/hypr/scripts/Hyprsunset.sh b/config/hypr/scripts/Hyprsunset.sh
new file mode 100755
index 00000000..c7c4b395
--- /dev/null
+++ b/config/hypr/scripts/Hyprsunset.sh
@@ -0,0 +1,99 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# Hyprsunset toggle + Waybar status helper
+# Phase 1: manual toggle only (no scheduling)
+# Icons:
+# - Off: bright sun
+# - On: sunset icon if available, otherwise a blue sun
+#
+# Customize via env vars:
+# HYPERSUNSET_TEMP default 4500 (K)
+# HYPERSUNSET_ICON_MODE sunset|blue (default: sunset)
+
+STATE_FILE="$HOME/.cache/.hyprsunset_state"
+TARGET_TEMP="${HYPERSUNSET_TEMP:-4500}"
+ICON_MODE="${HYPERSUNSET_ICON_MODE:-sunset}"
+
+ensure_state() {
+ [[ -f "$STATE_FILE" ]] || echo "off" > "$STATE_FILE"
+}
+
+# Render icons using pango markup to allow colorization
+icon_off() {
+ # universally available sun symbol
+ printf "☀"
+}
+
+icon_on() {
+ case "$ICON_MODE" in
+ sunset)
+ # sunset emoji (falls back to tofu if no emoji font)
+ printf "🌇"
+ ;;
+ blue)
+ # no color in text; rely on CSS .on to style if desired
+ printf "☀"
+ ;;
+ *)
+ printf "☀"
+ ;;
+ esac
+}
+
+cmd_toggle() {
+ ensure_state
+ state="$(cat "$STATE_FILE" || echo off)"
+
+ # Always stop any running hyprsunset first to avoid CTM manager conflicts
+ if pgrep -x hyprsunset >/dev/null 2>&1; then
+ pkill -x hyprsunset || true
+ # give it a moment to release the CTM manager
+ sleep 0.2
+ fi
+
+if [[ "$state" == "on" ]]; then
+ # Turning OFF: set identity and exit
+ if command -v hyprsunset >/dev/null 2>&1; then
+ nohup hyprsunset -i >/dev/null 2>&1 &
+ # if hyprsunset persists, stop it shortly after applying identity
+ sleep 0.3 && pkill -x hyprsunset || true
+ fi
+ echo off > "$STATE_FILE"
+ notify-send -u low "Hyprsunset: Disabled" || true
+ else
+ # Turning ON: start hyprsunset at target temp in background
+ if command -v hyprsunset >/dev/null 2>&1; then
+ nohup hyprsunset -t "$TARGET_TEMP" >/dev/null 2>&1 &
+ fi
+ echo on > "$STATE_FILE"
+ notify-send -u low "Hyprsunset: Enabled" "${TARGET_TEMP}K" || true
+ fi
+}
+
+cmd_status() {
+ ensure_state
+ # Prefer live process detection; fall back to state file
+ if pgrep -x hyprsunset >/dev/null 2>&1; then
+ onoff="on"
+ else
+ onoff="$(cat "$STATE_FILE" || echo off)"
+ fi
+
+ if [[ "$onoff" == "on" ]]; then
+ txt="<span size='18pt'>$(icon_on)</span>"
+ cls="on"
+ tip="Night light on @ ${TARGET_TEMP}K"
+ else
+ txt="<span size='16pt'>$(icon_off)</span>"
+ cls="off"
+ tip="Night light off"
+ fi
+ printf '{"text":"%s","class":"%s","tooltip":"%s"}\n' "$txt" "$cls" "$tip"
+}
+
+case "${1:-}" in
+ toggle) cmd_toggle ;;
+ status) cmd_status ;;
+ *) echo "usage: $0 [toggle|status]" >&2; exit 2 ;;
+ esac
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage