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
@ -46,8 +44,6 @@ Item {
} }
} }
NPill { NPill {
id: pill id: pill
icon: getIcon() icon: getIcon()
@ -55,10 +51,13 @@ 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()

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
@ -149,7 +151,7 @@ Singleton {
// 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: {
@ -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) {
@ -226,9 +226,9 @@ Singleton {
// 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) {
@ -242,7 +242,8 @@ Singleton {
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
@ -278,15 +279,13 @@ 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

@ -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