58 lines
1.3 KiB
QML
58 lines
1.3 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
import "." as M
|
|
|
|
M.BarSection {
|
|
id: root
|
|
spacing: M.Theme.moduleSpacing
|
|
visible: percent > 0
|
|
tooltip: "Brightness: " + root.percent + "%"
|
|
|
|
property int percent: 0
|
|
|
|
Process {
|
|
id: adjProc
|
|
property string cmd: ""
|
|
command: ["sh", "-c", cmd]
|
|
onRunningChanged: if (!running && cmd !== "")
|
|
current.reload()
|
|
}
|
|
|
|
function adjust(delta) {
|
|
adjProc.cmd = delta > 0 ? "light -A 5" : "light -U 5";
|
|
adjProc.running = true;
|
|
}
|
|
|
|
FileView {
|
|
id: current
|
|
path: "/sys/class/backlight/intel_backlight/brightness"
|
|
watchChanges: true
|
|
onFileChanged: reload()
|
|
onLoaded: root._update()
|
|
}
|
|
FileView {
|
|
id: max
|
|
path: "/sys/class/backlight/intel_backlight/max_brightness"
|
|
onLoaded: root._update()
|
|
}
|
|
|
|
function _update() {
|
|
const c = parseInt(current.text());
|
|
const m = parseInt(max.text());
|
|
if (m > 0)
|
|
root.percent = Math.round((c / m) * 100);
|
|
}
|
|
|
|
M.BarIcon {
|
|
icon: "\uF185"
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
M.BarLabel {
|
|
label: root.percent + "%"
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
|
|
WheelHandler {
|
|
onWheel: event => root.adjust(event.angleDelta.y)
|
|
}
|
|
}
|