fix: short nightlight fade duration if missed start or end time or if manually activated
This commit is contained in:
@@ -129,15 +129,15 @@ void NightlightManager::setFadeDuration(double duration) {
|
||||
emit fadeDurationChanged();
|
||||
}
|
||||
|
||||
void NightlightManager::toggle() {
|
||||
void NightlightManager::toggle(bool fast) {
|
||||
if (m_enabled) {
|
||||
end();
|
||||
end(fast ? 2 : m_fadeDuration);
|
||||
} else {
|
||||
start();
|
||||
start(fast ? 2 : m_fadeDuration);
|
||||
}
|
||||
}
|
||||
|
||||
void NightlightManager::start() {
|
||||
void NightlightManager::start(double fade) {
|
||||
if (m_enabled && m_initialized) return;
|
||||
|
||||
m_initialized = true;
|
||||
@@ -149,9 +149,7 @@ void NightlightManager::start() {
|
||||
m_process.setProgram("hyprctl");
|
||||
m_process.setArguments(
|
||||
{"dispatch",
|
||||
QString("hl.plugin.zshell.nlSet(%1, %2)")
|
||||
.arg(m_temp)
|
||||
.arg(m_fadeDuration)});
|
||||
QString("hl.plugin.zshell.nlSet(%1, %2)").arg(m_temp).arg(fade)});
|
||||
m_process.startDetached();
|
||||
} else {
|
||||
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;
|
||||
|
||||
m_initialized = true;
|
||||
@@ -172,8 +170,7 @@ void NightlightManager::end() {
|
||||
if (m_useNativeNightlight) {
|
||||
m_process.setProgram("hyprctl");
|
||||
m_process.setArguments(
|
||||
{"dispatch",
|
||||
QString("hl.plugin.zshell.nlDisable(%1)").arg(m_fadeDuration)});
|
||||
{"dispatch", QString("hl.plugin.zshell.nlDisable(%1)").arg(fade)});
|
||||
m_process.startDetached();
|
||||
} else {
|
||||
m_process.setProgram("hyprctl");
|
||||
@@ -195,10 +192,14 @@ void NightlightManager::apply() {
|
||||
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) {
|
||||
start();
|
||||
start(pastActivation ? 2 : m_fadeDuration);
|
||||
} else {
|
||||
end();
|
||||
end(pastActivation ? 2 : m_fadeDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class NightlightManager : public QObject {
|
||||
[[nodiscard]] int lastTemp() const;
|
||||
[[nodiscard]] int currentTemp() const;
|
||||
|
||||
Q_INVOKABLE void toggle();
|
||||
Q_INVOKABLE void toggle(bool fast);
|
||||
Q_INVOKABLE void apply();
|
||||
|
||||
void setStartTime(const int& time);
|
||||
@@ -105,8 +105,8 @@ class NightlightManager : public QObject {
|
||||
QByteArray m_socketBuffer;
|
||||
QTimer m_reconnectTimer;
|
||||
|
||||
void start();
|
||||
void end();
|
||||
void start(double fade);
|
||||
void end(double fade);
|
||||
[[nodiscard]] QString hyprlandDir() const;
|
||||
[[nodiscard]] QString eventSocketPath() const;
|
||||
[[nodiscard]] QString resolvePluginPath() const;
|
||||
|
||||
Reference in New Issue
Block a user