mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-28 15:32:50 -05:00
brightness: allow overriding exponent
This commit is contained in:
@@ -62,6 +62,7 @@ Singleton {
|
|||||||
property string lastBrightnessDevice: ""
|
property string lastBrightnessDevice: ""
|
||||||
property var brightnessExponentialDevices: ({})
|
property var brightnessExponentialDevices: ({})
|
||||||
property var brightnessUserSetValues: ({})
|
property var brightnessUserSetValues: ({})
|
||||||
|
property var brightnessExponentValues: ({})
|
||||||
|
|
||||||
property int selectedGpuIndex: 0
|
property int selectedGpuIndex: 0
|
||||||
property bool nvidiaGpuTempEnabled: false
|
property bool nvidiaGpuTempEnabled: false
|
||||||
@@ -111,6 +112,7 @@ Singleton {
|
|||||||
monitorWallpapersDark = settings.monitorWallpapersDark !== undefined ? settings.monitorWallpapersDark : {}
|
monitorWallpapersDark = settings.monitorWallpapersDark !== undefined ? settings.monitorWallpapersDark : {}
|
||||||
brightnessExponentialDevices = settings.brightnessExponentialDevices !== undefined ? settings.brightnessExponentialDevices : (settings.brightnessLogarithmicDevices || {})
|
brightnessExponentialDevices = settings.brightnessExponentialDevices !== undefined ? settings.brightnessExponentialDevices : (settings.brightnessLogarithmicDevices || {})
|
||||||
brightnessUserSetValues = settings.brightnessUserSetValues !== undefined ? settings.brightnessUserSetValues : {}
|
brightnessUserSetValues = settings.brightnessUserSetValues !== undefined ? settings.brightnessUserSetValues : {}
|
||||||
|
brightnessExponentValues = settings.brightnessExponentValues !== undefined ? settings.brightnessExponentValues : {}
|
||||||
doNotDisturb = settings.doNotDisturb !== undefined ? settings.doNotDisturb : false
|
doNotDisturb = settings.doNotDisturb !== undefined ? settings.doNotDisturb : false
|
||||||
nightModeEnabled = settings.nightModeEnabled !== undefined ? settings.nightModeEnabled : false
|
nightModeEnabled = settings.nightModeEnabled !== undefined ? settings.nightModeEnabled : false
|
||||||
nightModeTemperature = settings.nightModeTemperature !== undefined ? settings.nightModeTemperature : 4500
|
nightModeTemperature = settings.nightModeTemperature !== undefined ? settings.nightModeTemperature : 4500
|
||||||
@@ -191,6 +193,7 @@ Singleton {
|
|||||||
"monitorWallpapersDark": monitorWallpapersDark,
|
"monitorWallpapersDark": monitorWallpapersDark,
|
||||||
"brightnessExponentialDevices": brightnessExponentialDevices,
|
"brightnessExponentialDevices": brightnessExponentialDevices,
|
||||||
"brightnessUserSetValues": brightnessUserSetValues,
|
"brightnessUserSetValues": brightnessUserSetValues,
|
||||||
|
"brightnessExponentValues": brightnessExponentValues,
|
||||||
"doNotDisturb": doNotDisturb,
|
"doNotDisturb": doNotDisturb,
|
||||||
"nightModeEnabled": nightModeEnabled,
|
"nightModeEnabled": nightModeEnabled,
|
||||||
"nightModeTemperature": nightModeTemperature,
|
"nightModeTemperature": nightModeTemperature,
|
||||||
@@ -692,6 +695,22 @@ Singleton {
|
|||||||
return brightnessUserSetValues[deviceName]
|
return brightnessUserSetValues[deviceName]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setBrightnessExponent(deviceName, exponent) {
|
||||||
|
var newValues = Object.assign({}, brightnessExponentValues)
|
||||||
|
if (exponent !== undefined && exponent !== null) {
|
||||||
|
newValues[deviceName] = exponent
|
||||||
|
} else {
|
||||||
|
delete newValues[deviceName]
|
||||||
|
}
|
||||||
|
brightnessExponentValues = newValues
|
||||||
|
saveSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBrightnessExponent(deviceName) {
|
||||||
|
const value = brightnessExponentValues[deviceName]
|
||||||
|
return value !== undefined ? value : 1.2
|
||||||
|
}
|
||||||
|
|
||||||
function setSelectedGpuIndex(index) {
|
function setSelectedGpuIndex(index) {
|
||||||
selectedGpuIndex = index
|
selectedGpuIndex = index
|
||||||
saveSettings()
|
saveSettings()
|
||||||
|
|||||||
@@ -227,87 +227,174 @@ Rectangle {
|
|||||||
anchors.margins: Theme.spacingM
|
anchors.margins: Theme.spacingM
|
||||||
spacing: Theme.spacingS
|
spacing: Theme.spacingS
|
||||||
|
|
||||||
Row {
|
Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: Theme.spacingM
|
height: Math.max(deviceIconColumn.height, deviceInfoColumn.height, exponentControls.height)
|
||||||
|
|
||||||
Column {
|
Row {
|
||||||
|
anchors.left: parent.left
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
spacing: 2
|
spacing: Theme.spacingM
|
||||||
|
|
||||||
DankIcon {
|
Column {
|
||||||
name: {
|
id: deviceIconColumn
|
||||||
const deviceClass = modelData.class || ""
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
const deviceName = modelData.name || ""
|
spacing: 2
|
||||||
|
|
||||||
if (deviceClass === "backlight" || deviceClass === "ddc") {
|
DankIcon {
|
||||||
if (deviceBrightness <= 33)
|
name: {
|
||||||
return "brightness_low"
|
const deviceClass = modelData.class || ""
|
||||||
if (deviceBrightness <= 66)
|
const deviceName = modelData.name || ""
|
||||||
return "brightness_medium"
|
|
||||||
return "brightness_high"
|
if (deviceClass === "backlight" || deviceClass === "ddc") {
|
||||||
} else if (deviceName.includes("kbd")) {
|
if (deviceBrightness <= 33)
|
||||||
return "keyboard"
|
return "brightness_low"
|
||||||
} else {
|
if (deviceBrightness <= 66)
|
||||||
return "lightbulb"
|
return "brightness_medium"
|
||||||
|
return "brightness_high"
|
||||||
|
} else if (deviceName.includes("kbd")) {
|
||||||
|
return "keyboard"
|
||||||
|
} else {
|
||||||
|
return "lightbulb"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
size: Theme.iconSize
|
||||||
|
color: modelData.name === currentDeviceName ? Theme.primary : Theme.surfaceText
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: Math.round(deviceBrightness) + "%"
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceText
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
}
|
}
|
||||||
size: Theme.iconSize
|
|
||||||
color: modelData.name === currentDeviceName ? Theme.primary : Theme.surfaceText
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
Column {
|
||||||
text: Math.round(deviceBrightness) + "%"
|
id: deviceInfoColumn
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
color: Theme.surfaceText
|
width: parent.parent.width - deviceIconColumn.width - exponentControls.width - Theme.spacingM * 3
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
|
StyledText {
|
||||||
|
text: {
|
||||||
|
const name = modelData.name || ""
|
||||||
|
const deviceClass = modelData.class || ""
|
||||||
|
if (deviceClass === "backlight") {
|
||||||
|
return name.replace("_", " ").replace(/\b\w/g, c => c.toUpperCase())
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
|
color: Theme.surfaceText
|
||||||
|
font.weight: modelData.name === currentDeviceName ? Font.Medium : Font.Normal
|
||||||
|
elide: Text.ElideRight
|
||||||
|
width: parent.width
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: modelData.name
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceVariantText
|
||||||
|
elide: Text.ElideRight
|
||||||
|
width: parent.width
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: {
|
||||||
|
const deviceClass = modelData.class || ""
|
||||||
|
if (deviceClass === "backlight")
|
||||||
|
return "Backlight device"
|
||||||
|
if (deviceClass === "ddc")
|
||||||
|
return "DDC/CI monitor"
|
||||||
|
if (deviceClass === "leds")
|
||||||
|
return "LED device"
|
||||||
|
return deviceClass
|
||||||
|
}
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceVariantText
|
||||||
|
elide: Text.ElideRight
|
||||||
|
width: parent.width
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Row {
|
||||||
|
id: exponentControls
|
||||||
|
width: 140
|
||||||
|
height: 28
|
||||||
|
anchors.right: parent.right
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
width: parent.width - parent.spacing - 50
|
spacing: Theme.spacingXS
|
||||||
|
visible: SessionData.getBrightnessExponential(modelData.name)
|
||||||
|
z: 1
|
||||||
|
|
||||||
StyledText {
|
StyledRect {
|
||||||
text: {
|
width: 28
|
||||||
const name = modelData.name || ""
|
height: 28
|
||||||
const deviceClass = modelData.class || ""
|
radius: Theme.cornerRadius
|
||||||
if (deviceClass === "backlight") {
|
color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
|
||||||
return name.replace("_", " ").replace(/\b\w/g, c => c.toUpperCase())
|
opacity: SessionData.getBrightnessExponent(modelData.name) > 1.0 ? 1.0 : 0.4
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
name: "remove"
|
||||||
|
size: 14
|
||||||
|
color: Theme.surfaceText
|
||||||
|
}
|
||||||
|
|
||||||
|
StateLayer {
|
||||||
|
stateColor: Theme.primary
|
||||||
|
cornerRadius: parent.radius
|
||||||
|
enabled: SessionData.getBrightnessExponent(modelData.name) > 1.0
|
||||||
|
onClicked: {
|
||||||
|
const current = SessionData.getBrightnessExponent(modelData.name)
|
||||||
|
const newValue = Math.max(1.0, Math.round((current - 0.1) * 10) / 10)
|
||||||
|
SessionData.setBrightnessExponent(modelData.name, newValue)
|
||||||
}
|
}
|
||||||
return name
|
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
|
||||||
color: Theme.surfaceText
|
|
||||||
font.weight: modelData.name === currentDeviceName ? Font.Medium : Font.Normal
|
|
||||||
elide: Text.ElideRight
|
|
||||||
width: parent.width
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledRect {
|
||||||
text: modelData.name
|
width: 50
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
height: 28
|
||||||
color: Theme.surfaceVariantText
|
radius: Theme.cornerRadius
|
||||||
elide: Text.ElideRight
|
color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
|
||||||
width: parent.width
|
border.width: 0
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
text: SessionData.getBrightnessExponent(modelData.name).toFixed(1)
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
font.weight: Font.Medium
|
||||||
|
color: Theme.primary
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledRect {
|
||||||
text: {
|
width: 28
|
||||||
const deviceClass = modelData.class || ""
|
height: 28
|
||||||
if (deviceClass === "backlight")
|
radius: Theme.cornerRadius
|
||||||
return "Backlight device"
|
color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
|
||||||
if (deviceClass === "ddc")
|
opacity: SessionData.getBrightnessExponent(modelData.name) < 2.5 ? 1.0 : 0.4
|
||||||
return "DDC/CI monitor"
|
|
||||||
if (deviceClass === "leds")
|
DankIcon {
|
||||||
return "LED device"
|
anchors.centerIn: parent
|
||||||
return deviceClass
|
name: "add"
|
||||||
|
size: 14
|
||||||
|
color: Theme.surfaceText
|
||||||
|
}
|
||||||
|
|
||||||
|
StateLayer {
|
||||||
|
stateColor: Theme.primary
|
||||||
|
cornerRadius: parent.radius
|
||||||
|
enabled: SessionData.getBrightnessExponent(modelData.name) < 2.5
|
||||||
|
onClicked: {
|
||||||
|
const current = SessionData.getBrightnessExponent(modelData.name)
|
||||||
|
const newValue = Math.min(2.5, Math.round((current + 0.1) * 10) / 10)
|
||||||
|
SessionData.setBrightnessExponent(modelData.name, newValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
|
||||||
color: Theme.surfaceVariantText
|
|
||||||
elide: Text.ElideRight
|
|
||||||
width: parent.width
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,6 +438,7 @@ Rectangle {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.bottomMargin: 28
|
anchors.bottomMargin: 28
|
||||||
|
anchors.rightMargin: SessionData.getBrightnessExponential(modelData.name) ? 145 : 0
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ Singleton {
|
|||||||
if (userSetValue !== undefined) {
|
if (userSetValue !== undefined) {
|
||||||
displayValue = userSetValue
|
displayValue = userSetValue
|
||||||
} else {
|
} else {
|
||||||
displayValue = linearToExponential(device.currentPercent)
|
displayValue = linearToExponential(device.currentPercent, device.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ Singleton {
|
|||||||
if (userSetValue !== undefined) {
|
if (userSetValue !== undefined) {
|
||||||
newBrightness[device.id] = userSetValue
|
newBrightness[device.id] = userSetValue
|
||||||
} else {
|
} else {
|
||||||
newBrightness[device.id] = linearToExponential(device.currentPercent)
|
newBrightness[device.id] = linearToExponential(device.currentPercent, device.id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newBrightness[device.id] = device.currentPercent
|
newBrightness[device.id] = device.currentPercent
|
||||||
@@ -203,6 +203,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
if (isExponential) {
|
if (isExponential) {
|
||||||
params.exponential = true
|
params.exponential = true
|
||||||
|
params.exponent = SessionData.getBrightnessExponent(actualDevice)
|
||||||
}
|
}
|
||||||
|
|
||||||
DMSService.sendRequest("brightness.setBrightness", params, response => {
|
DMSService.sendRequest("brightness.setBrightness", params, response => {
|
||||||
@@ -242,10 +243,11 @@ Singleton {
|
|||||||
return 50
|
return 50
|
||||||
}
|
}
|
||||||
|
|
||||||
function linearToExponential(linearPercent) {
|
function linearToExponential(linearPercent, deviceName) {
|
||||||
const normalized = linearPercent / 100.0
|
const exponent = SessionData.getBrightnessExponent(deviceName)
|
||||||
const expPercent = Math.pow(normalized, 2.0) * 100.0
|
const hardwarePercent = linearPercent / 100.0
|
||||||
return Math.round(expPercent)
|
const normalizedPercent = Math.pow(hardwarePercent, 1.0 / exponent)
|
||||||
|
return Math.round(normalizedPercent * 100.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultDevice() {
|
function getDefaultDevice() {
|
||||||
|
|||||||
Reference in New Issue
Block a user