diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2010-03-06 22:12:47 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2010-03-06 22:12:47 +0100 |
commit | 9371839401f89afacf6919671fff4a414b4bb841 (patch) | |
tree | 23cea127ebf91a5bd308bbbb2296bd90a15f9989 | |
parent | dbd6c7b03edf6250b2f5acdf054b3392ace243e9 (diff) | |
download | vicious-legacy-9371839401f89afacf6919671fff4a414b4bb841.tar.xz |
volume: added real mute support
Widge type returns 1st value as the volume level and 2nd as the mute
state of the requested channel represented as a symbol.
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | bat.lua | 8 | ||||
-rw-r--r-- | cpufreq.lua | 8 | ||||
-rw-r--r-- | volume.lua | 32 |
4 files changed, 33 insertions, 20 deletions
@@ -293,10 +293,11 @@ vicious.widgets.mpd - returns 1st value as the currently playing song vicious.widgets.volume - - provides volume levels of requested ALSA mixers + - provides volume levels and state of requested ALSA mixers - takes the ALSA mixer control as an argument, i.e. "Master", optionally append the card ID or other options, i.e. "PCM -c 0" - - returns 1st value as the volume level of the requested channel + - returns 1st value as the volume level and 2nd as the mute state of + the requested channel vicious.widgets.weather - provides weather information for a requested station @@ -24,10 +24,10 @@ local function worker(format, batid) -- Apple PMU and ACPI/procfs battery widgets are in the [contrib] branch local battery = helpers.pathtotable("/sys/class/power_supply/" .. batid) local battery_state = { - ["Full\n"] = "↯", - ["Unknown\n"] = "⌁", - ["Charged\n"] = "↯", - ["Charging\n"] = "+", + ["Full\n"] = "↯", + ["Unknown\n"] = "⌁", + ["Charged\n"] = "↯", + ["Charging\n"] = "+", ["Discharging\n"] = "-" } diff --git a/cpufreq.lua b/cpufreq.lua index 7c62455..aa36151 100644 --- a/cpufreq.lua +++ b/cpufreq.lua @@ -19,10 +19,10 @@ module("vicious.cpufreq") local function worker(format, cpuid) local cpufreq = helpers.pathtotable("/sys/devices/system/cpu/"..cpuid.."/cpufreq") local governor_state = { - ["ondemand\n"] = "↯", - ["powersave\n"] = "⌁", - ["userspace\n"] = "¤", - ["performance\n"] = "⚡", + ["ondemand\n"] = "↯", + ["powersave\n"] = "⌁", + ["userspace\n"] = "¤", + ["performance\n"] = "⚡", ["conservative\n"] = "↯" } -- Default voltage values @@ -7,31 +7,43 @@ local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable -local string = { - find = string.find, - match = string.match -} +local string = { match = string.match } -- }}} --- Volume: provides volume levels of requested ALSA mixers +-- Volume: provides volume levels and state of requested ALSA mixers module("vicious.volume") -- {{{ Volume widget type local function worker(format, warg) + local mixer_state = { + ["on"] = "♫", -- "", + ["off"] = "♩" -- "M" + } + -- Get mixer control contents local f = io.popen("amixer get " .. warg) local mixer = f:read("*all") f:close() - local vol = tonumber(string.match(mixer, "([%d]?[%d]?[%d])%%")) - -- If mute return 0 (not "Mute") so we don't break progressbars - if string.find(mixer, "%[off%]") or vol == nil then - vol = 0 + -- Capture mixer control state: [5%] ... ... [on] + local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") + -- Handle mixers without data + if volu == nil then + return {0, mixer_state["off"]} + end + + -- Handle mixers without mute + if mute == "" and volu == "0" + -- Handle mixers that are muted + or mute == "off" then + mute = mixer_state["off"] + else + mute = mixer_state["on"] end - return {vol} + return {tonumber(volu), mute} end -- }}} |