diff --git a/ags/scripts/arg-handler.ts b/ags/scripts/arg-handler.ts index cfbd589..ca93230 100644 --- a/ags/scripts/arg-handler.ts +++ b/ags/scripts/arg-handler.ts @@ -6,6 +6,8 @@ import { Runner } from "../runner/Runner"; import { showWorkspaceNumber } from "../widget/bar/Workspaces"; import AstalIO from "gi://AstalIO"; +import { playSystemBell } from "./utils"; +import { Config } from "./config"; let wsTimeout: (AstalIO.Time|undefined); @@ -113,30 +115,33 @@ function handleVolumeArgs(args: Array) { case "set": command[0] === "sink" ? Wireplumber.getDefault().setSinkVolume(Number.parseInt(args[2])) - : - Wireplumber.getDefault().setSourceVolume(Number.parseInt(args[2])) + : Wireplumber.getDefault().setSourceVolume(Number.parseInt(args[2])) return `Done! Set ${command[0]} volume to ${args[2]}`; case "mute": command[0] === "sink" ? Wireplumber.getDefault().toggleMuteSink() - : - Wireplumber.getDefault().toggleMuteSource() + : Wireplumber.getDefault().toggleMuteSource() + return `Done toggling mute!`; case "increase": command[0] === "sink" ? Wireplumber.getDefault().increaseSinkVolume(Number.parseInt(args[2])) - : - Wireplumber.getDefault().increaseSourceVolume(Number.parseInt(args[2])) + : Wireplumber.getDefault().increaseSourceVolume(Number.parseInt(args[2])) + + Config.getDefault().getProperty("misc.play_bell_on_volume_change", "boolean") === true && + playSystemBell(); return `Done increasing volume by ${args[2]}`; case "decrease": command[0] === "sink" ? Wireplumber.getDefault().decreaseSinkVolume(Number.parseInt(args[2])) - : - Wireplumber.getDefault().decreaseSourceVolume(Number.parseInt(args[2])) + : Wireplumber.getDefault().decreaseSourceVolume(Number.parseInt(args[2])) + + Config.getDefault().getProperty("misc.play_bell_on_volume_change", "boolean") === true && + playSystemBell(); return `Done decreasing volume to ${args[2]}`; } diff --git a/ags/scripts/config.ts b/ags/scripts/config.ts index 26eb125..2dec5d9 100644 --- a/ags/scripts/config.ts +++ b/ags/scripts/config.ts @@ -28,7 +28,7 @@ export type ConfigEntries = Partial<{ }>; clock: Partial<{ - /** use the same formats as gnu's `date` command */ + /** use the same format as gnu's `date` command */ date_format: string; }>; @@ -42,6 +42,10 @@ export type ConfigEntries = Partial<{ /** whether to save night light values to disk */ save_on_shutdown: boolean; }>; + + misc: Partial<{ + play_bell_on_volume_change: boolean; + }>; }>; type ValueTypes = "string" | "boolean" | "object" | "number" | "undefined" | "any"; @@ -79,6 +83,10 @@ class Config extends GObject.Object { clock: { date_format: "%A %d, %H:%M" + }, + + misc: { + play_bell_on_volume_change: true } }; diff --git a/ags/scripts/utils.ts b/ags/scripts/utils.ts index 918be90..375f6bd 100644 --- a/ags/scripts/utils.ts +++ b/ags/scripts/utils.ts @@ -92,6 +92,12 @@ export function deleteFile(path: string): void { execAsync([ "rm", "-r", path ]); } +export function playSystemBell(): void { + execAsync("canberra-gtk-play -i bell").catch((e: Error) => { + console.error(`Couldn't play system bell. Stderr: ${e.message}\n${e.stack}`); + }); +} + export function isInstalled(commandName: string): boolean { const proc = Gio.Subprocess.new(["bash", "-c", `command -v ${commandName}`], Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE);