awesome-wm-widgets/_widgets/volume-widget.md

123 lines
4.7 KiB
Markdown
Raw Normal View History

---
layout: page
---
# Volume widget
2021-04-13 03:39:49 +02:00
Volume widget based on [amixer](https://linux.die.net/man/1/amixer) (is used for controlling the audio volume) and [pacmd](https://linux.die.net/man/1/pacmd) (is used for selecting a sink/source). Also, the widget provides an easy way to customize how it looks, following types are supported out-of-the-box:
2021-04-13 03:39:49 +02:00
![types](screenshots/variations.png)
2021-04-13 03:39:49 +02:00
From left to right: `horizontal_bar`, `vertical_bar`, `icon`, `icon_and_text`, `arc`
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
A right-click on the widget opens a popup where you can choose a sink/source:
![sink-sources](screenshots/volume-sink-sources.png)
2022-01-24 01:17:02 +01:00
Left click toggles mute and middle click opens a mixer ([pavucontrol](https://freedesktop.org/software/pulseaudio/pavucontrol/) by default).
2021-04-13 03:39:49 +02:00
### Features
2018-09-25 01:18:45 +02:00
2022-01-24 01:17:02 +01:00
- switch between sinks/sources by right click on the widget;
2021-04-13 03:39:49 +02:00
- more responsive than previous versions of volume widget, which were refreshed once a second;
- 5 predefined customizable looks;
2018-09-25 01:18:45 +02:00
2021-04-13 03:39:49 +02:00
## Installation
2021-04-13 03:39:49 +02:00
Clone the repo under **~/.config/awesome/** and add widget in **rc.lua**:
2018-09-15 23:33:42 +02:00
```lua
2021-04-13 03:39:49 +02:00
local volume_widget = require('awesome-wm-widgets.volume-widget.volume')
...
2021-04-13 03:39:49 +02:00
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
-- default
volume_widget(),
-- customized
volume_widget{
2022-01-24 01:17:02 +01:00
widget_type = 'arc'
2021-04-13 03:39:49 +02:00
},
2020-04-03 04:23:07 +02:00
```
2022-01-24 01:17:02 +01:00
Note that widget uses following command the get the current volume: `amixer -D pulse sget Master`, so please make sure that it works for you, otherwise you need to set parameter `device = 'default'`.
2021-04-13 03:39:49 +02:00
### Shortcuts
2020-04-03 04:23:07 +02:00
2021-04-13 03:39:49 +02:00
To improve responsiveness of the widget when volume level is changed by a shortcut use corresponding methods of the widget:
2020-04-03 04:23:07 +02:00
```lua
2022-01-24 01:17:02 +01:00
awful.key({ modkey }, "]", function() volume_widget:inc(5) end),
awful.key({ modkey }, "[", function() volume_widget:dec(5) end),
2021-04-13 03:39:49 +02:00
awful.key({ modkey }, "\\", function() volume_widget:toggle() end),
2018-09-15 23:33:42 +02:00
```
2021-04-13 03:39:49 +02:00
## Customization
2020-04-03 04:23:07 +02:00
2021-04-13 03:39:49 +02:00
It is possible to customize the widget by providing a table with all or some of the following config parameters:
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
### Generic parameter
2021-04-13 03:39:49 +02:00
| Name | Default | Description |
|---|---|---|
2022-01-24 01:17:02 +01:00
| `mixer_cmd` | `pavucontrol` | command to run on middle click (e.g. a mixer program) |
| `step` | `5` | How much the volume is raised or lowered at once (in %) |
| `widget_type`| `icon_and_text`| Widget type, one of `horizontal_bar`, `vertical_bar`, `icon`, `icon_and_text`, `arc` |
| `device` | `pulse` | Select the device name to control |
2019-12-15 21:38:54 +01:00
2022-01-24 01:17:02 +01:00
Depends on the chosen widget type add parameters from the corresponding section below:
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
#### `icon` parameters
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
| Name | Default | Description |
|---|---|---|
| `icon_dir`| `./icons`| Path to the folder with icons |
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
_Note:_ if you are changing icons, the folder should contain following .svg images:
- audio-volume-high-symbolic
- audio-volume-medium-symbolic
- audio-volume-low-symbolic
- audio-volume-muted-symbolic
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
#### `icon_and_text` parameters
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
| Name | Default | Description |
|---|---|---|
| `icon_dir`| `./icons`| Path to the folder with icons |
| `font` | `beautiful.font` | Font name and size, like `Play 12` |
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
#### `arc` parameters
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
| Name | Default | Description |
|---|---|---|
| `thickness` | 2 | Thickness of the arc |
| `main_color` | `beautiful.fg_color` | Color of the arc |
| `bg_color` | `#ffffff11` | Color of the arc's background |
| `mute_color` | `beautiful.fg_urgent` | Color of the arc when mute |
| `size` | 18 | Size of the widget |
2019-12-15 21:38:54 +01:00
2021-04-13 03:39:49 +02:00
#### `horizontal_bar` parameters
| Name | Default | Description |
|---|---|---|
| `main_color` | `beautiful.fg_normal` | Color of the bar |
| `mute_color` | `beautiful.fg_urgent` | Color of the bar when mute |
| `bg_color` | `'#ffffff11'` | Color of the bar's background |
| `width` | `50` | The bar width |
| `margins` | `10` | Top and bottom margins (if your wibar is 22 px high, bar will be 2 px = 22 - 2*10) |
| `shape` | `'bar'` | [gears.shape](https://awesomewm.org/doc/api/libraries/gears.shape.html), could be `octogon`, `hexagon`, `powerline`, etc |
| `with_icon` | `true` | Show volume icon|
_Note:_ I didn't figure out how does the `forced_height` property of progressbar widget work (maybe it doesn't work at all), thus there is a workaround with margins.
#### `vertical_bar` parameters
| Name | Default | Description |
|---|---|---|
| `main_color` | `beautiful.fg_normal` | Color of the bar |
| `mute_color` | `beautiful.fg_urgent` | Color of the bar when mute |
| `bg_color` | `'#ffffff11'` | Color of the bar's background |
| `width` | `10` | The bar width |
| `margins` | `20` | Top and bottom margins (if your wibar is 22 px high, bar will be 2 px = 22 - 2*10) |
| `shape` | `'bar'` | [gears.shape](https://awesomewm.org/doc/api/libraries/gears.shape.html), could be `octogon`, `hexagon`, `powerline`, etc |
| `with_icon` | `true` | Show volume icon|