add brightness and volume sliders

This commit is contained in:
Henry Hiles 2026-11-18 00:19:01 -05:00
commit 09e9522623
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
7 changed files with 206 additions and 11 deletions

View file

@ -8,6 +8,8 @@ down from it.
The bar shows the time, cellular, Wi-Fi, Bluetooth and battery. The sheet has: The bar shows the time, cellular, Wi-Fi, Bluetooth and battery. The sheet has:
- Brightness and volume sliders. Tap the speaker icon to mute, and the arrow next to it picks the
output, out of the ones that are plugged in.
- Wi-Fi, Bluetooth, cellular and mobile data toggles. The arrow on Wi-Fi opens `nmgui`, and on - Wi-Fi, Bluetooth, cellular and mobile data toggles. The arrow on Wi-Fi opens `nmgui`, and on
Bluetooth it opens `adw-bluetooth`. Bluetooth it opens `adw-bluetooth`.
- Location, which decides whether apps get your location through GeoClue. The bar shows an icon - Location, which decides whether apps get your location through GeoClue. The bar shows an icon
@ -45,14 +47,16 @@ spawn-at-startup "quadshell"
The lockscreen shows whatever image swaybg is showing (its `-i` argument), blurred. The lockscreen shows whatever image swaybg is showing (its `-i` argument), blurred.
It brings `nmcli`, `mmcli`, `nmgui` and `adw-bluetooth` with it. The system needs: It brings `nmcli`, `mmcli`, `pw-dump` and `nmgui` with it. The system needs:
- niri, NetworkManager and ModemManager running - niri, NetworkManager, ModemManager and PipeWire running
- systemd-logind, which the flashlight uses to set the LED without root - systemd-logind, which the flashlight and brightness slider use to set the LED and backlight without
root
- The `login` PAM service, which checks the lockscreen's password - The `login` PAM service, which checks the lockscreen's password
- The Papirus-Dark icon theme and the Inter font - The Papirus-Dark icon theme and the Inter font
- An on-screen keyboard that uses text-input-v3, like Stevia, to type the password - An on-screen keyboard that uses text-input-v3, like Stevia, to type the password
- No other notification daemon, like swaync or mako, as only one can run at a time - No other notification daemon, like swaync or mako, as only one can run at a time
- adw-bluetooth for the Bluetooth arrow, with its daemon: `services.adw-bluetooth.enable = true;`
- GeoClue, with quadshell as its agent, for the location toggle: - GeoClue, with quadshell as its agent, for the location toggle:
```nix ```nix

View file

@ -6,8 +6,8 @@
glib, glib,
networkmanager, networkmanager,
modemmanager, modemmanager,
pipewire,
nmgui, nmgui,
adw-bluetooth,
coreutils, coreutils,
gawk, gawk,
gnugrep, gnugrep,
@ -32,8 +32,8 @@ writeShellApplication {
runtimeInputs = [ runtimeInputs = [
networkmanager networkmanager
modemmanager modemmanager
pipewire # pw-dump, for which outputs are plugged in
nmgui nmgui
adw-bluetooth
coreutils coreutils
gawk gawk
gnugrep gnugrep

View file

@ -49,7 +49,7 @@ Scope {
} }
LockSurface { LockSurface {
lock: root lock: root // qmllint disable incompatible-type
} }
} }

View file

@ -17,7 +17,7 @@ Item {
// 0 is closed, 1 is open // 0 is closed, 1 is open
property real progress: 0 property real progress: 0
readonly property bool sheetShown: progress > 0 readonly property bool sheetShown: progress > 0
// Which row of options is dropped down: "", "rotate" or "power" // Which row of options is dropped down: "", "rotate", "output" or "power"
property string expanded: "" property string expanded: ""
function open() { function open() {
@ -159,6 +159,47 @@ Item {
] ]
} }
Slider {
visible: Status.backlight !== ""
Layout.fillWidth: true
icon: Status.brightnessIcon
value: Status.brightness
onMoved: value => Status.setBrightness(value)
}
RowLayout {
visible: Status.sink !== null
Layout.fillWidth: true
spacing: 8
Slider {
Layout.fillWidth: true
icon: Status.volumeIcon
value: Status.volume
active: !Status.muted
iconTappable: true
onMoved: value => Status.setVolume(value)
onIconTapped: Status.setMuted(!Status.muted)
}
RoundButton {
visible: Status.sinks.length > 1
icon: root.expanded === "output" ? "go-up-symbolic" : "go-down-symbolic"
active: root.expanded === "output"
onClicked: root.expanded = root.expanded === "output" ? "" : "output"
}
}
Options {
visible: root.expanded === "output"
Layout.fillWidth: true
model: Status.sinks.map(sink => ({
name: sink.description || sink.nickname || sink.name,
active: sink === Status.sink,
action: () => Status.setSink(sink),
}))
}
GridLayout { GridLayout {
Layout.fillWidth: true Layout.fillWidth: true
columns: 2 columns: 2

60
src/Slider.qml Normal file
View file

@ -0,0 +1,60 @@
import QtQuick
Rectangle {
id: slider
property string icon
// From 0 to 1
property real value
// Greys out the fill, like when the volume is muted
property bool active: true
// Tapping the icon emits iconTapped, rather than setting the value
property bool iconTappable: false
signal moved(real value)
signal iconTapped
implicitHeight: 40
radius: height / 2
color: Theme.surface
Rectangle {
width: slider.height + slider.value * (slider.width - slider.height)
height: parent.height
radius: slider.radius
color: slider.active ? Theme.accent : Theme.surfaceHigh
}
ShellIcon {
anchors {
left: parent.left
leftMargin: (slider.height - implicitSize) / 2
verticalCenter: parent.verticalCenter
}
name: slider.icon
implicitSize: 18
}
MouseArea {
anchors.fill: parent
preventStealing: true
property bool onIcon
function set(x) {
slider.moved(Math.max(0, Math.min(1, (x - slider.height / 2) / (slider.width - slider.height))));
}
onPressed: mouse => {
onIcon = slider.iconTappable && mouse.x < slider.height;
if (!onIcon) set(mouse.x);
}
onPositionChanged: mouse => {
onIcon = false;
set(mouse.x);
}
onReleased: {
if (onIcon) slider.iconTapped();
}
}
}

View file

@ -5,6 +5,7 @@ import Quickshell.Io
import Quickshell.Networking import Quickshell.Networking
import Quickshell.Bluetooth import Quickshell.Bluetooth
import Quickshell.Services.UPower import Quickshell.Services.UPower
import Quickshell.Services.Pipewire
Singleton { Singleton {
id: root id: root
@ -33,6 +34,10 @@ Singleton {
property bool dataActive property bool dataActive
property real cellularSignal property real cellularSignal
property bool flashlight property bool flashlight
// The first backlight, and its brightness from 0 to 1
property string backlight
property int maxBrightness
property real brightness
// From quadshell-location-agent, which only comes with the package // From quadshell-location-agent, which only comes with the package
property bool locationAvailable property bool locationAvailable
property bool location property bool location
@ -45,6 +50,23 @@ Singleton {
readonly property string flashlightLed: "white:flash" readonly property string flashlightLed: "white:flash"
readonly property string brightnessIcon: brightness > 0.67 ? "display-brightness-high-symbolic"
: brightness > 0.33 ? "display-brightness-medium-symbolic"
: "display-brightness-low-symbolic"
readonly property var sink: Pipewire.defaultAudioSink
readonly property var allSinks: Pipewire.nodes.values.filter(n => n.isSink && !n.isStream && n.audio) // qmllint disable missing-property
property var unavailableOutputs: []
// WirePlumber won't switch to an unavailable one, it just stays on the current sink
readonly property var sinks: allSinks.filter(n =>
!unavailableOutputs.includes(`${n.properties["device.id"]}:${n.properties["card.profile.device"]}`))
readonly property real volume: sink?.audio?.volume ?? 0
readonly property bool muted: sink?.audio?.muted ?? false
readonly property string volumeIcon: muted || volume === 0 ? "audio-volume-muted-symbolic"
: volume > 0.67 ? "audio-volume-high-symbolic"
: volume > 0.33 ? "audio-volume-medium-symbolic"
: "audio-volume-low-symbolic"
function signalLevel(strength) { function signalLevel(strength) {
if (strength > 0.8) return "excellent"; if (strength > 0.8) return "excellent";
if (strength > 0.6) return "good"; if (strength > 0.6) return "good";
@ -73,12 +95,38 @@ Singleton {
"sh", dataConnection, on ? "yes" : "no", on ? "up" : "down"]); "sh", dataConnection, on ? "yes" : "no", on ? "up" : "down"]);
} }
// logind lets the session set these without root
function logindBrightness(subsystem, device, value) {
return ["sh", "-c", `busctl call org.freedesktop.login1 \
"/org/freedesktop/login1/session/$(loginctl show-user "$USER" -p Display --value)" \
org.freedesktop.login1.Session SetBrightness ssu "$1" "$2" "$3"`,
"sh", subsystem, device, String(value)];
}
function setFlashlight(on) { function setFlashlight(on) {
flashlight = on; flashlight = on;
run(["sh", "-c", `busctl call org.freedesktop.login1 \ run(logindBrightness("leds", flashlightLed, on ? 255 : 0));
"/org/freedesktop/login1/session/$(loginctl show-user "$USER" -p Display --value)" \ }
org.freedesktop.login1.Session SetBrightness ssu leds "$1" "$2"`,
"sh", flashlightLed, on ? "255" : "0"]); function setBrightness(value) {
if (!backlight) return;
// All the way down would turn the screen off
brightness = Math.max(0.02, value);
if (!brightnessSetter.running) brightnessSetter.start();
}
function setVolume(value) {
if (!sink?.audio) return;
sink.audio.volume = value;
if (value > 0) sink.audio.muted = false;
}
function setMuted(on) {
if (sink?.audio) sink.audio.muted = on;
}
function setSink(node) {
Pipewire.preferredDefaultAudioSink = node;
} }
function setLocation(on) { function setLocation(on) {
@ -117,6 +165,25 @@ Singleton {
dataActive = values.active === "yes"; dataActive = values.active === "yes";
cellularSignal = (parseInt(values.signal) || 0) / 100; cellularSignal = (parseInt(values.signal) || 0) / 100;
flashlight = (parseInt(values.flashlight) || 0) > 0; flashlight = (parseInt(values.flashlight) || 0) > 0;
backlight = values.backlight ?? "";
maxBrightness = parseInt(values.maxBrightness) || 0;
// Not while it's being dragged, as this could be from before
if (maxBrightness > 0 && !brightnessSetter.running) brightness = (parseInt(values.brightness) || 0) / maxBrightness;
try {
// Like headphones that aren't plugged in, as "device:index", which sinks have as
// device.id and card.profile.device
const unavailable = [];
for (const device of JSON.parse(values.devices || "[]")) {
for (const route of device.info?.params?.EnumRoute ?? []) {
if (route.direction !== "Output" || route.available !== "no") continue;
for (const index of route.devices ?? []) unavailable.push(`${device.id}:${index}`);
}
}
unavailableOutputs = unavailable;
} catch (e) {
console.warn("Couldn't read PipeWire devices:", e);
}
try { try {
const outputs = Object.values(JSON.parse(values.outputs)); const outputs = Object.values(JSON.parse(values.outputs));
@ -141,6 +208,14 @@ Singleton {
fi fi
echo "signal=$(mmcli -m any -K 2>/dev/null | awk -F': *' '/signal-quality.value/ { print $2 }')" echo "signal=$(mmcli -m any -K 2>/dev/null | awk -F': *' '/signal-quality.value/ { print $2 }')"
echo "flashlight=$(cat /sys/class/leds/${root.flashlightLed}/brightness)" echo "flashlight=$(cat /sys/class/leds/${root.flashlightLed}/brightness)"
echo "devices=$(pw-dump -N Device | tr -d '\\n')"
for d in /sys/class/backlight/*; do
[ -e "$d/brightness" ] || continue
echo "backlight=$(basename "$d")"
echo "brightness=$(cat "$d/brightness")"
echo "maxBrightness=$(cat "$d/max_brightness")"
break
done
echo "outputs=$(niri msg -j outputs)" echo "outputs=$(niri msg -j outputs)"
`] `]
stdout: StdioCollector { stdout: StdioCollector {
@ -173,6 +248,20 @@ Singleton {
} }
} }
// Dragging the slider would start a process for every step, so this sends the latest at most
// this often
Timer {
id: brightnessSetter
interval: 50
onTriggered: Quickshell.execDetached(root.logindBrightness("backlight", root.backlight,
Math.round(root.brightness * root.maxBrightness)))
}
// Audio properties are only kept up to date for tracked nodes
PwObjectTracker {
objects: [root.sink, ...root.allSinks]
}
Timer { Timer {
id: refreshSoon id: refreshSoon
interval: 400 interval: 400

View file

@ -10,4 +10,5 @@ Panel Panel.qml
RoundButton RoundButton.qml RoundButton RoundButton.qml
Shade Shade.qml Shade Shade.qml
ShellIcon ShellIcon.qml ShellIcon ShellIcon.qml
Slider Slider.qml
Tile Tile.qml Tile Tile.qml