My configuration files for Debian/Ubuntu applications
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pulse.md 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ## Usage
  2. [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
  3. ### Description
  4. Shows and controls PulseAudio volume.
  5. ```lua
  6. local volume = lain.widget.pulse()
  7. ```
  8. ## Input table
  9. Variable | Meaning | Type | Default
  10. --- | --- | --- | ---
  11. `timeout` | Refresh timeout (in seconds) | integer | 5
  12. `devicetype` | PulseAudio device type | string ("sink", "source") | "sink"
  13. `cmd` | PulseAudio command | string or function | see [here](https://github.com/lcpz/lain/blob/master/widget/pulse.lua#L26)
  14. `settings` | User settings | function | empty function
  15. `widget` | Widget to render | function | `wibox.widget.textbox`
  16. `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:
  17. ```shell
  18. * index: 0
  19. volume: front-left: 18340 / 28% / -33.18 dB, front-right: 18340 / 28% / -33.18 dB
  20. muted: no
  21. device.string = "front:1"
  22. ```
  23. If your devices change dynamically, you can define it as a function which returns a command string.
  24. If sed doesn't work, you can try with a grep variant:
  25. ```lua
  26. cmd = "pacmd list-" .. pulse.devicetype .. "s | grep -e $(pactl info | grep -e 'ink' | cut -d' ' -f3) -e 'volume: front' -e 'muted'"
  27. ```
  28. ### `settings` variables
  29. `settings` can use the following variables:
  30. Variable | Meaning | Type | Values
  31. --- | --- | --- | ---
  32. `volume_now.device` | Device name | string | device name or "N/A"
  33. `volume_now.index` | Device index | string | >= "0"
  34. `volume_now.muted` | Device mute status | string | "yes", "no", "N/A"
  35. `volume_now.channel` | Device channels | table of string integers | `volume_now.channel[i]`, where `i >= 1`
  36. `volume_now.left` | Front left sink level or first source | string | "0"-"100"
  37. `volume_now.right` | Front right sink level or second source | string | "0"-"100"
  38. `volume_now.channel` is a table of your PulseAudio devices. Fetch a channel level like this: `volume_now.channel[i]`, where `i >= 1`.
  39. `volume_now.{left,right}` are pointers for `volume_now.{channel[1], channel[2]}` (stereo).
  40. ## Output table
  41. Variable | Meaning | Type
  42. --- | --- | ---
  43. `widget` | The widget | `wibox.widget.textbox`
  44. `update` | Update `widget` | function
  45. ## Buttons
  46. ```lua
  47. volume.widget:buttons(awful.util.table.join(
  48. awful.button({}, 1, function() -- left click
  49. awful.spawn("pavucontrol")
  50. end),
  51. awful.button({}, 2, function() -- middle click
  52. os.execute(string.format("pactl set-sink-volume %s 100%%", volume.device))
  53. volume.update()
  54. end),
  55. awful.button({}, 3, function() -- right click
  56. os.execute(string.format("pactl set-sink-mute %s toggle", volume.device))
  57. volume.update()
  58. end),
  59. awful.button({}, 4, function() -- scroll up
  60. os.execute(string.format("pactl set-sink-volume %s +1%%", volume.device))
  61. volume.update()
  62. end),
  63. awful.button({}, 5, function() -- scroll down
  64. os.execute(string.format("pactl set-sink-volume %s -1%%", volume.device))
  65. volume.update()
  66. end)
  67. ))
  68. ```
  69. ## Keybindings
  70. ```lua
  71. -- PulseAudio volume control
  72. awful.key({ altkey }, "Up",
  73. function ()
  74. os.execute(string.format("pactl set-sink-volume %s +1%%", volume.device))
  75. volume.update()
  76. end),
  77. awful.key({ altkey }, "Down",
  78. function ()
  79. os.execute(string.format("pactl set-sink-volume %s -1%%", volume.device))
  80. volume.update()
  81. end),
  82. awful.key({ altkey }, "m",
  83. function ()
  84. os.execute(string.format("pactl set-sink-mute %s toggle", volume.device))
  85. volume.update()
  86. end),
  87. awful.key({ altkey, "Control" }, "m",
  88. function ()
  89. os.execute(string.format("pactl set-sink-volume %s 100%%", volume.device))
  90. volume.update()
  91. end),
  92. awful.key({ altkey, "Control" }, "0",
  93. function ()
  94. os.execute(string.format("pactl set-sink-volume %s 0%%", volume.device))
  95. volume.update()
  96. end),
  97. ```
  98. where `altkey = "Mod1"`.
  99. ## Example
  100. ```lua
  101. -- PulseAudio volume (based on multicolor theme)
  102. local volume = lain.widget.pulse {
  103. settings = function()
  104. vlevel = volume_now.left .. "-" .. volume_now.right .. "% | " .. volume_now.device
  105. if volume_now.muted == "yes" then
  106. vlevel = vlevel .. " M"
  107. end
  108. widget:set_markup(lain.util.markup("#7493d2", vlevel))
  109. end
  110. }
  111. ```