Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Input to Volume Module #246

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b8062cc
add new volume module options
painerp Sep 10, 2024
f06b3e3
implement volume module options
painerp Sep 10, 2024
aa48239
add volume theme options to all themes
painerp Sep 11, 2024
34f735f
add subtitle to hide_muted_label
painerp Sep 11, 2024
dd988f2
fix bind loop on volume hooks
painerp Sep 11, 2024
cf15fd6
consolidate volume percentage update parameters
painerp Sep 11, 2024
ebcbc37
Merge branch 'refs/heads/master' into volume-module-output
painerp Sep 17, 2024
6222e19
Merge branch 'refs/heads/master' into volume-module-output
painerp Sep 18, 2024
be01571
remove hooks, improve readability, lint & format code
painerp Sep 18, 2024
a7f2b26
lint volume bar settings
painerp Sep 18, 2024
0c02572
add right icon support for split style
painerp Sep 19, 2024
7235cef
add volume toggle side effects
painerp Sep 19, 2024
4cc74cc
Merge branch 'refs/heads/master' into volume-module-output
painerp Sep 19, 2024
17bdd85
fix volume children type
painerp Sep 21, 2024
2283904
Merge branch 'refs/heads/master' into volume-module-output
painerp Sep 21, 2024
b76ff47
remove input icon from split style and replace it with a toggle to sw…
painerp Oct 12, 2024
aa776b8
Merge branch 'refs/heads/master' into volume-module-output
painerp Oct 22, 2024
54e3bcd
add theme changes
painerp Oct 23, 2024
3cc0e57
lint volume bar index
painerp Oct 23, 2024
6e1a589
add missing rightClick option to volume bar index
painerp Oct 23, 2024
ad66cc7
Merge branch 'refs/heads/master' into volume-module-output
painerp Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 81 additions & 38 deletions modules/bar/volume/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,64 @@ import Gdk from 'gi://Gdk?version=3.0';
const audio = await Service.import('audio');
import { openMenu } from '../utils.js';
import options from 'options';
import { Binding } from 'lib/utils.js';
import { VolumeIcons } from 'lib/types/volume.js';
import { BarBoxChild } from 'lib/types/bar.js';
import { Bind } from 'lib/types/variable.js';
import Button from 'types/widgets/button.js';
import { Attribute, Child } from 'lib/types/widget.js';
import { runAsyncCommand, throttledScrollHandler } from 'customModules/utils.js';
import Separator from 'types/widgets/separator';
import Label from 'types/widgets/label';

const { rightClick, middleClick, scrollUp, scrollDown } = options.bar.volume;
const { label, input, input_label, rightClick, middleClick, scrollUp, scrollDown } = options.bar.volume;

const Volume = (): BarBoxChild => {
const icons: VolumeIcons = {
101: '󰕾',
const outputIcons: VolumeIcons = {
101: '󱄠',
66: '󰕾',
34: '󰖀',
1: '󰕿',
0: '󰝟',
};

const getIcon = (): Bind => {
const icon: Binding<number> = Utils.merge(
[audio.speaker.bind('is_muted'), audio.speaker.bind('volume')],
(isMuted, vol) => {
if (isMuted) return 0;

const foundVol = [101, 66, 34, 1, 0].find((threshold) => threshold <= vol * 100);

if (foundVol !== undefined) {
return foundVol;
}

return 101;
},
);
const inputIcons: VolumeIcons = {
51: '󰍬',
1: '󰍮',
0: '󰍭',
};

return icon.as((i: number) => (i !== undefined ? icons[i] : icons[101]));
const getIcon = (icons: VolumeIcons, volume: number, isMuted: boolean): string => {
const keys: number[] = Object.keys(icons).map(Number).reverse();
let icon: number;
if (isMuted) {
icon = 0;
} else {
icon = keys.find((threshold) => threshold <= Math.round(volume * 100)) ?? keys[0];
}
return icons[icon];
};

const volIcn = Widget.Label({
hexpand: true,
label: getIcon(),
class_name: 'bar-button-icon volume txt-icon bar',
});
const volIcn = (volume: number, isMuted: boolean, icons: VolumeIcons, class_name: string): Label<never> => {
return Widget.Label({
hexpand: true,
class_name: `bar-button-icon volume txt-icon bar ${class_name}`,
label: getIcon(icons, volume, isMuted),
});
};

const volPct = Widget.Label({
hexpand: true,
label: audio.speaker.bind('volume').as((v) => `${Math.round(v * 100)}%`),
class_name: 'bar-button-label volume',
});
const volPct = (volume: number, isMuted: boolean, class_name: string): Label<never> => {
return Widget.Label({
hexpand: true,
class_name: `bar-button-label volume ${class_name}`,
label: isMuted ? '0%' : `${Math.round(volume * 100)}%`,
});
};

return {
component: Widget.Box({
hexpand: true,
vexpand: true,
className: Utils.merge(
[options.theme.bar.buttons.style.bind('value'), options.bar.volume.label.bind('value')],
[options.theme.bar.buttons.style.bind('value'), label.bind('value')],
(style, showLabel) => {
const styleMap = {
default: 'style1',
Expand All @@ -68,12 +70,53 @@ const Volume = (): BarBoxChild => {
return `volume-container ${styleMap[style]} ${!showLabel ? 'no-label' : ''}`;
},
),
children: options.bar.volume.label.bind('value').as((showLabel) => {
if (showLabel) {
return [volIcn, volPct];
}
return [volIcn];
}),
children: Utils.merge(
[
audio.speaker.bind('volume'),
audio.speaker.bind('is_muted'),
audio.microphone.bind('volume'),
audio.microphone.bind('is_muted'),
label.bind('value'),
input.bind('value'),
input_label.bind('value'),
],
(
outputVolume,
outputIsMuted,
inputVolume,
inputIsMuted,
showOutputLabel,
showInputIcon,
showInputLabel,
) => {
const children: (Label<Child> | Separator<Child>)[] = [];
const outputMuted = outputIsMuted !== false || Math.round(outputVolume * 100) === 0;
const inputMuted = inputIsMuted !== false || Math.round(inputVolume * 100) === 0;
const showLabel = showOutputLabel || showInputLabel;

if (showInputIcon) {
children.push(
volIcn(inputVolume, inputMuted, inputIcons, `input ${!showLabel ? 'no-label' : ''}`),
);
} else {
children.push(
volIcn(outputVolume, outputMuted, outputIcons, `output ${!showLabel ? 'no-label' : ''}`),
);
}

if (showOutputLabel) {
children.push(volPct(outputVolume, outputMuted, `output`));
}

if (showInputLabel) {
if (showOutputLabel) {
children.push(Widget.Separator({ vertical: true, class_name: 'bar-separator volume' }));
}
children.push(volPct(inputVolume, inputMuted, `input`));
}
return children;
},
),
}),
isVisible: true,
boxClass: 'volume',
Expand Down
9 changes: 7 additions & 2 deletions options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ const options = mkOptions(OPTIONS, {
enableBorder: opt(false),
border: opt(colors.maroon),
background: opt(colors.base2),
text: opt(colors.maroon),
icon: opt(colors.maroon),
output_text: opt(colors.maroon),
output_icon: opt(colors.maroon),
input_text: opt(colors.maroon),
input_icon: opt(colors.maroon),
separator: opt(colors.surface1),
icon_background: opt(colors.base2),
spacing: opt('0.5em'),
},
Expand Down Expand Up @@ -881,6 +884,8 @@ const options = mkOptions(OPTIONS, {
},
volume: {
label: opt(true),
input: opt(false),
input_label: opt(false),
rightClick: opt(''),
middleClick: opt(''),
scrollUp: opt('pactl set-sink-volume @DEFAULT_SINK@ +5%'),
Expand Down
34 changes: 28 additions & 6 deletions scss/style/bar/audio.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
.bar-button-icon.volume {
font-size: 1.3em;
color: if($bar-buttons-monochrome, $bar-buttons-icon, $bar-buttons-volume-icon);
font-size: 1.3em;

&.output {
color: if($bar-buttons-monochrome, $bar-buttons-icon, $bar-buttons-volume-output-icon);
}

&.input {
color: if($bar-buttons-monochrome, $bar-buttons-icon, $bar-buttons-volume-input-icon);
}
}

.bar-button-label.volume {
color: if($bar-buttons-monochrome, $bar-buttons-text, $bar-buttons-volume-text);
min-width: 2.2em;
margin-left: $bar-buttons-volume-spacing;
min-width: 2.2em;
margin-left: $bar-buttons-volume-spacing;

&.output {
color: if($bar-buttons-monochrome, $bar-buttons-text, $bar-buttons-volume-output-text);
}

&.input {
color: if($bar-buttons-monochrome, $bar-buttons-text, $bar-buttons-volume-input-text);
}
}

.bar-separator.volume {
color: if($bar-buttons-monochrome, $bar-buttons-text, $bar-buttons-volume-separator);
margin-left: $bar-buttons-volume-spacing;
}

.style2 {
Expand All @@ -31,9 +50,12 @@

.bar-button-label.volume {
padding: $bar-buttons-padding_y 0em;
padding-right: $bar-buttons-padding_x;
padding-left: $bar-buttons-volume-spacing;
margin-left: 0em;

&.no-separator {
padding-right: $bar-buttons-padding_x;
}
}
&.no-label.volume-container {
.bar-button-icon.volume {
Expand Down
9 changes: 6 additions & 3 deletions themes/catppuccin_frappe.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@
"theme.bar.buttons.network.icon": "#ca9ee6",
"theme.bar.buttons.network.text": "#ca9ee6",
"theme.bar.buttons.network.background": "#303446",
"theme.bar.buttons.volume.icon": "#ea999c",
"theme.bar.buttons.volume.text": "#ea999c",
"theme.bar.buttons.volume.background": "#303446",
"theme.bar.buttons.windowtitle.icon": "#f4b8e4",
"theme.bar.buttons.windowtitle.text": "#f4b8e4",
Expand Down Expand Up @@ -337,5 +335,10 @@
"theme.bar.buttons.modules.submap.text": "#81c8be",
"theme.bar.buttons.modules.submap.border": "#81c8be",
"theme.bar.buttons.modules.submap.icon": "#81c8be",
"theme.bar.buttons.modules.submap.icon_background": "#303446"
"theme.bar.buttons.modules.submap.icon_background": "#303446",
"theme.bar.buttons.volume.output_icon": "#ea999c",
"theme.bar.buttons.volume.output_text": "#ea999c",
"theme.bar.buttons.volume.input_icon": "#ea999c",
"theme.bar.buttons.volume.input_text": "#ea999c",
"theme.bar.buttons.volume.separator": "#51576d"
}
9 changes: 6 additions & 3 deletions themes/catppuccin_frappe_split.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@
"theme.bar.buttons.network.icon": "#303446",
"theme.bar.buttons.network.text": "#ca9ee6",
"theme.bar.buttons.network.background": "#303446",
"theme.bar.buttons.volume.icon": "#303446",
"theme.bar.buttons.volume.text": "#ea999c",
"theme.bar.buttons.volume.background": "#303446",
"theme.bar.buttons.windowtitle.icon": "#303446",
"theme.bar.buttons.windowtitle.text": "#f4b8e4",
Expand Down Expand Up @@ -337,5 +335,10 @@
"theme.bar.buttons.modules.submap.text": "#81c8be",
"theme.bar.buttons.modules.submap.border": "#81c8be",
"theme.bar.buttons.modules.submap.icon": "#181825",
"theme.bar.buttons.modules.submap.icon_background": "#81c8be"
"theme.bar.buttons.modules.submap.icon_background": "#81c8be",
"theme.bar.buttons.volume.output_icon": "#303446",
"theme.bar.buttons.volume.output_text": "#ea999c",
"theme.bar.buttons.volume.input_icon": "#303446",
"theme.bar.buttons.volume.input_text": "#ea999c",
"theme.bar.buttons.volume.separator": "#51576d"
}
9 changes: 6 additions & 3 deletions themes/catppuccin_latte.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@
"theme.bar.buttons.network.icon": "#8839ef",
"theme.bar.buttons.network.text": "#8839ef",
"theme.bar.buttons.network.background": "#dcdfe8",
"theme.bar.buttons.volume.icon": "#e64553",
"theme.bar.buttons.volume.text": "#e64553",
"theme.bar.buttons.volume.background": "#dcdfe8",
"theme.bar.buttons.windowtitle.icon": "#ea76cb",
"theme.bar.buttons.windowtitle.text": "#ea76cb",
Expand Down Expand Up @@ -337,5 +335,10 @@
"theme.bar.buttons.modules.submap.text": "#179299",
"theme.bar.buttons.modules.submap.border": "#179299",
"theme.bar.buttons.modules.submap.icon": "#179299",
"theme.bar.buttons.modules.submap.icon_background": "#dcdfe8"
"theme.bar.buttons.modules.submap.icon_background": "#dcdfe8",
"theme.bar.buttons.volume.output_icon": "#e64553",
"theme.bar.buttons.volume.output_text": "#e64553",
"theme.bar.buttons.volume.input_icon": "#e64553",
"theme.bar.buttons.volume.input_text": "#e64553",
"theme.bar.buttons.volume.separator": "#bcc0cc"
}
9 changes: 6 additions & 3 deletions themes/catppuccin_latte_split.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@
"theme.bar.buttons.network.background": "#dcdfe8",
"theme.bar.buttons.network.border": "#8839ef",
"theme.bar.buttons.volume.icon_background": "#e64553",
"theme.bar.buttons.volume.icon": "#dcdee8",
"theme.bar.buttons.volume.text": "#e64553",
"theme.bar.buttons.volume.background": "#dcdfe8",
"theme.bar.buttons.volume.border": "#e64553",
"theme.bar.buttons.media.icon_background": "#7287fd",
Expand Down Expand Up @@ -337,5 +335,10 @@
"theme.bar.buttons.modules.submap.text": "#179299",
"theme.bar.buttons.modules.submap.border": "#179299",
"theme.bar.buttons.modules.submap.icon": "#181825",
"theme.bar.buttons.modules.submap.icon_background": "#179299"
"theme.bar.buttons.modules.submap.icon_background": "#179299",
"theme.bar.buttons.volume.output_icon": "#dcdfe8",
"theme.bar.buttons.volume.output_text": "#e64553",
"theme.bar.buttons.volume.input_icon": "#dcdfe8",
"theme.bar.buttons.volume.input_text": "#e64553",
"theme.bar.buttons.volume.separator": "#bcc0cc"
}
9 changes: 6 additions & 3 deletions themes/catppuccin_macchiato.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@
"theme.bar.buttons.network.icon": "#c6a0f6",
"theme.bar.buttons.network.text": "#c6a0f6",
"theme.bar.buttons.network.background": "#24273a",
"theme.bar.buttons.volume.icon": "#ee99a0",
"theme.bar.buttons.volume.text": "#ee99a0",
"theme.bar.buttons.volume.background": "#24273a",
"theme.bar.buttons.windowtitle.icon": "#f5bde6",
"theme.bar.buttons.windowtitle.text": "#f5bde6",
Expand Down Expand Up @@ -337,5 +335,10 @@
"theme.bar.buttons.modules.submap.text": "#8bd5ca",
"theme.bar.buttons.modules.submap.border": "#8bd5ca",
"theme.bar.buttons.modules.submap.icon": "#8bd5ca",
"theme.bar.buttons.modules.submap.icon_background": "#24273a"
"theme.bar.buttons.modules.submap.icon_background": "#24273a",
"theme.bar.buttons.volume.output_icon": "#ee99a0",
"theme.bar.buttons.volume.output_text": "#ee99a0",
"theme.bar.buttons.volume.input_icon": "#ee99a0",
"theme.bar.buttons.volume.input_text": "#ee99a0",
"theme.bar.buttons.volume.separator": "#494d64"
}
9 changes: 6 additions & 3 deletions themes/catppuccin_macchiato_split.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@
"theme.bar.buttons.network.icon": "#24273a",
"theme.bar.buttons.network.text": "#c6a0f6",
"theme.bar.buttons.network.background": "#24273a",
"theme.bar.buttons.volume.icon": "#24273a",
"theme.bar.buttons.volume.text": "#ee99a0",
"theme.bar.buttons.volume.background": "#24273a",
"theme.bar.buttons.windowtitle.icon": "#24273a",
"theme.bar.buttons.windowtitle.text": "#f5bde6",
Expand Down Expand Up @@ -337,5 +335,10 @@
"theme.bar.buttons.modules.submap.text": "#8bd5ca",
"theme.bar.buttons.modules.submap.border": "#8bd5ca",
"theme.bar.buttons.modules.submap.icon": "#181825",
"theme.bar.buttons.modules.submap.icon_background": "#8bd5ca"
"theme.bar.buttons.modules.submap.icon_background": "#8bd5ca",
"theme.bar.buttons.volume.output_icon": "#24273a",
"theme.bar.buttons.volume.output_text": "#ee99a0",
"theme.bar.buttons.volume.input_icon": "#24273a",
"theme.bar.buttons.volume.input_text": "#ee99a0",
"theme.bar.buttons.volume.separator": "#494d64"
}
7 changes: 5 additions & 2 deletions themes/catppuccin_mocha.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@
"theme.bar.buttons.network.background": "#242438",
"theme.bar.buttons.network.border": "#cba6f7",
"theme.bar.buttons.volume.icon_background": "#eba0ac",
"theme.bar.buttons.volume.icon": "#eba0ac",
"theme.bar.buttons.volume.text": "#eba0ac",
"theme.bar.buttons.volume.output_icon": "#eba0ac",
"theme.bar.buttons.volume.output_text": "#eba0ac",
"theme.bar.buttons.volume.input_icon": "#eba0ac",
"theme.bar.buttons.volume.input_text": "#eba0ac",
"theme.bar.buttons.volume.separator": "#45475a",
"theme.bar.buttons.volume.background": "#242438",
"theme.bar.buttons.volume.border": "#eba0ac",
"theme.bar.buttons.media.icon_background": "#b4befe",
Expand Down
7 changes: 5 additions & 2 deletions themes/catppuccin_mocha_split.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@
"theme.bar.buttons.network.icon": "#242438",
"theme.bar.buttons.network.text": "#cba6f7",
"theme.bar.buttons.network.background": "#242438",
"theme.bar.buttons.volume.icon": "#242438",
"theme.bar.buttons.volume.text": "#eba0ac",
"theme.bar.buttons.volume.output_icon": "#242438",
"theme.bar.buttons.volume.output_text": "#eba0ac",
"theme.bar.buttons.volume.input_icon": "#242438",
"theme.bar.buttons.volume.input_text": "#eba0ac",
"theme.bar.buttons.volume.separator": "#45475a",
"theme.bar.buttons.volume.background": "#242438",
"theme.bar.buttons.windowtitle.icon": "#1e1e2e",
"theme.bar.buttons.windowtitle.text": "#f5c2e7",
Expand Down
Loading
Loading