From 838962e448cc54c9892e740e877c6ea37369e97e Mon Sep 17 00:00:00 2001 From: quadbyte Date: Fri, 15 Aug 2025 10:23:40 -0400 Subject: [PATCH] Formatting: Brightness, wifi, network --- Modules/Bar/Brightness.qml | 23 ++++---- Modules/Bar/WiFiMenu.qml | 4 +- Services/BrightnessService.qml | 97 +++++++++++++++++----------------- Services/Network.qml | 11 ++-- 4 files changed, 66 insertions(+), 69 deletions(-) diff --git a/Modules/Bar/Brightness.qml b/Modules/Bar/Brightness.qml index aa754b7..486611e 100644 --- a/Modules/Bar/Brightness.qml +++ b/Modules/Bar/Brightness.qml @@ -19,9 +19,7 @@ Item { return "brightness_auto" } var brightness = BrightnessService.brightness - return brightness <= 0 ? "brightness_1" : - brightness < 33 ? "brightness_low" : - brightness < 66 ? "brightness_medium" : "brightness_high" + return brightness <= 0 ? "brightness_1" : brightness < 33 ? "brightness_low" : brightness < 66 ? "brightness_medium" : "brightness_high" } // Connection used to open the pill when brightness changes @@ -29,25 +27,23 @@ Item { target: BrightnessService.focusedMonitor function onBrightnessUpdated() { var currentBrightness = BrightnessService.brightness - + // Ignore if this is the first time or if brightness hasn't actually changed if (!firstBrightnessReceived) { firstBrightnessReceived = true lastBrightness = currentBrightness return } - + // Only show pill if brightness actually changed (not just loaded from settings) if (Math.abs(currentBrightness - lastBrightness) > 0.1) { pill.show() } - + lastBrightness = currentBrightness } } - - NPill { id: pill icon: getIcon() @@ -55,11 +51,14 @@ Item { collapsedIconColor: Colors.mOnSurface autoHide: true text: Math.round(BrightnessService.brightness) + "%" - tooltipText: "Brightness: " + Math.round(BrightnessService.brightness) + "%\nMethod: " + BrightnessService.currentMethod + "\nLeft click for advanced settings.\nScroll up/down to change brightness." + tooltipText: "Brightness: " + Math.round( + BrightnessService.brightness) + "%\nMethod: " + BrightnessService.currentMethod + + "\nLeft click for advanced settings.\nScroll up/down to change brightness." onWheel: function (angle) { - if (!BrightnessService.available) return - + if (!BrightnessService.available) + return + if (angle > 0) { BrightnessService.increaseBrightness() } else if (angle < 0) { @@ -71,4 +70,4 @@ Item { settingsPanel.isLoaded = true } } -} \ No newline at end of file +} diff --git a/Modules/Bar/WiFiMenu.qml b/Modules/Bar/WiFiMenu.qml index 3ba335d..58754f3 100644 --- a/Modules/Bar/WiFiMenu.qml +++ b/Modules/Bar/WiFiMenu.qml @@ -154,7 +154,7 @@ NLoader { onToggled: function (value) { Settings.data.network.wifiEnabled = value network.setWifiEnabled(value) - + // If enabling WiFi while menu is open, refresh after a delay if (value) { wifiEnableRefreshTimer.start() @@ -467,4 +467,4 @@ NLoader { } } } -} \ No newline at end of file +} diff --git a/Services/BrightnessService.qml b/Services/BrightnessService.qml index dc7104b..72f5e4f 100644 --- a/Services/BrightnessService.qml +++ b/Services/BrightnessService.qml @@ -1,5 +1,6 @@ pragma Singleton -pragma ComponentBehavior: Bound + +pragma ComponentBehavior import QtQuick import Quickshell @@ -17,15 +18,16 @@ Singleton { readonly property bool available: focusedMonitor !== null readonly property string currentMethod: focusedMonitor ? focusedMonitor.method : Settings.data.brightness.lastMethod readonly property var detectedDisplays: monitors.map(m => ({ - name: m.modelData.name, - type: m.isDdc ? "external" : "internal", - method: m.method, - index: m.busNum - })) + "name": m.modelData.name, + "type": m.isDdc ? "external" : "internal", + "method": m.method, + "index": m.busNum + })) // Get the currently focused monitor readonly property Monitor focusedMonitor: { - if (monitors.length === 0) return null + if (monitors.length === 0) + return null // For now, return the first monitor. Could be enhanced to detect focused monitor return monitors[0] } @@ -61,8 +63,7 @@ Singleton { } // Backward compatibility functions - function updateBrightness(): void { - // No longer needed with the new architecture + function updateBrightness(): void {// No longer needed with the new architecture } function setDisplay(displayIndex: int): bool { @@ -72,18 +73,21 @@ Singleton { function getDisplayInfo(): var { return focusedMonitor ? { - name: focusedMonitor.modelData.name, - type: focusedMonitor.isDdc ? "external" : "internal", - method: focusedMonitor.method, - index: focusedMonitor.busNum - } : null + "name": focusedMonitor.modelData.name, + "type": focusedMonitor.isDdc ? "external" : "internal", + "method": focusedMonitor.method, + "index": focusedMonitor.busNum + } : null } function getAvailableMethods(): list { var methods = [] - if (monitors.some(m => m.isDdc)) methods.push("ddcutil") - if (monitors.some(m => !m.isDdc)) methods.push("internal") - if (appleDisplayPresent) methods.push("apple") + if (monitors.some(m => m.isDdc)) + methods.push("ddcutil") + if (monitors.some(m => !m.isDdc)) + methods.push("internal") + if (appleDisplayPresent) + methods.push("apple") return methods } @@ -121,19 +125,17 @@ Singleton { onStreamFinished: { var displays = text.trim().split("\n\n").filter(d => d.startsWith("Display ")) root.ddcMonitors = displays.map(d => { - var modelMatch = d.match(/Monitor:.*:(.*):.*/) - var busMatch = d.match(/I2C bus:[ ]*\/dev\/i2c-([0-9]+)/) - return { - model: modelMatch ? modelMatch[1] : "", - busNum: busMatch ? busMatch[1] : "" - } - }) + var modelMatch = d.match(/Monitor:.*:(.*):.*/) + var busMatch = d.match(/I2C bus:[ ]*\/dev\/i2c-([0-9]+)/) + return { + "model": modelMatch ? modelMatch[1] : "", + "busNum": busMatch ? busMatch[1] : "" + } + }) } } } - - component Monitor: QtObject { id: monitor @@ -142,19 +144,19 @@ Singleton { readonly property string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? "" readonly property bool isAppleDisplay: root.appleDisplayPresent && modelData.model.startsWith("StudioDisplay") readonly property string method: isAppleDisplay ? "apple" : (isDdc ? "ddcutil" : "internal") - + property real brightness: getStoredBrightness() property real queuedBrightness: NaN // Signal for brightness changes signal brightnessUpdated(real newBrightness) - // Initialize brightness + // Initialize brightness readonly property Process initProc: Process { stdout: StdioCollector { onStreamFinished: { console.log("[BrightnessService] Raw brightness data for", monitor.modelData.name + ":", text.trim()) - + if (monitor.isAppleDisplay) { var val = parseInt(text.trim()) if (!isNaN(val)) { @@ -183,7 +185,7 @@ Singleton { } } } - + if (monitor.brightness > 0) { // Save the detected brightness to settings monitor.saveBrightness(monitor.brightness) @@ -204,9 +206,7 @@ Singleton { } } - - - function getStoredBrightness(): real { + function getStoredBrightness(): real { // Try to get stored brightness for this specific monitor var stored = Settings.data.brightness.monitorBrightness.find(m => m.name === modelData.name) if (stored) { @@ -218,19 +218,19 @@ Singleton { function saveBrightness(value: real): void { var brightnessPercent = Math.round(value * 100) - + // Update general last brightness Settings.data.brightness.lastBrightness = brightnessPercent Settings.data.brightness.lastMethod = method - + // Update monitor-specific brightness var monitorIndex = Settings.data.brightness.monitorBrightness.findIndex(m => m.name === modelData.name) var monitorData = { - name: modelData.name, - brightness: brightnessPercent, - method: method + "name": modelData.name, + "brightness": brightnessPercent, + "method": method } - + if (monitorIndex >= 0) { Settings.data.brightness.monitorBrightness[monitorIndex] = monitorData } else { @@ -241,8 +241,9 @@ Singleton { function setBrightness(value: real): void { value = Math.max(0, Math.min(1, value)) var rounded = Math.round(value * 100) - - if (Math.round(brightness * 100) === rounded) return + + if (Math.round(brightness * 100) === rounded) + return if (isDdc && timer.running) { queuedBrightness = value @@ -251,7 +252,7 @@ Singleton { brightness = value brightnessUpdated(brightness) - + // Save to settings saveBrightness(value) @@ -278,16 +279,14 @@ Singleton { initProc.command = ["asdbctl", "get"] } else if (isDdc) { initProc.command = ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] - } else { - // Internal backlight - try to find the first available backlight device - initProc.command = ["sh", "-c", "for dev in /sys/class/backlight/*; do if [ -f \"$dev/brightness\" ] && [ -f \"$dev/max_brightness\" ]; then echo \"$(cat $dev/brightness) $(cat $dev/max_brightness)\"; break; fi; done"] - } + } else { + // Internal backlight - try to find the first available backlight device + initProc.command = ["sh", "-c", "for dev in /sys/class/backlight/*; do if [ -f \"$dev/brightness\" ] && [ -f \"$dev/max_brightness\" ]; then echo \"$(cat $dev/brightness) $(cat $dev/max_brightness)\"; break; fi; done"] + } initProc.running = true } - - onBusNumChanged: initBrightness() Component.onCompleted: initBrightness() } -} \ No newline at end of file +} diff --git a/Services/Network.qml b/Services/Network.qml index bd8c70f..c25c646 100644 --- a/Services/Network.qml +++ b/Services/Network.qml @@ -48,7 +48,7 @@ QtObject { break } } - + // Disable WiFi radio disableWifiProcess.running = true } @@ -135,8 +135,7 @@ QtObject { } } - function onMenuClosed() { - // No need to do anything special on close + function onMenuClosed() {// No need to do anything special on close } // Process to enable WiFi radio @@ -167,12 +166,12 @@ QtObject { onTriggered: { // Force refresh networks multiple times to ensure UI updates root.refreshNetworks() - + // Try to auto-reconnect to the last connected network if it exists if (lastConnectedNetwork) { autoReconnectTimer.start() } - + // Set up additional refresh to ensure UI is populated postEnableRefreshTimer.start() } @@ -464,4 +463,4 @@ QtObject { refreshNetworks() } } -} \ No newline at end of file +}