From f69a0841a8bedf771dfcb9ae8bb9fec350fcf5d8 Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Thu, 27 Feb 2025 01:24:07 -0800 Subject: [PATCH] Create Microphone bar module. (#801) * Implement microphone module. * Add catppuccin themes * Add rest of themes * Fix comment * Add nix settings --- nix/module.nix | 2 + src/components/bar/exports.ts | 2 + src/components/bar/index.tsx | 2 + .../bar/modules/microphone/index.tsx | 76 ++ src/components/bar/settings/config.tsx | 17 + src/components/bar/settings/theme.tsx | 17 + src/options.ts | 19 + src/scss/style/bar/style.scss | 30 +- themes/catppuccin_frappe.json | 7 +- themes/catppuccin_frappe_split.json | 7 +- themes/catppuccin_frappe_vivid.json | 7 +- themes/catppuccin_latte.json | 7 +- themes/catppuccin_latte_split.json | 7 +- themes/catppuccin_latte_vivid.json | 7 +- themes/catppuccin_macchiato.json | 7 +- themes/catppuccin_macchiato_split.json | 7 +- themes/catppuccin_macchiato_vivid.json | 7 +- themes/catppuccin_mocha.json | 7 +- themes/catppuccin_mocha_split.json | 7 +- themes/catppuccin_mocha_vivid.json | 7 +- themes/cyberpunk.json | 7 +- themes/cyberpunk_split.json | 7 +- themes/cyberpunk_vivid.json | 7 +- themes/dracula.json | 7 +- themes/dracula_split.json | 7 +- themes/dracula_vivid.json | 7 +- themes/everforest.json | 7 +- themes/everforest_split.json | 7 +- themes/everforest_vivid.json | 7 +- themes/gruvbox.json | 7 +- themes/gruvbox_split.json | 7 +- themes/gruvbox_vivid.json | 7 +- themes/monochrome.json | 7 +- themes/monochrome_split.json | 7 +- themes/monochrome_vivid.json | 7 +- themes/nord.json | 7 +- themes/nord_split.json | 7 +- themes/nord_vivid.json | 7 +- themes/one_dark.json | 7 +- themes/one_dark_split.json | 7 +- themes/one_dark_vivid.json | 7 +- themes/rose_pine.json | 7 +- themes/rose_pine_moon.json | 7 +- themes/rose_pine_moon_split.json | 7 +- themes/rose_pine_moon_vivid.json | 7 +- themes/rose_pine_split.json | 7 +- themes/rose_pine_vivid.json | 7 +- themes/tokyo_night.json | 7 +- themes/tokyo_night_moon.json | 779 ++++++++--------- themes/tokyo_night_moon_split.json | 780 +++++++++--------- themes/tokyo_night_moon_vivid.json | 779 ++++++++--------- themes/tokyo_night_split.json | 7 +- themes/tokyo_night_vivid.json | 7 +- 53 files changed, 1592 insertions(+), 1205 deletions(-) create mode 100644 src/components/bar/modules/microphone/index.tsx diff --git a/nix/module.nix b/nix/module.nix index ca12dfa..1f1eaf5 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -466,6 +466,8 @@ in theme.bar.buttons.modules.kbLayout.enableBorder = mkBoolOption false; theme.bar.buttons.modules.kbLayout.spacing = mkStrOption "0.45em"; theme.bar.buttons.modules.netstat.enableBorder = mkBoolOption false; + theme.bar.buttons.modules.microphone.enableBorder = mkBoolOption false, + theme.bar.buttons.modules.microphone.spacing = mkStrOption "0.45em", theme.bar.buttons.modules.netstat.spacing = mkStrOption "0.45em"; theme.bar.buttons.modules.power.enableBorder = mkBoolOption false; theme.bar.buttons.modules.power.spacing = mkStrOption "0.45em"; diff --git a/src/components/bar/exports.ts b/src/components/bar/exports.ts index fc4f9b5..dbc3648 100644 --- a/src/components/bar/exports.ts +++ b/src/components/bar/exports.ts @@ -11,6 +11,7 @@ import { Clock } from '../../components/bar/modules/clock/index'; import { SysTray } from '../../components/bar/modules/systray/index'; // Custom Modules +import { Microphone } from '../../components/bar/modules/microphone/index'; import { Ram } from '../../components/bar/modules/ram/index'; import { Cpu } from '../../components/bar/modules/cpu/index'; import { CpuTemp } from '../../components/bar/modules/cputemp/index'; @@ -39,6 +40,7 @@ export { SysTray, // Custom Modules + Microphone, Ram, Cpu, CpuTemp, diff --git a/src/components/bar/index.tsx b/src/components/bar/index.tsx index 5246f98..115fd43 100644 --- a/src/components/bar/index.tsx +++ b/src/components/bar/index.tsx @@ -12,6 +12,7 @@ import { SysTray, // Custom Modules + Microphone, Ram, Cpu, CpuTemp, @@ -51,6 +52,7 @@ const widget = { bluetooth: (): JSX.Element => WidgetContainer(Bluetooth()), clock: (): JSX.Element => WidgetContainer(Clock()), systray: (): JSX.Element => WidgetContainer(SysTray()), + microphone: (): JSX.Element => WidgetContainer(Microphone()), ram: (): JSX.Element => WidgetContainer(Ram()), cpu: (): JSX.Element => WidgetContainer(Cpu()), cputemp: (): JSX.Element => WidgetContainer(CpuTemp()), diff --git a/src/components/bar/modules/microphone/index.tsx b/src/components/bar/modules/microphone/index.tsx new file mode 100644 index 0000000..6a3a8e8 --- /dev/null +++ b/src/components/bar/modules/microphone/index.tsx @@ -0,0 +1,76 @@ +import options from 'src/options'; +import { Module } from '../../shared/Module'; +import { bind, Variable } from 'astal'; +import { BarBoxChild } from 'src/lib/types/bar'; +import { Astal } from 'astal/gtk3'; +import { inputHandler } from '../../utils/helpers'; +import AstalWp from 'gi://AstalWp?version=0.1'; + +const wireplumber = AstalWp.get_default() as AstalWp.Wp; +const audioService = wireplumber.audio; + +const { label, mutedIcon, unmutedIcon, leftClick, rightClick, middleClick, scrollUp, scrollDown } = + options.bar.customModules.microphone; + +export const Microphone = (): BarBoxChild => { + const iconBinding = Variable.derive( + [ + bind(mutedIcon), + bind(unmutedIcon), + bind(audioService.defaultMicrophone, 'volume'), + bind(audioService.defaultMicrophone, 'mute'), + ], + (iconMuted, iconUnmuted, volume, isMuted) => { + if (isMuted || volume === 0) { + return iconMuted; + } + + return iconUnmuted; + }, + ); + + const tooltipBinding = Variable.derive( + [ + bind(mutedIcon), + bind(unmutedIcon), + bind(audioService.defaultMicrophone, 'description'), + bind(audioService.defaultMicrophone, 'volume'), + bind(audioService.defaultMicrophone, 'mute'), + ], + (iconMuted, iconUnmuted, description, volume, isMuted) => { + const icon = isMuted || !volume ? iconMuted : iconUnmuted; + + return `${icon} ${description}`; + }, + ); + const microphoneModule = Module({ + textIcon: iconBinding(), + label: bind(audioService.defaultMicrophone, 'volume').as((vol) => `${Math.round(vol * 100)}%`), + tooltipText: tooltipBinding(), + boxClass: 'mic', + showLabelBinding: bind(label), + props: { + setup: (self: Astal.Button) => { + inputHandler(self, { + onPrimaryClick: { + cmd: leftClick, + }, + onSecondaryClick: { + cmd: rightClick, + }, + onMiddleClick: { + cmd: middleClick, + }, + onScrollUp: { + cmd: scrollUp, + }, + onScrollDown: { + cmd: scrollDown, + }, + }); + }, + }, + }); + + return microphoneModule; +}; diff --git a/src/components/bar/settings/config.tsx b/src/components/bar/settings/config.tsx index 925dfa0..363255a 100644 --- a/src/components/bar/settings/config.tsx +++ b/src/components/bar/settings/config.tsx @@ -16,6 +16,23 @@ export const CustomModuleSettings = (): JSX.Element => {