Enhance brightness control functionality and update README for zigbrightness integration

This commit is contained in:
ferreo 2025-07-22 17:33:27 +01:00
parent 7d568694bd
commit b9fa9dae22
3 changed files with 89 additions and 25 deletions

View file

@ -1,41 +1,95 @@
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Settings
import qs.Components
import qs.Settings
Item {
id: brightnessDisplay
property int brightness: -1
property int previousBrightness: -1
property var screen: (typeof modelData !== 'undefined' ? modelData : null)
property string monitorName: screen ? screen.name : "DP-1"
property bool isSettingBrightness: false
property bool hasPendingSet: false
property int pendingSetValue: -1
width: pill.width
height: pill.height
FileView {
id: brightnessFile
path: "/tmp/brightness_osd_level"
watchChanges: true
blockLoading: true
Process {
id: getBrightnessProcess
command: [Quickshell.shellDir + "/Programs/zigbrightness", "get", monitorName]
onLoaded: updateBrightness()
onFileChanged: {
brightnessFile.reload()
updateBrightness()
}
stdout: StdioCollector {
onStreamFinished: {
const output = this.text.trim()
const val = parseInt(output)
function updateBrightness() {
const val = parseInt(brightnessFile.text())
if (!isNaN(val) && val !== brightnessDisplay.brightness) {
brightnessDisplay.brightness = val
if (!isNaN(val) && val >= 0 && val !== previousBrightness) {
previousBrightness = brightness
brightness = val
pill.text = brightness + "%"
pill.show()
}
}
}
}
function getBrightness() {
if (isSettingBrightness) {
return
}
getBrightnessProcess.running = true
}
Process {
id: setBrightnessProcess
property int targetValue: -1
command: [Quickshell.shellDir + "/Programs/zigbrightness", "set", monitorName, targetValue.toString()]
stdout: StdioCollector {
onStreamFinished: {
const output = this.text.trim()
const val = parseInt(output)
if (!isNaN(val) && val >= 0) {
brightness = val
pill.text = brightness + "%"
pill.show()
}
isSettingBrightness = false
if (hasPendingSet) {
hasPendingSet = false
const pendingValue = pendingSetValue
pendingSetValue = -1
setBrightness(pendingValue)
}
}
}
}
function setBrightness(newValue) {
newValue = Math.max(0, Math.min(100, newValue))
if (isSettingBrightness) {
hasPendingSet = true
pendingSetValue = newValue
return
}
isSettingBrightness = true
setBrightnessProcess.targetValue = newValue
setBrightnessProcess.running = true
}
PillIndicator {
id: pill
icon: "brightness_high"
text: brightness >= 0 ? brightness + "%" : ""
text: brightness >= 0 ? brightness + "%" : "--"
pillColor: Theme.surfaceVariant
iconCircleColor: Theme.accentPrimary
iconTextColor: Theme.backgroundPrimary
@ -43,8 +97,17 @@ Item {
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: brightnessTooltip.tooltipVisible = true
onEntered: {
getBrightness()
brightnessTooltip.tooltipVisible = true
}
onExited: brightnessTooltip.tooltipVisible = false
onWheel: function(wheel) {
const delta = wheel.angleDelta.y > 0 ? 5 : -5
const newBrightness = brightness + delta
setBrightness(newBrightness)
}
}
StyledTooltip {
id: brightnessTooltip
@ -56,6 +119,7 @@ Item {
}
Component.onCompleted: {
getBrightness()
if (brightness >= 0) {
pill.show()
}

BIN
Programs/zigbrightness Executable file

Binary file not shown.

View file

@ -177,11 +177,11 @@ You will need to install a few things to get everything working:
- `swww` to add fancy wallpaper animations (optional)
- `wallust` to theme the setup based on wallpaper (optional)
## zigstat is bundled - source can be found [here](https://git.pika-os.com/wm-packages/pikabar/src/branch/main/src/zigstat).
## zigstat and zigbrightnesss is bundled - source can be found [here](https://git.pika-os.com/wm-packages/pikabar/src/t).
## Known issues
Currently the brightness indicator is very opiniated (using ddcutil with a script to log current brightness). This will be fixed **asap**!
It is perfect now
---