1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

brightness: default IPCs to pinned devices per-display

fixes #875
This commit is contained in:
bbedward
2025-12-04 13:55:14 -05:00
parent 7d177eb1d4
commit 185333a615

View File

@@ -357,6 +357,35 @@ Singleton {
return devices.length > 0 ? devices[0].id : ""; return devices.length > 0 ? devices[0].id : "";
} }
function getPinnedDeviceForFocusedScreen() {
const focusedScreen = CompositorService.getFocusedScreen();
if (!focusedScreen)
return "";
const pins = SettingsData.brightnessDevicePins || {};
const screenKey = SettingsData.getScreenDisplayName(focusedScreen);
if (!screenKey)
return "";
const pinnedDevice = pins[screenKey];
if (!pinnedDevice)
return "";
const deviceExists = devices.some(d => d.id === pinnedDevice);
if (!deviceExists)
return "";
return pinnedDevice;
}
function getPreferredDevice() {
const pinned = getPinnedDeviceForFocusedScreen();
if (pinned)
return pinned;
return getDefaultDevice();
}
function getCurrentDeviceInfo() { function getCurrentDeviceInfo() {
const deviceToUse = lastIpcDevice === "" ? getDefaultDevice() : (lastIpcDevice || currentDevice); const deviceToUse = lastIpcDevice === "" ? getDefaultDevice() : (lastIpcDevice || currentDevice);
if (!deviceToUse) { if (!deviceToUse) {
@@ -809,110 +838,95 @@ Singleton {
// IPC Handler for external control // IPC Handler for external control
IpcHandler { IpcHandler {
function set(percentage: string, device: string): string { function set(percentage: string, device: string): string {
if (!root.brightnessAvailable) { if (!root.brightnessAvailable)
return "Brightness control not available"; return "Brightness control not available";
}
const value = parseInt(percentage); const value = parseInt(percentage);
if (isNaN(value)) { if (isNaN(value))
return "Invalid brightness value: " + percentage; return "Invalid brightness value: " + percentage;
}
const targetDevice = device || ""; const actualDevice = device || root.getPreferredDevice();
if (targetDevice && !root.devices.some(d => d.id === targetDevice)) { if (actualDevice && !root.devices.some(d => d.id === actualDevice))
return "Device not found: " + targetDevice; return "Device not found: " + actualDevice;
}
const deviceInfo = targetDevice ? root.getCurrentDeviceInfoByName(targetDevice) : null; const deviceInfo = actualDevice ? root.getCurrentDeviceInfoByName(actualDevice) : null;
const minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0; const minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0;
const clampedValue = Math.max(minValue, Math.min(100, value)); const clampedValue = Math.max(minValue, Math.min(100, value));
root.lastIpcDevice = targetDevice; root.lastIpcDevice = actualDevice;
if (targetDevice && targetDevice !== root.currentDevice) { if (actualDevice && actualDevice !== root.currentDevice)
root.setCurrentDevice(targetDevice, false); root.setCurrentDevice(actualDevice, false);
}
root.setBrightness(clampedValue, targetDevice);
if (targetDevice) { root.setBrightness(clampedValue, actualDevice);
return "Brightness set to " + clampedValue + "% on " + targetDevice;
} else { return actualDevice ? "Brightness set to " + clampedValue + "% on " + actualDevice : "Brightness set to " + clampedValue + "%";
return "Brightness set to " + clampedValue + "%";
}
} }
function increment(step: string, device: string): string { function increment(step: string, device: string): string {
if (!root.brightnessAvailable) { if (!root.brightnessAvailable)
return "Brightness control not available"; return "Brightness control not available";
}
const targetDevice = device || ""; const actualDevice = device || root.getPreferredDevice();
const actualDevice = targetDevice === "" ? root.getDefaultDevice() : targetDevice;
if (actualDevice && !root.devices.some(d => d.id === actualDevice)) { if (actualDevice && !root.devices.some(d => d.id === actualDevice))
return "Device not found: " + actualDevice; return "Device not found: " + actualDevice;
}
const stepValue = parseInt(step || "5"); const stepValue = parseInt(step || "5");
root.lastIpcDevice = actualDevice; root.lastIpcDevice = actualDevice;
if (actualDevice && actualDevice !== root.currentDevice) { if (actualDevice && actualDevice !== root.currentDevice)
root.setCurrentDevice(actualDevice, false); root.setCurrentDevice(actualDevice, false);
}
const isExponential = SessionData.getBrightnessExponential(actualDevice); const isExponential = SessionData.getBrightnessExponential(actualDevice);
const currentBrightness = root.getDeviceBrightness(actualDevice); const currentBrightness = root.getDeviceBrightness(actualDevice);
const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice); const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice);
let maxValue = 100; const maxValue = isExponential ? 100 : (deviceInfo?.displayMax || 100);
if (isExponential) {
maxValue = 100;
} else {
maxValue = deviceInfo?.displayMax || 100;
}
const newBrightness = Math.min(maxValue, currentBrightness + stepValue); const newBrightness = Math.min(maxValue, currentBrightness + stepValue);
root.setBrightness(newBrightness, actualDevice); root.setBrightness(newBrightness, actualDevice);
return "Brightness increased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : ""); return "Brightness increased by " + stepValue + "%" + (device ? " on " + actualDevice : "");
} }
function decrement(step: string, device: string): string { function decrement(step: string, device: string): string {
if (!root.brightnessAvailable) { if (!root.brightnessAvailable)
return "Brightness control not available"; return "Brightness control not available";
}
const targetDevice = device || ""; const actualDevice = device || root.getPreferredDevice();
const actualDevice = targetDevice === "" ? root.getDefaultDevice() : targetDevice;
if (actualDevice && !root.devices.some(d => d.id === actualDevice)) { if (actualDevice && !root.devices.some(d => d.id === actualDevice))
return "Device not found: " + actualDevice; return "Device not found: " + actualDevice;
}
const stepValue = parseInt(step || "5"); const stepValue = parseInt(step || "5");
root.lastIpcDevice = actualDevice; root.lastIpcDevice = actualDevice;
if (actualDevice && actualDevice !== root.currentDevice) { if (actualDevice && actualDevice !== root.currentDevice)
root.setCurrentDevice(actualDevice, false); root.setCurrentDevice(actualDevice, false);
}
const isExponential = SessionData.getBrightnessExponential(actualDevice); const isExponential = SessionData.getBrightnessExponential(actualDevice);
const currentBrightness = root.getDeviceBrightness(actualDevice); const currentBrightness = root.getDeviceBrightness(actualDevice);
const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice); const deviceInfo = root.getCurrentDeviceInfoByName(actualDevice);
let minValue = 0; let minValue = 0;
if (isExponential) { switch (true) {
case isExponential:
minValue = 1; minValue = 1;
} else { break;
minValue = (deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc")) ? 1 : 0; case deviceInfo && (deviceInfo.class === "backlight" || deviceInfo.class === "ddc"):
minValue = 1;
break;
default:
minValue = 0;
break;
} }
const newBrightness = Math.max(minValue, currentBrightness - stepValue); const newBrightness = Math.max(minValue, currentBrightness - stepValue);
root.setBrightness(newBrightness, actualDevice); root.setBrightness(newBrightness, actualDevice);
return "Brightness decreased by " + stepValue + "%" + (targetDevice ? " on " + targetDevice : ""); return "Brightness decreased by " + stepValue + "%" + (device ? " on " + actualDevice : "");
} }
function status(): string { function status(): string {