Replace our NightLight solution with wlsunset.

NightLight: add temperature solution
NTextInput: add input hint support
This commit is contained in:
Ly-sec 2025-08-28 15:34:47 +02:00
parent 57a67bf4df
commit 2a686b55c4
9 changed files with 167 additions and 130 deletions

View file

@ -4,63 +4,106 @@ import QtQuick
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Services
Singleton {
id: root
// Night Light properties - directly bound to settings
readonly property var params: Settings.data.nightLight
// Deprecated overlay flag removed; service only manages wlsunset now
property bool isActive: false
property bool isRunning: false
property string lastCommand: ""
property var nextCommand: []
// Computed properties
readonly property color overlayColor: params.enabled ? calculateOverlayColor() : "transparent"
property bool isActive: params.enabled && (params.autoSchedule ? isWithinSchedule() : true)
Component.onCompleted: apply()
Component.onCompleted: {
Logger.log("NightLight", "Service started")
}
function calculateOverlayColor() {
if (!isActive) {
return "transparent"
}
// More vibrant color formula - stronger effect at high warmth
var red = 1.0
var green = 1.0 - (0.43 * params.intensity)
var blue = 1.0 - (0.84 * params.intensity)
var alpha = (params.intensity * 0.25) // Higher alpha for more noticeable effect
return Qt.rgba(red, green, blue, alpha)
}
function isWithinSchedule() {
if (!params.autoSchedule) {
return true
}
var now = new Date()
var currentTime = now.getHours() * 60 + now.getMinutes()
var startParts = params.startTime.split(":")
var stopParts = params.stopTime.split(":")
var startMinutes = parseInt(startParts[0]) * 60 + parseInt(startParts[1])
var stopMinutes = parseInt(stopParts[0]) * 60 + parseInt(stopParts[1])
// Handle overnight schedule (e.g., 20:00 to 07:00)
if (stopMinutes < startMinutes) {
return currentTime >= startMinutes || currentTime <= stopMinutes
function buildCommand() {
var cmd = ["wlsunset"]
// Use user-configured temps; if intensity is used, bias lowTemp towards user low
var i = Math.max(0, Math.min(1, params.intensity))
var loCfg = params.lowTemp || 3500
var hiCfg = params.highTemp || 6500
var lowTemp = Math.round(hiCfg - (hiCfg - loCfg) * Math.pow(i, 0.6))
cmd.push("-t", lowTemp.toString())
cmd.push("-T", hiCfg.toString())
if (params.autoSchedule && LocationService.data.coordinatesReady && LocationService.data.stableLatitude !== "" && LocationService.data.stableLongitude !== "") {
cmd.push("-l", LocationService.data.stableLatitude)
cmd.push("-L", LocationService.data.stableLongitude)
} else {
return currentTime >= startMinutes && currentTime <= stopMinutes
// Manual schedule
if (params.startTime && params.stopTime) {
cmd.push("-S", params.startTime)
cmd.push("-s", params.stopTime)
}
// Optional: do not pass duration, use wlsunset defaults
}
return cmd
}
// Timer to check schedule changes
function stopIfRunning() {
// Best-effort stop; wlsunset runs as foreground, so pkill is simplest
Quickshell.execDetached(["pkill", "-x", "wlsunset"])
isRunning = false
}
function apply() {
if (!params.enabled) {
// Disable immediately
debounceStart.stop()
nextCommand = []
stopIfRunning()
return
}
// Debounce rapid changes (slider)
nextCommand = buildCommand()
lastCommand = nextCommand.join(" ")
stopIfRunning()
debounceStart.restart()
}
// Observe setting changes and location readiness
Connections {
target: Settings.data.nightLight
function onEnabledChanged() { apply() }
function onIntensityChanged() { apply() }
function onAutoScheduleChanged() { apply() }
function onStartTimeChanged() { apply() }
function onStopTimeChanged() { apply() }
}
Connections {
target: LocationService.data
function onCoordinatesReadyChanged() { if (params.enabled && params.autoSchedule) apply() }
function onStableLatitudeChanged() { if (params.enabled && params.autoSchedule) apply() }
function onStableLongitudeChanged() { if (params.enabled && params.autoSchedule) apply() }
}
// Foreground process runner
Process {
id: runner
running: false
onStarted: { isRunning = true; Logger.log("NightLight", "Started wlsunset:", root.lastCommand) }
onExited: function (code, status) {
isRunning = false
Logger.log("NightLight", "wlsunset exited:", code, status)
// Do not auto-restart here; debounceStart handles starts
}
stdout: StdioCollector {}
stderr: StdioCollector {}
}
// Debounce timer to avoid flicker when moving sliders
Timer {
interval: 60000 // Check every minute
running: params.enabled && params.autoSchedule
repeat: true
id: debounceStart
interval: 300
repeat: false
onTriggered: {
isActive = isWithinSchedule()
if (params.enabled && nextCommand.length > 0) {
runner.command = nextCommand
runner.running = true
}
}
}
}