9c1e5c43819e718431d108e176ee165232ac9bc2
[dotfiles/.git] / .config / awesome / lain / wiki / alsa.md
1 ## Usage
2
3 [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
4
5 ### Description
6
7 Shows ALSA volume.
8
9 ```lua
10 local volume = lain.widget.alsa()
11 ```
12
13 ## Input table
14
15 Variable | Meaning | Type | Default
16 --- | --- | --- | ---
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
22
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`.
24
25 `settings` can use the following variables:
26
27 Variable | Meaning | Type | Values
28 --- | --- | --- | ---
29 `volume_now.level` | Volume level | integer | 0-100
30 `volume_now.status` | Device status | string | "on", "off"
31
32 ## Output table
33
34 Variable | Meaning | Type
35 --- | --- | ---
36 `widget` | The widget | `wibox.widget.textbox`
37 `channel` | ALSA channel | string
38 `update` | Update `widget` | function
39
40 ## Toggle channel
41
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.
43
44 For instance, if card number is 1 and S/PDIF number is 3:
45
46 ```shell
47 $ amixer -c 1 scontents
48 Simple mixer control 'Master',0
49   Capabilities: volume
50   Playback channels: Front Left - Front Right
51   Capture channels: Front Left - Front Right
52   Limits: 0 - 255
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
58   Mono: Playback [on]
59 Simple mixer control 'IEC958',1
60   Capabilities: pswitch pswitch-joined
61   Playback channels: Mono
62   Mono: Playback [on]
63 Simple mixer control 'IEC958',2
64   Capabilities: pswitch pswitch-joined
65   Playback channels: Mono
66   Mono: Playback [on]
67 Simple mixer control 'IEC958',3
68   Capabilities: pswitch pswitch-joined
69   Playback channels: Mono
70   Mono: Playback [on]
71 ```
72
73 you have to set `togglechannel = "IEC958,3"`.
74
75 ## Buttons
76
77 If you want buttons, just add the following after your widget in `rc.lua`.
78
79 ```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))
83     end),
84     awful.button({}, 2, function() -- middle click
85         os.execute(string.format("%s set %s 100%%", volume.cmd, volume.channel))
86         volume.update()
87     end),
88     awful.button({}, 3, function() -- right click
89         os.execute(string.format("%s set %s toggle", volume.cmd, volume.togglechannel or volume.channel))
90         volume.update()
91     end),
92     awful.button({}, 4, function() -- scroll up
93         os.execute(string.format("%s set %s 1%%+", volume.cmd, volume.channel))
94         volume.update()
95     end),
96     awful.button({}, 5, function() -- scroll down
97         os.execute(string.format("%s set %s 1%%-", volume.cmd, volume.channel))
98         volume.update()
99     end)
100 ))
101 ```
102
103 ## Keybindings
104
105 You can control the widget with keybindings like these:
106
107 ```lua
108 -- ALSA volume control
109 awful.key({ altkey }, "Up",
110         function ()
111                 os.execute(string.format("amixer set %s 1%%+", volume.channel))
112                 volume.update()
113         end),
114 awful.key({ altkey }, "Down",
115         function ()
116                 os.execute(string.format("amixer set %s 1%%-", volume.channel))
117                 volume.update()
118         end),
119 awful.key({ altkey }, "m",
120         function ()
121                 os.execute(string.format("amixer set %s toggle", volume.togglechannel or volume.channel))
122                 volume.update()
123         end),
124 awful.key({ altkey, "Control" }, "m",
125         function ()
126                 os.execute(string.format("amixer set %s 100%%", volume.channel))
127                 volume.update()
128         end),
129 awful.key({ altkey, "Control" }, "0",
130         function ()
131                 os.execute(string.format("amixer set %s 0%%", volume.channel))
132                 volume.update()
133         end),
134 ```
135
136 where `altkey = "Mod1"`.
137
138 ### Muting with PulseAudio
139
140 If you are using this widget in conjuction with PulseAudio, add the option `-D pulse` to the muting keybinding, like this:
141
142 ```lua
143 awful.key({ altkey }, "m",
144         function ()
145                 os.execute(string.format("amixer -D pulse set %s toggle", volume.togglechannel or volume.channel))
146                 volume.update()
147         end),
148 ```