Formatting: Brightness, wifi, network

This commit is contained in:
quadbyte 2025-08-15 10:23:40 -04:00
parent 13df665f94
commit 838962e448
4 changed files with 66 additions and 69 deletions

View file

@ -19,9 +19,7 @@ Item {
return "brightness_auto" return "brightness_auto"
} }
var brightness = BrightnessService.brightness var brightness = BrightnessService.brightness
return brightness <= 0 ? "brightness_1" : return brightness <= 0 ? "brightness_1" : brightness < 33 ? "brightness_low" : brightness < 66 ? "brightness_medium" : "brightness_high"
brightness < 33 ? "brightness_low" :
brightness < 66 ? "brightness_medium" : "brightness_high"
} }
// Connection used to open the pill when brightness changes // Connection used to open the pill when brightness changes
@ -29,25 +27,23 @@ Item {
target: BrightnessService.focusedMonitor target: BrightnessService.focusedMonitor
function onBrightnessUpdated() { function onBrightnessUpdated() {
var currentBrightness = BrightnessService.brightness var currentBrightness = BrightnessService.brightness
// Ignore if this is the first time or if brightness hasn't actually changed // Ignore if this is the first time or if brightness hasn't actually changed
if (!firstBrightnessReceived) { if (!firstBrightnessReceived) {
firstBrightnessReceived = true firstBrightnessReceived = true
lastBrightness = currentBrightness lastBrightness = currentBrightness
return return
} }
// Only show pill if brightness actually changed (not just loaded from settings) // Only show pill if brightness actually changed (not just loaded from settings)
if (Math.abs(currentBrightness - lastBrightness) > 0.1) { if (Math.abs(currentBrightness - lastBrightness) > 0.1) {
pill.show() pill.show()
} }
lastBrightness = currentBrightness lastBrightness = currentBrightness
} }
} }
NPill { NPill {
id: pill id: pill
icon: getIcon() icon: getIcon()
@ -55,11 +51,14 @@ Item {
collapsedIconColor: Colors.mOnSurface collapsedIconColor: Colors.mOnSurface
autoHide: true autoHide: true
text: Math.round(BrightnessService.brightness) + "%" 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) { onWheel: function (angle) {
if (!BrightnessService.available) return if (!BrightnessService.available)
return
if (angle > 0) { if (angle > 0) {
BrightnessService.increaseBrightness() BrightnessService.increaseBrightness()
} else if (angle < 0) { } else if (angle < 0) {
@ -71,4 +70,4 @@ Item {
settingsPanel.isLoaded = true settingsPanel.isLoaded = true
} }
} }
} }

View file

@ -154,7 +154,7 @@ NLoader {
onToggled: function (value) { onToggled: function (value) {
Settings.data.network.wifiEnabled = value Settings.data.network.wifiEnabled = value
network.setWifiEnabled(value) network.setWifiEnabled(value)
// If enabling WiFi while menu is open, refresh after a delay // If enabling WiFi while menu is open, refresh after a delay
if (value) { if (value) {
wifiEnableRefreshTimer.start() wifiEnableRefreshTimer.start()
@ -467,4 +467,4 @@ NLoader {
} }
} }
} }
} }

View file

@ -1,5 +1,6 @@
pragma Singleton pragma Singleton
pragma ComponentBehavior: Bound
pragma ComponentBehavior
import QtQuick import QtQuick
import Quickshell import Quickshell
@ -17,15 +18,16 @@ Singleton {
readonly property bool available: focusedMonitor !== null readonly property bool available: focusedMonitor !== null
readonly property string currentMethod: focusedMonitor ? focusedMonitor.method : Settings.data.brightness.lastMethod readonly property string currentMethod: focusedMonitor ? focusedMonitor.method : Settings.data.brightness.lastMethod
readonly property var detectedDisplays: monitors.map(m => ({ readonly property var detectedDisplays: monitors.map(m => ({
name: m.modelData.name, "name": m.modelData.name,
type: m.isDdc ? "external" : "internal", "type": m.isDdc ? "external" : "internal",
method: m.method, "method": m.method,
index: m.busNum "index": m.busNum
})) }))
// Get the currently focused monitor // Get the currently focused monitor
readonly property Monitor focusedMonitor: { 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 // For now, return the first monitor. Could be enhanced to detect focused monitor
return monitors[0] return monitors[0]
} }
@ -61,8 +63,7 @@ Singleton {
} }
// Backward compatibility functions // Backward compatibility functions
function updateBrightness(): void { function updateBrightness(): void {// No longer needed with the new architecture
// No longer needed with the new architecture
} }
function setDisplay(displayIndex: int): bool { function setDisplay(displayIndex: int): bool {
@ -72,18 +73,21 @@ Singleton {
function getDisplayInfo(): var { function getDisplayInfo(): var {
return focusedMonitor ? { return focusedMonitor ? {
name: focusedMonitor.modelData.name, "name": focusedMonitor.modelData.name,
type: focusedMonitor.isDdc ? "external" : "internal", "type": focusedMonitor.isDdc ? "external" : "internal",
method: focusedMonitor.method, "method": focusedMonitor.method,
index: focusedMonitor.busNum "index": focusedMonitor.busNum
} : null } : null
} }
function getAvailableMethods(): list<string> { function getAvailableMethods(): list<string> {
var methods = [] var methods = []
if (monitors.some(m => m.isDdc)) methods.push("ddcutil") if (monitors.some(m => m.isDdc))
if (monitors.some(m => !m.isDdc)) methods.push("internal") methods.push("ddcutil")
if (appleDisplayPresent) methods.push("apple") if (monitors.some(m => !m.isDdc))
methods.push("internal")
if (appleDisplayPresent)
methods.push("apple")
return methods return methods
} }
@ -121,19 +125,17 @@ Singleton {
onStreamFinished: { onStreamFinished: {
var displays = text.trim().split("\n\n").filter(d => d.startsWith("Display ")) var displays = text.trim().split("\n\n").filter(d => d.startsWith("Display "))
root.ddcMonitors = displays.map(d => { root.ddcMonitors = displays.map(d => {
var modelMatch = d.match(/Monitor:.*:(.*):.*/) var modelMatch = d.match(/Monitor:.*:(.*):.*/)
var busMatch = d.match(/I2C bus:[ ]*\/dev\/i2c-([0-9]+)/) var busMatch = d.match(/I2C bus:[ ]*\/dev\/i2c-([0-9]+)/)
return { return {
model: modelMatch ? modelMatch[1] : "", "model": modelMatch ? modelMatch[1] : "",
busNum: busMatch ? busMatch[1] : "" "busNum": busMatch ? busMatch[1] : ""
} }
}) })
} }
} }
} }
component Monitor: QtObject { component Monitor: QtObject {
id: monitor id: monitor
@ -142,19 +144,19 @@ Singleton {
readonly property string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? "" 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 bool isAppleDisplay: root.appleDisplayPresent && modelData.model.startsWith("StudioDisplay")
readonly property string method: isAppleDisplay ? "apple" : (isDdc ? "ddcutil" : "internal") readonly property string method: isAppleDisplay ? "apple" : (isDdc ? "ddcutil" : "internal")
property real brightness: getStoredBrightness() property real brightness: getStoredBrightness()
property real queuedBrightness: NaN property real queuedBrightness: NaN
// Signal for brightness changes // Signal for brightness changes
signal brightnessUpdated(real newBrightness) signal brightnessUpdated(real newBrightness)
// Initialize brightness // Initialize brightness
readonly property Process initProc: Process { readonly property Process initProc: Process {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
console.log("[BrightnessService] Raw brightness data for", monitor.modelData.name + ":", text.trim()) console.log("[BrightnessService] Raw brightness data for", monitor.modelData.name + ":", text.trim())
if (monitor.isAppleDisplay) { if (monitor.isAppleDisplay) {
var val = parseInt(text.trim()) var val = parseInt(text.trim())
if (!isNaN(val)) { if (!isNaN(val)) {
@ -183,7 +185,7 @@ Singleton {
} }
} }
} }
if (monitor.brightness > 0) { if (monitor.brightness > 0) {
// Save the detected brightness to settings // Save the detected brightness to settings
monitor.saveBrightness(monitor.brightness) monitor.saveBrightness(monitor.brightness)
@ -204,9 +206,7 @@ Singleton {
} }
} }
function getStoredBrightness(): real {
function getStoredBrightness(): real {
// Try to get stored brightness for this specific monitor // Try to get stored brightness for this specific monitor
var stored = Settings.data.brightness.monitorBrightness.find(m => m.name === modelData.name) var stored = Settings.data.brightness.monitorBrightness.find(m => m.name === modelData.name)
if (stored) { if (stored) {
@ -218,19 +218,19 @@ Singleton {
function saveBrightness(value: real): void { function saveBrightness(value: real): void {
var brightnessPercent = Math.round(value * 100) var brightnessPercent = Math.round(value * 100)
// Update general last brightness // Update general last brightness
Settings.data.brightness.lastBrightness = brightnessPercent Settings.data.brightness.lastBrightness = brightnessPercent
Settings.data.brightness.lastMethod = method Settings.data.brightness.lastMethod = method
// Update monitor-specific brightness // Update monitor-specific brightness
var monitorIndex = Settings.data.brightness.monitorBrightness.findIndex(m => m.name === modelData.name) var monitorIndex = Settings.data.brightness.monitorBrightness.findIndex(m => m.name === modelData.name)
var monitorData = { var monitorData = {
name: modelData.name, "name": modelData.name,
brightness: brightnessPercent, "brightness": brightnessPercent,
method: method "method": method
} }
if (monitorIndex >= 0) { if (monitorIndex >= 0) {
Settings.data.brightness.monitorBrightness[monitorIndex] = monitorData Settings.data.brightness.monitorBrightness[monitorIndex] = monitorData
} else { } else {
@ -241,8 +241,9 @@ Singleton {
function setBrightness(value: real): void { function setBrightness(value: real): void {
value = Math.max(0, Math.min(1, value)) value = Math.max(0, Math.min(1, value))
var rounded = Math.round(value * 100) var rounded = Math.round(value * 100)
if (Math.round(brightness * 100) === rounded) return if (Math.round(brightness * 100) === rounded)
return
if (isDdc && timer.running) { if (isDdc && timer.running) {
queuedBrightness = value queuedBrightness = value
@ -251,7 +252,7 @@ Singleton {
brightness = value brightness = value
brightnessUpdated(brightness) brightnessUpdated(brightness)
// Save to settings // Save to settings
saveBrightness(value) saveBrightness(value)
@ -278,16 +279,14 @@ Singleton {
initProc.command = ["asdbctl", "get"] initProc.command = ["asdbctl", "get"]
} else if (isDdc) { } else if (isDdc) {
initProc.command = ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] initProc.command = ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"]
} else { } else {
// Internal backlight - try to find the first available backlight device // 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.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 initProc.running = true
} }
onBusNumChanged: initBrightness() onBusNumChanged: initBrightness()
Component.onCompleted: initBrightness() Component.onCompleted: initBrightness()
} }
} }

View file

@ -48,7 +48,7 @@ QtObject {
break break
} }
} }
// Disable WiFi radio // Disable WiFi radio
disableWifiProcess.running = true disableWifiProcess.running = true
} }
@ -135,8 +135,7 @@ QtObject {
} }
} }
function onMenuClosed() { function onMenuClosed() {// No need to do anything special on close
// No need to do anything special on close
} }
// Process to enable WiFi radio // Process to enable WiFi radio
@ -167,12 +166,12 @@ QtObject {
onTriggered: { onTriggered: {
// Force refresh networks multiple times to ensure UI updates // Force refresh networks multiple times to ensure UI updates
root.refreshNetworks() root.refreshNetworks()
// Try to auto-reconnect to the last connected network if it exists // Try to auto-reconnect to the last connected network if it exists
if (lastConnectedNetwork) { if (lastConnectedNetwork) {
autoReconnectTimer.start() autoReconnectTimer.start()
} }
// Set up additional refresh to ensure UI is populated // Set up additional refresh to ensure UI is populated
postEnableRefreshTimer.start() postEnableRefreshTimer.start()
} }
@ -464,4 +463,4 @@ QtObject {
refreshNetworks() refreshNetworks()
} }
} }
} }