summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/Brightness.qml43
1 files changed, 34 insertions, 9 deletions
diff --git a/services/Brightness.qml b/services/Brightness.qml
index dfef1b6..eab5468 100644
--- a/services/Brightness.qml
+++ b/services/Brightness.qml
@@ -11,6 +11,7 @@ Singleton {
property list<var> ddcMonitors: []
readonly property list<Monitor> monitors: variants.instances
+ property bool appleDisplayPresent: false
function getMonitorForScreen(screen: ShellScreen): var {
return monitors.find(m => m.modelData === screen);
@@ -46,6 +47,14 @@ Singleton {
}
Process {
+ running: true
+ command: ["sh", "-c", "asdbctl get"] // To avoid warnings if asdbctl is not installed
+ stdout: StdioCollector {
+ onStreamFinished: root.appleDisplayPresent = text.trim().length > 0
+ }
+ }
+
+ Process {
id: ddcProc
command: ["ddcutil", "detect", "--brief"]
@@ -75,13 +84,19 @@ Singleton {
required property ShellScreen modelData
readonly property bool isDdc: root.ddcMonitors.some(m => m.model === modelData.model)
readonly property string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? ""
+ readonly property bool isAppleDisplay: root.appleDisplayPresent && modelData.model.startsWith("StudioDisplay")
property real brightness
readonly property Process initProc: Process {
stdout: StdioCollector {
onStreamFinished: {
- const [, , , current, max] = text.split(" ");
- monitor.brightness = parseInt(current) / parseInt(max);
+ if (monitor.isAppleDisplay) {
+ const val = parseInt(text.trim());
+ monitor.brightness = val / 101;
+ } else {
+ const [, , , cur, max] = text.split(" ");
+ monitor.brightness = parseInt(cur) / parseInt(max);
+ }
}
}
}
@@ -92,17 +107,27 @@ Singleton {
if (Math.round(brightness * 100) === rounded)
return;
brightness = value;
- Quickshell.execDetached(isDdc ? ["ddcutil", "-b", busNum, "setvcp", "10", rounded] : ["brightnessctl", "s", `${rounded}%`]);
- }
- onBusNumChanged: {
- initProc.command = isDdc ? ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] : ["sh", "-c", `echo "a b c $(brightnessctl g) $(brightnessctl m)"`];
- initProc.running = true;
+ if (isAppleDisplay)
+ Quickshell.execDetached(["asdbctl", "set", rounded]);
+ else if (isDdc)
+ Quickshell.execDetached(["ddcutil", "-b", busNum, "setvcp", "10", rounded]);
+ else
+ Quickshell.execDetached(["brightnessctl", "s", `${rounded}%`]);
}
- Component.onCompleted: {
- initProc.command = isDdc ? ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] : ["sh", "-c", `echo "a b c $(brightnessctl g) $(brightnessctl m)"`];
+ function initBrightness(): void {
+ if (isAppleDisplay)
+ initProc.command = ["asdbctl", "get"];
+ else if (isDdc)
+ initProc.command = ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"];
+ else
+ initProc.command = ["sh", "-c", "echo a b c $(brightnessctl g) $(brightnessctl m)"];
+
initProc.running = true;
}
+
+ onBusNumChanged: initBrightness()
+ Component.onCompleted: initBrightness()
}
}