fix: short nightlight fade duration if missed start or end time or if manually activated

This commit is contained in:
2026-10-19 19:21:57 +02:00
parent d3345906b9
commit 6781078467
4 changed files with 18 additions and 17 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ Singleton {
function toggleNightLight(): void { function toggleNightLight(): void {
service.manualToggle = true; service.manualToggle = true;
service.toggle(); service.toggle(true);
} }
NightlightManager { NightlightManager {
+1 -1
View File
@@ -199,7 +199,7 @@ PageBase {
stepSize: 1 stepSize: 1
subtext: qsTr("How long it takes for the gradual nightlight to finish (s)") subtext: qsTr("How long it takes for the gradual nightlight to finish (s)")
text: qsTr("Fade duration") text: qsTr("Fade duration")
to: 60 * 5 to: 60 * 20
value: Config.display.nightlight.fadeDuration / 1000 value: Config.display.nightlight.fadeDuration / 1000
onMoved: v => Config.display.nightlight.fadeDuration = v * 1000 onMoved: v => Config.display.nightlight.fadeDuration = v * 1000
+13 -12
View File
@@ -129,15 +129,15 @@ void NightlightManager::setFadeDuration(double duration) {
emit fadeDurationChanged(); emit fadeDurationChanged();
} }
void NightlightManager::toggle() { void NightlightManager::toggle(bool fast) {
if (m_enabled) { if (m_enabled) {
end(); end(fast ? 2 : m_fadeDuration);
} else { } else {
start(); start(fast ? 2 : m_fadeDuration);
} }
} }
void NightlightManager::start() { void NightlightManager::start(double fade) {
if (m_enabled && m_initialized) return; if (m_enabled && m_initialized) return;
m_initialized = true; m_initialized = true;
@@ -149,9 +149,7 @@ void NightlightManager::start() {
m_process.setProgram("hyprctl"); m_process.setProgram("hyprctl");
m_process.setArguments( m_process.setArguments(
{"dispatch", {"dispatch",
QString("hl.plugin.zshell.nlSet(%1, %2)") QString("hl.plugin.zshell.nlSet(%1, %2)").arg(m_temp).arg(fade)});
.arg(m_temp)
.arg(m_fadeDuration)});
m_process.startDetached(); m_process.startDetached();
} else { } else {
m_process.setProgram("hyprctl"); m_process.setProgram("hyprctl");
@@ -161,7 +159,7 @@ void NightlightManager::start() {
} }
} }
void NightlightManager::end() { void NightlightManager::end(double fade) {
if (!m_enabled && m_initialized) return; if (!m_enabled && m_initialized) return;
m_initialized = true; m_initialized = true;
@@ -172,8 +170,7 @@ void NightlightManager::end() {
if (m_useNativeNightlight) { if (m_useNativeNightlight) {
m_process.setProgram("hyprctl"); m_process.setProgram("hyprctl");
m_process.setArguments( m_process.setArguments(
{"dispatch", {"dispatch", QString("hl.plugin.zshell.nlDisable(%1)").arg(fade)});
QString("hl.plugin.zshell.nlDisable(%1)").arg(m_fadeDuration)});
m_process.startDetached(); m_process.startDetached();
} else { } else {
m_process.setProgram("hyprctl"); m_process.setProgram("hyprctl");
@@ -195,10 +192,14 @@ void NightlightManager::apply() {
isDarkTime = (currentMin >= m_startTime || currentMin < m_endTime); isDarkTime = (currentMin >= m_startTime || currentMin < m_endTime);
} }
const auto activationTime = isDarkTime ? m_startTime : m_endTime;
const auto elapsed = (currentMin - activationTime + 1440) % 1440;
const bool pastActivation = elapsed > 20;
if (isDarkTime) { if (isDarkTime) {
start(); start(pastActivation ? 2 : m_fadeDuration);
} else { } else {
end(); end(pastActivation ? 2 : m_fadeDuration);
} }
} }
@@ -54,7 +54,7 @@ class NightlightManager : public QObject {
[[nodiscard]] int lastTemp() const; [[nodiscard]] int lastTemp() const;
[[nodiscard]] int currentTemp() const; [[nodiscard]] int currentTemp() const;
Q_INVOKABLE void toggle(); Q_INVOKABLE void toggle(bool fast);
Q_INVOKABLE void apply(); Q_INVOKABLE void apply();
void setStartTime(const int& time); void setStartTime(const int& time);
@@ -105,8 +105,8 @@ class NightlightManager : public QObject {
QByteArray m_socketBuffer; QByteArray m_socketBuffer;
QTimer m_reconnectTimer; QTimer m_reconnectTimer;
void start(); void start(double fade);
void end(); void end(double fade);
[[nodiscard]] QString hyprlandDir() const; [[nodiscard]] QString hyprlandDir() const;
[[nodiscard]] QString eventSocketPath() const; [[nodiscard]] QString eventSocketPath() const;
[[nodiscard]] QString resolvePluginPath() const; [[nodiscard]] QString resolvePluginPath() const;