Skip to content

Commit

Permalink
ags: add volume slider
Browse files Browse the repository at this point in the history
  • Loading branch information
brckd committed Jul 1, 2024
1 parent 150a3f1 commit 9f4b847
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions modules/home/ags/style/main.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import "bar.scss";
@import "slider.scss";
3 changes: 3 additions & 0 deletions modules/home/ags/style/slider.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.slider {
min-width: 200px;
}
16 changes: 10 additions & 6 deletions modules/home/ags/widget/Bar.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import GLib from "gi://GLib";
import VolumeSlider from "./VolumeSlider";

export const clock = Variable(GLib.DateTime.new_now_local(), {
poll: [1000, () => GLib.DateTime.new_now_local()],
})
poll: [1000, () => GLib.DateTime.new_now_local()],
});

export const time = Utils.derive([clock], (c) => c.format("%B %d - %H:%M") ?? "")
export const time = Utils.derive(
[clock],
(c) => c.format("%B %d - %H:%M") ?? "",
);

export const Start = () =>
Widget.Box({
Expand All @@ -17,15 +21,15 @@ export const Center = () =>
Widget.Box({
hpack: "center",
child: Widget.Label({
label: time.bind(),
})
label: time.bind(),
}),
});

export const End = () =>
Widget.Box({
hexpand: true,
hpack: "end",
child: Widget.Icon("nixos-symbolic"),
child: VolumeSlider(),
});

export const Bar = (monitor = 0) =>
Expand Down
20 changes: 20 additions & 0 deletions modules/home/ags/widget/VolumeSlider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const audio = await Service.import("audio");

export const VolumeSlider = (type: "speaker" | "microphone" = "speaker") =>
Widget.Box({
children: [
Widget.Label({
label: audio[type].bind("volume").transform(v => Math.round(v * 100).toString()),
}),
Widget.Slider({
className: "slider",
hexpand: true,
drawValue: false,

onChange: ({ value }) => (audio[type].volume = value),
value: audio[type].bind("volume"),
}),
],
});

export default VolumeSlider;

0 comments on commit 9f4b847

Please sign in to comment.