Skip to content
Luke Bonham edited this page Jan 23, 2017 · 58 revisions

Shows and controls ALSA volume with a textbox.

volumewidget = lain.widgets.alsa()

Input table

Variable Meaning Type Default
timeout Refresh timeout seconds int 5
cmd Alsa mixer command string "amixer"
channel Mixer channel string "Master"
settings User settings function empty function

cmd is useful if you need to pass additional arguments to amixer. For instance, users with multiple sound cards may define cmd = "amixer -c X" in order to set amixer with card X.

settings can use the following variables:

Variable Meaning Type Values
volume_now.level Volume level int 0-100
volume_now.status Device status string "on", "off"

Output table

Variable Meaning Type
widget The widget wibox.widget.textbox
channel Alsa channel string
update Update widget function

Keybindings

You can control the widget with keybindings like these:

-- ALSA volume control
awful.key({ altkey }, "Up",
	function ()
		os.execute(string.format("amixer set %s 1%%+", volume.channel))
		volume.update()
	end),
awful.key({ altkey }, "Down",
	function ()
		os.execute(string.format("amixer set %s 1%%-", volume.channel))
		volume.update()
	end),
awful.key({ altkey }, "m",
	function ()
		os.execute(string.format("amixer set %s toggle", volume.channel))
		volume.update()
	end),
awful.key({ altkey, "Control" }, "m",
	function ()
		os.execute(string.format("amixer set %s 100%%", volume.channel))
		volume.update()
	end),
awful.key({ altkey, "Control" }, "0",
	function ()
		os.execute(string.format("amixer set %s 0%%", volume.channel))
		volume.update()
	end),

where altkey = "Mod1".

In case you are using an HDMI output, and mute can't be mapped to Master, redefine toggle keybinding with your S/PDIF device. You can get the correct ID device with scontents command.

For instance, if card number is 1 and S/PDF number is 3:

$ amixer -c1 scontents
Simple mixer control 'Master',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 255
  Front Left: 255 [100%]
  Front Right: 255 [100%]
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',1
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',2
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',3
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]

you have to set

awful.key({ altkey }, "m",
	function ()
		os.execute("amixer set IEC958,3 toggle")
		volume.update()
	end),
Clone this wiki locally