mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 05:55:37 -05:00
Improve brightness device detection
This commit is contained in:
@@ -20,12 +20,16 @@ PanelWindow {
|
|||||||
interval: BrightnessService.ddcAvailable ? 500 : 50
|
interval: BrightnessService.ddcAvailable ? 500 : 50
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
BrightnessService.setBrightnessInternal(pendingValue)
|
BrightnessService.setBrightnessInternal(pendingValue, BrightnessService.lastIpcDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
root.brightnessPopupVisible = true
|
root.brightnessPopupVisible = true
|
||||||
|
// Update slider to current device brightness when showing
|
||||||
|
if (BrightnessService.brightnessAvailable) {
|
||||||
|
brightnessSlider.value = BrightnessService.brightnessLevel
|
||||||
|
}
|
||||||
hideTimer.restart()
|
hideTimer.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,9 +115,20 @@ PanelWindow {
|
|||||||
|
|
||||||
DankIcon {
|
DankIcon {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
name: BrightnessService.brightnessLevel
|
name: {
|
||||||
< 30 ? "brightness_low" : BrightnessService.brightnessLevel
|
const deviceInfo = BrightnessService.getCurrentDeviceInfo();
|
||||||
< 70 ? "brightness_medium" : "brightness_high"
|
|
||||||
|
if (!deviceInfo || deviceInfo.class === "backlight") {
|
||||||
|
// Display backlight
|
||||||
|
return "brightness_medium";
|
||||||
|
} else if (deviceInfo.name.includes("kbd")) {
|
||||||
|
// Keyboard brightness
|
||||||
|
return "keyboard";
|
||||||
|
} else {
|
||||||
|
// Other devices (LEDs, etc.)
|
||||||
|
return "lightbulb";
|
||||||
|
}
|
||||||
|
}
|
||||||
size: Theme.iconSize
|
size: Theme.iconSize
|
||||||
color: Theme.primary
|
color: Theme.primary
|
||||||
}
|
}
|
||||||
@@ -145,7 +160,7 @@ PanelWindow {
|
|||||||
onSliderDragFinished: function (finalValue) {
|
onSliderDragFinished: function (finalValue) {
|
||||||
if (BrightnessService.brightnessAvailable) {
|
if (BrightnessService.brightnessAvailable) {
|
||||||
brightnessDebounceTimer.stop()
|
brightnessDebounceTimer.stop()
|
||||||
BrightnessService.setBrightnessInternal(finalValue)
|
BrightnessService.setBrightnessInternal(finalValue, BrightnessService.lastIpcDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +169,10 @@ PanelWindow {
|
|||||||
brightnessSlider.value = BrightnessService.brightnessLevel
|
brightnessSlider.value = BrightnessService.brightnessLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onDeviceSwitched() {
|
||||||
|
brightnessSlider.value = BrightnessService.brightnessLevel
|
||||||
|
}
|
||||||
|
|
||||||
target: BrightnessService
|
target: BrightnessService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DankSlider {
|
DankSlider {
|
||||||
|
id: brightnessSlider
|
||||||
width: parent.width
|
width: parent.width
|
||||||
value: BrightnessService.brightnessLevel
|
value: BrightnessService.brightnessLevel
|
||||||
leftIcon: "brightness_low"
|
leftIcon: "brightness_low"
|
||||||
@@ -115,6 +116,17 @@ Item {
|
|||||||
brightnessDebounceTimer.stop();
|
brightnessDebounceTimer.stop();
|
||||||
BrightnessService.setBrightnessInternal(finalValue, BrightnessService.currentDevice);
|
BrightnessService.setBrightnessInternal(finalValue, BrightnessService.currentDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: BrightnessService
|
||||||
|
function onBrightnessChanged() {
|
||||||
|
brightnessSlider.value = BrightnessService.brightnessLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDeviceSwitched() {
|
||||||
|
brightnessSlider.value = BrightnessService.brightnessLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,30 @@ Singleton {
|
|||||||
|
|
||||||
property bool brightnessAvailable: devices.length > 0
|
property bool brightnessAvailable: devices.length > 0
|
||||||
property var devices: []
|
property var devices: []
|
||||||
|
property var deviceBrightness: ({})
|
||||||
property string currentDevice: ""
|
property string currentDevice: ""
|
||||||
property int brightnessLevel: 50
|
property string lastIpcDevice: ""
|
||||||
|
property int brightnessLevel: {
|
||||||
|
const deviceToUse = lastIpcDevice === "" ? getDefaultDevice() : (lastIpcDevice || currentDevice);
|
||||||
|
return deviceToUse ? (deviceBrightness[deviceToUse] || 50) : 50;
|
||||||
|
}
|
||||||
property int maxBrightness: 100
|
property int maxBrightness: 100
|
||||||
property bool brightnessInitialized: false
|
property bool brightnessInitialized: false
|
||||||
|
|
||||||
signal brightnessChanged()
|
signal brightnessChanged()
|
||||||
|
signal deviceSwitched()
|
||||||
|
|
||||||
function setBrightnessInternal(percentage, device) {
|
function setBrightnessInternal(percentage, device) {
|
||||||
const clampedValue = Math.max(1, Math.min(100, percentage));
|
const clampedValue = Math.max(1, Math.min(100, percentage));
|
||||||
brightnessLevel = clampedValue;
|
const actualDevice = device === "" ? getDefaultDevice() : (device || currentDevice || getDefaultDevice());
|
||||||
|
|
||||||
|
// Update the device brightness cache
|
||||||
|
if (actualDevice) {
|
||||||
|
var newBrightness = deviceBrightness;
|
||||||
|
newBrightness[actualDevice] = clampedValue;
|
||||||
|
deviceBrightness = newBrightness;
|
||||||
|
}
|
||||||
|
|
||||||
if (device)
|
if (device)
|
||||||
brightnessSetProcess.command = ["brightnessctl", "-d", device, "set", clampedValue + "%"];
|
brightnessSetProcess.command = ["brightnessctl", "-d", device, "set", clampedValue + "%"];
|
||||||
else
|
else
|
||||||
@@ -36,6 +50,8 @@ Singleton {
|
|||||||
return ;
|
return ;
|
||||||
|
|
||||||
currentDevice = deviceName;
|
currentDevice = deviceName;
|
||||||
|
lastIpcDevice = deviceName;
|
||||||
|
deviceSwitched();
|
||||||
brightnessGetProcess.command = ["brightnessctl", "-m", "-d", deviceName, "get"];
|
brightnessGetProcess.command = ["brightnessctl", "-m", "-d", deviceName, "get"];
|
||||||
brightnessGetProcess.running = true;
|
brightnessGetProcess.running = true;
|
||||||
}
|
}
|
||||||
@@ -44,6 +60,33 @@ Singleton {
|
|||||||
deviceListProcess.running = true;
|
deviceListProcess.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDeviceBrightness(deviceName) {
|
||||||
|
return deviceBrightness[deviceName] || 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultDevice() {
|
||||||
|
// Find first backlight device
|
||||||
|
for (const device of devices) {
|
||||||
|
if (device.class === "backlight") {
|
||||||
|
return device.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fallback to first device if no backlight found
|
||||||
|
return devices.length > 0 ? devices[0].name : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentDeviceInfo() {
|
||||||
|
const deviceToUse = lastIpcDevice === "" ? getDefaultDevice() : (lastIpcDevice || currentDevice);
|
||||||
|
if (!deviceToUse) return null;
|
||||||
|
|
||||||
|
for (const device of devices) {
|
||||||
|
if (device.name === deviceToUse) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
refreshDevices();
|
refreshDevices();
|
||||||
}
|
}
|
||||||
@@ -128,9 +171,18 @@ Singleton {
|
|||||||
const current = parseInt(parts[2]);
|
const current = parseInt(parts[2]);
|
||||||
const max = parseInt(parts[4]);
|
const max = parseInt(parts[4]);
|
||||||
maxBrightness = max;
|
maxBrightness = max;
|
||||||
brightnessLevel = Math.round((current / max) * 100);
|
const brightness = Math.round((current / max) * 100);
|
||||||
|
|
||||||
|
// Update the device brightness cache
|
||||||
|
if (currentDevice) {
|
||||||
|
var newBrightness = deviceBrightness;
|
||||||
|
newBrightness[currentDevice] = brightness;
|
||||||
|
deviceBrightness = newBrightness;
|
||||||
|
}
|
||||||
|
|
||||||
brightnessInitialized = true;
|
brightnessInitialized = true;
|
||||||
console.log("BrightnessService: Device", currentDevice, "brightness:", brightnessLevel + "%");
|
console.log("BrightnessService: Device", currentDevice, "brightness:", brightness + "%");
|
||||||
|
brightnessChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,6 +198,10 @@ Singleton {
|
|||||||
const value = parseInt(percentage);
|
const value = parseInt(percentage);
|
||||||
const clampedValue = Math.max(1, Math.min(100, value));
|
const clampedValue = Math.max(1, Math.min(100, value));
|
||||||
const targetDevice = device || "";
|
const targetDevice = device || "";
|
||||||
|
root.lastIpcDevice = targetDevice;
|
||||||
|
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||||
|
root.setCurrentDevice(targetDevice);
|
||||||
|
}
|
||||||
root.setBrightness(clampedValue, targetDevice);
|
root.setBrightness(clampedValue, targetDevice);
|
||||||
if (targetDevice)
|
if (targetDevice)
|
||||||
return "Brightness set to " + clampedValue + "% on " + targetDevice;
|
return "Brightness set to " + clampedValue + "% on " + targetDevice;
|
||||||
@@ -157,10 +213,15 @@ Singleton {
|
|||||||
if (!root.brightnessAvailable)
|
if (!root.brightnessAvailable)
|
||||||
return "Brightness control not available";
|
return "Brightness control not available";
|
||||||
|
|
||||||
const currentLevel = root.brightnessLevel;
|
const targetDevice = device || "";
|
||||||
|
const actualDevice = targetDevice === "" ? root.getDefaultDevice() : targetDevice;
|
||||||
|
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel;
|
||||||
const stepValue = parseInt(step || "10");
|
const stepValue = parseInt(step || "10");
|
||||||
const newLevel = Math.max(1, Math.min(100, currentLevel + stepValue));
|
const newLevel = Math.max(1, Math.min(100, currentLevel + stepValue));
|
||||||
const targetDevice = device || "";
|
root.lastIpcDevice = targetDevice;
|
||||||
|
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||||
|
root.setCurrentDevice(targetDevice);
|
||||||
|
}
|
||||||
root.setBrightness(newLevel, targetDevice);
|
root.setBrightness(newLevel, targetDevice);
|
||||||
if (targetDevice)
|
if (targetDevice)
|
||||||
return "Brightness increased to " + newLevel + "% on " + targetDevice;
|
return "Brightness increased to " + newLevel + "% on " + targetDevice;
|
||||||
@@ -172,10 +233,15 @@ Singleton {
|
|||||||
if (!root.brightnessAvailable)
|
if (!root.brightnessAvailable)
|
||||||
return "Brightness control not available";
|
return "Brightness control not available";
|
||||||
|
|
||||||
const currentLevel = root.brightnessLevel;
|
const targetDevice = device || "";
|
||||||
|
const actualDevice = targetDevice === "" ? root.getDefaultDevice() : targetDevice;
|
||||||
|
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel;
|
||||||
const stepValue = parseInt(step || "10");
|
const stepValue = parseInt(step || "10");
|
||||||
const newLevel = Math.max(1, Math.min(100, currentLevel - stepValue));
|
const newLevel = Math.max(1, Math.min(100, currentLevel - stepValue));
|
||||||
const targetDevice = device || "";
|
root.lastIpcDevice = targetDevice;
|
||||||
|
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||||
|
root.setCurrentDevice(targetDevice);
|
||||||
|
}
|
||||||
root.setBrightness(newLevel, targetDevice);
|
root.setBrightness(newLevel, targetDevice);
|
||||||
if (targetDevice)
|
if (targetDevice)
|
||||||
return "Brightness decreased to " + newLevel + "% on " + targetDevice;
|
return "Brightness decreased to " + newLevel + "% on " + targetDevice;
|
||||||
|
|||||||
Reference in New Issue
Block a user