mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-09 15:05:39 -05:00
Update brightness controls for portable PC users
This commit is contained in:
@@ -9,8 +9,10 @@ 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 brightnessAvailable: false
|
property bool brightnessAvailable: laptopBacklightAvailable || ddcMonitors.length > 0
|
||||||
|
property bool laptopBacklightAvailable: false
|
||||||
property int brightnessLevel: 75
|
property int brightnessLevel: 75
|
||||||
|
property int laptopBrightnessLevel: 75
|
||||||
|
|
||||||
function getMonitorForScreen(screen: ShellScreen): var {
|
function getMonitorForScreen(screen: ShellScreen): var {
|
||||||
return monitors.find(function(m) { return m.modelData === screen; });
|
return monitors.find(function(m) { return m.modelData === screen; });
|
||||||
@@ -29,38 +31,68 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property var laptopDebounceTimer: Timer {
|
||||||
|
id: laptopDebounceTimer
|
||||||
|
interval: 50
|
||||||
|
repeat: false
|
||||||
|
property int pendingValue: 0
|
||||||
|
onTriggered: {
|
||||||
|
laptopBrightnessProcess.command = ["brightnessctl", "set", pendingValue + "%"];
|
||||||
|
laptopBrightnessProcess.running = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setBrightness(percentage) {
|
function setBrightness(percentage) {
|
||||||
root.brightnessLevel = percentage;
|
if (root.laptopBacklightAvailable) {
|
||||||
debounceTimer.pendingValue = percentage;
|
// Use laptop backlight control
|
||||||
debounceTimer.restart();
|
root.laptopBrightnessLevel = percentage;
|
||||||
|
laptopDebounceTimer.pendingValue = percentage;
|
||||||
|
laptopDebounceTimer.restart();
|
||||||
|
} else {
|
||||||
|
// Use external monitor control
|
||||||
|
root.brightnessLevel = percentage;
|
||||||
|
debounceTimer.pendingValue = percentage;
|
||||||
|
debounceTimer.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function increaseBrightness(): void {
|
function increaseBrightness(): void {
|
||||||
const focusedMonitor = monitors.find(function(m) { return m.modelData === Quickshell.screens[0]; });
|
if (root.laptopBacklightAvailable) {
|
||||||
if (focusedMonitor)
|
setBrightness(Math.min(100, root.laptopBrightnessLevel + 10));
|
||||||
focusedMonitor.setBrightness(focusedMonitor.brightness + 0.1);
|
} else {
|
||||||
|
const focusedMonitor = monitors.find(function(m) { return m.modelData === Quickshell.screens[0]; });
|
||||||
|
if (focusedMonitor)
|
||||||
|
focusedMonitor.setBrightness(focusedMonitor.brightness + 0.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function decreaseBrightness(): void {
|
function decreaseBrightness(): void {
|
||||||
const focusedMonitor = monitors.find(function(m) { return m.modelData === Quickshell.screens[0]; });
|
if (root.laptopBacklightAvailable) {
|
||||||
if (focusedMonitor)
|
setBrightness(Math.max(1, root.laptopBrightnessLevel - 10));
|
||||||
focusedMonitor.setBrightness(focusedMonitor.brightness - 0.1);
|
} else {
|
||||||
|
const focusedMonitor = monitors.find(function(m) { return m.modelData === Quickshell.screens[0]; });
|
||||||
|
if (focusedMonitor)
|
||||||
|
focusedMonitor.setBrightness(focusedMonitor.brightness - 0.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMonitorsChanged: {
|
onMonitorsChanged: {
|
||||||
ddcMonitors = [];
|
ddcMonitors = [];
|
||||||
if (ddcAvailable) {
|
if (root.brightnessAvailable) {
|
||||||
ddcProc.running = true;
|
ddcProc.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update brightness level from first monitor
|
// Update brightness level from laptop or first monitor
|
||||||
if (monitors.length > 0) {
|
if (root.laptopBacklightAvailable) {
|
||||||
|
// Laptop brightness is already set by laptopBrightnessInitProcess
|
||||||
|
} else if (monitors.length > 0) {
|
||||||
root.brightnessLevel = Math.round(monitors[0].brightness * 100);
|
root.brightnessLevel = Math.round(monitors[0].brightness * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
ddcAvailabilityChecker.running = true;
|
ddcAvailabilityChecker.running = true;
|
||||||
|
laptopBacklightChecker.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variants {
|
Variants {
|
||||||
@@ -80,6 +112,76 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: laptopBacklightChecker
|
||||||
|
command: ["brightnessctl", "--list"]
|
||||||
|
onExited: function(exitCode) {
|
||||||
|
root.laptopBacklightAvailable = (exitCode === 0);
|
||||||
|
if (root.laptopBacklightAvailable) {
|
||||||
|
laptopBrightnessInitProcess.running = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: laptopBrightnessProcess
|
||||||
|
running: false
|
||||||
|
|
||||||
|
onExited: function(exitCode) {
|
||||||
|
if (exitCode === 0) {
|
||||||
|
// Update was successful
|
||||||
|
root.brightnessLevel = root.laptopBrightnessLevel;
|
||||||
|
} else {
|
||||||
|
console.warn("Failed to set laptop brightness, exit code:", exitCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: laptopBrightnessInitProcess
|
||||||
|
command: ["brightnessctl", "get"]
|
||||||
|
running: false
|
||||||
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
if (text.trim()) {
|
||||||
|
// Get max brightness to calculate percentage
|
||||||
|
laptopMaxBrightnessProcess.running = true;
|
||||||
|
root.laptopBrightnessLevel = parseInt(text.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onExited: function(exitCode) {
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
console.warn("Failed to get laptop brightness, exit code:", exitCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: laptopMaxBrightnessProcess
|
||||||
|
command: ["brightnessctl", "max"]
|
||||||
|
running: false
|
||||||
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
if (text.trim()) {
|
||||||
|
const maxBrightness = parseInt(text.trim());
|
||||||
|
const currentPercentage = Math.round((root.laptopBrightnessLevel / maxBrightness) * 100);
|
||||||
|
root.laptopBrightnessLevel = currentPercentage;
|
||||||
|
root.brightnessLevel = currentPercentage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onExited: function(exitCode) {
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
console.warn("Failed to get max laptop brightness, exit code:", exitCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: ddcProc
|
id: ddcProc
|
||||||
command: ["ddcutil", "detect", "--brief"]
|
command: ["ddcutil", "detect", "--brief"]
|
||||||
|
|||||||
Reference in New Issue
Block a user