From c05f5904cc2ba3bc62778c84d8d407e400a5f9e1 Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Fri, 4 Apr 2025 23:43:50 -0400 Subject: [PATCH] scroll volume --- widget/WirePlumber.tsx | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/widget/WirePlumber.tsx b/widget/WirePlumber.tsx index 518c0d5..f68ef68 100644 --- a/widget/WirePlumber.tsx +++ b/widget/WirePlumber.tsx @@ -2,11 +2,57 @@ import { bind, derive } from "astal"; import { Gdk } from "astal/gtk4"; import AstalWp from "gi://AstalWp"; +const volIncr = 5 / 100; + const WirePlumber = function () { const audio = AstalWp.get_default()?.audio!; const speakers = bind(audio, "speakers"); + return speakers.as((speakers) => { + const defaultSpeaker = speakers.find((speaker) => speaker.is_default); + if (!defaultSpeaker) { + return <>; + } + return ( + { + defaultSpeaker.set_volume( + Math.min(defaultSpeaker.volume + -Math.sign(dy) * volIncr, 1.0), + ); + }} + > + + ); + }); + return ( {speakers.as((speakers) => { @@ -25,6 +71,11 @@ const WirePlumber = function () { tooltipText={bind(defaultSpeaker, "description").as( (description) => description, )} + onScroll={(_, __, dy) => { + bind(defaultSpeaker, "volume").as((vol) => { + defaultSpeaker.set_volume(vol + Math.sign(dy) * volIncr); + }); + }} /> ); })}