2019-09-14 05:33:40 +02:00
|
|
|
-- volume widget type for GNU/Linux
|
|
|
|
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
|
|
|
-- Copyright (C) 2017 Brandon Hartshorn <brandonhartshorn@gmail.com>
|
|
|
|
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
|
|
|
-- Copyright (C) 2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
|
|
|
|
--
|
|
|
|
-- This file is part of Vicious.
|
|
|
|
--
|
|
|
|
-- Vicious is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as
|
|
|
|
-- published by the Free Software Foundation, either version 2 of the
|
|
|
|
-- License, or (at your option) any later version.
|
|
|
|
--
|
|
|
|
-- Vicious is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
--
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
|
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
|
2019-05-16 13:52:22 +02:00
|
|
|
local type = type
|
2009-10-26 20:32:48 +01:00
|
|
|
local tonumber = tonumber
|
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-15 11:01:49 +02:00
|
|
|
if volume == nil then return {} 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
|
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
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
2019-05-15 11:01:49 +02:00
|
|
|
return helpers.setasyncall(volume_linux)
|