From d91a6357813e3ec11b75722d1c75bbc8281ca2e8 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Wed, 10 Sep 2025 12:34:52 +0200 Subject: [PATCH] NightLight: add force activation --- Commons/Settings.qml | 1 + Modules/Bar/Widgets/NightLight.qml | 18 +++++++++--- Modules/SettingsPanel/Tabs/BrightnessTab.qml | 19 ++++++++++++ Services/NightLightService.qml | 31 +++++++++++++++----- 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/Commons/Settings.qml b/Commons/Settings.qml index 224dbd3..762a92c 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -443,6 +443,7 @@ Singleton { // night light property JsonObject nightLight: JsonObject { property bool enabled: false + property bool forced: false property bool autoSchedule: true property string nightTemp: "4000" property string dayTemp: "6500" diff --git a/Modules/Bar/Widgets/NightLight.qml b/Modules/Bar/Widgets/NightLight.qml index f9d4b76..c82e76c 100644 --- a/Modules/Bar/Widgets/NightLight.qml +++ b/Modules/Bar/Widgets/NightLight.qml @@ -15,14 +15,24 @@ NIconButton { property real scaling: 1.0 sizeRatio: 0.8 - colorBg: Settings.data.nightLight.enabled ? Color.mPrimary : Color.mSurfaceVariant + colorBg: Settings.data.nightLight.enabled ? (Settings.data.nightLight.forced ? Color.mTertiary : Color.mPrimary) : Color.mSurfaceVariant colorFg: Settings.data.nightLight.enabled ? Color.mOnPrimary : Color.mOnSurface colorBorder: Color.transparent colorBorderHover: Color.transparent - icon: Settings.data.nightLight.enabled ? "nightlight-on" : "nightlight-off" - tooltipText: `Night light: ${Settings.data.nightLight.enabled ? "enabled." : "disabled."}\nLeft click to toggle.\nRight click to access settings.` - onClicked: Settings.data.nightLight.enabled = !Settings.data.nightLight.enabled + icon: Settings.data.nightLight.enabled ? (Settings.data.nightLight.forced ? "alert-triangle" : "nightlight-on") : "nightlight-off" + tooltipText: `Night light: ${Settings.data.nightLight.enabled ? (Settings.data.nightLight.forced ? "forced." : "enabled.") : "disabled."}\nLeft click to cycle (disabled → normal → forced).\nRight click to access settings.` + onClicked: { + if (!Settings.data.nightLight.enabled) { + Settings.data.nightLight.enabled = true + Settings.data.nightLight.forced = false + } else if (Settings.data.nightLight.enabled && !Settings.data.nightLight.forced) { + Settings.data.nightLight.forced = true + } else { + Settings.data.nightLight.enabled = false + Settings.data.nightLight.forced = false + } + } onRightClicked: { var settingsPanel = PanelService.getPanel("settingsPanel") diff --git a/Modules/SettingsPanel/Tabs/BrightnessTab.qml b/Modules/SettingsPanel/Tabs/BrightnessTab.qml index 0b02d4a..a8f0135 100644 --- a/Modules/SettingsPanel/Tabs/BrightnessTab.qml +++ b/Modules/SettingsPanel/Tabs/BrightnessTab.qml @@ -194,6 +194,7 @@ ColumnLayout { wlsunsetCheck.running = true } else { Settings.data.nightLight.enabled = false + Settings.data.nightLight.forced = false NightLightService.apply() ToastService.showNotice("Night Light", "Disabled") } @@ -276,6 +277,7 @@ ColumnLayout { ColumnLayout { spacing: Style.marginXS * scaling visible: Settings.data.nightLight.enabled && !Settings.data.nightLight.autoSchedule + && !Settings.data.nightLight.forced RowLayout { Layout.fillWidth: false @@ -319,4 +321,21 @@ ColumnLayout { } } } + + // Force activation toggle + NToggle { + label: "Force activation" + description: "Immediately apply night temperature without scheduling or fade." + checked: Settings.data.nightLight.forced + onToggled: checked => { + Settings.data.nightLight.forced = checked + if (checked && !Settings.data.nightLight.enabled) { + // Ensure enabled when forcing + wlsunsetCheck.running = true + } else { + NightLightService.apply() + } + } + visible: Settings.data.nightLight.enabled + } } diff --git a/Services/NightLightService.qml b/Services/NightLightService.qml index 77084f2..6e19675 100644 --- a/Services/NightLightService.qml +++ b/Services/NightLightService.qml @@ -15,7 +15,7 @@ Singleton { function apply() { // If using LocationService, wait for it to be ready - if (params.autoSchedule && !LocationService.coordinatesReady) { + if (!params.forced && params.autoSchedule && !LocationService.coordinatesReady) { return } @@ -34,14 +34,25 @@ Singleton { function buildCommand() { var cmd = ["wlsunset"] - cmd.push("-t", `${params.nightTemp}`, "-T", `${params.dayTemp}`) - if (params.autoSchedule) { - cmd.push("-l", `${LocationService.stableLatitude}`, "-L", `${LocationService.stableLongitude}`) + if (params.forced) { + // Force immediate full night temperature regardless of time + // Keep distinct day/night temps but set times so we're effectively always in "night" + cmd.push("-t", `${params.nightTemp}`, "-T", `${params.dayTemp}`) + // Night spans from sunset (00:00) to sunrise (23:59) covering almost the full day + cmd.push("-S", "23:59") // sunrise very late + cmd.push("-s", "00:00") // sunset at midnight + // Near-instant transition + cmd.push("-d", 1) } else { - cmd.push("-S", params.manualSunrise) - cmd.push("-s", params.manualSunset) + cmd.push("-t", `${params.nightTemp}`, "-T", `${params.dayTemp}`) + if (params.autoSchedule) { + cmd.push("-l", `${LocationService.stableLatitude}`, "-L", `${LocationService.stableLongitude}`) + } else { + cmd.push("-S", params.manualSunrise) + cmd.push("-s", params.manualSunset) + } + cmd.push("-d", 60 * 15) // 15min progressive fade at sunset/sunrise } - cmd.push("-d", 60 * 15) // 15min progressive fade at sunset/sunrise return cmd } @@ -54,6 +65,12 @@ Singleton { const enabled = !!Settings.data.nightLight.enabled ToastService.showNotice("Night Light", enabled ? "Enabled" : "Disabled") } + function onForcedChanged() { + apply() + if (Settings.data.nightLight.enabled) { + ToastService.showNotice("Night Light", Settings.data.nightLight.forced ? "Forced activation" : "Normal mode") + } + } function onNightTempChanged() { apply() }