| 1 | -- contrib/ac_linux.lua |
| 2 | -- Copyright (C) 2012 jinleileiking <[email protected]> |
| 3 | -- Copyright (C) 2017 Jörg Thalheim <[email protected]> |
| 4 | -- |
| 5 | -- This file is part of Vicious. |
| 6 | -- |
| 7 | -- Vicious is free software: you can redistribute it and/or modify |
| 8 | -- it under the terms of the GNU General Public License as |
| 9 | -- published by the Free Software Foundation, either version 2 of the |
| 10 | -- License, or (at your option) any later version. |
| 11 | -- |
| 12 | -- Vicious is distributed in the hope that it will be useful, |
| 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | -- GNU General Public License for more details. |
| 16 | -- |
| 17 | -- You should have received a copy of the GNU General Public License |
| 18 | -- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 19 | |
| 20 | -- {{{ Grab environment |
| 21 | local tonumber = tonumber |
| 22 | local setmetatable = setmetatable |
| 23 | local string = { format = string.format } |
| 24 | local helpers = require("vicious.helpers") |
| 25 | local math = { |
| 26 | min = math.min, |
| 27 | floor = math.floor |
| 28 | } |
| 29 | -- }}} |
| 30 | |
| 31 | local ac_linux = {} |
| 32 | |
| 33 | -- {{{ AC widget type |
| 34 | local function worker(format, warg) |
| 35 | local ac = helpers.pathtotable("/sys/class/power_supply/"..warg) |
| 36 | |
| 37 | local state = ac.online |
| 38 | if state == nil then |
| 39 | return {"N/A"} |
| 40 | elseif state == "1\n" then |
| 41 | return {"On"} |
| 42 | else |
| 43 | return {"Off"} |
| 44 | end |
| 45 | end |
| 46 | -- }}} |
| 47 | |
| 48 | |
| 49 | return setmetatable(ac_linux, { __call = function(_, ...) return worker(...) end }) |