forked from Shinonome/dots-hyprland
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 QtQuick
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import qs.services
|
import qs.services
|
||||||
import "../"
|
import ".."
|
||||||
|
|
||||||
NestableObject {
|
NestableObject {
|
||||||
id: root
|
id: root
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ QuickToggleModel {
|
|||||||
name: Translation.tr("Night Light")
|
name: Translation.tr("Night Light")
|
||||||
statusText: (auto ? Translation.tr("Auto, ") : "") + (toggled ? Translation.tr("Active") : Translation.tr("Inactive"))
|
statusText: (auto ? Translation.tr("Auto, ") : "") + (toggled ? Translation.tr("Active") : Translation.tr("Inactive"))
|
||||||
|
|
||||||
toggled: Hyprsunset.active
|
toggled: Hyprsunset.temperatureActive
|
||||||
icon: auto ? "night_sight_auto" : "bedtime"
|
icon: auto ? "night_sight_auto" : "bedtime"
|
||||||
|
|
||||||
mainAction: () => {
|
mainAction: () => {
|
||||||
Hyprsunset.toggle()
|
Hyprsunset.toggleTemperature()
|
||||||
}
|
}
|
||||||
hasMenu: true
|
hasMenu: true
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ OsdValueIndicator {
|
|||||||
property var focusedScreen: Quickshell.screens.find(s => s.name === Hyprland.focusedMonitor?.name)
|
property var focusedScreen: Quickshell.screens.find(s => s.name === Hyprland.focusedMonitor?.name)
|
||||||
property var brightnessMonitor: Brightness.getMonitorForScreen(focusedScreen)
|
property var brightnessMonitor: Brightness.getMonitorForScreen(focusedScreen)
|
||||||
|
|
||||||
icon: Hyprsunset.active ? "routine" : "light_mode"
|
icon: Hyprsunset.temperatureActive ? "routine" : "light_mode"
|
||||||
rotateIcon: true
|
rotateIcon: true
|
||||||
scaleIcon: true
|
scaleIcon: true
|
||||||
name: Translation.tr("Brightness")
|
name: Translation.tr("Brightness")
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ WindowDialog {
|
|||||||
iconSize: Appearance.font.pixelSize.larger
|
iconSize: Appearance.font.pixelSize.larger
|
||||||
buttonIcon: "check"
|
buttonIcon: "check"
|
||||||
text: Translation.tr("Enable now")
|
text: Translation.tr("Enable now")
|
||||||
checked: Hyprsunset.active
|
checked: Hyprsunset.temperatureActive
|
||||||
onCheckedChanged: {
|
onCheckedChanged: {
|
||||||
Hyprsunset.toggle(checked)
|
Hyprsunset.toggleTemperature(checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -6,10 +6,10 @@ import Quickshell.Io
|
|||||||
|
|
||||||
QuickToggleButton {
|
QuickToggleButton {
|
||||||
id: nightLightButton
|
id: nightLightButton
|
||||||
toggled: Hyprsunset.active
|
toggled: Hyprsunset.temperatureActive
|
||||||
buttonIcon: Config.options.light.night.automatic ? "night_sight_auto" : "bedtime"
|
buttonIcon: Config.options.light.night.automatic ? "night_sight_auto" : "bedtime"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Hyprsunset.toggle()
|
Hyprsunset.toggleTemperature()
|
||||||
}
|
}
|
||||||
|
|
||||||
altAction: () => {
|
altAction: () => {
|
||||||
|
|||||||
+2
-2
@@ -87,9 +87,9 @@ Item {
|
|||||||
name: Translation.tr("Enable now")
|
name: Translation.tr("Enable now")
|
||||||
description: Translation.tr("More comfortable viewing at night")
|
description: Translation.tr("More comfortable viewing at night")
|
||||||
iconName: WIcons.nightLightIcon
|
iconName: WIcons.nightLightIcon
|
||||||
checked: Hyprsunset.active
|
checked: Hyprsunset.temperatureActive
|
||||||
onCheckedChanged: {
|
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 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"
|
property string notificationsIcon: Notifications.silent ? "alert-snooze" : "alert"
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function increaseBrightness(): void {
|
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 focusedName = Hyprland.focusedMonitor.name;
|
||||||
const monitor = monitors.find(m => focusedName === m.screen.name);
|
const monitor = monitors.find(m => focusedName === m.screen.name);
|
||||||
if (monitor)
|
if (monitor)
|
||||||
@@ -37,8 +43,12 @@ Singleton {
|
|||||||
function decreaseBrightness(): void {
|
function decreaseBrightness(): void {
|
||||||
const focusedName = Hyprland.focusedMonitor.name;
|
const focusedName = Hyprland.focusedMonitor.name;
|
||||||
const monitor = monitors.find(m => focusedName === m.screen.name);
|
const monitor = monitors.find(m => focusedName === m.screen.name);
|
||||||
if (monitor)
|
if (monitor && monitor.brightness > 0)
|
||||||
monitor.setBrightness(monitor.brightness - 0.05);
|
monitor.setBrightness(monitor.brightness - 0.05);
|
||||||
|
// if brightness is 0, then decrease gamma
|
||||||
|
else {
|
||||||
|
Hyprsunset.setGamma(Hyprsunset.gamma - 5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadableId: "brightness"
|
reloadableId: "brightness"
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ Singleton {
|
|||||||
property string to: Config.options?.light?.night?.to ?? "06:30"
|
property string to: Config.options?.light?.night?.to ?? "06:30"
|
||||||
property bool automatic: Config.options?.light?.night?.automatic && (Config?.ready ?? true)
|
property bool automatic: Config.options?.light?.night?.automatic && (Config?.ready ?? true)
|
||||||
property int colorTemperature: Config.options?.light?.night?.colorTemperature ?? 5000
|
property int colorTemperature: Config.options?.light?.night?.colorTemperature ?? 5000
|
||||||
|
property int gamma: 100
|
||||||
property bool shouldBeOn
|
property bool shouldBeOn
|
||||||
property bool firstEvaluation: true
|
property bool firstEvaluation: true
|
||||||
property bool active: false
|
property bool temperatureActive: false
|
||||||
|
|
||||||
property int fromHour: Number(from.split(":")[0])
|
property int fromHour: Number(from.split(":")[0])
|
||||||
property int fromMinute: Number(from.split(":")[1])
|
property int fromMinute: Number(from.split(":")[1])
|
||||||
@@ -71,24 +72,55 @@ Singleton {
|
|||||||
if (!root.automatic || root.manualActive !== undefined)
|
if (!root.automatic || root.manualActive !== undefined)
|
||||||
return;
|
return;
|
||||||
if (root.shouldBeOn) {
|
if (root.shouldBeOn) {
|
||||||
root.enable();
|
root.enableTemperature();
|
||||||
} else {
|
} else {
|
||||||
root.disable();
|
root.disableTemperature();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function load() { } // Dummy to force init
|
function load() { } // Dummy to force init
|
||||||
|
|
||||||
function enable() {
|
function enableTemperature() {
|
||||||
root.active = true;
|
root.temperatureActive = true;
|
||||||
// console.log("[Hyprsunset] Enabling");
|
// 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() {
|
function disableTemperature() {
|
||||||
root.active = false;
|
root.temperatureActive = false;
|
||||||
// console.log("[Hyprsunset] Disabling");
|
// 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() {
|
function fetchState() {
|
||||||
@@ -104,26 +136,26 @@ Singleton {
|
|||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
const output = stateCollector.text.trim();
|
const output = stateCollector.text.trim();
|
||||||
if (output.length == 0 || output.startsWith("Couldn't"))
|
if (output.length == 0 || output.startsWith("Couldn't"))
|
||||||
root.active = false;
|
root.temperatureActive = false;
|
||||||
else
|
else
|
||||||
root.active = (output != "6500"); // 6500 is the default when off
|
root.temperatureActive = (output != "6500"); // 6500 is the default when off
|
||||||
// console.log("[Hyprsunset] Fetched state:", output, "->", root.active);
|
// console.log("[Hyprsunset] Fetched state:", output, "->", root.temperatureActive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle(active = undefined) {
|
function toggleTemperature(active = undefined) {
|
||||||
if (root.manualActive === undefined) {
|
if (root.manualActive === undefined) {
|
||||||
root.manualActive = root.active;
|
root.manualActive = root.temperatureActive;
|
||||||
root.manualActiveHour = root.clockHour;
|
root.manualActiveHour = root.clockHour;
|
||||||
root.manualActiveMinute = root.clockMinute;
|
root.manualActiveMinute = root.clockMinute;
|
||||||
}
|
}
|
||||||
|
|
||||||
root.manualActive = active !== undefined ? active : !root.manualActive;
|
root.manualActive = active !== undefined ? active : !root.manualActive;
|
||||||
if (root.manualActive) {
|
if (root.manualActive) {
|
||||||
root.enable();
|
root.enableTemperature();
|
||||||
} else {
|
} else {
|
||||||
root.disable();
|
root.disableTemperature();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,9 +163,9 @@ Singleton {
|
|||||||
Connections {
|
Connections {
|
||||||
target: Config.options.light.night
|
target: Config.options.light.night
|
||||||
function onColorTemperatureChanged() {
|
function onColorTemperatureChanged() {
|
||||||
if (!root.active) return;
|
if (!root.temperatureActive) return;
|
||||||
Hyprland.dispatch(`hyprctl hyprsunset temperature ${Config.options.light.night.colorTemperature}`);
|
Hyprland.dispatch(`hyprctl hyprsunset temperature ${Config.options.light.night.colorTemperature}`);
|
||||||
Quickshell.execDetached(["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