Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wibox = require("wibox")
- local awful = require("awful")
- volume_widget = wibox.widget.textbox()
- volume_widget:set_align("right")
- volume_widget:set_font("DejaVu Sans Mono 9")
- function update_volume(widget)
- -- The following approach uses io.popen() to launch external application
- -- It is not good, because it causes application lock
- -- We will use awful.util.pread() instead
- --local fd = io.popen("amixer sget Master")
- --local status = fd:read("*all")
- --fd:close()
- local status = awful.util.pread("amixer sget Master")
- -- Parse it
- local volume = string.match(status, "(%d?%d?%d)%%")
- volume = string.format("% 3d", volume)
- status = string.match(status, "%[(o[^%]]*)%]")
- if string.find(status, "on", 1, true) then
- -- For the volume numbers
- volume = volume .. "%"
- else
- -- For the mute button
- volume = volume .. "M"
- end
- widget:set_markup(volume)
- widget:buttons(awful.util.table.join(
- -- Left-click to toggle
- awful.button({ }, 1, function () awful.util.spawn_with_shell('amixer set Master toggle && echo "update_volume(volume_widget)" | awesome-client') end),
- -- Right-click to launch pavucontrol
- awful.button({ }, 3, function () awful.util.spawn("pavucontrol") end),
- -- Scroll to change volume
- awful.button({ }, 4, function () awful.util.spawn_with_shell('amixer set Master on 4%+ && echo "update_volume(volume_widget)" | awesome-client') end),
- awful.button({ }, 5, function () awful.util.spawn_with_shell('amixer set Master on 4%- && echo "update_volume(volume_widget)" | awesome-client') end)))
- end
- update_volume(volume_widget)
- -- Update every 5 seconds (widget data is updated automatically, when you change volume using keybinds defined in rc.lua. See Multimedia section in rc.lua)
- mytimer = timer({ timeout = 5 })
- mytimer:connect_signal("timeout", function () update_volume(volume_widget) end)
- mytimer:start()
Add Comment
Please, Sign In to add comment