mirror of
https://github.com/end-4/dots-hyprland.git
synced 2026-06-05 14:59:27 -05:00
Decrease gamma when brightness is requested to go lower beyond 0
This commit is contained in:
@@ -3,7 +3,7 @@ import QtQml
|
||||
import QtQuick
|
||||
import Quickshell.Io
|
||||
import qs.services
|
||||
import "../"
|
||||
import ".."
|
||||
|
||||
NestableObject {
|
||||
id: root
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+1
-1
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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: () => {
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,7 +163,7 @@ 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}`]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user