From 86640f5d7f50dd1a18cafcb8348fcc09cb6345d7 Mon Sep 17 00:00:00 2001 From: rope Date: Mon, 3 Aug 2026 22:44:09 +0100 Subject: [PATCH] quickshell: ramp nightlight across twilight instead of snapping at sunset Co-Authored-By: Claude Opus 5 --- settings/quickshell.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/settings/quickshell.nix b/settings/quickshell.nix index a5c434a..6fe7555 100644 --- a/settings/quickshell.nix +++ b/settings/quickshell.nix @@ -971,6 +971,9 @@ in // real times by the bar's open-meteo weather fetch. property int sunriseMins: 7 * 60 property int sunsetMins: 21 * 60 + // Twilight ramp: warmth fades in over this many minutes after + // sunset and back out over the same span before sunrise. + readonly property int nlFadeMins: 90 readonly property var nightlight: nlState FileView { @@ -993,12 +996,25 @@ in nlFile.writeAdapter(); } + // 0 in daylight, 1 in full night, linear in between across the + // nlFadeMins twilight windows. Handles the midnight wrap and + // nights shorter than two fade windows (min() just peaks lower). + function nightFactor(mins) { + let sr = sunriseMins, ss = sunsetMins; + let day = sr < ss ? (mins >= sr && mins < ss) + : (mins >= sr || mins < ss); + if (day) return 0; + let sinceSet = (mins - ss + 1440) % 1440; + let toRise = (sr - mins + 1440) % 1440; + return Math.min(1, sinceSet / nlFadeMins, toRise / nlFadeMins); + } + function applyNightlight() { let w = nlState.warmth; if (nlState.autoOn) { let now = new Date(); let mins = now.getHours() * 60 + now.getMinutes(); - if (mins >= sunriseMins && mins < sunsetMins) w = 0; // daytime + w *= nightFactor(mins); } nlApply.command = w < 0.02 ? ["hyprctl", "hyprsunset", "identity"]