massive update, probably broken
[dotfiles/.git] / .config / awesome / lain / wiki / pulse.md
1 ## Usage
2
3 [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
4
5 ### Description
6
7 Shows and controls PulseAudio volume.
8
9 ```lua
10 local volume = lain.widget.pulse()
11 ```
12
13 ## Input table
14
15 Variable | Meaning | Type | Default
16 --- | --- | --- | ---
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
21
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:
23
24 ```shell
25 * index: 0
26     volume: front-left: 18340 /  28% / -33.18 dB,   front-right: 18340 /  28% / -33.18 dB
27     muted: no
28     device.string = "front:1"
29 ```
30
31 If your devices change dynamically, you can define it as a function which returns a command string.
32
33 If sed doesn't work, you can try with a grep variant:
34
35 ```lua
36 cmd = "pacmd list-" .. pulse.devicetype .. "s | grep -e $(pactl info | grep -e 'ink' | cut -d' ' -f3) -e 'volume: front' -e 'muted'"
37 ```
38
39 ### `settings` variables
40
41 `settings` can use the following variables:
42
43 Variable | Meaning | Type | Values
44 --- | --- | --- | ---
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"
51
52 `volume_now.channel` is a table of your PulseAudio devices. Fetch a channel level like this: `volume_now.channel[i]`, where `i >= 1`.
53
54 `volume_now.{left,right}` are pointers for `volume_now.{channel[1], channel[2]}` (stereo).
55
56 ## Output table
57
58 Variable | Meaning | Type
59 --- | --- | ---
60 `widget` | The widget | `wibox.widget.textbox`
61 `update` | Update `widget` | function
62
63 ## Buttons
64
65 ```lua
66 volume.widget:buttons(awful.util.table.join(
67     awful.button({}, 1, function() -- left click
68         awful.spawn("pavucontrol")
69     end),
70     awful.button({}, 2, function() -- middle click
71         os.execute(string.format("pactl set-sink-volume %s 100%%", volume.device))
72         volume.update()
73     end),
74     awful.button({}, 3, function() -- right click
75         os.execute(string.format("pactl set-sink-mute %s toggle", volume.device))
76         volume.update()
77     end),
78     awful.button({}, 4, function() -- scroll up
79         os.execute(string.format("pactl set-sink-volume %s +1%%", volume.device))
80         volume.update()
81     end),
82     awful.button({}, 5, function() -- scroll down
83         os.execute(string.format("pactl set-sink-volume %s -1%%", volume.device))
84         volume.update()
85     end)
86 ))
87 ```
88
89 ## Keybindings
90
91 ```lua
92 -- PulseAudio volume control
93 awful.key({ altkey }, "Up",
94     function ()
95         os.execute(string.format("pactl set-sink-volume %s +1%%", volume.device))
96         volume.update()
97     end),
98 awful.key({ altkey }, "Down",
99     function ()
100         os.execute(string.format("pactl set-sink-volume %s -1%%", volume.device))
101         volume.update()
102     end),
103 awful.key({ altkey }, "m",
104     function ()
105         os.execute(string.format("pactl set-sink-mute %s toggle", volume.device))
106         volume.update()
107     end),
108 awful.key({ altkey, "Control" }, "m",
109     function ()
110         os.execute(string.format("pactl set-sink-volume %s 100%%", volume.device))
111         volume.update()
112     end),
113 awful.key({ altkey, "Control" }, "0",
114     function ()
115         os.execute(string.format("pactl set-sink-volume %s 0%%", volume.device))
116         volume.update()
117     end),
118 ```
119
120 where `altkey = "Mod1"`.
121
122 ## Example
123
124 ```lua
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"
131         end
132         widget:set_markup(lain.util.markup("#7493d2", vlevel))
133     end
134 }
135 ```