3 [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
7 Shows and controls PulseAudio volume.
10 local volume = lain.widget.pulse()
15 Variable | Meaning | Type | Default
17 `timeout` | Refresh timeout (in seconds) | integer | 5
18 `devicetype` | PulseAudio device type | string ("sink", "source") | "sink"
19 `cmd` | PulseAudio command | string or function | see [here](https://github.com/lcpz/lain/blob/master/widget/pulse.lua#L26)
20 `settings` | User settings | function | empty function
22 `cmd` is a terminal command to catch infos from current default device. You can redefine it, being sure that the ouput is something like this:
26 volume: front-left: 18340 / 28% / -33.18 dB, front-right: 18340 / 28% / -33.18 dB
28 device.string = "front:1"
31 If your devices change dynamically, you can define it as a function which returns a command string.
33 If sed doesn't work, you can try with a grep variant:
36 cmd = "pacmd list-" .. pulse.devicetype .. "s | grep -e $(pactl info | grep -e 'ink' | cut -d' ' -f3) -e 'volume: front' -e 'muted'"
39 ### `settings` variables
41 `settings` can use the following variables:
43 Variable | Meaning | Type | Values
45 `volume_now.device` | Device name | string | device name or "N/A"
46 `volume_now.index` | Device index | string | >= "0"
47 `volume_now.muted` | Device mute status | string | "yes", "no", "N/A"
48 `volume_now.channel` | Device channels | table of string integers | `volume_now.channel[i]`, where `i >= 1`
49 `volume_now.left` | Front left sink level or first source | string | "0"-"100"
50 `volume_now.right` | Front right sink level or second source | string | "0"-"100"
52 `volume_now.channel` is a table of your PulseAudio devices. Fetch a channel level like this: `volume_now.channel[i]`, where `i >= 1`.
54 `volume_now.{left,right}` are pointers for `volume_now.{channel[1], channel[2]}` (stereo).
58 Variable | Meaning | Type
60 `widget` | The widget | `wibox.widget.textbox`
61 `update` | Update `widget` | function
66 volume.widget:buttons(awful.util.table.join(
67 awful.button({}, 1, function() -- left click
68 awful.spawn("pavucontrol")
70 awful.button({}, 2, function() -- middle click
71 os.execute(string.format("pactl set-sink-volume %s 100%%", volume.device))
74 awful.button({}, 3, function() -- right click
75 os.execute(string.format("pactl set-sink-mute %s toggle", volume.device))
78 awful.button({}, 4, function() -- scroll up
79 os.execute(string.format("pactl set-sink-volume %s +1%%", volume.device))
82 awful.button({}, 5, function() -- scroll down
83 os.execute(string.format("pactl set-sink-volume %s -1%%", volume.device))
92 -- PulseAudio volume control
93 awful.key({ altkey }, "Up",
95 os.execute(string.format("pactl set-sink-volume %s +1%%", volume.device))
98 awful.key({ altkey }, "Down",
100 os.execute(string.format("pactl set-sink-volume %s -1%%", volume.device))
103 awful.key({ altkey }, "m",
105 os.execute(string.format("pactl set-sink-mute %s toggle", volume.device))
108 awful.key({ altkey, "Control" }, "m",
110 os.execute(string.format("pactl set-sink-volume %s 100%%", volume.device))
113 awful.key({ altkey, "Control" }, "0",
115 os.execute(string.format("pactl set-sink-volume %s 0%%", volume.device))
120 where `altkey = "Mod1"`.
125 -- PulseAudio volume (based on multicolor theme)
126 local volume = lain.widget.pulse {
127 settings = function()
128 vlevel = volume_now.left .. "-" .. volume_now.right .. "% | " .. volume_now.device
129 if volume_now.muted == "yes" then
130 vlevel = vlevel .. " M"
132 widget:set_markup(lain.util.markup("#7493d2", vlevel))