2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2010-01-02 21:21:54 +01:00
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2009-10-26 20:32:48 +01:00
|
|
|
local tonumber = tonumber
|
2009-08-01 23:11:41 +02:00
|
|
|
local setmetatable = setmetatable
|
2010-03-06 22:12:47 +01:00
|
|
|
local string = { match = string.match }
|
2019-05-14 09:33:09 +02:00
|
|
|
local table = { concat = table.concat }
|
|
|
|
|
2014-11-12 23:43:24 +01:00
|
|
|
local helpers = require("vicious.helpers")
|
2019-05-13 07:30:35 +02:00
|
|
|
local spawn = require("vicious.spawn")
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
2010-03-06 22:12:47 +01:00
|
|
|
-- Volume: provides volume levels and state of requested ALSA mixers
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.volume
|
2017-01-25 17:56:22 +01:00
|
|
|
local volume_linux = {}
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
-- {{{ Volume widget type
|
2019-05-14 09:33:09 +02:00
|
|
|
local STATE = { on = '🔉', off = '🔈' }
|
2017-10-08 16:33:32 +02:00
|
|
|
|
2019-05-14 09:33:09 +02:00
|
|
|
local function parse(stdout, stderr, exitreason, exitcode)
|
|
|
|
-- Capture mixer control state, e.g. [ 42 % ] [ on ]
|
|
|
|
local volume, state = string.match(stdout, "%[([%d]+)%%%].*%[([%l]*)%]")
|
2010-03-06 22:12:47 +01:00
|
|
|
-- Handle mixers without data
|
2019-05-14 09:33:09 +02:00
|
|
|
if volume == nil then return { 0, STATE.off } end
|
2010-03-06 22:12:47 +01:00
|
|
|
|
2019-05-14 09:33:09 +02:00
|
|
|
if state == "" and volume == "0" -- handle mixers without mute
|
|
|
|
or state == "off" then -- handle muted mixers
|
|
|
|
return { tonumber(volume), STATE.off }
|
2010-03-06 22:12:47 +01:00
|
|
|
else
|
2019-05-14 09:33:09 +02:00
|
|
|
return { tonumber(volume), STATE.on }
|
2009-10-02 21:48:05 +02:00
|
|
|
end
|
2019-05-14 09:33:09 +02:00
|
|
|
end
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
2019-05-14 09:33:09 +02:00
|
|
|
function volume_linux.async(format, warg, callback)
|
|
|
|
if not warg then return callback{} end
|
|
|
|
if type(warg) ~= "table" then warg = { warg } end
|
|
|
|
spawn.easy_async("amixer -M get " .. table.concat(warg, " "),
|
|
|
|
function (...) callback(parse(...)) end)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function worker(format, warg)
|
|
|
|
local ret
|
|
|
|
volume_linux.async(format, warg, function (volume) ret = volume end)
|
|
|
|
while ret == nil do end
|
|
|
|
return ret
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
2017-01-25 17:56:22 +01:00
|
|
|
return setmetatable(volume_linux, { __call = function(_, ...) return worker(...) end })
|