diff --git a/util/Mathf.ts b/util/Mathf.ts
new file mode 100644
index 0000000..4c4157a
--- /dev/null
+++ b/util/Mathf.ts
@@ -0,0 +1,12 @@
+export const Mathf = {
+ clamp: (value: number, min: number, max: number) => {
+ if (value < min) return min;
+ if (value > max) return max;
+ return value;
+ },
+ sign: (value: number) => {
+ if (value > 0) return 1;
+ if (value < 0) return -1;
+ return 0;
+ },
+};
diff --git a/widget/WirePlumber.tsx b/widget/WirePlumber.tsx
index f68ef68..e7d4f62 100644
--- a/widget/WirePlumber.tsx
+++ b/widget/WirePlumber.tsx
@@ -1,8 +1,7 @@
import { bind, derive } from "astal";
import { Gdk } from "astal/gtk4";
import AstalWp from "gi://AstalWp";
-
-const volIncr = 5 / 100;
+import { Mathf } from "../util/Mathf";
const WirePlumber = function () {
const audio = AstalWp.get_default()?.audio!;
@@ -18,7 +17,11 @@ const WirePlumber = function () {
{
defaultSpeaker.set_volume(
- Math.min(defaultSpeaker.volume + -Math.sign(dy) * volIncr, 1.0),
+ Mathf.clamp(
+ defaultSpeaker.volume - Mathf.sign(dy) * 0.02,
+ 0.0,
+ 1.0,
+ ),
);
}}
>
@@ -52,53 +55,6 @@ const WirePlumber = function () {
);
});
-
- return (
-
- {speakers.as((speakers) => {
- const defaultSpeaker = speakers.find((speaker) => speaker.is_default);
- if (!defaultSpeaker) {
- return <>>;
- }
- return (
-
- );
};
export default WirePlumber;