Skip to content

Commit 3c7e434

Browse files
authored
Merge pull request #460 from JakeStanger/feat/volume
Volume module
2 parents 947c314 + f0e34e6 commit 3c7e434

File tree

21 files changed

+1295
-7
lines changed

21 files changed

+1295
-7
lines changed

Diff for: .github/workflows/build.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Install build deps
3535
run: |
3636
sudo apt-get update
37-
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev
37+
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev libpulse-dev
3838
3939
- name: Clippy
4040
run: cargo clippy --no-default-features --features config+json
@@ -55,7 +55,7 @@ jobs:
5555
- name: Install build deps
5656
run: |
5757
sudo apt-get update
58-
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev
58+
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev libpulse-dev
5959
6060
- name: Clippy
6161
run: cargo clippy --all-targets --all-features
@@ -74,7 +74,7 @@ jobs:
7474
- name: Install build deps
7575
run: |
7676
sudo apt-get update
77-
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev
77+
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev libpulse-dev
7878
7979
- name: Build
8080
run: cargo build --verbose

Diff for: .github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install build deps
2121
run: |
2222
sudo apt-get update
23-
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev
23+
sudo apt-get install libgtk-3-dev libgtk-layer-shell-dev libpulse-dev
2424
2525
- name: Update CHANGELOG
2626
id: changelog

Diff for: Cargo.lock

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ default = [
2222
"sys_info",
2323
"tray",
2424
"upower",
25+
"volume",
2526
"workspaces+all"
2627
]
2728

@@ -62,6 +63,8 @@ tray = ["system-tray"]
6263

6364
upower = ["upower_dbus", "zbus", "futures-lite"]
6465

66+
volume = ["libpulse-binding"]
67+
6568
workspaces = ["futures-util"]
6669
"workspaces+all" = ["workspaces", "workspaces+sway", "workspaces+hyprland"]
6770
"workspaces+sway" = ["workspaces", "swayipc-async"]
@@ -132,6 +135,10 @@ upower_dbus = { version = "0.3.2", optional = true }
132135
futures-lite = { version = "2.2.0", optional = true }
133136
zbus = { version = "3.15.2", optional = true }
134137

138+
# volume
139+
libpulse-binding = { version = "2.28.1", optional = true }
140+
# libpulse-glib-binding = { version = "2.27.1", optional = true }
141+
135142
# workspaces
136143
swayipc-async = { version = "2.0.1", optional = true }
137144
hyprland = { version = "0.3.13", features = ["silent"], optional = true }
@@ -140,4 +147,4 @@ futures-util = { version = "0.3.30", optional = true }
140147
# shared
141148
regex = { version = "1.10.3", default-features = false, features = [
142149
"std",
143-
], optional = true } # music, sys_info
150+
], optional = true } # music, sys_info

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,4 @@ All are welcome, but I ask a few basic things to help make things easier. Please
183183
- [Rustbar](https://github.com/zeroeightysix/rustbar) - Served as a good demo for writing a basic GTK bar in Rust
184184
- [Smithay Client Toolkit](https://github.com/Smithay/client-toolkit) - Essential in being able to communicate to Wayland
185185
- [gtk-layer-shell](https://github.com/wmww/gtk-layer-shell) - Ironbar and many other projects would be impossible without this
186+
- [Mixxc](https://github.com/Elvyria/Mixxc) - Basis for Ironbar's PulseAudio client code and a cool standalone volume widget.

Diff for: docs/Compiling.md

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ You also need rust; only the latest stable version is supported.
2020
pacman -S gtk3 gtk-layer-shell
2121
# for http support
2222
pacman -S openssl
23+
# for volume support
24+
pacman -S libpulse
2325
```
2426

2527
### Ubuntu/Debian
@@ -28,6 +30,8 @@ pacman -S openssl
2830
apt install build-essential libgtk-3-dev libgtk-layer-shell-dev
2931
# for http support
3032
apt install libssl-dev
33+
# for volume support
34+
apt install libpulse-dev
3135
```
3236

3337
### Fedora
@@ -36,6 +40,8 @@ apt install libssl-dev
3640
dnf install gtk3-devel gtk-layer-shell-devel
3741
# for http support
3842
dnf install openssl-devel
43+
# for volume support
44+
dnf install libpulseaudio-devel
3945
```
4046

4147
## Features
@@ -81,6 +87,7 @@ cargo build --release --no-default-features \
8187
| sys_info | Enables the `sys_info` module. |
8288
| tray | Enables the `tray` module. |
8389
| upower | Enables the `upower` module. |
90+
| volume | Enables the `volume` module. |
8491
| workspaces+all | Enables the `workspaces` module with support for all compositors. |
8592
| workspaces+sway | Enables the `workspaces` module with support for Sway. |
8693
| workspaces+hyprland | Enables the `workspaces` module with support for Hyprland. |

Diff for: docs/_Sidebar.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
- [Sys_Info](sys-info)
3535
- [Tray](tray)
3636
- [Upower](upower)
37+
- [Volume](volume)
3738
- [Workspaces](workspaces)

Diff for: docs/modules/Volume.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Displays the current volume level.
2+
Clicking on the widget opens a volume mixer, which allows you to change the device output level,
3+
the default playback device, and control application volume levels individually.
4+
5+
This requires PulseAudio to function (`pipewire-pulse` is supported).
6+
7+
TODO: Screenshot
8+
9+
## Configuration
10+
11+
> Type: `volume`
12+
13+
| Name | Type | Default | Description |
14+
|-----------------------|----------|------------------------|----------------------------------------------------------------------------------------------------------------|
15+
| `format` | `string` | `{icon} {percentage}%` | Format string to use for the widget button label. |
16+
| `max_volume` | `float` | `100` | Maximum value to allow volume sliders to reach. Pulse supports values > 100 but this may result in distortion. |
17+
| `icons.volume_high` | `string` | `󰕾` | Icon to show for high volume levels. |
18+
| `icons.volume_medium` | `string` | `󰖀` | Icon to show for medium volume levels. |
19+
| `icons.volume_low` | `string` | `󰕿` | Icon to show for low volume levels. |
20+
| `icons.muted` | `string` | `󰝟` | Icon to show for muted outputs. |
21+
22+
<details>
23+
<summary>JSON</summary>
24+
25+
```json
26+
{
27+
"end": [
28+
{
29+
"type": "volume",
30+
"format": "{icon} {percentage}%",
31+
"max_volume": 100,
32+
"icons": {
33+
"volume_high": "󰕾",
34+
"volume_medium": "󰖀",
35+
"volume_low": "󰕿",
36+
"muted": "󰝟"
37+
}
38+
}
39+
]
40+
}
41+
42+
```
43+
44+
</details>
45+
46+
<details>
47+
<summary>TOML</summary>
48+
49+
```toml
50+
[[end]]
51+
type = "volume"
52+
format = "{icon} {percentage}%"
53+
max_volume = 100
54+
55+
[[end.icons]]
56+
volume_high = "󰕾"
57+
volume_medium = "󰖀"
58+
volume_low = "󰕿"
59+
muted = "󰝟"
60+
```
61+
62+
</details>
63+
64+
<details>
65+
<summary>YAML</summary>
66+
67+
```yaml
68+
end:
69+
- type: "volume"
70+
format: "{icon} {percentage}%"
71+
max_volume: 100
72+
icons:
73+
volume_high: "󰕾"
74+
volume_medium: "󰖀"
75+
volume_low: "󰕿"
76+
muted: "󰝟"
77+
```
78+
79+
</details>
80+
81+
<details>
82+
<summary>Corn</summary>
83+
84+
```corn
85+
{
86+
end = [
87+
{
88+
type = "volume"
89+
format = "{icon} {percentage}%"
90+
max_volume = 100
91+
icons.volume_high = "󰕾"
92+
icons.volume_medium = "󰖀"
93+
icons.volume_low = "󰕿"
94+
icons.muted = "󰝟"
95+
}
96+
]
97+
}
98+
```
99+
100+
</details>
101+
102+
### Formatting Tokens
103+
104+
The following tokens can be used in the `format` config option:
105+
106+
| Token | Description |
107+
|----------------|-------------------------------------------|
108+
| `{percentage}` | The active device volume percentage. |
109+
| `{icon}` | The icon representing the current volume. |
110+
| `{name}` | The active device name. |
111+
112+
## Styling
113+
114+
| Selector | Description |
115+
|----------------------------------------------|----------------------------------------------------|
116+
| `.volume` | Volume widget button. |
117+
| `.popup-volume` | Volume popup box. |
118+
| `.popup-volume .device-box` | Box for the device volume controls. |
119+
| `.popup-volume .device-box .device-selector` | Default device dropdown selector. |
120+
| `.popup-volume .device-box .slider` | Device volume slider. |
121+
| `.popup-volume .device-box .btn-mute` | Device volume mute toggle button. |
122+
| `.popup-volume .apps-box` | Parent box for the application volume controls. |
123+
| `.popup-volume .apps-box .app-box` | Box for an individual application volume controls. |
124+
| `.popup-volume .apps-box .app-box .title` | Name of the application playback stream. |
125+
| `.popup-volume .apps-box .app-box .slider` | Application volume slider. |
126+
| `.popup-volume .apps-box .app-box .btn-mute` | Application volume mute toggle button. |
127+
128+
For more information on styling, please see the [styling guide](styling-guide).

Diff for: examples/config.corn

+11-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ let {
6767

6868
$clipboard = { type = "clipboard" max_items = 3 truncate.mode = "end" truncate.length = 50 }
6969

70+
$volume = {
71+
type = "volume"
72+
format = "{icon} {volume}%"
73+
max_volume = 100
74+
icons.volume_high = "󰕾"
75+
icons.volume_medium = "󰖀"
76+
icons.volume_low = "󰕿"
77+
icons.muted = "󰝟"
78+
}
79+
7080
$label = { type = "label" label = "random num: {{500:echo FIXME}}" }
7181

7282
// -- begin custom --
@@ -100,7 +110,7 @@ let {
100110
// -- end custom --
101111

102112
$left = [ $workspaces $launcher $label ]
103-
$right = [ $mpd_local $mpd_server $phone_battery $sys_info $clipboard $power_menu $clock ]
113+
$right = [ $mpd_local $mpd_server $phone_battery $sys_info $volume $clipboard $power_menu $clock ]
104114
}
105115
in {
106116
anchor_to_edges = true

Diff for: examples/style.css

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ scale trough {
174174
margin-left: 10px;
175175
}
176176

177+
/* -- volume -- */
178+
179+
.popup-volume .device-box {
180+
border-right: 1px solid @color_border;
181+
}
177182

178183
/* -- workspaces -- */
179184

Diff for: flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
hicolor-icon-theme
128128
gsettings-desktop-schemas
129129
libxkbcommon
130+
libpulseaudio
130131
];
131132

132133
RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";

Diff for: nix/default.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
gtk-layer-shell,
1313
gnome,
1414
libxkbcommon,
15+
libpulseaudio,
1516
openssl,
1617
pkg-config,
1718
hicolor-icon-theme,
@@ -30,7 +31,7 @@
3031
path = lib.cleanSource ../.;
3132
};
3233
nativeBuildInputs = [pkg-config wrapGAppsHook gobject-introspection];
33-
buildInputs = [gtk3 gdk-pixbuf glib gtk-layer-shell glib-networking shared-mime-info gnome.adwaita-icon-theme hicolor-icon-theme gsettings-desktop-schemas libxkbcommon openssl];
34+
buildInputs = [gtk3 gdk-pixbuf glib gtk-layer-shell glib-networking shared-mime-info gnome.adwaita-icon-theme hicolor-icon-theme gsettings-desktop-schemas libxkbcommon libpulseaudio openssl];
3435
propagatedBuildInputs = [
3536
gtk3
3637
];

Diff for: src/bar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ fn add_modules(
392392
ModuleConfig::Tray(mut module) => add_module!(module, id),
393393
#[cfg(feature = "upower")]
394394
ModuleConfig::Upower(mut module) => add_module!(module, id),
395+
#[cfg(feature = "volume")]
396+
ModuleConfig::Volume(mut module) => add_module!(module, id),
395397
#[cfg(feature = "workspaces")]
396398
ModuleConfig::Workspaces(mut module) => add_module!(module, id),
397399
}

0 commit comments

Comments
 (0)