Removed submodule and added the raw files.
This commit is contained in:
parent
9da8ea9542
commit
6397c554c3
96 changed files with 8176 additions and 0 deletions
69
.config/awesome/vicious/widgets/amdgpu_linux.lua
Normal file
69
.config/awesome/vicious/widgets/amdgpu_linux.lua
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
-- AMD GPU widget type for Linux
|
||||
-- Copyright (C) 2022 Rémy Clouard <shikamaru shikamaru fr>
|
||||
--
|
||||
-- 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/>.
|
||||
|
||||
local io = { open = io.open }
|
||||
local string = { match = string.match }
|
||||
local tonumber = tonumber
|
||||
local type = type
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
|
||||
local _mem = nil
|
||||
|
||||
-- {{{ AMDGPU widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- see https://www.kernel.org/doc/html/v5.9/gpu/amdgpu.html#busy-percent
|
||||
local amdgpu = "/sys/class/drm/"..warg.."/device"
|
||||
local _data = {}
|
||||
|
||||
local f = io.open(amdgpu .. "/gpu_busy_percent", "r")
|
||||
if f then
|
||||
_data["{gpu_usage}"] = f:read("*line")
|
||||
f:close()
|
||||
else
|
||||
_data["{gpu_usage}"] = "N/A"
|
||||
end
|
||||
|
||||
if _mem == nil then
|
||||
f = io.open(amdgpu .. "/mem_info_vram_total", "r")
|
||||
if f then
|
||||
_mem = tonumber(string.match(f:read("*line"), "([%d]+)"))
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
|
||||
f = io.open(amdgpu .. "/mem_info_vram_used", "r")
|
||||
if f then
|
||||
local _used = tonumber(string.match(f:read("*line"), "([%d]+)"))
|
||||
if type(_used) == 'number' and type(_mem) == 'number'
|
||||
and _mem > 0 then
|
||||
_data["{mem_usage}"] = _used/_mem*100
|
||||
else
|
||||
_data["{mem_usage}"] = "N/A"
|
||||
end
|
||||
f:close()
|
||||
else
|
||||
_data["{mem_usage}"] = "N/A"
|
||||
end
|
||||
|
||||
return _data
|
||||
|
||||
end)
|
||||
--}}}
|
||||
94
.config/awesome/vicious/widgets/bat_freebsd.lua
Normal file
94
.config/awesome/vicious/widgets/bat_freebsd.lua
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
-- battery widget type for FreeBSD
|
||||
-- Copyright (C) 2017-2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local math = { floor = math.floor }
|
||||
local string = {
|
||||
gmatch = string.gmatch,
|
||||
format = string.format
|
||||
}
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
-- Battery: provides battery level of requested battery
|
||||
-- vicious.widgets.battery_freebsd
|
||||
local bat_freebsd = {}
|
||||
|
||||
-- {{{ Battery widget type
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
local bat_info = {}
|
||||
for line in string.gmatch(stdout, "[^\n]+") do
|
||||
for key,value in string.gmatch(line, "(.+):%s+(.+)") do
|
||||
bat_info[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
-- current state
|
||||
-- see: https://github.com/freebsd/freebsd/blob/master/usr.sbin/acpi/acpiconf/acpiconf.c
|
||||
local battery_state = {
|
||||
["high"] = "↯",
|
||||
["charging"] = "+",
|
||||
["critical charging"] = "+",
|
||||
["discharging"] = "-",
|
||||
["critical discharging"] = "!",
|
||||
["critical"] = "!",
|
||||
}
|
||||
local state = battery_state[bat_info["State"]] or "N/A"
|
||||
|
||||
-- battery capacity in percent
|
||||
local percent = tonumber(bat_info["Remaining capacity"]:match"[%d]+")
|
||||
|
||||
-- use remaining (charging or discharging) time calculated by acpiconf
|
||||
local time = bat_info["Remaining time"]
|
||||
if time == "unknown" then
|
||||
time = "∞"
|
||||
end
|
||||
|
||||
-- calculate wear level from (last full / design) capacity
|
||||
local wear = "N/A"
|
||||
if bat_info["Last full capacity"] and bat_info["Design capacity"] then
|
||||
local l_full = tonumber(bat_info["Last full capacity"]:match"[%d]+")
|
||||
local design = tonumber(bat_info["Design capacity"]:match"[%d]+")
|
||||
wear = math.floor(l_full / design * 100)
|
||||
end
|
||||
|
||||
-- dis-/charging rate as presented by battery
|
||||
local rate = bat_info["Present rate"]:match"([%d]+)%smW"
|
||||
rate = string.format("%2.1f", tonumber(rate / 1000))
|
||||
|
||||
-- returns
|
||||
-- * state (high "↯", discharging "-", charging "+", N/A "⌁" }
|
||||
-- * remaining_capacity (percent)
|
||||
-- * remaining_time, by battery
|
||||
-- * wear level (percent)
|
||||
-- * present_rate (mW)
|
||||
return {state, percent, time, wear, rate}
|
||||
end
|
||||
|
||||
function bat_freebsd.async(format, warg, callback)
|
||||
local battery = warg or "batt"
|
||||
spawn.easy_async("acpiconf -i " .. helpers.shellquote(battery),
|
||||
function (...) callback(parse(...)) end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(bat_freebsd)
|
||||
115
.config/awesome/vicious/widgets/bat_linux.lua
Normal file
115
.config/awesome/vicious/widgets/bat_linux.lua
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
-- battery widget type for GNU/Linux
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2013 NormalRa <normalrawr@gmail.com>
|
||||
-- Copyright (C) 2017 David Udelson <dru5@cornell.edu>
|
||||
-- Copyright (C) 2017 Roberto <empijei@users.noreply.github.com>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2024 arch-stack <arch-stack@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local string = { format = string.format }
|
||||
local math = {
|
||||
min = math.min,
|
||||
floor = math.floor
|
||||
}
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- {{{ Battery widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
|
||||
local battery = helpers.pathtotable("/sys/class/power_supply/"..warg)
|
||||
local battery_state = {
|
||||
["Full\n"] = "↯",
|
||||
["Unknown\n"] = "⌁",
|
||||
["Charged\n"] = "↯",
|
||||
["Charging\n"] = "+",
|
||||
["Discharging\n"] = "-"
|
||||
}
|
||||
|
||||
-- Get current power usage in watt
|
||||
local curpower = "N/A"
|
||||
|
||||
if battery.power_now then
|
||||
curpower = string.format("%.2f", tonumber(battery.power_now) /1000000)
|
||||
elseif battery.current_now and battery.voltage_now then
|
||||
local current = tonumber(battery.current_now)
|
||||
local voltage = tonumber(battery.voltage_now)
|
||||
curpower = string.format("%.2f", current * voltage / 10^12)
|
||||
end
|
||||
|
||||
-- Check if the battery is present
|
||||
if battery.present ~= "1\n" then
|
||||
return {battery_state["Unknown\n"], 0, "N/A", 0, curpower}
|
||||
end
|
||||
|
||||
-- Get state information
|
||||
local state = battery_state[battery.status] or battery_state["Unknown\n"]
|
||||
|
||||
-- Get capacity information
|
||||
local remaining, capacity, capacity_design
|
||||
if battery.charge_now then
|
||||
remaining, capacity = battery.charge_now, battery.charge_full
|
||||
capacity_design = battery.charge_full_design or capacity
|
||||
elseif battery.energy_now then
|
||||
remaining, capacity = battery.energy_now, battery.energy_full
|
||||
capacity_design = battery.energy_full_design or capacity
|
||||
else
|
||||
return {battery_state["Unknown\n"], 0, "N/A", 0, curpower}
|
||||
end
|
||||
|
||||
-- Calculate capacity and wear percentage (but work around broken BAT/ACPI implementations)
|
||||
local percent = math.min(math.floor(remaining / capacity * 100), 100)
|
||||
local wear = math.floor(100 - capacity / capacity_design * 100)
|
||||
|
||||
-- Get charge information
|
||||
local rate
|
||||
if battery.current_now then
|
||||
rate = tonumber(battery.current_now)
|
||||
elseif battery.power_now then
|
||||
rate = tonumber(battery.power_now)
|
||||
else
|
||||
return {state, percent, "N/A", wear, curpower}
|
||||
end
|
||||
|
||||
-- Calculate remaining (charging or discharging) time
|
||||
local time = "N/A"
|
||||
|
||||
if rate ~= nil and rate ~= 0 then
|
||||
local timeleft
|
||||
if state == "+" then
|
||||
timeleft = (tonumber(capacity)-tonumber(remaining)) / tonumber(rate)
|
||||
elseif state == "-" then
|
||||
timeleft = tonumber(remaining) / tonumber(rate)
|
||||
else
|
||||
return {state, percent, time, wear, curpower}
|
||||
end
|
||||
|
||||
-- Calculate time
|
||||
local hoursleft = math.floor(timeleft)
|
||||
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
|
||||
|
||||
time = string.format("%02d:%02d", hoursleft, minutesleft)
|
||||
end
|
||||
|
||||
return {state, percent, time, wear, curpower}
|
||||
end)
|
||||
-- }}}
|
||||
94
.config/awesome/vicious/widgets/bat_openbsd.lua
Normal file
94
.config/awesome/vicious/widgets/bat_openbsd.lua
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
-- battery widget type for OpenBSD
|
||||
-- Copyright (C) 2019 Enric Morales <me@enric.me>
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local pairs = pairs
|
||||
local tonumber = tonumber
|
||||
local table = {
|
||||
insert = table.insert
|
||||
}
|
||||
|
||||
local math = {
|
||||
floor = math.floor,
|
||||
modf = math.modf
|
||||
}
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
local bat_openbsd = {}
|
||||
function bat_openbsd.async(format, warg, callback)
|
||||
local battery_id = warg or "bat0"
|
||||
|
||||
local fields = {
|
||||
charging_rate = ("hw.sensors.acpi%s.power0"):format(battery_id),
|
||||
last_full_capacity = ("hw.sensors.acpi%s.watthour0"):format(battery_id),
|
||||
remaining_capacity = ("hw.sensors.acpi%s.watthour3"):format(battery_id),
|
||||
design_capacity = ("hw.sensors.acpi%s.watthour4"):format(battery_id),
|
||||
state = ("hw.sensors.acpi%s.raw0"):format(battery_id)
|
||||
}
|
||||
|
||||
local sysctl_args = {}
|
||||
for _, v in pairs(fields) do table.insert(sysctl_args, v) end
|
||||
|
||||
local battery = {}
|
||||
helpers.sysctl_async(sysctl_args, function (ret)
|
||||
for k, v in pairs(fields) do
|
||||
-- discard the description that comes after the values
|
||||
battery[k] = tonumber(ret[v]:match("(.-) "))
|
||||
end
|
||||
|
||||
local states = {
|
||||
[0] = "↯", -- not charging
|
||||
[1] = "-", -- discharging
|
||||
[2] = "!", -- critical
|
||||
[3] = "+", -- charging
|
||||
[4] = "N/A", -- unknown status
|
||||
[255] = "N/A" -- unimplemented by the driver
|
||||
}
|
||||
local state = states[battery.state]
|
||||
|
||||
local charge = tonumber(battery.remaining_capacity
|
||||
/ battery.last_full_capacity * 100)
|
||||
|
||||
local remaining_time
|
||||
if battery.charging_rate < 1 then
|
||||
remaining_time = "∞"
|
||||
else
|
||||
local raw_time = battery.remaining_capacity / battery.rate
|
||||
local hours, hour_fraction = math.modf(raw_time)
|
||||
local minutes = math.floor(60 * hour_fraction)
|
||||
remaining_time = ("%d:%0.2d"):format(hours, minutes)
|
||||
end
|
||||
|
||||
local wear = math.floor(battery.last_full_capacity,
|
||||
battery.design_capacity)
|
||||
|
||||
-- Pass the following arguments to callback function:
|
||||
-- * battery state symbol (↯, -, !, + or N/A)
|
||||
-- * remaining capacity (in percent)
|
||||
-- * remaining time, as reported by the battery
|
||||
-- * wear level (in percent)
|
||||
-- * present_rate (in Watts/hour)
|
||||
return callback({ state, charge, remaining_time,
|
||||
wear, battery.charging_rate })
|
||||
end)
|
||||
end
|
||||
|
||||
return helpers.setasyncall(bat_openbsd)
|
||||
66
.config/awesome/vicious/widgets/cmus_all.lua
Normal file
66
.config/awesome/vicious/widgets/cmus_all.lua
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
-- cmus music player widget type
|
||||
-- Copyright (C) 2017 JuanKman94 <juan.carlos.menonita@gmail.com>
|
||||
-- Copyright (C) 2017 Joerg Thalheim <joerg@thalheim.io>
|
||||
-- Copyright (C) 2018-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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
local os = { getenv = os.getenv }
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
-- }}}
|
||||
|
||||
local CMUS_SOCKET = helpers.shellquote(os.getenv"CMUS_SOCKET")
|
||||
|
||||
-- Cmus: provides CMUS information
|
||||
-- vicious.widgets.cmus
|
||||
return helpers.setasyncall{
|
||||
async = function (format, warg, callback)
|
||||
local server = ""
|
||||
if type(warg) == "table" then
|
||||
server = " --server " .. helpers.shellquote(warg.host or warg[1])
|
||||
elseif CMUS_SOCKET ~= nil then
|
||||
server = " --server " .. CMUS_SOCKET
|
||||
end
|
||||
|
||||
local cmus_state = { ["{duration}"] = 0, ["{file}"] = "N/A",
|
||||
["{status}"] = "N/A", ["{title}"] = "N/A",
|
||||
["{artist}"] = "N/A", ["{continue}"] = "off",
|
||||
["{shuffle}"] = "off", ["{repeat}"] = "off" }
|
||||
|
||||
spawn.with_line_callback("cmus-remote --query" .. server, {
|
||||
stdout = function (line)
|
||||
for module, value in line:gmatch"([%w]+) (.*)$" do
|
||||
if module == "file" or module == "status" then
|
||||
cmus_state["{"..module.."}"] = value
|
||||
elseif module == "duration" then
|
||||
cmus_state["{"..module.."}"] = tonumber(value)
|
||||
else
|
||||
local k, v = value:gmatch("([%w]+) (.*)$")()
|
||||
if module == "tag" then
|
||||
cmus_state["{"..k.."}"] = v
|
||||
elseif module == "set" and v == "true" then
|
||||
cmus_state["{"..k.."}"] = "on"
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
output_done = function () callback(cmus_state) end })
|
||||
end }
|
||||
89
.config/awesome/vicious/widgets/cpu_freebsd.lua
Normal file
89
.config/awesome/vicious/widgets/cpu_freebsd.lua
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
-- CPU usage widget type for FreeBSD
|
||||
-- Copyright (C) 2017,2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local math = { floor = math.floor }
|
||||
local string = { gmatch = string.gmatch }
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- Cpu: provides CPU usage for all available CPUs/cores
|
||||
-- vicious.widgets.cpu_freebsd
|
||||
local cpu_freebsd = {}
|
||||
|
||||
-- Initialize function tables
|
||||
local cpu_total = {}
|
||||
local cpu_idle = {}
|
||||
|
||||
-- {{{ CPU widget type
|
||||
function cpu_freebsd.async(format, warg, callback)
|
||||
local matches = {}
|
||||
local tmp_total = {}
|
||||
local tmp_idle = {}
|
||||
local tmp_usage = {}
|
||||
|
||||
helpers.sysctl_async({ "kern.cp_times" }, function(ret)
|
||||
-- Read input data
|
||||
for v in string.gmatch(ret["kern.cp_times"], "([%d]+)") do
|
||||
table.insert(matches, v)
|
||||
end
|
||||
|
||||
-- Set first value of function tables
|
||||
if #cpu_total == 0 then -- check for empty table
|
||||
for i = 1, #matches / 5 + 1 do
|
||||
cpu_total[i] = 0
|
||||
cpu_idle[i] = 0
|
||||
end
|
||||
end
|
||||
for i = 1, #matches / 5 + 1 do
|
||||
tmp_total[i] = 0
|
||||
tmp_idle[i] = 0
|
||||
tmp_usage[i] = 0
|
||||
end
|
||||
|
||||
-- CPU usage
|
||||
for i, v in ipairs(matches) do
|
||||
local index = math.floor((i-1) / 5) + 2 -- current cpu
|
||||
|
||||
tmp_total[1] = tmp_total[1] + v
|
||||
tmp_total[index] = tmp_total[index] + v
|
||||
|
||||
if (i-1) % 5 == 4 then
|
||||
tmp_idle[1] = tmp_idle[1] + v
|
||||
tmp_idle[index] = tmp_idle[index] + v
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #tmp_usage do
|
||||
tmp_usage[i] = tmp_total[i] - cpu_total[i]
|
||||
tmp_usage[i] = math.floor(
|
||||
(tmp_usage[i] - (tmp_idle[i] - cpu_idle[i]))
|
||||
/ tmp_usage[i] * 100)
|
||||
end
|
||||
|
||||
cpu_total = tmp_total
|
||||
cpu_idle = tmp_idle
|
||||
|
||||
return callback(tmp_usage)
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(cpu_freebsd)
|
||||
86
.config/awesome/vicious/widgets/cpu_linux.lua
Normal file
86
.config/awesome/vicious/widgets/cpu_linux.lua
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
-- CPU usage widget type for GNU/Linux
|
||||
-- Copyright (C) 2009 Lucas de Vries <lucas@glacicle.com>
|
||||
-- Copyright (C) 2011 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2011 Jörg Thalheim <jthalheim@gmail.com>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local ipairs = ipairs
|
||||
local io = { open = io.open }
|
||||
local math = { floor = math.floor }
|
||||
local table = { insert = table.insert }
|
||||
local string = {
|
||||
sub = string.sub,
|
||||
gmatch = string.gmatch
|
||||
}
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- Initialize function tables
|
||||
local cpu_usage = {}
|
||||
local cpu_total = {}
|
||||
local cpu_active = {}
|
||||
|
||||
-- {{{ CPU widget type
|
||||
return helpers.setcall(function ()
|
||||
local cpu_lines = {}
|
||||
|
||||
-- Get CPU stats
|
||||
local f = io.open("/proc/stat")
|
||||
for line in f:lines() do
|
||||
if string.sub(line, 1, 3) ~= "cpu" then break end
|
||||
|
||||
cpu_lines[#cpu_lines+1] = {}
|
||||
|
||||
for i in string.gmatch(line, "[%s]+([^%s]+)") do
|
||||
table.insert(cpu_lines[#cpu_lines], i)
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
|
||||
-- Ensure tables are initialized correctly
|
||||
for i = #cpu_total + 1, #cpu_lines do
|
||||
cpu_total[i] = 0
|
||||
cpu_usage[i] = 0
|
||||
cpu_active[i] = 0
|
||||
end
|
||||
|
||||
for i, v in ipairs(cpu_lines) do
|
||||
-- Calculate totals
|
||||
local total_new = 0
|
||||
for j = 1, #v do
|
||||
total_new = total_new + v[j]
|
||||
end
|
||||
local active_new = total_new - (v[4] + v[5])
|
||||
|
||||
-- Calculate percentage
|
||||
local diff_total = total_new - cpu_total[i]
|
||||
local diff_active = active_new - cpu_active[i]
|
||||
|
||||
if diff_total == 0 then diff_total = 1E-6 end
|
||||
cpu_usage[i] = math.floor((diff_active / diff_total) * 100)
|
||||
|
||||
-- Store totals
|
||||
cpu_total[i] = total_new
|
||||
cpu_active[i] = active_new
|
||||
end
|
||||
|
||||
return cpu_usage
|
||||
end)
|
||||
-- }}}
|
||||
60
.config/awesome/vicious/widgets/cpu_openbsd.lua
Normal file
60
.config/awesome/vicious/widgets/cpu_openbsd.lua
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
-- CPU usage widget type for OpenBSD
|
||||
-- Copyright (C) 2019 Enric Morales
|
||||
--
|
||||
-- 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/>.
|
||||
|
||||
local math = { ceil = math.ceil }
|
||||
local string = { gmatch = string.gmatch }
|
||||
local table = { insert = table.insert }
|
||||
local tonumber = tonumber
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
|
||||
|
||||
-- cpu_openbsd: provides both a helper function that allows reading
|
||||
-- the CPU usage on OpenBSD systems.
|
||||
local cpu_openbsd = {}
|
||||
|
||||
-- Initialize the table that will contain the ticks spent in each subsystem
|
||||
-- values: user, nice, system, spin, interrupts, idle
|
||||
local ticks = { 0, 0, 0, 0, 0, 0 }
|
||||
|
||||
function cpu_openbsd.async(format, warg, callback)
|
||||
helpers.sysctl_async({ "kern.cp_time" },
|
||||
function (ret)
|
||||
local current_ticks = {}
|
||||
for match in string.gmatch(ret["kern.cp_time"], "(%d+)") do
|
||||
table.insert(current_ticks, tonumber(match))
|
||||
end
|
||||
|
||||
local period_ticks = {}
|
||||
for i = 1, 6 do
|
||||
table.insert(period_ticks,
|
||||
current_ticks[i] - ticks[i])
|
||||
end
|
||||
|
||||
local cpu_total, cpu_busy = 0, 0
|
||||
for i = 1, 6 do cpu_total = cpu_total + period_ticks[i] end
|
||||
for i = 1, 5 do cpu_busy = cpu_busy + period_ticks[i] end
|
||||
|
||||
local cpu_usage = math.ceil((cpu_busy / cpu_total) * 100)
|
||||
|
||||
ticks = current_ticks
|
||||
return callback({ cpu_usage })
|
||||
end)
|
||||
end
|
||||
|
||||
return helpers.setasyncall(cpu_openbsd)
|
||||
57
.config/awesome/vicious/widgets/cpufreq_freebsd.lua
Normal file
57
.config/awesome/vicious/widgets/cpufreq_freebsd.lua
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
-- CPU frequency widget type for FreeBSD
|
||||
-- Copyright (C) 2017,2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- Cpufreq: provides freq, voltage and governor info for a requested CPU
|
||||
-- vicious.widgets.cpufreq
|
||||
local cpufreq_freebsd = {}
|
||||
|
||||
-- {{{ CPU frequency widget type
|
||||
function cpufreq_freebsd.async(format, warg, callback)
|
||||
if not warg then return callback({}) end
|
||||
|
||||
-- Default frequency and voltage values
|
||||
local freqv = {
|
||||
["mhz"] = "N/A", ["ghz"] = "N/A",
|
||||
["v"] = "N/A", ["mv"] = "N/A",
|
||||
["governor"] = "N/A",
|
||||
}
|
||||
|
||||
helpers.sysctl_async(
|
||||
{ "dev.cpu." .. warg .. ".freq" },
|
||||
function (ret)
|
||||
freqv.mhz = tonumber(ret["dev.cpu." .. warg .. ".freq"])
|
||||
freqv.ghz = freqv.mhz / 1000
|
||||
|
||||
return callback({
|
||||
freqv.mhz,
|
||||
freqv.ghz,
|
||||
freqv.mv,
|
||||
freqv.v,
|
||||
freqv.governor
|
||||
})
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(cpufreq_freebsd)
|
||||
68
.config/awesome/vicious/widgets/cpufreq_linux.lua
Normal file
68
.config/awesome/vicious/widgets/cpufreq_linux.lua
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
-- CPU frequency widget type for GNU/Linux
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
local GOVERNOR_STATE = {
|
||||
["ondemand\n"] = "↯",
|
||||
["powersave\n"] = "⌁",
|
||||
["userspace\n"] = "¤",
|
||||
["performance\n"] = "⚡",
|
||||
["conservative\n"] = "⊚"
|
||||
}
|
||||
|
||||
-- {{{ CPU frequency widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
|
||||
local _cpufreq = helpers.pathtotable(
|
||||
("/sys/devices/system/cpu/%s/cpufreq"):format(warg))
|
||||
-- Default frequency and voltage values
|
||||
local freqv = {
|
||||
["mhz"] = "N/A", ["ghz"] = "N/A",
|
||||
["v"] = "N/A", ["mv"] = "N/A",
|
||||
}
|
||||
|
||||
-- Get the current frequency
|
||||
local freq = tonumber(_cpufreq.scaling_cur_freq)
|
||||
-- Calculate MHz and GHz
|
||||
if freq then
|
||||
freqv.mhz = freq / 1000
|
||||
freqv.ghz = freqv.mhz / 1000
|
||||
|
||||
-- Get the current voltage
|
||||
if _cpufreq.scaling_voltages then
|
||||
freqv.mv = tonumber(
|
||||
_cpufreq.scaling_voltages:match(freq .. "[%s]([%d]+)"))
|
||||
-- Calculate voltage from mV
|
||||
freqv.v = freqv.mv / 1000
|
||||
end
|
||||
end
|
||||
|
||||
-- Get the current governor
|
||||
local governor = _cpufreq.scaling_governor
|
||||
-- Represent the governor as a symbol
|
||||
governor = GOVERNOR_STATE[governor] or governor or "N/A"
|
||||
|
||||
return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor}
|
||||
end)
|
||||
-- }}}
|
||||
50
.config/awesome/vicious/widgets/cpuinf_linux.lua
Normal file
50
.config/awesome/vicious/widgets/cpuinf_linux.lua
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
-- CPU information widget type for GNU/Linux
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local io = { lines = io.lines }
|
||||
local string = { gmatch = string.gmatch }
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- {{{ CPU Information widget type
|
||||
return helpers.setcall(function ()
|
||||
local id = nil
|
||||
|
||||
local cpu_info = {} -- Get CPU info
|
||||
for line in io.lines("/proc/cpuinfo") do
|
||||
for k, v in string.gmatch(line, "([%a%s]+)[%s]+:[%s]([%d]+).-$") do
|
||||
if k == "processor" then
|
||||
id = v
|
||||
elseif k == "cpu MHz\t" or k == "cpu MHz" then
|
||||
local speed = tonumber(v)
|
||||
cpu_info["{cpu"..id.." mhz}"] = speed
|
||||
cpu_info["{cpu"..id.." ghz}"] = speed / 1000
|
||||
elseif k == "cache size" then
|
||||
local cache = tonumber(v)
|
||||
cpu_info["{cpu"..id.." kb}"] = cache
|
||||
cpu_info["{cpu"..id.." mb}"] = cache / 1024
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return cpu_info
|
||||
end)
|
||||
-- }}}
|
||||
29
.config/awesome/vicious/widgets/date_all.lua
Normal file
29
.config/awesome/vicious/widgets/date_all.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
-- date and time widget type using os.date with optional time formatting
|
||||
-- Copyright (C) 2009 Lucas de Vries <lucas@glacicle.com>
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local os = { date = os.date, time = os.time }
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
return helpers.setcall(function (format, warg)
|
||||
return os.date(format or nil, warg and os.time()+warg or nil)
|
||||
end)
|
||||
79
.config/awesome/vicious/widgets/dio_linux.lua
Normal file
79
.config/awesome/vicious/widgets/dio_linux.lua
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
-- disk I/O widget type for GNU/Linux
|
||||
-- Copyright (C) 2011 Jörg T. <jthalheim@gmail.com>
|
||||
-- Copyright (C) 2017 Elric Milon <whirm@gmx.com>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local pairs = pairs
|
||||
local io = { lines = io.lines }
|
||||
local os = { time = os.time, difftime = os.difftime }
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- Initialize function tables
|
||||
local disk_usage = {}
|
||||
local disk_stats = {}
|
||||
local disk_time = 0
|
||||
-- Constant definitions
|
||||
local unit = { ["s"] = 1, ["kb"] = 2, ["mb"] = 2048 }
|
||||
local time_unit = { ["ms"] = 1, ["s"] = 1000 }
|
||||
|
||||
-- {{{ Disk I/O widget type
|
||||
return helpers.setcall(function ()
|
||||
local disk_lines = {}
|
||||
|
||||
for line in io.lines("/proc/diskstats") do
|
||||
local device, read, write, iotime =
|
||||
-- Linux kernel documentation: Documentation/iostats.txt
|
||||
line:match"([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+) %d+ %d+ (%d+)"
|
||||
disk_lines[device] = { read, write, iotime }
|
||||
end
|
||||
|
||||
local time = os.time()
|
||||
local interval = os.difftime(time, disk_time)
|
||||
if interval == 0 then interval = 1 end
|
||||
|
||||
for device, stats in pairs(disk_lines) do
|
||||
-- Avoid insane values on startup
|
||||
local last_stats = disk_stats[device] or stats
|
||||
|
||||
-- Check for overflows and counter resets (> 2^32)
|
||||
if stats[1] < last_stats[1] or stats[2] < last_stats[2] then
|
||||
for i = 1,3 do last_stats[i] = stats[i] end
|
||||
end
|
||||
|
||||
-- Diskstats are absolute, substract our last reading
|
||||
-- * divide by timediff because we don't know the timer value
|
||||
local read = (stats[1] - last_stats[1]) / interval
|
||||
local write = (stats[2] - last_stats[2]) / interval
|
||||
local iotime = (stats[3] - last_stats[3]) / interval
|
||||
|
||||
-- Calculate and store I/O
|
||||
helpers.uformat(disk_usage, device.." read", read, unit)
|
||||
helpers.uformat(disk_usage, device.." write", write, unit)
|
||||
helpers.uformat(disk_usage, device.." total", read + write, unit)
|
||||
helpers.uformat(disk_usage, device.." iotime", iotime, time_unit)
|
||||
end
|
||||
|
||||
disk_time = time
|
||||
disk_stats = disk_lines
|
||||
|
||||
return disk_usage
|
||||
end)
|
||||
-- }}}
|
||||
55
.config/awesome/vicious/widgets/fanspeed_freebsd.lua
Normal file
55
.config/awesome/vicious/widgets/fanspeed_freebsd.lua
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
-- fan speed widget type for FreeBSD
|
||||
-- Copyright (C) 2017,2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local type = type
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- fanspeed: provides speed level of fans
|
||||
-- vicious.widgets.fanspeed
|
||||
--
|
||||
-- expects one or multiple full sysctl strings to entry
|
||||
-- e.g.: "dev.acpi_ibm.0.fan_speed"
|
||||
local fanspeed_freebsd = {}
|
||||
|
||||
-- {{{ fanspeed widget type
|
||||
function fanspeed_freebsd.async(format, warg, callback)
|
||||
if not warg then return callback({}) end
|
||||
if type(warg) ~= "table" then warg = { warg } end
|
||||
|
||||
helpers.sysctl_async(warg, function(ret)
|
||||
local fanspeed = {}
|
||||
|
||||
for i=1,#warg do
|
||||
if ret[warg[i]] ~= nil then
|
||||
fanspeed[i] = tonumber(ret[warg[i]])
|
||||
else
|
||||
fanspeed[i] = "N/A"
|
||||
end
|
||||
end
|
||||
|
||||
callback(fanspeed)
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(fanspeed_freebsd)
|
||||
55
.config/awesome/vicious/widgets/fs_all.lua
Normal file
55
.config/awesome/vicious/widgets/fs_all.lua
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
-- filesystem widget type
|
||||
-- Copyright (C) 2009 Lucas de Vries <lucas@glacicle.com>
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 Joerg Thalheim <joerg@thalheim.io>
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
-- }}}
|
||||
|
||||
-- Mebibyte and gibibyte respectively, because backward compatibility
|
||||
local UNIT = { mb = 1024, gb = 1024^2 }
|
||||
|
||||
-- FS: provides file system disk space usage
|
||||
-- vicious.widgets.fs
|
||||
return helpers.setasyncall{
|
||||
async = function(format, warg, callback)
|
||||
local fs_info = {} -- Get data from df
|
||||
spawn.with_line_callback_with_shell(
|
||||
warg and "LC_ALL=C df -kP" or "LC_ALL=C df -klP",
|
||||
{ stdout = function (line)
|
||||
-- (1024-blocks) (Used) (Available) (Capacity)% (Mounted on)
|
||||
local s, u, a, p, m = line:match(
|
||||
"^.-%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%%%s+([%p%w]+)")
|
||||
|
||||
if u and m then -- Handle 1st line and broken regexp
|
||||
helpers.uformat(fs_info, m .. " size", s, UNIT)
|
||||
helpers.uformat(fs_info, m .. " used", u, UNIT)
|
||||
helpers.uformat(fs_info, m .. " avail", a, UNIT)
|
||||
|
||||
fs_info["{" .. m .. " used_p}"] = tonumber(p)
|
||||
fs_info["{" .. m .. " avail_p}"] = 100 - tonumber(p)
|
||||
end
|
||||
end,
|
||||
output_done = function () callback(fs_info) end })
|
||||
end }
|
||||
64
.config/awesome/vicious/widgets/gmail_all.lua
Normal file
64
.config/awesome/vicious/widgets/gmail_all.lua
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
-- new e-mails count and last e-mail subject on Gmail
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2017 starenka <starenka0@gmail.com>
|
||||
-- Copyright (C) 2018-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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
local string = { match = string.match }
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
-- Gmail: provides count of new and subject of last e-mail on Gmail
|
||||
-- vicious.widgets.gmail
|
||||
local gmail_all = {}
|
||||
|
||||
-- {{{ Gmail widget type
|
||||
local function parse(warg, stdout, stderr, exitreason, exitcode)
|
||||
local count = -- Count comes before messages and matches at least 0
|
||||
tonumber(string.match(stdout, "<fullcount>([%d]+)</fullcount>")) or 0
|
||||
|
||||
-- Find subject tag
|
||||
local title = string.match(stdout, "<entry>.-<title>(.-)</title>") or "N/A"
|
||||
|
||||
-- Check if we should scroll, or maybe truncate
|
||||
if type(warg) == "number" then
|
||||
title = helpers.truncate(title, warg)
|
||||
elseif type(warg) == "table" then
|
||||
title = helpers.scroll(title, warg[1], warg[2])
|
||||
end
|
||||
|
||||
return { ["{count}"] = count, ["{subject}"] = title }
|
||||
end
|
||||
|
||||
function gmail_all.async(format, warg, callback)
|
||||
-- Get info from the Gmail atom feed using curl --netrc.
|
||||
-- With username 'user' and password 'pass'
|
||||
-- $HOME/.netrc should look similar to:
|
||||
-- machine mail.google.com login user password pass
|
||||
-- BE AWARE THAT MAKING THESE SETTINGS IS A SECURITY RISK!
|
||||
spawn.easy_async("curl -fsn https://mail.google.com/mail/feed/atom",
|
||||
function (...) callback(parse(warg, ...)) end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(gmail_all)
|
||||
42
.config/awesome/vicious/widgets/hddtemp_linux.lua
Normal file
42
.config/awesome/vicious/widgets/hddtemp_linux.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
-- hard drive temperatures widget type using hddtemp daemon
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
-- }}}
|
||||
|
||||
-- Hddtemp: provides hard drive temperatures using the hddtemp daemon
|
||||
-- vicious.widgets.hddtemp
|
||||
return helpers.setasyncall{
|
||||
async = function(format, warg, callback)
|
||||
if warg == nil then warg = 7634 end -- fallback to default hddtemp port
|
||||
local hdd_temp = {} -- get info from the hddtemp daemon
|
||||
spawn.with_line_callback_with_shell(
|
||||
"echo | curl -fs telnet://127.0.0.1:" .. warg,
|
||||
{ stdout = function (line)
|
||||
for d, t in line:gmatch"|([%/%w]+)|.-|(%d+)|[CF]|" do
|
||||
hdd_temp["{"..d.."}"] = tonumber(t)
|
||||
end
|
||||
end,
|
||||
output_done = function () callback(hdd_temp) end })
|
||||
end }
|
||||
67
.config/awesome/vicious/widgets/hwmontemp_linux.lua
Normal file
67
.config/awesome/vicious/widgets/hwmontemp_linux.lua
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
-- widget type providing name-indexed temperatures from /sys/class/hwmon
|
||||
-- Copyright (C) 2019, 2020 Alexander Koch <lynix47@gmail.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/>.
|
||||
|
||||
-- environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
local io = { open = io.open }
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
|
||||
local pathcache = {}
|
||||
|
||||
local function read_sensor(path, callback)
|
||||
local f = io.open(path, "r")
|
||||
callback{ tonumber(f:read"*line") / 1000 }
|
||||
f:close()
|
||||
end
|
||||
|
||||
-- hwmontemp: provides name-indexed temps from /sys/class/hwmon
|
||||
-- vicious.widgets.hwmontemp
|
||||
return helpers.setasyncall{
|
||||
async = function (format, warg, callback)
|
||||
if type(warg) ~= "table" or type(warg[1]) ~= "string" then
|
||||
return callback{}
|
||||
end
|
||||
|
||||
local input = warg[2]
|
||||
if type(input) == "number" then
|
||||
input = ("temp%d_input"):format(input)
|
||||
else
|
||||
input = "temp1_input"
|
||||
end
|
||||
|
||||
local sensor = warg[1]
|
||||
if pathcache[sensor] then
|
||||
read_sensor(pathcache[sensor] .. input, callback)
|
||||
else
|
||||
spawn.easy_async_with_shell(
|
||||
"grep " .. sensor .. " -wl /sys/class/hwmon/*/name",
|
||||
function (stdout, stderr, exitreason, exitcode)
|
||||
if exitreason == "exit" and exitcode == 0 then
|
||||
pathcache[sensor] = stdout:gsub("name%s+", "")
|
||||
read_sensor(pathcache[sensor] .. input, callback)
|
||||
else
|
||||
callback{}
|
||||
end
|
||||
end)
|
||||
end
|
||||
end }
|
||||
-- vim: ts=4:sw=4:expandtab
|
||||
24
.config/awesome/vicious/widgets/init.lua
Normal file
24
.config/awesome/vicious/widgets/init.lua
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
-- widget types initialization
|
||||
-- Copyright (C) 2010 Adrian C. (anrxc) <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2011,2012 Jörg Thalheim <jthalheim@gmail.com>
|
||||
-- Copyright (C) 2012 Arvydas Sidorenko <asido4@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/>.
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local wrequire = require("vicious.helpers").wrequire
|
||||
|
||||
return setmetatable({ _NAME = "vicious.widgets" }, { __index = wrequire })
|
||||
55
.config/awesome/vicious/widgets/mbox_all.lua
Normal file
55
.config/awesome/vicious/widgets/mbox_all.lua
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
-- widget type providing the subject of last e-mail in a mbox file
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2018 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local io = { open = io.open }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- Initialize variables
|
||||
local subject = "N/A"
|
||||
|
||||
-- {{{ Mailbox widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
|
||||
local f = io.open(type(warg) == "table" and warg[1] or warg)
|
||||
f:seek("end", -30720)
|
||||
-- mbox could be huge, get a 30kb chunk from EOF
|
||||
-- * attachment could be much bigger than 30kb
|
||||
local txt = f:read("*all")
|
||||
f:close()
|
||||
|
||||
-- Find all Subject lines
|
||||
for i in txt:gmatch"Subject: ([^\n]*)" do subject = i end
|
||||
|
||||
-- Check if we should scroll, or maybe truncate
|
||||
if type(warg) == "table" then
|
||||
if warg[3] ~= nil then
|
||||
subject = helpers.scroll(subject, warg[2], warg[3])
|
||||
else
|
||||
subject = helpers.truncate(subject, warg[2])
|
||||
end
|
||||
end
|
||||
|
||||
return { subject }
|
||||
end)
|
||||
-- }}}
|
||||
63
.config/awesome/vicious/widgets/mboxc_all.lua
Normal file
63
.config/awesome/vicious/widgets/mboxc_all.lua
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
-- widget type providing the count of total, old and new messages in mbox files
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local io = { open = io.open }
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- {{{ Mbox count widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Initialize counters
|
||||
local count = { old = 0, total = 0, new = 0 }
|
||||
|
||||
-- Get data from mbox files
|
||||
for i=1, #warg do
|
||||
local f = io.open(warg[i])
|
||||
|
||||
while true do
|
||||
-- Read the mbox line by line, if we are going to read
|
||||
-- some *HUGE* folders then switch to reading chunks
|
||||
local lines = f:read("*line")
|
||||
if not lines then break end
|
||||
|
||||
-- Find all messages
|
||||
-- * http://www.jwz.org/doc/content-length.html
|
||||
local _, from = lines:find"^From[%s]"
|
||||
if from ~= nil then count.total = count.total + 1 end
|
||||
|
||||
-- Read messages have the Status header
|
||||
local _, status = lines:find"^Status:[%s]RO$"
|
||||
if status ~= nil then count.old = count.old + 1 end
|
||||
|
||||
-- Skip the folder internal data
|
||||
local _, int = lines:find"^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA"
|
||||
if int ~= nil then count.total = count.total - 1 end
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
|
||||
-- Substract total from old to get the new count
|
||||
count.new = count.total - count.old
|
||||
|
||||
return {count.total, count.old, count.new}
|
||||
end)
|
||||
-- }}}
|
||||
54
.config/awesome/vicious/widgets/mdir_all.lua
Normal file
54
.config/awesome/vicious/widgets/mdir_all.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
-- widget type providing number of new and unread Maildir messages
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2010 Fredrik Ax
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
-- }}}
|
||||
|
||||
-- vicious.widgets.mdir
|
||||
local mdir_all = {}
|
||||
|
||||
-- {{{ Maildir widget type
|
||||
function mdir_all.async(format, warg, callback)
|
||||
if type(warg) ~= "table" then return callback{} end
|
||||
local starting_points = ""
|
||||
for _,dir in ipairs(warg) do
|
||||
starting_points = starting_points .. " " .. helpers.shellquote(dir)
|
||||
end
|
||||
if starting_points == "" then return callback{ 0, 0 } end
|
||||
|
||||
local new, cur = 0, 0
|
||||
spawn.with_line_callback(
|
||||
"find" .. starting_points .. " -type f -regex '.*/cur/.*2,[^S]*$'",
|
||||
{ stdout = function (filename) cur = cur + 1 end,
|
||||
output_done = function ()
|
||||
spawn.with_line_callback(
|
||||
"find" .. starting_points .. " -type f -path '*/new/*'",
|
||||
{ stdout = function (filename) new = new + 1 end,
|
||||
output_done = function () callback{ new, cur } end })
|
||||
end })
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(mdir_all)
|
||||
139
.config/awesome/vicious/widgets/mem_freebsd.lua
Normal file
139
.config/awesome/vicious/widgets/mem_freebsd.lua
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
-- RAM and swap usage widget type for FreeBSD
|
||||
-- Copyright (C) 2017-2019 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2018 Andreas Geisenhainer <psycorama@datenhalde.de>
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local math = { floor = math.floor }
|
||||
local string = {
|
||||
match = string.match,
|
||||
gmatch = string.gmatch,
|
||||
find = string.find
|
||||
}
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
-- Mem: provides RAM and Swap usage statistics
|
||||
-- vicious.widgets.mem_freebsd
|
||||
local mem_freebsd = {}
|
||||
|
||||
|
||||
-- {{{ Memory widget type
|
||||
function mem_freebsd.async(format, warg, callback)
|
||||
helpers.sysctl_async({ "hw.pagesize",
|
||||
"vm.stats.vm",
|
||||
"vm.swap_total",
|
||||
"vm.swap_enabled" },
|
||||
function(ret)
|
||||
|
||||
local pgsz = tonumber(ret["hw.pagesize"])
|
||||
local _mem = { buf = {}, total = nil }
|
||||
|
||||
-- Get memory space in bytes
|
||||
_mem.total = tonumber(ret["vm.stats.vm.v_page_count"]) * pgsz
|
||||
_mem.buf.free = tonumber(ret["vm.stats.vm.v_free_count"]) * pgsz
|
||||
_mem.buf.laundry = tonumber(ret["vm.stats.vm.v_laundry_count"]) * pgsz
|
||||
_mem.buf.cache = tonumber(ret["vm.stats.vm.v_cache_count"]) * pgsz
|
||||
_mem.buf.wired = tonumber(ret["vm.stats.vm.v_wire_count"]) * pgsz
|
||||
|
||||
-- Rework into megabytes
|
||||
_mem.total = math.floor(_mem.total/1048576)
|
||||
_mem.buf.free = math.floor(_mem.buf.free/1048576)
|
||||
_mem.buf.laundry = math.floor(_mem.buf.laundry/1048576)
|
||||
_mem.buf.cache = math.floor(_mem.buf.cache/1048576)
|
||||
_mem.buf.wired = math.floor(_mem.buf.wired/1048576)
|
||||
|
||||
-- Calculate memory percentage
|
||||
_mem.free = _mem.buf.free + _mem.buf.cache
|
||||
-- used memory basically consists of active+inactive+wired
|
||||
_mem.inuse = _mem.total - _mem.free
|
||||
_mem.notfreeable = _mem.inuse - _mem.buf.laundry
|
||||
_mem.wire = _mem.buf.wired
|
||||
|
||||
_mem.usep = math.floor(_mem.inuse / _mem.total * 100)
|
||||
_mem.wirep = math.floor(_mem.wire / _mem.total * 100)
|
||||
_mem.notfreeablep = math.floor(_mem.notfreeable / _mem.total * 100)
|
||||
|
||||
-- Get swap states
|
||||
local vm_swap_total = tonumber(ret["vm.swap_total"])
|
||||
local vm_swap_enabled = tonumber(ret["vm.swap_enabled"])
|
||||
local _swp = { buf = {}, total = nil }
|
||||
|
||||
if vm_swap_enabled == 1 and vm_swap_total > 0 then
|
||||
-- Initialise variables
|
||||
_swp.usep = 0
|
||||
_swp.inuse = 0
|
||||
_swp.total = 0
|
||||
_swp.buf.free = 0
|
||||
|
||||
-- Read output of swapinfo in Mbytes (from async function call)
|
||||
-- Read content and sum up
|
||||
spawn.with_line_callback("swapinfo -m", {
|
||||
stdout = function(line)
|
||||
if not string.find(line, "Device") then
|
||||
local ltotal, lused, lfree = string.match(
|
||||
line, "%s+([%d]+)%s+([%d]+)%s+([%d]+)")
|
||||
-- Add swap space in Mbytes
|
||||
_swp.total = _swp.total + tonumber(ltotal)
|
||||
_swp.inuse = _swp.inuse + tonumber(lused)
|
||||
_swp.buf.free = _swp.buf.free + tonumber(lfree)
|
||||
end
|
||||
end,
|
||||
output_done = function()
|
||||
print(_swp.inuse, _swp.total)
|
||||
_swp.usep = math.floor(_swp.inuse / _swp.total * 100)
|
||||
callback({ _mem.usep,
|
||||
_mem.inuse,
|
||||
_mem.total,
|
||||
_mem.free,
|
||||
_swp.usep,
|
||||
_swp.inuse,
|
||||
_swp.total,
|
||||
_swp.buf.free,
|
||||
_mem.wirep,
|
||||
_mem.wire,
|
||||
_mem.notfreeablep,
|
||||
_mem.notfreeable })
|
||||
end
|
||||
})
|
||||
else
|
||||
_swp.usep = -1
|
||||
_swp.inuse = -1
|
||||
_swp.total = -1
|
||||
_swp.buf.free = -1
|
||||
callback({ _mem.usep,
|
||||
_mem.inuse,
|
||||
_mem.total,
|
||||
_mem.free,
|
||||
_swp.usep,
|
||||
_swp.inuse,
|
||||
_swp.total,
|
||||
_swp.buf.free,
|
||||
_mem.wirep,
|
||||
_mem.wire,
|
||||
_mem.notfreeablep,
|
||||
_mem.notfreeable })
|
||||
end
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(mem_freebsd)
|
||||
60
.config/awesome/vicious/widgets/mem_linux.lua
Normal file
60
.config/awesome/vicious/widgets/mem_linux.lua
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
-- RAM and swap usage widget type for GNU/Linux
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2009 Lucas de Vries <lucas@glacicle.com>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2018 Jay Kamat <jaygkamat@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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local io = { lines = io.lines }
|
||||
local math = { floor = math.floor }
|
||||
local string = { gmatch = string.gmatch }
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- {{{ Memory widget type
|
||||
return helpers.setcall(function ()
|
||||
local _mem = { buf = {}, swp = {} }
|
||||
|
||||
-- Get MEM info
|
||||
for line in io.lines("/proc/meminfo") do
|
||||
for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do
|
||||
if k == "MemTotal" then _mem.total = math.floor(v/1024)
|
||||
elseif k == "MemFree" then _mem.buf.f = math.floor(v/1024)
|
||||
elseif k == "MemAvailable" then _mem.buf.a = math.floor(v/1024)
|
||||
elseif k == "Buffers" then _mem.buf.b = math.floor(v/1024)
|
||||
elseif k == "Cached" then _mem.buf.c = math.floor(v/1024)
|
||||
elseif k == "SwapTotal" then _mem.swp.t = math.floor(v/1024)
|
||||
elseif k == "SwapFree" then _mem.swp.f = math.floor(v/1024)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Calculate memory percentage
|
||||
_mem.free = _mem.buf.a
|
||||
_mem.inuse = _mem.total - _mem.free
|
||||
_mem.bcuse = _mem.total - _mem.buf.f
|
||||
_mem.usep = math.floor(_mem.inuse / _mem.total * 100)
|
||||
-- Calculate swap percentage
|
||||
_mem.swp.inuse = _mem.swp.t - _mem.swp.f
|
||||
_mem.swp.usep = math.floor(_mem.swp.inuse / _mem.swp.t * 100)
|
||||
|
||||
return {_mem.usep, _mem.inuse, _mem.total, _mem.free,
|
||||
_mem.swp.usep, _mem.swp.inuse, _mem.swp.t, _mem.swp.f,
|
||||
_mem.bcuse }
|
||||
end)
|
||||
-- }}}
|
||||
181
.config/awesome/vicious/widgets/mpd_all.lua
Normal file
181
.config/awesome/vicious/widgets/mpd_all.lua
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
-- Music Player Daemon widget type
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017,2019 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2018 Jörg Thalheim <joerg@thalheim.io>
|
||||
-- Copyright (C) 2018-2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
|
||||
-- Copyright (C) 2019 Juan Carlos Menonita <JuanKman94@users.noreply.github.com>
|
||||
-- Copyright (C) 2019 Lorenzo Gaggini <lg@lgaggini.net>
|
||||
-- Copyright (C) 2022 Constantin Piber <cp.piber@gmail.com>
|
||||
-- Copyright (C) 2023 Cássio Ávila <cassioavila@autistici.org>
|
||||
--
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local math = { floor = math.floor }
|
||||
local type = type
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
-- }}}
|
||||
|
||||
-- Mpd: provides Music Player Daemon information
|
||||
-- vicious.widgets.mpd
|
||||
local mpd_all = {}
|
||||
|
||||
|
||||
-- {{{ Return true if number is nonzero
|
||||
local function cbool(number)
|
||||
return type(number) == "number" and number ~= 0 or number
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Format playing progress
|
||||
local function format_progress(elapsed, duration)
|
||||
local em, es = math.floor(elapsed / 60), math.floor(elapsed % 60)
|
||||
local dm, ds = math.floor(duration / 60), math.floor(duration % 60)
|
||||
|
||||
if dm < 10 then
|
||||
return ("%d:%02d"):format(em, es), ("%d:%02d"):format(dm, ds)
|
||||
elseif dm < 60 then
|
||||
return ("%02d:%02d"):format(em, es), ("%02d:%02d"):format(dm, ds)
|
||||
end
|
||||
|
||||
local eh, dh = math.floor(em / 60), math.floor(dm / 60)
|
||||
em, dm = math.floor(em % 60), math.floor(dm % 60)
|
||||
if dm < 600 then
|
||||
return ("%d:%02d:%02d"):format(eh, em, es),
|
||||
("%d:%02d:%02d"):format(dh, dm, ds)
|
||||
else
|
||||
return ("%02d:%02d:%02d"):format(eh, em, es),
|
||||
("%02d:%02d:%02d"):format(dh, dm, ds)
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Format playing progress (percentage)
|
||||
local function format_progress_percentage(elapsed, duration)
|
||||
if duration > 0 then
|
||||
local percentage = math.floor((elapsed / duration) * 100 + 0.5)
|
||||
return ("%d%%"):format(percentage)
|
||||
else
|
||||
return("0%")
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Build shell command from mpd command string
|
||||
local function build_cmd(warg, q)
|
||||
-- Construct MPD client options, fallback to defaults when necessary
|
||||
local query = ("printf 'password %s\n%sclose\n'"):format(
|
||||
warg and (warg.password or warg[1]) or '""',
|
||||
q)
|
||||
local connect = ("curl --connect-timeout 1 -fsm 3 telnet://%s:%s"):format(
|
||||
warg and (warg.host or warg[2]) or "127.0.0.1",
|
||||
warg and (warg.port or warg[3]) or "6600")
|
||||
return query .. "|" .. connect
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Common MPD commands
|
||||
function mpd_all.playpause(warg)
|
||||
spawn.with_shell(build_cmd(warg, "pause\n"))
|
||||
end
|
||||
function mpd_all.play(warg)
|
||||
spawn.with_shell(build_cmd(warg, "pause 0\n"))
|
||||
end
|
||||
function mpd_all.pause(warg)
|
||||
spawn.with_shell(build_cmd(warg, "pause 1\n"))
|
||||
end
|
||||
function mpd_all.stop(warg)
|
||||
spawn.with_shell(build_cmd(warg, "stop\n"))
|
||||
end
|
||||
function mpd_all.next(warg)
|
||||
spawn.with_shell(build_cmd(warg, "next\n"))
|
||||
end
|
||||
function mpd_all.previous(warg)
|
||||
spawn.with_shell(build_cmd(warg, "previous\n"))
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ MPD widget type
|
||||
function mpd_all.async(format, warg, callback)
|
||||
-- Fallback values
|
||||
local mpd_state = {
|
||||
["{volume}"] = 0,
|
||||
["{bitrate}"] = 0,
|
||||
["{elapsed}"] = 0,
|
||||
["{duration}"] = 0,
|
||||
["{repeat}"] = 0,
|
||||
["{random}"] = 0,
|
||||
["{state}"] = "N/A",
|
||||
["{Artist}"] = "N/A",
|
||||
["{Artists}"] = "N/A",
|
||||
["{Title}"] = "N/A",
|
||||
["{Album}"] = "N/A",
|
||||
["{Genre}"] = "N/A",
|
||||
["{Genres}"] = "N/A",
|
||||
}
|
||||
|
||||
local separator = warg and (warg.separator or warg[4]) or ", "
|
||||
|
||||
local cmd = build_cmd(warg, "status\ncurrentsong\n")
|
||||
|
||||
local function append_with_separator (current, value)
|
||||
return ("%s%s%s"):format(current, separator, value)
|
||||
end
|
||||
|
||||
-- Get data from MPD server
|
||||
spawn.with_line_callback_with_shell(cmd, {
|
||||
stdout = function (line)
|
||||
for k, v in line:gmatch"([%w]+):[%s](.*)$" do
|
||||
local key = "{" .. k .. "}"
|
||||
if k == "volume" or k == "bitrate" or
|
||||
k == "elapsed" or k == "duration" then
|
||||
mpd_state[key] = v and tonumber(v)
|
||||
elseif k == "repeat" or k == "random" then
|
||||
mpd_state[key] = cbool(v)
|
||||
elseif k == "state" then
|
||||
mpd_state[key] = helpers.capitalize(v)
|
||||
elseif k == "Artist" or k == "Title" or
|
||||
k == "Album" or k == "Genre" then
|
||||
if k == "Artist" or k == "Genre" then
|
||||
local current_key = "{" .. k .. "s}"
|
||||
local current_state = mpd_state[current_key]
|
||||
if current_state == "N/A" then
|
||||
mpd_state[current_key] = v
|
||||
else
|
||||
mpd_state[current_key] = append_with_separator(
|
||||
current_state, v)
|
||||
end
|
||||
end
|
||||
mpd_state[key] = v
|
||||
end
|
||||
end
|
||||
end,
|
||||
output_done = function ()
|
||||
-- Formatted elapsed and duration
|
||||
mpd_state["{Elapsed}"], mpd_state["{Duration}"] = format_progress(
|
||||
mpd_state["{elapsed}"], mpd_state["{duration}"])
|
||||
-- Formatted playing progress percentage
|
||||
mpd_state["{Progress}"] = format_progress_percentage(
|
||||
mpd_state["{elapsed}"], mpd_state["{duration}"])
|
||||
callback(mpd_state)
|
||||
end })
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(mpd_all)
|
||||
108
.config/awesome/vicious/widgets/net_freebsd.lua
Normal file
108
.config/awesome/vicious/widgets/net_freebsd.lua
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
-- network status and usage widget type for FreeBSD
|
||||
-- Copyright (C) 2017,2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local os = { time = os.time }
|
||||
local string = {
|
||||
match = string.match,
|
||||
gmatch = string.gmatch
|
||||
}
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
|
||||
-- Net: provides state and usage statistics of all network interfaces
|
||||
-- vicious.widgets.net
|
||||
local net_freebsd = {}
|
||||
|
||||
|
||||
-- Initialize function tables
|
||||
local nets = {}
|
||||
-- Variable definitions
|
||||
local unit = { ["b"] = 1, ["kb"] = 1024,
|
||||
["mb"] = 1024^2, ["gb"] = 1024^3
|
||||
}
|
||||
|
||||
-- {{{ Net widget type
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
|
||||
local args = {}
|
||||
local buffer = nil
|
||||
local now = os.time()
|
||||
|
||||
for line in string.gmatch(stdout, "[^\n]+") do
|
||||
if not (line:find("<Link") or line:find("Name")) then -- skipping missleading lines
|
||||
local split = { line:match(("([^%s]*)%s*"):rep(12)) }
|
||||
|
||||
if buffer == nil then
|
||||
buffer = { tonumber(split[8]), tonumber(split[11]) } -- recv (field 8) and send (field 11)
|
||||
else
|
||||
buffer = { buffer[1] + tonumber(split[8]),
|
||||
buffer[2] + tonumber(split[11]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if buffer == nil then
|
||||
args["{carrier}"] = 0
|
||||
helpers.uformat(args, "rx", 0, unit)
|
||||
helpers.uformat(args, "tx", 0, unit)
|
||||
helpers.uformat(args, "down", 0, unit)
|
||||
helpers.uformat(args, "up", 0, unit)
|
||||
else
|
||||
args["{carrier}"] = 1
|
||||
helpers.uformat(args, "rx", buffer[1], unit)
|
||||
helpers.uformat(args, "tx", buffer[2], unit)
|
||||
|
||||
if next(nets) == nil then
|
||||
helpers.uformat(args, "down", 0, unit)
|
||||
helpers.uformat(args, "up", 0, unit)
|
||||
else
|
||||
local interval = now - nets["time"]
|
||||
if interval <= 0 then interval = 1 end
|
||||
|
||||
local down = (buffer[1] - nets[1]) / interval
|
||||
local up = (buffer[2] - nets[2]) / interval
|
||||
|
||||
helpers.uformat(args, "down", down, unit)
|
||||
helpers.uformat(args, "up", up, unit)
|
||||
end
|
||||
|
||||
nets["time"] = now
|
||||
|
||||
-- Store totals
|
||||
nets[1] = buffer[1]
|
||||
nets[2] = buffer[2]
|
||||
end
|
||||
|
||||
return args
|
||||
|
||||
end
|
||||
|
||||
function net_freebsd.async(format, warg, callback)
|
||||
if not warg then return callback{} end
|
||||
spawn.easy_async("netstat -n -b -I " .. helpers.shellquote(warg),
|
||||
function (...) callback(parse(...)) end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(net_freebsd)
|
||||
85
.config/awesome/vicious/widgets/net_linux.lua
Normal file
85
.config/awesome/vicious/widgets/net_linux.lua
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
-- network status and usage widget type for GNU/Linux
|
||||
-- Copyright (C) 2009 Lucas de Vries <lucas@glacicle.com>
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local os = { time = os.time }
|
||||
local io = { lines = io.lines }
|
||||
local string = { match = string.match }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- Initialize function tables
|
||||
local nets = {}
|
||||
-- Variable definitions
|
||||
local unit = { ["b"] = 1, ["kb"] = 1024,
|
||||
["mb"] = 1024^2, ["gb"] = 1024^3
|
||||
}
|
||||
|
||||
-- {{{ Net widget type
|
||||
return helpers.setcall(function ()
|
||||
local args = {}
|
||||
|
||||
-- Get NET stats
|
||||
for line in io.lines("/proc/net/dev") do
|
||||
-- Match wmaster0 as well as rt0 (multiple leading spaces)
|
||||
local name = string.match(line, "^[%s]?[%s]?[%s]?[%s]?([%w]+):")
|
||||
if name ~= nil then
|
||||
-- Received bytes, first value after the name
|
||||
local recv = tonumber(string.match(line, ":[%s]*([%d]+)"))
|
||||
-- Transmited bytes, 7 fields from end of the line
|
||||
local send = tonumber(string.match(line,
|
||||
"([%d]+)%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d$"))
|
||||
|
||||
helpers.uformat(args, name .. " rx", recv, unit)
|
||||
helpers.uformat(args, name .. " tx", send, unit)
|
||||
|
||||
-- Operational state and carrier detection
|
||||
local sysnet = helpers.pathtotable("/sys/class/net/" .. name)
|
||||
args["{"..name.." carrier}"] = tonumber(sysnet.carrier) or 0
|
||||
|
||||
local now = os.time()
|
||||
if nets[name] == nil then
|
||||
-- Default values on the first run
|
||||
nets[name] = {}
|
||||
helpers.uformat(args, name .. " down", 0, unit)
|
||||
helpers.uformat(args, name .. " up", 0, unit)
|
||||
else -- Net stats are absolute, substract our last reading
|
||||
local interval = now - nets[name].time
|
||||
if interval <= 0 then interval = 1 end
|
||||
|
||||
local down = (recv - nets[name][1]) / interval
|
||||
local up = (send - nets[name][2]) / interval
|
||||
|
||||
helpers.uformat(args, name .. " down", down, unit)
|
||||
helpers.uformat(args, name .. " up", up, unit)
|
||||
end
|
||||
|
||||
nets[name].time = now
|
||||
|
||||
-- Store totals
|
||||
nets[name][1] = recv
|
||||
nets[name][2] = send
|
||||
end
|
||||
end
|
||||
|
||||
return args
|
||||
end)
|
||||
-- }}}
|
||||
38
.config/awesome/vicious/widgets/notmuch_all.lua
Normal file
38
.config/awesome/vicious/widgets/notmuch_all.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
-- notmuch_all - count messages that match a notmuch query
|
||||
-- Copyright (C) 2019 Enric Morales <me@enric.me>
|
||||
--
|
||||
-- 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 Affero General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU Affero General Public License
|
||||
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
local tonumber = tonumber
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
|
||||
|
||||
local notmuch = {}
|
||||
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
local output = { count = "N/A" }
|
||||
if exitcode == 0 then output.count = tonumber(stdout) end
|
||||
return output
|
||||
end
|
||||
|
||||
function notmuch.async(format, warg, callback)
|
||||
local cmd = ("notmuch count '^%s'"):format(warg)
|
||||
|
||||
spawn.easy_async(cmd, function (...) callback(parse(...)) end)
|
||||
end
|
||||
|
||||
return helpers.setasyncall(notmuch)
|
||||
65
.config/awesome/vicious/widgets/org_all.lua
Normal file
65
.config/awesome/vicious/widgets/org_all.lua
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
-- widget type providing agenda from Emacs org-mode
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2010 org-awesome, Damien Leone
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local io = { lines = io.lines }
|
||||
local os = { time = os.time, date = os.date }
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- {{{ OrgMode widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
|
||||
-- Compute delays
|
||||
local today = os.time{ year = os.date("%Y"), month = os.date("%m"),
|
||||
day = os.date("%d") }
|
||||
local soon = today + 24*3600*3 -- 3 days ahead is close
|
||||
local future = today + 24*3600*7 -- 7 days ahead is maximum
|
||||
|
||||
-- Initialize counters
|
||||
local count = { past = 0, today = 0, soon = 0, future = 0 }
|
||||
|
||||
-- Get data from agenda files
|
||||
for i = 1,#warg do
|
||||
for line in io.lines(warg[i]) do
|
||||
local scheduled = line:find"SCHEDULED:"
|
||||
local deadline = line:find"DEADLINE:"
|
||||
local closed = line:find"CLOSED:"
|
||||
local b, _, y, m, d = line:find"(%d%d%d%d)-(%d%d)-(%d%d)"
|
||||
|
||||
if (scheduled or deadline) and not closed and b then
|
||||
local t = os.time{ year = y, month = m, day = d }
|
||||
if t < today then
|
||||
count.past = count.past + 1
|
||||
elseif t == today then
|
||||
count.today = count.today + 1
|
||||
elseif t <= soon then
|
||||
count.soon = count.soon + 1
|
||||
elseif t <= future then
|
||||
count.future = count.future + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return { count.past, count.today, count.soon, count.future }
|
||||
end)
|
||||
-- }}}
|
||||
58
.config/awesome/vicious/widgets/os_bsd.lua
Normal file
58
.config/awesome/vicious/widgets/os_bsd.lua
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
-- operating system widget type for *BSD
|
||||
-- Copyright (C) 2019 mutlusun <mutlusun@users.noreply.github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local los = { getenv = os.getenv }
|
||||
local string = { match = string.match }
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
-- OS: provides operating system information
|
||||
-- vicious.widgets.os
|
||||
local os_bsd = {}
|
||||
|
||||
-- {{{ Operating system widget type
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
local system = {
|
||||
["ostype"] = "N/A",
|
||||
["hostname"] = "N/A",
|
||||
["osrelease"] = "N/A",
|
||||
["username"] = "N/A",
|
||||
["entropy"] = "N/A",
|
||||
["entropy_p"] = "N/A"
|
||||
}
|
||||
|
||||
-- BSD manual page: uname(1)
|
||||
system["ostype"], system["hostname"], system["osrelease"] =
|
||||
string.match(stdout, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)")
|
||||
|
||||
-- Get user from the environment
|
||||
system["username"] = los.getenv("USER")
|
||||
|
||||
return {system["ostype"], system["osrelease"], system["username"],
|
||||
system["hostname"], system["entropy"], system["entropy_p"]}
|
||||
end
|
||||
|
||||
function os_bsd.async(format, warg, callback)
|
||||
spawn.easy_async("uname -snr",
|
||||
function (...) callback(parse(...)) end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(os_bsd)
|
||||
66
.config/awesome/vicious/widgets/os_linux.lua
Normal file
66
.config/awesome/vicious/widgets/os_linux.lua
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
-- operating system widget type for GNU/Linux
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
|
||||
-- Copyright (C) 2019 mutlusun <mutlusun@users.noreply.github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local pairs = pairs
|
||||
local tonumber = tonumber
|
||||
local math = { ceil = math.ceil }
|
||||
local los = { getenv = os.getenv }
|
||||
local string = { gsub = string.gsub }
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- {{{ Operating system widget type
|
||||
return helpers.setcall(function ()
|
||||
local system = {
|
||||
["ostype"] = "N/A",
|
||||
["hostname"] = "N/A",
|
||||
["osrelease"] = "N/A",
|
||||
["username"] = "N/A",
|
||||
["entropy"] = "N/A",
|
||||
["entropy_p"] = "N/A"
|
||||
}
|
||||
|
||||
-- Linux manual page: uname(2)
|
||||
local kernel = helpers.pathtotable("/proc/sys/kernel")
|
||||
for k, _ in pairs(system) do
|
||||
if kernel[k] then
|
||||
system[k] = string.gsub(kernel[k], "[%s]*$", "")
|
||||
end
|
||||
end
|
||||
|
||||
-- Linux manual page: random(4)
|
||||
if kernel.random then
|
||||
-- Linux 2.6 default entropy pool is 4096-bits
|
||||
local poolsize = tonumber(kernel.random.poolsize)
|
||||
|
||||
-- Get available entropy and calculate percentage
|
||||
system["entropy"] = tonumber(kernel.random.entropy_avail)
|
||||
system["entropy_p"] = math.ceil(system["entropy"] * 100 / poolsize)
|
||||
end
|
||||
|
||||
-- Get user from the environment
|
||||
system["username"] = los.getenv("USER")
|
||||
|
||||
return {system["ostype"], system["osrelease"], system["username"],
|
||||
system["hostname"], system["entropy"], system["entropy_p"]}
|
||||
end)
|
||||
-- }}}
|
||||
62
.config/awesome/vicious/widgets/pkg_all.lua
Normal file
62
.config/awesome/vicious/widgets/pkg_all.lua
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
-- widget type providing number of pending updates
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 Joerg Thalheim <joerg@thalheim.io>
|
||||
-- Copyright (C) 2017 getzze <getzze@gmail.com>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
|
||||
-- Copyright (C) 2020 Elmeri Niemelä <niemela.elmeri@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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local spawn = require("vicious.spawn")
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- Pkg: provides number of pending updates on UNIX systems
|
||||
-- vicious.widgets.pkg
|
||||
local pkg_all = {}
|
||||
|
||||
local PKGMGR = {
|
||||
["Arch"] = { cmd = "pacman -Qu", sub = 0 },
|
||||
["Arch C"] = { cmd = "checkupdates", sub = 0 },
|
||||
["Arch S"] = { cmd = "yes | pacman -Sup", sub = 1 },
|
||||
["Debian"] = { cmd = "apt list --upgradable", sub = 1 },
|
||||
["Ubuntu"] = { cmd = "apt list --upgradable", sub = 1 },
|
||||
["Fedora"] = { cmd = "dnf check-update", sub = 2 },
|
||||
["FreeBSD"] = { cmd = "pkg version -I -l '<'", sub = 0 },
|
||||
["Mandriva"] = { cmd = "urpmq --auto-select", sub = 0 }
|
||||
}
|
||||
|
||||
-- {{{ Packages widget type
|
||||
function pkg_all.async(format, warg, callback)
|
||||
if not warg then return callback{} end
|
||||
local pkgmgr = PKGMGR[warg]
|
||||
|
||||
local size, lines = -pkgmgr.sub, ""
|
||||
spawn.with_line_callback_with_shell(pkgmgr.cmd, {
|
||||
stdout = function (str)
|
||||
size = size + 1
|
||||
if size > 0 then lines = lines .. str .. "\n" end
|
||||
end,
|
||||
output_done = function ()
|
||||
callback{ size, lines }
|
||||
end
|
||||
})
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(pkg_all)
|
||||
67
.config/awesome/vicious/widgets/raid_linux.lua
Normal file
67
.config/awesome/vicious/widgets/raid_linux.lua
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
-- widget type providing RAID array information on GNU/Linux
|
||||
-- Copyright (C) 2010 Hagen Schink <troja84@googlemail.com>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local io = { open = io.open }
|
||||
local string = {
|
||||
len = string.len,
|
||||
sub = string.sub,
|
||||
match = string.match,
|
||||
gmatch = string.gmatch
|
||||
}
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- Initialize function tables
|
||||
local mddev = {}
|
||||
|
||||
-- {{{ RAID widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
mddev[warg] = {
|
||||
["found"] = false,
|
||||
["active"] = 0,
|
||||
["assigned"] = 0
|
||||
}
|
||||
|
||||
-- Linux manual page: md(4)
|
||||
local f = io.open("/proc/mdstat")
|
||||
for line in f:lines() do
|
||||
if mddev[warg]["found"] then
|
||||
local updev = string.match(line, "%[[_U]+%]")
|
||||
|
||||
for _ in string.gmatch(updev, "U") do
|
||||
mddev[warg]["active"] = mddev[warg]["active"] + 1
|
||||
end
|
||||
|
||||
break
|
||||
elseif string.sub(line, 1, string.len(warg)) == warg then
|
||||
mddev[warg]["found"] = true
|
||||
|
||||
for _ in string.gmatch(line, "%[[%d]%]") do
|
||||
mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
|
||||
return {mddev[warg]["assigned"], mddev[warg]["active"]}
|
||||
end)
|
||||
-- }}}
|
||||
52
.config/awesome/vicious/widgets/thermal_freebsd.lua
Normal file
52
.config/awesome/vicious/widgets/thermal_freebsd.lua
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
-- temperature widget type for FreeBSD
|
||||
-- Copyright (C) 2017,2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local string = { match = string.match }
|
||||
local type = type
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- Thermal: provides temperature levels of ACPI and coretemp thermal zones
|
||||
-- vicious.widgets.thermal
|
||||
local thermal_freebsd = {}
|
||||
|
||||
-- {{{ Thermal widget type
|
||||
function thermal_freebsd.async(format, warg, callback)
|
||||
if not warg then return callback{} end
|
||||
if type(warg) ~= "table" then warg = { warg } end
|
||||
|
||||
helpers.sysctl_async(warg, function(ret)
|
||||
local thermals = {}
|
||||
|
||||
for i=1,#warg do
|
||||
if ret[warg[i]] ~= nil then
|
||||
thermals[i] = string.match(ret[warg[i]], "[%d]+")
|
||||
else
|
||||
thermals[i] = "N/A"
|
||||
end
|
||||
end
|
||||
|
||||
callback(thermals)
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(thermal_freebsd)
|
||||
54
.config/awesome/vicious/widgets/thermal_linux.lua
Normal file
54
.config/awesome/vicious/widgets/thermal_linux.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
-- temperature widget type for GNU/Linux
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
local string = { match = string.match }
|
||||
local math = { floor = math.floor }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- {{{ Thermal widget type
|
||||
return helpers.setcall(function (format, warg)
|
||||
if not warg then return end
|
||||
|
||||
local zone = { -- Known temperature data sources
|
||||
["sys"] = {"/sys/class/thermal/", file = "temp", div = 1000},
|
||||
["core"] = {"/sys/devices/platform/", file = "temp2_input",div = 1000},
|
||||
["hwmon"] = {"/sys/class/hwmon/", file = "temp1_input",div = 1000},
|
||||
["proc"] = {"/proc/acpi/thermal_zone/",file = "temperature"}
|
||||
} -- Default to /sys/class/thermal
|
||||
warg = type(warg) == "table" and warg or { warg, "sys" }
|
||||
|
||||
-- Get temperature from thermal zone
|
||||
local _thermal = helpers.pathtotable(zone[warg[2]][1] .. warg[1])
|
||||
|
||||
local data = warg[3] and _thermal[warg[3]] or _thermal[zone[warg[2]].file]
|
||||
if data then
|
||||
if zone[warg[2]].div then
|
||||
return {math.floor(data / zone[warg[2]].div)}
|
||||
else -- /proc/acpi "temperature: N C"
|
||||
return {tonumber(string.match(data, "[%d]+"))}
|
||||
end
|
||||
end
|
||||
|
||||
return {0}
|
||||
end)
|
||||
-- }}}
|
||||
52
.config/awesome/vicious/widgets/uptime_freebsd.lua
Normal file
52
.config/awesome/vicious/widgets/uptime_freebsd.lua
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
-- uptime widget type for FreeBSD
|
||||
-- Copyright (C) 2017,2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local math = { floor = math.floor }
|
||||
local os = { time = os.time }
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- Uptime: provides system uptime and load information
|
||||
-- vicious.widgets.uptime
|
||||
local uptime_freebsd = {}
|
||||
|
||||
-- {{{ Uptime widget type
|
||||
function uptime_freebsd.async(format, warg, callback)
|
||||
helpers.sysctl_async(
|
||||
{ "vm.loadavg", "kern.boottime" },
|
||||
function(ret)
|
||||
local l1, l5, l15 = ret["vm.loadavg"]:match(
|
||||
"{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }")
|
||||
local up_t = os.time() - tonumber(
|
||||
ret["kern.boottime"]:match"sec = ([%d]+)")
|
||||
|
||||
-- Get system uptime
|
||||
local up_d = math.floor(up_t / (3600 * 24))
|
||||
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
|
||||
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
|
||||
|
||||
return callback({ up_d, up_h, up_m, l1, l5, l15 })
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(uptime_freebsd)
|
||||
41
.config/awesome/vicious/widgets/uptime_linux.lua
Normal file
41
.config/awesome/vicious/widgets/uptime_linux.lua
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-- uptime widget type for GNU/Linux
|
||||
-- Copyright (C) 2009 Lucas de Vries <lucas@glacicle.com>
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local math = { floor = math.floor }
|
||||
local string = { match = string.match }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
-- {{{ Uptime widget type
|
||||
return helpers.setcall(function ()
|
||||
local proc = helpers.pathtotable("/proc")
|
||||
|
||||
-- Get system uptime
|
||||
local up_t = math.floor(string.match(proc.uptime, "[%d]+"))
|
||||
local up_d = math.floor(up_t / (3600 * 24))
|
||||
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
|
||||
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
|
||||
|
||||
local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes
|
||||
string.match(proc.loadavg, "([%d%.]+)[%s]([%d%.]+)[%s]([%d%.]+)")
|
||||
return {up_d, up_h, up_m, l1, l5, l15}
|
||||
end)
|
||||
-- }}}
|
||||
48
.config/awesome/vicious/widgets/volume_freebsd.lua
Normal file
48
.config/awesome/vicious/widgets/volume_freebsd.lua
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
-- volume widget type for FreeBSD
|
||||
-- Copyright (C) 2017,2019 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local string = { match = string.match }
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
-- Volume: provides volume levels and state of requested mixer
|
||||
-- vicious.widgets.volume_freebsd
|
||||
local volume_freebsd = {}
|
||||
|
||||
-- {{{ Volume widget type
|
||||
local STATE = { on = '🔉', off = '🔈' }
|
||||
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
-- Capture mixer control state, e.g. 42 : 42
|
||||
local voll, volr = string.match(stdout, "([%d]+):([%d]+)\n$")
|
||||
if voll == "0" and volr == "0" then return { 0, 0, STATE.off } end
|
||||
return { tonumber(voll), tonumber(volr), STATE.on }
|
||||
end
|
||||
|
||||
function volume_freebsd.async(format, warg, callback)
|
||||
if not warg then return callback{} end
|
||||
spawn.easy_async("mixer " .. helpers.shellquote(warg),
|
||||
function (...) callback(parse(...)) end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(volume_freebsd)
|
||||
61
.config/awesome/vicious/widgets/volume_linux.lua
Normal file
61
.config/awesome/vicious/widgets/volume_linux.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
local string = { match = string.match }
|
||||
local table = { concat = table.concat }
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
-- Volume: provides volume levels and state of requested ALSA mixers
|
||||
-- vicious.widgets.volume
|
||||
local volume_linux = {}
|
||||
|
||||
-- {{{ Volume widget type
|
||||
local STATE = { on = '🔉', off = '🔈' }
|
||||
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
-- Capture mixer control state, e.g. [ 42 % ] [ on ]
|
||||
local volume, state = string.match(stdout, "%[([%d]+)%%%].*%[([%l]*)%]")
|
||||
-- Handle mixers without data
|
||||
if volume == nil then return {} end
|
||||
|
||||
if state == "" and volume == "0" -- handle mixers without mute
|
||||
or state == "off" then -- handle muted mixers
|
||||
return { tonumber(volume), STATE.off }
|
||||
else
|
||||
return { tonumber(volume), STATE.on }
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(volume_linux)
|
||||
139
.config/awesome/vicious/widgets/weather_all.lua
Normal file
139
.config/awesome/vicious/widgets/weather_all.lua
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
-- weather widget type fetching from from US NOAA
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2019 Arthur Axel 'fREW' Schmidt <git@frew.co>
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local math = { ceil = math.ceil }
|
||||
local os = { date = os.date, difftime = os.difftime, time = os.time }
|
||||
local string = { format = string.format }
|
||||
|
||||
local spawn = require"vicious.spawn"
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
-- Weather: provides weather information for a requested station
|
||||
-- vicious.widgets.weather
|
||||
local weather_all = {}
|
||||
|
||||
-- copied from http://lua-users.org/wiki/TimeZone
|
||||
local function get_timezone_offset()
|
||||
local ts = os.time()
|
||||
local utcdate = os.date("!*t", ts)
|
||||
local localdate = os.date("*t", ts)
|
||||
localdate.isdst = false -- this is the trick
|
||||
return os.difftime(os.time(localdate), os.time(utcdate))
|
||||
end
|
||||
|
||||
-- {{{ Weather widget type
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
-- Initialize function tables
|
||||
local _weather = {
|
||||
["{city}"] = "N/A",
|
||||
["{when}"] = "N/A",
|
||||
["{wind}"] = "N/A",
|
||||
["{windmph}"] = "N/A",
|
||||
["{windkmh}"] = "N/A",
|
||||
["{sky}"] = "N/A",
|
||||
["{weather}"] = "N/A",
|
||||
["{tempf}"] = "N/A",
|
||||
["{tempc}"] = "N/A",
|
||||
["{dewf}"] = "N/A",
|
||||
["{dewc}"] = "N/A",
|
||||
["{humid}"] = "N/A",
|
||||
["{press}"] = "N/A"
|
||||
}
|
||||
|
||||
-- Check if there was a timeout or a problem with the station
|
||||
if stdout == '' then return _weather end
|
||||
|
||||
_weather["{city}"] = -- City and/or area
|
||||
stdout:match"^(.+)%,.*%([%u]+%)"
|
||||
or _weather["{city}"]
|
||||
_weather["{wind}"] = -- Wind direction and degrees if available
|
||||
stdout:match"Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$"
|
||||
or _weather["{wind}"]
|
||||
_weather["{windmph}"] = -- Wind speed in MPH if available
|
||||
stdout:match"Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH"
|
||||
or _weather["{windmph}"]
|
||||
_weather["{sky}"] = -- Sky conditions if available
|
||||
stdout:match"Sky[%s]conditions:[%s](.-)[%c]"
|
||||
or _weather["{sky}"]
|
||||
_weather["{weather}"] = -- Weather conditions if available
|
||||
stdout:match"Weather:[%s](.-)[%c]"
|
||||
or _weather["{weather}"]
|
||||
_weather["{tempf}"] = -- Temperature in fahrenheit
|
||||
stdout:match"Temperature:[%s]([%-]?[%d%.]+).*[%c]"
|
||||
or _weather["{tempf}"]
|
||||
_weather["{dewf}"] = -- Dew Point in fahrenheit
|
||||
stdout:match"Dew[%s]Point:[%s]([%-]?[%d%.]+).*[%c]"
|
||||
or _weather["{dewf}"]
|
||||
_weather["{humid}"] = -- Relative humidity in percent
|
||||
stdout:match"Relative[%s]Humidity:[%s]([%d]+)%%"
|
||||
or _weather["{humid}"]
|
||||
_weather["{press}"] = -- Pressure in hPa
|
||||
stdout:match"Pressure[%s].+%((.+)[%s]hPa%)"
|
||||
or _weather["{press}"]
|
||||
|
||||
local year, month, day, hour, min =
|
||||
stdout:match"(%d%d%d%d).(%d%d).(%d%d) (%d%d)(%d%d) UTC"
|
||||
if year ~= nil then
|
||||
local utctable = { year = year, month = month, day = day,
|
||||
hour = hour, min = min }
|
||||
_weather["{when}"] = os.time(utctable) + get_timezone_offset()
|
||||
end
|
||||
|
||||
-- Wind speed in km/h if MPH was available
|
||||
if _weather["{windmph}"] ~= "N/A" then
|
||||
_weather["{windmph}"] = tonumber(_weather["{windmph}"])
|
||||
_weather["{windkmh}"] = math.ceil(_weather["{windmph}"] * 1.6)
|
||||
end -- Temperature in °C if °F was available
|
||||
if _weather["{tempf}"] ~= "N/A" then
|
||||
_weather["{tempf}"] = tonumber(_weather["{tempf}"])
|
||||
_weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9)
|
||||
end -- Dew Point in °C if °F was available
|
||||
if _weather["{dewf}"] ~= "N/A" then
|
||||
_weather["{dewf}"] = tonumber(_weather["{dewf}"])
|
||||
_weather["{dewc}"] = math.ceil((_weather["{dewf}"] - 32) * 5/9)
|
||||
end -- Capitalize some stats so they don't look so out of place
|
||||
if _weather["{sky}"] ~= "N/A" then
|
||||
_weather["{sky}"] = helpers.capitalize(_weather["{sky}"])
|
||||
end
|
||||
if _weather["{weather}"] ~= "N/A" then
|
||||
_weather["{weather}"] = helpers.capitalize(_weather["{weather}"])
|
||||
end
|
||||
|
||||
return _weather
|
||||
end
|
||||
|
||||
function weather_all.async(format, warg, callback)
|
||||
if not warg then return callback{} end
|
||||
|
||||
-- Get weather forceast by the station ICAO code, from:
|
||||
-- * US National Oceanic and Atmospheric Administration
|
||||
local url = string.format(
|
||||
"https://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT",
|
||||
warg)
|
||||
spawn.easy_async("curl -fs " .. url,
|
||||
function (...) callback(parse(...)) end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(weather_all)
|
||||
67
.config/awesome/vicious/widgets/wifi_linux.lua
Normal file
67
.config/awesome/vicious/widgets/wifi_linux.lua
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
-- Wi-Fi widget type for GNU/Linux using iwconfig
|
||||
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2018-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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
local math = { floor = math.floor }
|
||||
|
||||
local helpers = require"vicious.helpers"
|
||||
local spawn = require"vicious.spawn"
|
||||
-- }}}
|
||||
|
||||
-- Wifi: provides wireless information for a requested interface using iwconfig
|
||||
-- vicious.widgets.wifi
|
||||
local wifi_linux = {}
|
||||
|
||||
-- {{{ Wireless widget type
|
||||
local function parser(stdout, stderr, exitreason, exitcode)
|
||||
local winfo = {}
|
||||
-- Output differs from system to system, stats can be separated by
|
||||
-- either = or :. Some stats may not be supported by driver.
|
||||
-- SSID can have almost anything in it.
|
||||
winfo["{ssid}"] = stdout:match'ESSID[=:]"(.-)"' or "N/A"
|
||||
-- Modes are simple, but also match the "-" in Ad-Hoc
|
||||
winfo["{mode}"] = stdout:match"Mode[=:]([%w%-]+)" or "N/A"
|
||||
winfo["{chan}"] = tonumber(stdout:match"Channel[=:](%d+)" or 0)
|
||||
winfo["{rate}"] = -- Bitrate without unit (Mb/s)
|
||||
tonumber(stdout:match"Bit Rate[=:]%s?([%d%.]+)" or 0)
|
||||
winfo["{freq}"] = -- Frequency in MHz (is output always in GHz?)
|
||||
tonumber(stdout:match"Frequency[=:]%s?([%d%.]+)" or 0) * 1000
|
||||
winfo["{txpw}"] = -- Transmission power in dBm
|
||||
tonumber(stdout:match"Tx%-Power[=:](%d+)" or 0)
|
||||
winfo["{link}"] = -- Link quality over 70
|
||||
tonumber(stdout:match"Link Quality[=:](%d+)" or 0)
|
||||
winfo["{linp}"] = -- Link quality percentage if quality was available
|
||||
winfo["{link}"] ~= 0 and math.floor(winfo["{link}"]/0.7 + 0.5) or 0
|
||||
-- Signal level without unit (dBm), can be negative value
|
||||
winfo["{sign}"] = tonumber(stdout:match"Signal level[=:](%-?%d+)" or 0)
|
||||
return winfo
|
||||
end
|
||||
|
||||
function wifi_linux.async(format, warg, callback)
|
||||
if type(warg) ~= "string" then return callback{} end
|
||||
spawn.easy_async_with_shell(
|
||||
"PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin iwconfig " .. warg,
|
||||
function (...) callback(parser(...)) end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(wifi_linux)
|
||||
76
.config/awesome/vicious/widgets/wifiiw_linux.lua
Normal file
76
.config/awesome/vicious/widgets/wifiiw_linux.lua
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
-- Wi-Fi widget type for GNU/Linux using iw
|
||||
-- Copyright (C) 2016 Marius M. <mellich@gmx.net>
|
||||
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
||||
-- Copyright (C) 2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
|
||||
-- Copyright (C) 2019 Xaver Hellauer <xaver@hellauer.bayern>
|
||||
--
|
||||
-- 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/>.
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
||||
-- Wifiiw: provides wireless information for a requested interface
|
||||
-- using iw instead of deprecated iwconfig
|
||||
-- vicious.widgets.wifiiw
|
||||
local wifiiw_linux = {}
|
||||
|
||||
local LINK = "PATH=$PATH:/sbin/:/usr/sbin:/usr/local/sbin iw dev %s link"
|
||||
local INFO = "PATH=$PATH:/sbin/:/usr/sbin:/usr/local/sbin iw dev %s info"
|
||||
|
||||
-- {{{ Wireless widget type
|
||||
function wifiiw_linux.async(format, warg, callback)
|
||||
if type(warg) ~= "string" then return callback{} end
|
||||
local winfo = {}
|
||||
|
||||
local function parse_link(stdout)
|
||||
winfo["{bssid}"] = stdout:match"Connected to ([%x:]*)" or "N/A"
|
||||
winfo["{ssid}"] = stdout:match"SSID: ([^\n]*)" or "N/A"
|
||||
winfo["{freq}"] = tonumber(stdout:match"freq: (%d+)" or 0)
|
||||
winfo["{sign}"] = -- Signal level can be negative; w/o unit (dBm)
|
||||
tonumber(stdout:match"signal: (%-?%d+)" or 0)
|
||||
winfo["{linp}"] = -- Link Quality (-100dBm->0%, -50dBm->100%)
|
||||
winfo["{sign}"] ~= 0 and 200 + winfo["{sign}"]*2 or 0
|
||||
winfo["{rate}"] = -- Transmission rate, without unit (Mb/s)
|
||||
tonumber(stdout:match"tx bitrate: ([%d%.]+)" or 0)
|
||||
end
|
||||
|
||||
local function parse_info(stdout)
|
||||
winfo["{mode}"] = stdout:match"type ([^\n]*)" or "N/A"
|
||||
winfo["{chan}"] = tonumber(stdout:match"channel (%d+)" or 0)
|
||||
-- Transmission power, without unit (dBm)
|
||||
winfo["{txpw}"] = tonumber(stdout:match"txpower (%-?%d+)" or 0)
|
||||
end
|
||||
|
||||
spawn.easy_async_with_shell(
|
||||
LINK:format(warg),
|
||||
function (std_out, std_err, exit_reason, exit_code)
|
||||
parse_link(std_out)
|
||||
spawn.easy_async_with_shell(
|
||||
INFO:format(warg),
|
||||
function (stdout, stderr, exitreason, exitcode)
|
||||
parse_info(stdout)
|
||||
callback(winfo)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers.setasyncall(wifiiw_linux)
|
||||
Loading…
Add table
Add a link
Reference in a new issue