mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-13 00:42:49 -05:00
bright brightness OSD
This commit is contained in:
@@ -14,29 +14,19 @@ PanelWindow {
|
||||
property bool brightnessPopupVisible: false
|
||||
property var brightnessDebounceTimer
|
||||
|
||||
brightnessDebounceTimer: Timer {
|
||||
property int pendingValue: 0
|
||||
|
||||
interval: BrightnessService.ddcAvailable ? 500 : 50
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
BrightnessService.setBrightnessInternal(
|
||||
pendingValue, BrightnessService.lastIpcDevice)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
if (BrightnessService.brightnessAvailable)
|
||||
brightnessSlider.value = BrightnessService.brightnessLevel;
|
||||
|
||||
hideTimer.restart();
|
||||
}
|
||||
|
||||
function resetHideTimer() {
|
||||
if (root.brightnessPopupVisible)
|
||||
hideTimer.restart()
|
||||
hideTimer.restart();
|
||||
|
||||
}
|
||||
|
||||
screen: modelData
|
||||
@@ -60,15 +50,15 @@ PanelWindow {
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
if (!brightnessPopup.containsMouse)
|
||||
root.brightnessPopupVisible = false
|
||||
root.brightnessPopupVisible = false;
|
||||
else
|
||||
hideTimer.restart()
|
||||
hideTimer.restart();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onBrightnessChanged() {
|
||||
root.show()
|
||||
root.show();
|
||||
}
|
||||
|
||||
target: BrightnessService
|
||||
@@ -86,8 +76,7 @@ PanelWindow {
|
||||
anchors.bottomMargin: Theme.spacingM
|
||||
color: Theme.popupBackground()
|
||||
radius: Theme.cornerRadius
|
||||
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g,
|
||||
Theme.outline.b, 0.08)
|
||||
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.08)
|
||||
border.width: 1
|
||||
opacity: root.brightnessPopupVisible ? 1 : 0
|
||||
scale: root.brightnessPopupVisible ? 1 : 0.9
|
||||
@@ -117,20 +106,18 @@ PanelWindow {
|
||||
DankIcon {
|
||||
anchors.centerIn: parent
|
||||
name: {
|
||||
const deviceInfo = BrightnessService.getCurrentDeviceInfo()
|
||||
|
||||
if (!deviceInfo || deviceInfo.class === "backlight"
|
||||
|| deviceInfo.class === "ddc") {
|
||||
return "brightness_medium"
|
||||
} else if (deviceInfo.name.includes("kbd")) {
|
||||
return "keyboard"
|
||||
} else {
|
||||
return "lightbulb"
|
||||
}
|
||||
const deviceInfo = BrightnessService.getCurrentDeviceInfo();
|
||||
if (!deviceInfo || deviceInfo.class === "backlight" || deviceInfo.class === "ddc")
|
||||
return "brightness_medium";
|
||||
else if (deviceInfo.name.includes("kbd"))
|
||||
return "keyboard";
|
||||
else
|
||||
return "lightbulb";
|
||||
}
|
||||
size: Theme.iconSize
|
||||
color: Theme.primary
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DankSlider {
|
||||
@@ -147,37 +134,43 @@ PanelWindow {
|
||||
unit: "%"
|
||||
Component.onCompleted: {
|
||||
if (BrightnessService.brightnessAvailable)
|
||||
value = BrightnessService.brightnessLevel
|
||||
value = BrightnessService.brightnessLevel;
|
||||
|
||||
}
|
||||
onSliderValueChanged: function (newValue) {
|
||||
onSliderValueChanged: function(newValue) {
|
||||
if (BrightnessService.brightnessAvailable) {
|
||||
brightnessDebounceTimer.pendingValue = newValue
|
||||
brightnessDebounceTimer.restart()
|
||||
root.resetHideTimer()
|
||||
brightnessDebounceTimer.pendingValue = newValue;
|
||||
brightnessDebounceTimer.restart();
|
||||
root.resetHideTimer();
|
||||
}
|
||||
}
|
||||
onSliderDragFinished: function (finalValue) {
|
||||
onSliderDragFinished: function(finalValue) {
|
||||
if (BrightnessService.brightnessAvailable) {
|
||||
brightnessDebounceTimer.stop()
|
||||
BrightnessService.setBrightnessInternal(
|
||||
finalValue,
|
||||
BrightnessService.lastIpcDevice)
|
||||
brightnessDebounceTimer.stop();
|
||||
BrightnessService.setBrightnessInternal(finalValue, BrightnessService.lastIpcDevice);
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onBrightnessChanged() {
|
||||
brightnessSlider.value = BrightnessService.brightnessLevel
|
||||
if (!brightnessSlider.pressed)
|
||||
brightnessSlider.value = BrightnessService.brightnessLevel;
|
||||
|
||||
}
|
||||
|
||||
function onDeviceSwitched() {
|
||||
brightnessSlider.value = BrightnessService.brightnessLevel
|
||||
if (!brightnessSlider.pressed)
|
||||
brightnessSlider.value = BrightnessService.brightnessLevel;
|
||||
|
||||
}
|
||||
|
||||
target: BrightnessService
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
@@ -208,6 +201,7 @@ PanelWindow {
|
||||
duration: Theme.mediumDuration
|
||||
easing.type: Theme.emphasizedEasing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Behavior on scale {
|
||||
@@ -215,6 +209,7 @@ PanelWindow {
|
||||
duration: Theme.mediumDuration
|
||||
easing.type: Theme.emphasizedEasing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Behavior on transform {
|
||||
@@ -222,10 +217,26 @@ PanelWindow {
|
||||
duration: Theme.mediumDuration
|
||||
easing.type: Theme.emphasizedEasing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
brightnessDebounceTimer: Timer {
|
||||
property int pendingValue: 0
|
||||
|
||||
interval: {
|
||||
const deviceInfo = BrightnessService.getCurrentDeviceInfo()
|
||||
return (deviceInfo && deviceInfo.class === "ddc") ? 200 : 50
|
||||
}
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
BrightnessService.setBrightnessInternal(pendingValue, BrightnessService.lastIpcDevice);
|
||||
}
|
||||
}
|
||||
|
||||
mask: Region {
|
||||
item: brightnessPopup
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,22 +20,11 @@ Singleton {
|
||||
property var ddcInitQueue: []
|
||||
property bool skipDdcRead: false
|
||||
property int brightnessLevel: {
|
||||
const deviceToUse = lastIpcDevice === "" ? getDefaultDevice(
|
||||
) : (lastIpcDevice
|
||||
|| currentDevice)
|
||||
if (!deviceToUse)
|
||||
return 50
|
||||
const deviceToUse = lastIpcDevice === "" ? getDefaultDevice() : (lastIpcDevice || currentDevice)
|
||||
if (!deviceToUse) return 50
|
||||
|
||||
const deviceInfo = getCurrentDeviceInfoByName(deviceToUse)
|
||||
if (deviceInfo && deviceInfo.class === "ddc") {
|
||||
if (ddcPendingInit[deviceToUse]) {
|
||||
return deviceBrightness[deviceToUse] || 50
|
||||
}
|
||||
return deviceBrightness[deviceToUse] || 50
|
||||
}
|
||||
|
||||
// For non-DDC devices, don't use cache - they're fast to read
|
||||
return deviceBrightness[deviceToUse] || 50
|
||||
// Always use cached values for consistency
|
||||
return getDeviceBrightness(deviceToUse)
|
||||
}
|
||||
property int maxBrightness: 100
|
||||
property bool brightnessInitialized: false
|
||||
@@ -51,15 +40,15 @@ Singleton {
|
||||
) : (device || currentDevice
|
||||
|| getDefaultDevice())
|
||||
|
||||
// Update the device brightness cache
|
||||
const deviceInfo = getCurrentDeviceInfoByName(actualDevice)
|
||||
if (actualDevice && deviceInfo && deviceInfo.class === "ddc") {
|
||||
// Always cache DDC values since we never read them again
|
||||
// Update the device brightness cache immediately for all devices
|
||||
if (actualDevice) {
|
||||
var newBrightness = Object.assign({}, deviceBrightness)
|
||||
newBrightness[actualDevice] = clampedValue
|
||||
deviceBrightness = newBrightness
|
||||
}
|
||||
|
||||
const deviceInfo = getCurrentDeviceInfoByName(actualDevice)
|
||||
|
||||
if (deviceInfo && deviceInfo.class === "ddc") {
|
||||
// Use ddcutil for DDC devices
|
||||
ddcBrightnessSetProcess.command = ["ddcutil", "setvcp", "-d", String(
|
||||
@@ -149,9 +138,20 @@ Singleton {
|
||||
}
|
||||
|
||||
function getDeviceBrightness(deviceName) {
|
||||
if (!deviceName) return 50
|
||||
|
||||
const deviceInfo = getCurrentDeviceInfoByName(deviceName)
|
||||
if (!deviceInfo) return 50
|
||||
|
||||
// For DDC devices, always use cached values
|
||||
if (deviceInfo.class === "ddc") {
|
||||
return deviceBrightness[deviceName] || 50
|
||||
}
|
||||
|
||||
// For regular devices, try cache first, then device info
|
||||
return deviceBrightness[deviceName] || deviceInfo.percentage || 50
|
||||
}
|
||||
|
||||
function getDefaultDevice() {
|
||||
for (const device of devices) {
|
||||
if (device.class === "backlight") {
|
||||
@@ -502,7 +502,7 @@ Singleton {
|
||||
|
||||
// Update the device brightness cache
|
||||
if (currentDevice) {
|
||||
var newBrightness = deviceBrightness
|
||||
var newBrightness = Object.assign({}, deviceBrightness)
|
||||
newBrightness[currentDevice] = brightness
|
||||
deviceBrightness = newBrightness
|
||||
}
|
||||
@@ -542,7 +542,7 @@ Singleton {
|
||||
|
||||
// Update the device brightness cache
|
||||
if (currentDevice) {
|
||||
var newBrightness = deviceBrightness
|
||||
var newBrightness = Object.assign({}, deviceBrightness)
|
||||
newBrightness[currentDevice] = brightness
|
||||
deviceBrightness = newBrightness
|
||||
}
|
||||
@@ -604,13 +604,24 @@ Singleton {
|
||||
return "Brightness control not available"
|
||||
|
||||
const value = parseInt(percentage)
|
||||
if (isNaN(value)) {
|
||||
return "Invalid brightness value: " + percentage
|
||||
}
|
||||
|
||||
const clampedValue = Math.max(1, Math.min(100, value))
|
||||
const targetDevice = device || ""
|
||||
|
||||
// Ensure device exists if specified
|
||||
if (targetDevice && !root.devices.some(d => d.name === targetDevice)) {
|
||||
return "Device not found: " + targetDevice
|
||||
}
|
||||
|
||||
root.lastIpcDevice = targetDevice
|
||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(targetDevice, false)
|
||||
}
|
||||
root.setBrightness(clampedValue, targetDevice)
|
||||
|
||||
if (targetDevice)
|
||||
return "Brightness set to " + clampedValue + "% on " + targetDevice
|
||||
else
|
||||
@@ -622,18 +633,23 @@ Singleton {
|
||||
return "Brightness control not available"
|
||||
|
||||
const targetDevice = device || ""
|
||||
const actualDevice = targetDevice === "" ? root.getDefaultDevice(
|
||||
) : targetDevice
|
||||
const currentLevel = actualDevice ? root.getDeviceBrightness(
|
||||
actualDevice) : root.brightnessLevel
|
||||
const actualDevice = targetDevice === "" ? root.getDefaultDevice() : targetDevice
|
||||
|
||||
// Ensure device exists
|
||||
if (actualDevice && !root.devices.some(d => d.name === actualDevice)) {
|
||||
return "Device not found: " + actualDevice
|
||||
}
|
||||
|
||||
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel
|
||||
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))
|
||||
|
||||
root.lastIpcDevice = targetDevice
|
||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(targetDevice, false)
|
||||
}
|
||||
root.setBrightness(newLevel, targetDevice)
|
||||
|
||||
if (targetDevice)
|
||||
return "Brightness increased to " + newLevel + "% on " + targetDevice
|
||||
else
|
||||
@@ -645,18 +661,23 @@ Singleton {
|
||||
return "Brightness control not available"
|
||||
|
||||
const targetDevice = device || ""
|
||||
const actualDevice = targetDevice === "" ? root.getDefaultDevice(
|
||||
) : targetDevice
|
||||
const currentLevel = actualDevice ? root.getDeviceBrightness(
|
||||
actualDevice) : root.brightnessLevel
|
||||
const actualDevice = targetDevice === "" ? root.getDefaultDevice() : targetDevice
|
||||
|
||||
// Ensure device exists
|
||||
if (actualDevice && !root.devices.some(d => d.name === actualDevice)) {
|
||||
return "Device not found: " + actualDevice
|
||||
}
|
||||
|
||||
const currentLevel = actualDevice ? root.getDeviceBrightness(actualDevice) : root.brightnessLevel
|
||||
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))
|
||||
|
||||
root.lastIpcDevice = targetDevice
|
||||
if (targetDevice && targetDevice !== root.currentDevice) {
|
||||
root.setCurrentDevice(targetDevice, false)
|
||||
}
|
||||
root.setBrightness(newLevel, targetDevice)
|
||||
|
||||
if (targetDevice)
|
||||
return "Brightness decreased to " + newLevel + "% on " + targetDevice
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user