Reverted some changes from the last commits (see below)

In the pulseaudio widget:
- Renamed 'factory' to 'worker', to match other widgets.
- Removed lengthy sed explanation.
- Removed tooltip.
- Removed default settings.
This commit is contained in:
Calvin Timmer 2017-02-02 19:35:04 +01:00
parent 69baf55e0e
commit 58a060dfcb
1 changed files with 4 additions and 23 deletions

View File

@ -11,40 +11,22 @@ local awful = require("awful")
local wibox = require("wibox")
local string = { gmatch = string.gmatch,
match = string.match }
local setmetatable = setmetatable
-- PulseAudio volume
-- lain.widgets.pulseaudio
local function factory(args)
local function worker(args)
local pulseaudio = {}
local args = args or {}
local devicetype = args.devicetype or "sink"
local timeout = args.timeout or 5
local settings = args.settings or function() end
local scallback = args.scallback
local cmd = args.cmd or ("pacmd list-" .. devicetype .. "s | sed -n -e '/* index:/,/index:/ !d' -e '/* index:/ p' -e '/base volume:/ d' -e '/volume:/ p' -e '/muted:/ p' -e '/device\\.string/ p'")
-- sed script explanation:
-- '/* index:/,/index:/ !d' removes all lines outside of the range between the line containing '* index:' and the next line containing 'index:'. '* index:' denotes the beginning of the default device section.
-- '/* index:/ p' prints the line containing '* index:'.
-- '/base volume:/ d' removes the line containing 'base volume:'. This is necessary due to the following script.
-- '/volume:/ p' prints the line containing 'volume:'.
-- '/muted:/ p' prints the line containing 'muted:'.
-- '/device\\.string/ p' prints the line containing 'device.string:'.
local settings = args.settings or function()
widgettext = volume_now.left .. "%"
tooltiptext = volume_now.left .. "% (" .. devicetype .. " " .. volume_now.index .. " \"" .. volume_now.device .. "\")"
if volume_now.muted == "yes" then
widgettext = "Mute"
tooltiptext = "Mute/" .. tooltiptext
end
widget:set_text(widgettext)
tooltip:set_text(tooltiptext)
end
pulseaudio.widget = wibox.widget.textbox()
pulseaudio.tooltip = awful.tooltip({ objects = { pulseaudio.widget } })
function pulseaudio.update()
if scallback then cmd = scallback() end
@ -68,7 +50,6 @@ local function factory(args)
volume_now.right = volume_now.channel[2] or "N/A"
widget = pulseaudio.widget
tooltip = pulseaudio.tooltip
settings()
end)
@ -79,4 +60,4 @@ local function factory(args)
return pulseaudio
end
return factory
return setmetatable({}, { __call = function(_, ...) return worker(...) end })