Brightness improvements
- we dont want to save brightness in settings as it is saved in the hardware - fixed a few DDCutil weirdness
This commit is contained in:
parent
1e4ed52c51
commit
593821e998
3 changed files with 7 additions and 58 deletions
|
|
@ -188,9 +188,6 @@ Singleton {
|
||||||
property JsonObject brightness
|
property JsonObject brightness
|
||||||
|
|
||||||
brightness: JsonObject {
|
brightness: JsonObject {
|
||||||
property real lastBrightness: 50.0
|
|
||||||
property string lastMethod: "internal"
|
|
||||||
property list<var> monitorBrightness: []
|
|
||||||
property int brightnessStep: 5
|
property int brightnessStep: 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ Item {
|
||||||
|
|
||||||
width: pill.width
|
width: pill.width
|
||||||
height: pill.height
|
height: pill.height
|
||||||
visible: Settings.data.bar.showBrightness
|
visible: Settings.data.bar.showBrightness && firstBrightnessReceived
|
||||||
|
|
||||||
// Used to avoid opening the pill on Quickshell startup
|
// Used to avoid opening the pill on Quickshell startup
|
||||||
property bool firstBrightnessReceived: false
|
property bool firstBrightnessReceived: false
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ Singleton {
|
||||||
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
|
||||||
property real lastBrightness: 0
|
property real lastBrightness: 0
|
||||||
property real queuedBrightness: NaN
|
property real queuedBrightness: NaN
|
||||||
|
|
||||||
|
|
@ -110,9 +110,9 @@ Singleton {
|
||||||
}
|
}
|
||||||
} else if (monitor.isDdc) {
|
} else if (monitor.isDdc) {
|
||||||
var parts = dataText.split(" ")
|
var parts = dataText.split(" ")
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 4) {
|
||||||
var current = parseInt(parts[0])
|
var current = parseInt(parts[3])
|
||||||
var max = parseInt(parts[1])
|
var max = parseInt(parts[4])
|
||||||
if (!isNaN(current) && !isNaN(max) && max > 0) {
|
if (!isNaN(current) && !isNaN(max) && max > 0) {
|
||||||
monitor.brightness = current / max
|
monitor.brightness = current / max
|
||||||
Logger.log("Brightness", "DDC brightness:", current + "/" + max + " =", monitor.brightness)
|
Logger.log("Brightness", "DDC brightness:", current + "/" + max + " =", monitor.brightness)
|
||||||
|
|
@ -131,11 +131,8 @@ Singleton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor.brightness > 0) {
|
// Always update
|
||||||
// Save the detected brightness to settings
|
monitor.brightnessUpdated(monitor.brightness)
|
||||||
monitor.saveBrightness(monitor.brightness)
|
|
||||||
monitor.brightnessUpdated(monitor.brightness)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -161,48 +158,6 @@ Singleton {
|
||||||
setBrightnessDebounced(monitor.brightness - stepSize)
|
setBrightnessDebounced(monitor.brightness - stepSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStoredBrightness(): real {
|
|
||||||
// Try to get stored brightness for this specific monitor
|
|
||||||
var stored = Settings.data.brightness.monitorBrightness.find(m => {
|
|
||||||
if (m !== null) {
|
|
||||||
return m.name === modelData.name
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
if (stored) {
|
|
||||||
return stored.brightness / 100
|
|
||||||
}
|
|
||||||
// Fallback to general last brightness
|
|
||||||
return Settings.data.brightness.lastBrightness / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
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 => {
|
|
||||||
if (m !== null) {
|
|
||||||
return m.name === modelData.name
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
})
|
|
||||||
var monitorData = {
|
|
||||||
"name": modelData.name,
|
|
||||||
"brightness": brightnessPercent,
|
|
||||||
"method": method
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitorIndex >= 0) {
|
|
||||||
Settings.data.brightness.monitorBrightness[monitorIndex] = monitorData
|
|
||||||
} else {
|
|
||||||
Settings.data.brightness.monitorBrightness.push(monitorData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -218,9 +173,6 @@ Singleton {
|
||||||
brightness = value
|
brightness = value
|
||||||
brightnessUpdated(brightness)
|
brightnessUpdated(brightness)
|
||||||
|
|
||||||
// Save to settings
|
|
||||||
saveBrightness(value)
|
|
||||||
|
|
||||||
if (isAppleDisplay) {
|
if (isAppleDisplay) {
|
||||||
Quickshell.execDetached(["asdbctl", "set", rounded])
|
Quickshell.execDetached(["asdbctl", "set", rounded])
|
||||||
} else if (isDdc) {
|
} else if (isDdc) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue