Merge pull request #38 from ferrreo/main
Enhance brightness control functionality and update README for zigbri…
This commit is contained in:
commit
e11ae45ca8
3 changed files with 89 additions and 25 deletions
|
|
@ -1,41 +1,95 @@
|
||||||
import QtQuick
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import qs.Settings
|
|
||||||
import qs.Components
|
import qs.Components
|
||||||
|
import qs.Settings
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: brightnessDisplay
|
id: brightnessDisplay
|
||||||
property int brightness: -1
|
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
|
width: pill.width
|
||||||
height: pill.height
|
height: pill.height
|
||||||
|
|
||||||
FileView {
|
Process {
|
||||||
id: brightnessFile
|
id: getBrightnessProcess
|
||||||
path: "/tmp/brightness_osd_level"
|
command: [Quickshell.shellDir + "/Programs/zigbrightness", "get", monitorName]
|
||||||
watchChanges: true
|
|
||||||
blockLoading: true
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
onLoaded: updateBrightness()
|
const output = this.text.trim()
|
||||||
onFileChanged: {
|
const val = parseInt(output)
|
||||||
brightnessFile.reload()
|
|
||||||
updateBrightness()
|
if (!isNaN(val) && val >= 0 && val !== previousBrightness) {
|
||||||
}
|
previousBrightness = brightness
|
||||||
|
brightness = val
|
||||||
function updateBrightness() {
|
pill.text = brightness + "%"
|
||||||
const val = parseInt(brightnessFile.text())
|
pill.show()
|
||||||
if (!isNaN(val) && val !== brightnessDisplay.brightness) {
|
}
|
||||||
brightnessDisplay.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 {
|
PillIndicator {
|
||||||
id: pill
|
id: pill
|
||||||
icon: "brightness_high"
|
icon: "brightness_high"
|
||||||
text: brightness >= 0 ? brightness + "%" : ""
|
text: brightness >= 0 ? brightness + "%" : "--"
|
||||||
pillColor: Theme.surfaceVariant
|
pillColor: Theme.surfaceVariant
|
||||||
iconCircleColor: Theme.accentPrimary
|
iconCircleColor: Theme.accentPrimary
|
||||||
iconTextColor: Theme.backgroundPrimary
|
iconTextColor: Theme.backgroundPrimary
|
||||||
|
|
@ -43,8 +97,17 @@ Item {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onEntered: brightnessTooltip.tooltipVisible = true
|
onEntered: {
|
||||||
|
getBrightness()
|
||||||
|
brightnessTooltip.tooltipVisible = true
|
||||||
|
}
|
||||||
onExited: brightnessTooltip.tooltipVisible = false
|
onExited: brightnessTooltip.tooltipVisible = false
|
||||||
|
|
||||||
|
onWheel: function(wheel) {
|
||||||
|
const delta = wheel.angleDelta.y > 0 ? 5 : -5
|
||||||
|
const newBrightness = brightness + delta
|
||||||
|
setBrightness(newBrightness)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StyledTooltip {
|
StyledTooltip {
|
||||||
id: brightnessTooltip
|
id: brightnessTooltip
|
||||||
|
|
@ -56,8 +119,9 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
getBrightness()
|
||||||
if (brightness >= 0) {
|
if (brightness >= 0) {
|
||||||
pill.show()
|
pill.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
Programs/zigbrightness
Executable file
BIN
Programs/zigbrightness
Executable file
Binary file not shown.
|
|
@ -177,11 +177,11 @@ You will need to install a few things to get everything working:
|
||||||
- `swww` to add fancy wallpaper animations (optional)
|
- `swww` to add fancy wallpaper animations (optional)
|
||||||
- `wallust` to theme the setup based on wallpaper (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
|
## 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
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue