ags(control-center/mixer): add per-app volume control to sliders

This commit is contained in:
retrozinndev
2025-04-23 12:03:36 -03:00
parent c6cb481b4d
commit ef474e9742
2 changed files with 129 additions and 58 deletions
+57 -58
View File
@@ -1,62 +1,61 @@
import { bind } from "astal"; import { bind } from "astal";
import { Gtk, Widget } from "astal/gtk3"; import { Gtk, Widget } from "astal/gtk3";
import { Wireplumber } from "../../scripts/volume"; import { Wireplumber } from "../../scripts/volume";
import { Pages } from "./Pages";
import { PageMixer } from "./pages/Mixer";
export const Sliders = () => new Widget.Box({ export function Sliders() {
className: "sliders", const slidersPages = new Pages();
orientation: Gtk.Orientation.VERTICAL,
expand: true, return new Widget.Box({
children: [ className: "sliders",
new Widget.Box({ orientation: Gtk.Orientation.VERTICAL,
className: "sink speaker", expand: true,
children: [ children: [
new Widget.Label({ new Widget.Box({
className: "nf icon", className: "sink speaker",
label: "󰕾" children: bind(Wireplumber.getWireplumber(), "defaultSpeaker").as((sink) => [
} as Widget.LabelProps), new Widget.Button({
new Widget.Slider({ className: "nf",
drawValue: false, label: bind(sink, "mute").as((muted) => !muted ? "󰕾" : "󰖁"),
hexpand: true, onClick: () => Wireplumber.getDefault().toggleMuteSink()
setup: (slider) => slider.set_value(Wireplumber.getDefault().getSinkVolume()), } as Widget.ButtonProps),
value: bind(Wireplumber.getDefault().getDefaultSink(), "volume").as((volume: number) => new Widget.Slider({
Math.floor(volume * 100)), drawValue: false,
max: Wireplumber.getDefault().getMaxSinkVolume(), hexpand: true,
onDragged: (slider: Gtk.Scale) => Wireplumber.getDefault().setSinkVolume(slider.get_value()) setup: (slider) => slider.value = Math.floor(sink.volume * 100),
} as Widget.SliderProps) value: bind(sink, "volume").as((vol) => Math.floor(vol * 100)),
] max: Wireplumber.getDefault().getMaxSinkVolume(),
} as Widget.BoxProps), onDragged: (slider) => sink.volume = slider.value / 100
new Widget.Box({ } as Widget.SliderProps),
className: "source microphone", new Widget.Button({
children: [ className: "more",
new Widget.Label({ image: new Widget.Icon({
className: "nf icon", icon: "go-next-symbolic",
label: "󰍬" } as Widget.IconProps),
} as Widget.LabelProps), onClick: (_) => slidersPages.toggle(PageMixer())
new Widget.Slider({ } as Widget.ButtonProps)
drawValue: false, ])
hexpand: true, } as Widget.BoxProps),
setup: (slider) => slider.set_value(Wireplumber.getDefault().getSourceVolume()), new Widget.Box({
value: bind(Wireplumber.getDefault().getDefaultSource(), "volume").as((volume: number) => className: "source microphone",
Math.floor(volume * 100)), children: bind(Wireplumber.getWireplumber(), "defaultMicrophone").as((source) => [
max: Wireplumber.getDefault().getMaxSourceVolume(), new Widget.Button({
onDragged: (slider: Gtk.Scale) => Wireplumber.getDefault().setSourceVolume(slider.get_value()) className: "nf",
} as Widget.SliderProps) label: bind(source, "mute").as((muted) => !muted ? "󰍬" : "󰍭"),
] onClick: () => Wireplumber.getDefault().toggleMuteSource()
} as Widget.BoxProps), } as Widget.ButtonProps),
/*new Widget.Box({ new Widget.Slider({
className: "brightness", drawValue: false,
children: [ hexpand: true,
new Widget.Label({ setup: (slider) => slider.set_value(Math.floor(source.volume * 100)),
className: "icon nf", value: bind(source, "volume").as((vol) => Math.floor(vol * 100)),
label: "󰃠" max: Wireplumber.getDefault().getMaxSourceVolume(),
} as Widget.LabelProps), onDragged: (slider) => source.volume = slider.value / 100
new Widget.Slider({ } as Widget.SliderProps)
drawValue: false, ])
hexpand: true, } as Widget.BoxProps),
value: 216, slidersPages
max: 255 ]
} as Widget.SliderProps) } as Widget.BoxProps);
] }
} as Widget.BoxProps)*/
]
} as Widget.BoxProps);
+72
View File
@@ -0,0 +1,72 @@
import { Page, PageProps } from "./Page";
import { bind } from "astal";
import { Gtk, Widget } from "astal/gtk3";
import AstalWp from "gi://AstalWp";
import { getAppIcon } from "../../../scripts/apps";
import { Wireplumber } from "../../../scripts/volume";
export function PageMixer(): Page {
return new Page({
id: "mixer",
title: "Mixer",
description: "Control per-application volume!",
children: bind(Wireplumber.getWireplumber(), "endpoints").as((endpoints) => [
...endpoints.filter((ep) => ep.mediaClass === AstalWp.MediaClass.AUDIO_STREAM ||
ep.mediaClass === AstalWp.MediaClass.VIDEO_STREAM).map((ep) =>
new Widget.EventBox({
hexpand: true,
setup: (eventbox) => {
const connections: Array<number> = [];
eventbox.add(new Widget.Box({
orientation: Gtk.Orientation.HORIZONTAL,
children: [
new Widget.Icon({
icon: getStreamIcon(ep) ?? "application-x-executable-symbolic",
css: "font-size: 18px; margin-right: 6px;"
} as Widget.IconProps),
new Widget.Box({
orientation: Gtk.Orientation.VERTICAL,
hexpand: true,
children: [
new Widget.Revealer({
transitionDuration: 180,
transitionType: Gtk.RevealerTransitionType.SLIDE_DOWN,
setup: (self) => connections.push(
eventbox.connect("hover", () => self.revealChild = true),
eventbox.connect("hover-lost", () => self.revealChild = false)
),
onDestroy: () => connections.map(id => eventbox.disconnect(id)),
child: new Widget.Label({
label: ep.name || "Unknown",
className: "name",
xalign: 0
} as Widget.LabelProps)
} as Widget.RevealerProps),
new Widget.Slider({
min: 0,
drawValue: false,
max: 100,
setup: (self) => self.value = Math.floor(ep.volume * 100),
value: bind(ep, "volume").as((vol) => Math.floor(vol * 100)),
onDragged: (self) => ep.volume = self.value / 100
} as Widget.SliderProps)
]
} as Widget.BoxProps)
]
} as Widget.BoxProps))
}
} as Widget.EventBoxProps)
)
])
} as PageProps);
}
function getStreamIcon(endpoint: AstalWp.Endpoint): (string|undefined) {
let icon = getAppIcon(endpoint.icon);
if(icon) return icon;
icon = getAppIcon(endpoint.name.split(' ')[0]);
if(icon) return icon;
return undefined;
}