From 4caa59dd9e2da6e0d9290094b7866cc6b2f70467 Mon Sep 17 00:00:00 2001 From: altrup <51763643+altrup@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:36:17 -0400 Subject: [PATCH] Decrease gamma when brightness is requested to go lower beyond 0 --- .../models/hyprland/HyprlandConfigOption.qml | 2 +- .../models/quickToggles/NightLightToggle.qml | 4 +- .../indicators/BrightnessIndicator.qml | 2 +- .../nightLight/NightLightDialog.qml | 4 +- .../quickToggles/classicStyle/NightLight.qml | 4 +- .../nightLight/NightLightControl.qml | 4 +- .../ii/modules/waffle/looks/WIcons.qml | 2 +- .../quickshell/ii/services/Brightness.qml | 12 +++- .../quickshell/ii/services/Hyprsunset.qml | 68 ++++++++++++++----- 9 files changed, 72 insertions(+), 30 deletions(-) diff --git a/dots/.config/quickshell/ii/modules/common/models/hyprland/HyprlandConfigOption.qml b/dots/.config/quickshell/ii/modules/common/models/hyprland/HyprlandConfigOption.qml index 0422aab02..3219a8a12 100644 --- a/dots/.config/quickshell/ii/modules/common/models/hyprland/HyprlandConfigOption.qml +++ b/dots/.config/quickshell/ii/modules/common/models/hyprland/HyprlandConfigOption.qml @@ -3,7 +3,7 @@ import QtQml import QtQuick import Quickshell.Io import qs.services -import "../" +import ".." NestableObject { id: root diff --git a/dots/.config/quickshell/ii/modules/common/models/quickToggles/NightLightToggle.qml b/dots/.config/quickshell/ii/modules/common/models/quickToggles/NightLightToggle.qml index d53af9740..f71c97ee9 100644 --- a/dots/.config/quickshell/ii/modules/common/models/quickToggles/NightLightToggle.qml +++ b/dots/.config/quickshell/ii/modules/common/models/quickToggles/NightLightToggle.qml @@ -12,11 +12,11 @@ QuickToggleModel { name: Translation.tr("Night Light") statusText: (auto ? Translation.tr("Auto, ") : "") + (toggled ? Translation.tr("Active") : Translation.tr("Inactive")) - toggled: Hyprsunset.active + toggled: Hyprsunset.temperatureActive icon: auto ? "night_sight_auto" : "bedtime" mainAction: () => { - Hyprsunset.toggle() + Hyprsunset.toggleTemperature() } hasMenu: true diff --git a/dots/.config/quickshell/ii/modules/ii/onScreenDisplay/indicators/BrightnessIndicator.qml b/dots/.config/quickshell/ii/modules/ii/onScreenDisplay/indicators/BrightnessIndicator.qml index fbdbd7152..a4381757c 100644 --- a/dots/.config/quickshell/ii/modules/ii/onScreenDisplay/indicators/BrightnessIndicator.qml +++ b/dots/.config/quickshell/ii/modules/ii/onScreenDisplay/indicators/BrightnessIndicator.qml @@ -9,7 +9,7 @@ OsdValueIndicator { property var focusedScreen: Quickshell.screens.find(s => s.name === Hyprland.focusedMonitor?.name) property var brightnessMonitor: Brightness.getMonitorForScreen(focusedScreen) - icon: Hyprsunset.active ? "routine" : "light_mode" + icon: Hyprsunset.temperatureActive ? "routine" : "light_mode" rotateIcon: true scaleIcon: true name: Translation.tr("Brightness") diff --git a/dots/.config/quickshell/ii/modules/ii/sidebarRight/nightLight/NightLightDialog.qml b/dots/.config/quickshell/ii/modules/ii/sidebarRight/nightLight/NightLightDialog.qml index e6f7509f2..6ad9307cb 100644 --- a/dots/.config/quickshell/ii/modules/ii/sidebarRight/nightLight/NightLightDialog.qml +++ b/dots/.config/quickshell/ii/modules/ii/sidebarRight/nightLight/NightLightDialog.qml @@ -44,9 +44,9 @@ WindowDialog { iconSize: Appearance.font.pixelSize.larger buttonIcon: "check" text: Translation.tr("Enable now") - checked: Hyprsunset.active + checked: Hyprsunset.temperatureActive onCheckedChanged: { - Hyprsunset.toggle(checked) + Hyprsunset.toggleTemperature(checked) } } diff --git a/dots/.config/quickshell/ii/modules/ii/sidebarRight/quickToggles/classicStyle/NightLight.qml b/dots/.config/quickshell/ii/modules/ii/sidebarRight/quickToggles/classicStyle/NightLight.qml index 8b7e69a5a..7fa6f18ae 100644 --- a/dots/.config/quickshell/ii/modules/ii/sidebarRight/quickToggles/classicStyle/NightLight.qml +++ b/dots/.config/quickshell/ii/modules/ii/sidebarRight/quickToggles/classicStyle/NightLight.qml @@ -6,10 +6,10 @@ import Quickshell.Io QuickToggleButton { id: nightLightButton - toggled: Hyprsunset.active + toggled: Hyprsunset.temperatureActive buttonIcon: Config.options.light.night.automatic ? "night_sight_auto" : "bedtime" onClicked: { - Hyprsunset.toggle() + Hyprsunset.toggleTemperature() } altAction: () => { diff --git a/dots/.config/quickshell/ii/modules/waffle/actionCenter/nightLight/NightLightControl.qml b/dots/.config/quickshell/ii/modules/waffle/actionCenter/nightLight/NightLightControl.qml index 591e56399..09d00fda9 100644 --- a/dots/.config/quickshell/ii/modules/waffle/actionCenter/nightLight/NightLightControl.qml +++ b/dots/.config/quickshell/ii/modules/waffle/actionCenter/nightLight/NightLightControl.qml @@ -87,9 +87,9 @@ Item { name: Translation.tr("Enable now") description: Translation.tr("More comfortable viewing at night") iconName: WIcons.nightLightIcon - checked: Hyprsunset.active + checked: Hyprsunset.temperatureActive onCheckedChanged: { - Hyprsunset.toggle(checked); + Hyprsunset.toggleTemperature(checked); } } diff --git a/dots/.config/quickshell/ii/modules/waffle/looks/WIcons.qml b/dots/.config/quickshell/ii/modules/waffle/looks/WIcons.qml index b804aa3d9..ce026da29 100644 --- a/dots/.config/quickshell/ii/modules/waffle/looks/WIcons.qml +++ b/dots/.config/quickshell/ii/modules/waffle/looks/WIcons.qml @@ -71,7 +71,7 @@ Singleton { property string bluetoothIcon: BluetoothStatus.connected ? "bluetooth-connected" : BluetoothStatus.enabled ? "bluetooth" : "bluetooth-disabled" - property string nightLightIcon: Hyprsunset.active ? "weather-moon" : "weather-moon-off" + property string nightLightIcon: Hyprsunset.temperatureActive ? "weather-moon" : "weather-moon-off" property string notificationsIcon: Notifications.silent ? "alert-snooze" : "alert" diff --git a/dots/.config/quickshell/ii/services/Brightness.qml b/dots/.config/quickshell/ii/services/Brightness.qml index b0c7f303e..939bc37d8 100644 --- a/dots/.config/quickshell/ii/services/Brightness.qml +++ b/dots/.config/quickshell/ii/services/Brightness.qml @@ -28,6 +28,12 @@ Singleton { } function increaseBrightness(): void { + // if gamma is not yet 100, first increase gamma + if (Hyprsunset.gamma !== 100) { + Hyprsunset.setGamma(Hyprsunset.gamma + 5); + return; + } + const focusedName = Hyprland.focusedMonitor.name; const monitor = monitors.find(m => focusedName === m.screen.name); if (monitor) @@ -37,8 +43,12 @@ Singleton { function decreaseBrightness(): void { const focusedName = Hyprland.focusedMonitor.name; const monitor = monitors.find(m => focusedName === m.screen.name); - if (monitor) + if (monitor && monitor.brightness > 0) monitor.setBrightness(monitor.brightness - 0.05); + // if brightness is 0, then decrease gamma + else { + Hyprsunset.setGamma(Hyprsunset.gamma - 5); + } } reloadableId: "brightness" diff --git a/dots/.config/quickshell/ii/services/Hyprsunset.qml b/dots/.config/quickshell/ii/services/Hyprsunset.qml index 8f0e36529..f1c17025e 100644 --- a/dots/.config/quickshell/ii/services/Hyprsunset.qml +++ b/dots/.config/quickshell/ii/services/Hyprsunset.qml @@ -17,9 +17,10 @@ Singleton { property string to: Config.options?.light?.night?.to ?? "06:30" property bool automatic: Config.options?.light?.night?.automatic && (Config?.ready ?? true) property int colorTemperature: Config.options?.light?.night?.colorTemperature ?? 5000 + property int gamma: 100 property bool shouldBeOn property bool firstEvaluation: true - property bool active: false + property bool temperatureActive: false property int fromHour: Number(from.split(":")[0]) property int fromMinute: Number(from.split(":")[1]) @@ -71,24 +72,55 @@ Singleton { if (!root.automatic || root.manualActive !== undefined) return; if (root.shouldBeOn) { - root.enable(); + root.enableTemperature(); } else { - root.disable(); + root.disableTemperature(); } } function load() { } // Dummy to force init - function enable() { - root.active = true; + function enableTemperature() { + root.temperatureActive = true; // console.log("[Hyprsunset] Enabling"); - Quickshell.execDetached(["bash", "-c", `pidof hyprsunset || hyprsunset --temperature ${root.colorTemperature}`]); + Quickshell.execDetached(["bash", "-c", ` + if pidof hyprsunset > /dev/null; then + hyprctl hyprsunset temperature ${root.colorTemperature}; + else + hyprsunset --temperature ${root.colorTemperature}; + fi + `]); } - function disable() { - root.active = false; + function disableTemperature() { + root.temperatureActive = false; // console.log("[Hyprsunset] Disabling"); - Quickshell.execDetached(["bash", "-c", `pkill hyprsunset`]); + if (root.gamma === 100) { + Quickshell.execDetached(["bash", "-c", `pkill hyprsunset`]); + } else { + Quickshell.execDetached(["hyprctl", "hyprsunset", "identity"]); + } + } + + function setGamma(gamma) { + root.gamma = Math.max(0, Math.min(100, gamma)); + + if (root.gamma !== 100) { + // console.log("[Hyprsunset] Enabling"); + Quickshell.execDetached(["bash", "-c", ` + if pidof hyprsunset > /dev/null; then + hyprctl hyprsunset gamma ${root.gamma}; + else + hyprsunset --gamma ${root.gamma}; + fi + `]); + } else { + if (!root.temperatureActive) { + Quickshell.execDetached(["bash", "-c", `pkill hyprsunset`]); + } else { + Quickshell.execDetached(["hyprctl", "hyprsunset", "gamma", "100"]); + } + } } function fetchState() { @@ -104,26 +136,26 @@ Singleton { onStreamFinished: { const output = stateCollector.text.trim(); if (output.length == 0 || output.startsWith("Couldn't")) - root.active = false; + root.temperatureActive = false; else - root.active = (output != "6500"); // 6500 is the default when off - // console.log("[Hyprsunset] Fetched state:", output, "->", root.active); + root.temperatureActive = (output != "6500"); // 6500 is the default when off + // console.log("[Hyprsunset] Fetched state:", output, "->", root.temperatureActive); } } } - function toggle(active = undefined) { + function toggleTemperature(active = undefined) { if (root.manualActive === undefined) { - root.manualActive = root.active; + root.manualActive = root.temperatureActive; root.manualActiveHour = root.clockHour; root.manualActiveMinute = root.clockMinute; } root.manualActive = active !== undefined ? active : !root.manualActive; if (root.manualActive) { - root.enable(); + root.enableTemperature(); } else { - root.disable(); + root.disableTemperature(); } } @@ -131,9 +163,9 @@ Singleton { Connections { target: Config.options.light.night function onColorTemperatureChanged() { - if (!root.active) return; + if (!root.temperatureActive) return; Hyprland.dispatch(`hyprctl hyprsunset temperature ${Config.options.light.night.colorTemperature}`); Quickshell.execDetached(["hyprctl", "hyprsunset", "temperature", `${Config.options.light.night.colorTemperature}`]); } } -} +} \ No newline at end of file