feat: add apple studio display brightness support (#214)
* chore: add studio display support * some fixes * more fixes --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
parent
3ecc0267fa
commit
7412052d12
1 changed files with 34 additions and 9 deletions
|
|
@ -11,6 +11,7 @@ Singleton {
|
||||||
|
|
||||||
property list<var> ddcMonitors: []
|
property list<var> ddcMonitors: []
|
||||||
readonly property list<Monitor> monitors: variants.instances
|
readonly property list<Monitor> monitors: variants.instances
|
||||||
|
property bool appleDisplayPresent: false
|
||||||
|
|
||||||
function getMonitorForScreen(screen: ShellScreen): var {
|
function getMonitorForScreen(screen: ShellScreen): var {
|
||||||
return monitors.find(m => m.modelData === screen);
|
return monitors.find(m => m.modelData === screen);
|
||||||
|
|
@ -45,6 +46,14 @@ Singleton {
|
||||||
Monitor {}
|
Monitor {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
Process {
|
||||||
id: ddcProc
|
id: ddcProc
|
||||||
|
|
||||||
|
|
@ -75,13 +84,19 @@ Singleton {
|
||||||
required property ShellScreen modelData
|
required property ShellScreen modelData
|
||||||
readonly property bool isDdc: root.ddcMonitors.some(m => m.model === modelData.model)
|
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 string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? ""
|
||||||
|
readonly property bool isAppleDisplay: root.appleDisplayPresent && modelData.model.startsWith("StudioDisplay")
|
||||||
property real brightness
|
property real brightness
|
||||||
|
|
||||||
readonly property Process initProc: Process {
|
readonly property Process initProc: Process {
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
const [, , , current, max] = text.split(" ");
|
if (monitor.isAppleDisplay) {
|
||||||
monitor.brightness = parseInt(current) / parseInt(max);
|
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)
|
if (Math.round(brightness * 100) === rounded)
|
||||||
return;
|
return;
|
||||||
brightness = value;
|
brightness = value;
|
||||||
Quickshell.execDetached(isDdc ? ["ddcutil", "-b", busNum, "setvcp", "10", rounded] : ["brightnessctl", "s", `${rounded}%`]);
|
|
||||||
|
if (isAppleDisplay)
|
||||||
|
Quickshell.execDetached(["asdbctl", "set", rounded]);
|
||||||
|
else if (isDdc)
|
||||||
|
Quickshell.execDetached(["ddcutil", "-b", busNum, "setvcp", "10", rounded]);
|
||||||
|
else
|
||||||
|
Quickshell.execDetached(["brightnessctl", "s", `${rounded}%`]);
|
||||||
}
|
}
|
||||||
|
|
||||||
onBusNumChanged: {
|
function initBrightness(): void {
|
||||||
initProc.command = isDdc ? ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] : ["sh", "-c", `echo "a b c $(brightnessctl g) $(brightnessctl m)"`];
|
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;
|
initProc.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
onBusNumChanged: initBrightness()
|
||||||
initProc.command = isDdc ? ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] : ["sh", "-c", `echo "a b c $(brightnessctl g) $(brightnessctl m)"`];
|
Component.onCompleted: initBrightness()
|
||||||
initProc.running = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue