3 [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
10 local volume = lain.widget.alsa()
15 Variable | Meaning | Type | Default
17 `timeout` | Refresh timeout (in seconds) | integer | 5
18 `cmd` | Alsa mixer command | string | "amixer"
19 `channel` | Mixer channel | string | "Master"
20 `togglechannel` | Toggle channel | string | `nil`
21 `settings` | User settings | function | empty function
23 `cmd` is useful if you need to pass additional arguments to amixer. For instance, you may want to define `cmd = "amixer -c X"` in order to set amixer with card `X`.
25 `settings` can use the following variables:
27 Variable | Meaning | Type | Values
29 `volume_now.level` | Volume level | integer | 0-100
30 `volume_now.status` | Device status | string | "on", "off"
34 Variable | Meaning | Type
36 `widget` | The widget | `wibox.widget.textbox`
37 `channel` | ALSA channel | string
38 `update` | Update `widget` | function
42 In case mute toggling can't be mapped to master channel (this happens, for instance, when you are using an HDMI output), define togglechannel as your S/PDIF device. You can get the device ID with `scontents` command.
44 For instance, if card number is 1 and S/PDIF number is 3:
47 $ amixer -c 1 scontents
48 Simple mixer control 'Master',0
50 Playback channels: Front Left - Front Right
51 Capture channels: Front Left - Front Right
53 Front Left: 255 [100%]
54 Front Right: 255 [100%]
55 Simple mixer control 'IEC958',0
56 Capabilities: pswitch pswitch-joined
57 Playback channels: Mono
59 Simple mixer control 'IEC958',1
60 Capabilities: pswitch pswitch-joined
61 Playback channels: Mono
63 Simple mixer control 'IEC958',2
64 Capabilities: pswitch pswitch-joined
65 Playback channels: Mono
67 Simple mixer control 'IEC958',3
68 Capabilities: pswitch pswitch-joined
69 Playback channels: Mono
73 you have to set `togglechannel = "IEC958,3"`.
77 If you want buttons, just add the following after your widget in `rc.lua`.
80 volume.widget:buttons(awful.util.table.join(
81 awful.button({}, 1, function() -- left click
82 awful.spawn(string.format("%s -e alsamixer", terminal))
84 awful.button({}, 2, function() -- middle click
85 os.execute(string.format("%s set %s 100%%", volume.cmd, volume.channel))
88 awful.button({}, 3, function() -- right click
89 os.execute(string.format("%s set %s toggle", volume.cmd, volume.togglechannel or volume.channel))
92 awful.button({}, 4, function() -- scroll up
93 os.execute(string.format("%s set %s 1%%+", volume.cmd, volume.channel))
96 awful.button({}, 5, function() -- scroll down
97 os.execute(string.format("%s set %s 1%%-", volume.cmd, volume.channel))
105 You can control the widget with keybindings like these:
108 -- ALSA volume control
109 awful.key({ altkey }, "Up",
111 os.execute(string.format("amixer set %s 1%%+", volume.channel))
114 awful.key({ altkey }, "Down",
116 os.execute(string.format("amixer set %s 1%%-", volume.channel))
119 awful.key({ altkey }, "m",
121 os.execute(string.format("amixer set %s toggle", volume.togglechannel or volume.channel))
124 awful.key({ altkey, "Control" }, "m",
126 os.execute(string.format("amixer set %s 100%%", volume.channel))
129 awful.key({ altkey, "Control" }, "0",
131 os.execute(string.format("amixer set %s 0%%", volume.channel))
136 where `altkey = "Mod1"`.
138 ### Muting with PulseAudio
140 If you are using this widget in conjuction with PulseAudio, add the option `-D pulse` to the muting keybinding, like this:
143 awful.key({ altkey }, "m",
145 os.execute(string.format("amixer -D pulse set %s toggle", volume.togglechannel or volume.channel))