quickshell: ramp nightlight across twilight instead of snapping at sunset

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-08-03 22:44:09 +01:00
parent 6937279290
commit 86640f5d7f

View file

@ -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"]