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