diff --git a/config/niri/.config/niri/config.kdl b/config/niri/.config/niri/config.kdl index e510ea6..2682b39 100644 --- a/config/niri/.config/niri/config.kdl +++ b/config/niri/.config/niri/config.kdl @@ -137,7 +137,7 @@ spawn-sh-at-startup "wl-paste --type text --watch cliphist store" spawn-sh-at-startup "wl-paste --type image --watch cliphist store" // wlsunset -spawn-at-startup "sunset" +// spawn-at-startup "sunset" // Logitech spawn-sh-at-startup "solaar -w hide" diff --git a/config/quickshell/.config/quickshell/Assets/Config/Settings.json b/config/quickshell/.config/quickshell/Assets/Config/Settings.json index 82d79b6..58fd139 100644 --- a/config/quickshell/.config/quickshell/Assets/Config/Settings.json +++ b/config/quickshell/.config/quickshell/Assets/Config/Settings.json @@ -5,5 +5,6 @@ }, "primaryColor": "#89b4fa", "showLyricsBar": false, + "sunsetDefaultEnabled": true, "wifiEnabled": true } diff --git a/config/quickshell/.config/quickshell/Modules/Panel/Cards/SystemMonitorCard.qml b/config/quickshell/.config/quickshell/Modules/Panel/Cards/SystemMonitorCard.qml index ad24efa..0ed7ea2 100644 --- a/config/quickshell/.config/quickshell/Modules/Panel/Cards/SystemMonitorCard.qml +++ b/config/quickshell/.config/quickshell/Modules/Panel/Cards/SystemMonitorCard.qml @@ -7,53 +7,87 @@ import qs.Noctalia import qs.Services import qs.Utils -// Unified system card: monitors CPU, temp, memory, disk -NBox { +ColumnLayout { id: root - compact: true + spacing: 0 - ColumnLayout { - id: content + RowLayout { + id: sunsetControlRow - anchors.fill: parent - anchors.margins: Style.marginXS - spacing: Style.marginS + Layout.fillWidth: true - MonitorSlider { - icon: "cpu-usage" - value: SystemStatService.cpuUsage - from: 0 - to: 100 - colorFill: Colors.teal - Layout.fillWidth: true + NIconButton { + id: barLyricsButton + + implicitHeight: 32 + implicitWidth: 32 + colorBg: SunsetService.isRunning ? Colors.flamingo : Color.transparent + colorBgHover: Colors.flamingo + colorFg: SunsetService.isRunning ? Colors.base : Colors.flamingo + icon: "sunset-2" + onClicked: SunsetService.toggleSunset() } - MonitorSlider { - icon: "memory" - value: SystemStatService.memPercent - from: 0 - to: 100 - colorFill: Colors.green + NText { Layout.fillWidth: true + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignHCenter + text: SunsetService.isRunning ? "Temp: " + SunsetService.temperature + " K" : "Sunset Off" } - MonitorSlider { - icon: "cpu-temperature" - value: SystemStatService.cpuTemp - from: 0 - to: 100 - colorFill: Colors.yellow - Layout.fillWidth: true - } + } + + NBox { + id: monitors + + compact: true + Layout.fillWidth: true + Layout.fillHeight: true + + ColumnLayout { + id: content + + anchors.fill: parent + anchors.margins: Style.marginS + spacing: Style.marginS + + MonitorSlider { + icon: "cpu-usage" + value: SystemStatService.cpuUsage + from: 0 + to: 100 + colorFill: Colors.teal + Layout.fillWidth: true + } + + MonitorSlider { + icon: "memory" + value: SystemStatService.memPercent + from: 0 + to: 100 + colorFill: Colors.green + Layout.fillWidth: true + } + + MonitorSlider { + icon: "cpu-temperature" + value: SystemStatService.cpuTemp + from: 0 + to: 100 + colorFill: Colors.yellow + Layout.fillWidth: true + } + + MonitorSlider { + icon: "storage" + value: SystemStatService.diskPercent + from: 0 + to: 100 + colorFill: Colors.peach + Layout.fillWidth: true + } - MonitorSlider { - icon: "storage" - value: SystemStatService.diskPercent - from: 0 - to: 100 - colorFill: Colors.peach - Layout.fillWidth: true } } diff --git a/config/quickshell/.config/quickshell/Services/IPCService.qml b/config/quickshell/.config/quickshell/Services/IPCService.qml index 12fdad6..0759631 100644 --- a/config/quickshell/.config/quickshell/Services/IPCService.qml +++ b/config/quickshell/.config/quickshell/Services/IPCService.qml @@ -48,4 +48,12 @@ Item { target: "recording" } + IpcHandler { + function toggleSunset() { + SunsetService.toggleSunset(); + } + + target: "sunset" + } + } diff --git a/config/quickshell/.config/quickshell/Services/SettingsService.qml b/config/quickshell/.config/quickshell/Services/SettingsService.qml index 411333f..fb7f18d 100644 --- a/config/quickshell/.config/quickshell/Services/SettingsService.qml +++ b/config/quickshell/.config/quickshell/Services/SettingsService.qml @@ -11,6 +11,7 @@ Singleton { property alias notifications: adapter.notifications property alias location: adapter.location property alias wifiEnabled: adapter.wifiEnabled + property alias sunsetDefaultEnabled: adapter.sunsetDefaultEnabled property string settingsFilePath: Qt.resolvedUrl("../Assets/Config/Settings.json") FileView { @@ -29,6 +30,7 @@ Singleton { property JsonObject notifications property string location: "New York" property bool wifiEnabled: true + property bool sunsetDefaultEnabled: true notifications: JsonObject { property bool doNotDisturb: false diff --git a/config/quickshell/.config/quickshell/Services/SunsetService.qml b/config/quickshell/.config/quickshell/Services/SunsetService.qml new file mode 100644 index 0000000..f4c4d9d --- /dev/null +++ b/config/quickshell/.config/quickshell/Services/SunsetService.qml @@ -0,0 +1,94 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import qs.Services +import qs.Utils +pragma Singleton + +Singleton { + id: root + + property bool defaultRunning: SettingsService.sunsetDefaultEnabled + property double _latitude: -1 + property double _longitude: -1 + property alias isRunning: sunsetProcess.running + property int temperature: 0 + + function startSunset() { + if (isRunning) + return ; + + if (_latitude == -1 || _longitude == -1) { + Logger.warn("Sunset", "Cannot start sunset process, invalid coordinates"); + return ; + } + sunsetProcess.command = ["wlsunset", "-l", _latitude.toString(), "-L", _longitude.toString()]; + sunsetProcess.running = true; + } + + function stopSunset() { + if (!isRunning) + return ; + + sunsetProcess.running = false; + } + + function toggleSunset() { + if (isRunning) + stopSunset(); + else + startSunset(); + } + + function setLat(lat) { + _latitude = lat; + Logger.log("Sunset", "Updated latitude to " + lat); + checkStart(); + } + + function setLong(lng) { + _longitude = lng; + Logger.log("Sunset", "Updated longitude to " + lng); + checkStart(); + } + + function checkStart() { + if (_latitude != -1 && _longitude != -1 && defaultRunning && !isRunning) + startSunset(); + + } + + Connections { + target: LocationService.data + onLatitudeChanged: { + setLat(LocationService.data.latitude); + } + onLongitudeChanged: { + setLong(LocationService.data.longitude); + } + } + + Process { + id: sunsetProcess + + running: false + + stderr: SplitParser { + splitMarker: "\n" + onRead: (line) => { + // console.log(line); + var tempMatch = line.match(/setting temperature to (\d+) K/); + if (tempMatch && tempMatch.length == 2) { + temperature = parseInt(tempMatch[1]); + Logger.log("Sunset", "Updated temperature to " + temperature + " K"); + } + } + } + + } + + NetworkFetch { + id: curl + } + +} diff --git a/config/quickshell/.config/quickshell/shell.qml b/config/quickshell/.config/quickshell/shell.qml index eb12dbb..a8a6aec 100644 --- a/config/quickshell/.config/quickshell/shell.qml +++ b/config/quickshell/.config/quickshell/shell.qml @@ -16,6 +16,10 @@ ShellRoot { active: CacheService.loaded && NukeKded6.done sourceComponent: Item { + Component.onCompleted: { + SunsetService; + } + Notification { id: notification }