61 lines
1.4 KiB
QML
61 lines
1.4 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
import QtQuick.Controls
|
|
import "." as M
|
|
|
|
Row {
|
|
id: root
|
|
spacing: 4
|
|
visible: percent > 0
|
|
|
|
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);
|
|
}
|
|
|
|
Text {
|
|
text: root.percent + "% "
|
|
color: M.Theme.base05
|
|
font.pixelSize: M.Theme.fontSize
|
|
font.family: M.Theme.fontFamily
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
|
|
WheelHandler {
|
|
onWheel: event => root.adjust(event.angleDelta.y)
|
|
}
|
|
HoverHandler { id: hover }
|
|
ToolTip {
|
|
visible: hover.hovered
|
|
text: "Brightness: " + root.percent + "%"
|
|
}
|
|
}
|