mirror of https://github.com/lcpz/lain.git
parent
69ddbc74a5
commit
912bd26ede
12
helpers.lua
12
helpers.lua
|
@ -76,10 +76,16 @@ end
|
||||||
|
|
||||||
helpers.timer_table = {}
|
helpers.timer_table = {}
|
||||||
|
|
||||||
function helpers.newtimer(name, timeout, fun, nostart)
|
function helpers.newtimer(_name, timeout, fun, nostart)
|
||||||
helpers.timer_table[name] = capi.timer({ timeout = timeout })
|
local name = timeout
|
||||||
|
|
||||||
|
if not helpers.timer_table[name] then
|
||||||
|
helpers.timer_table[name] = capi.timer({ timeout = timeout })
|
||||||
|
helpers.timer_table[name]:start()
|
||||||
|
end
|
||||||
|
|
||||||
helpers.timer_table[name]:connect_signal("timeout", fun)
|
helpers.timer_table[name]:connect_signal("timeout", fun)
|
||||||
helpers.timer_table[name]:start()
|
|
||||||
if not nostart then
|
if not nostart then
|
||||||
helpers.timer_table[name]:emit_signal("timeout")
|
helpers.timer_table[name]:emit_signal("timeout")
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local async = require("lain.asyncshell")
|
local async = require("lain.asyncshell")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
|
@ -19,21 +19,26 @@ local setmetatable = setmetatable
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local abase = {}
|
local abase = {}
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 1
|
||||||
local cmd = args.cmd or ""
|
local cmd = args.cmd or ""
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
abase.widget = wibox.widget.textbox('')
|
abase.widget = wibox.widget.textbox('')
|
||||||
|
helpers.set_map(cmd, '')
|
||||||
|
|
||||||
function abase.update()
|
function abase.update()
|
||||||
async.request(cmd, function(f)
|
async.request(cmd, function(f)
|
||||||
output = f
|
output = f
|
||||||
widget = abase.widget
|
|
||||||
settings()
|
if helpers.get_map(cmd) ~= output then
|
||||||
|
widget = abase.widget
|
||||||
|
settings()
|
||||||
|
helpers.set_map(cmd, output)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(cmd, timeout, abase.update)
|
helpers.newtimer(cmd, timeout, abase.update)
|
||||||
|
|
||||||
return setmetatable(abase, { __index = abase.widget })
|
return setmetatable(abase, { __index = abase.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,11 +19,14 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- ALSA volume
|
-- ALSA volume
|
||||||
-- lain.widgets.alsa
|
-- lain.widgets.alsa
|
||||||
local alsa = {}
|
local alsa = {
|
||||||
|
level = "0",
|
||||||
|
status = "off",
|
||||||
|
}
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 1
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
alsa.cmd = args.cmd or "amixer"
|
alsa.cmd = args.cmd or "amixer"
|
||||||
|
@ -54,8 +57,14 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
widget = alsa.widget
|
if alsa.level ~= volume_now.level or alsa.status ~= volume_now.status
|
||||||
settings()
|
then
|
||||||
|
widget = alsa.widget
|
||||||
|
settings()
|
||||||
|
|
||||||
|
alsa.level = volume_now.level
|
||||||
|
alsa.status = volume_now.status
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
||||||
|
|
|
@ -47,7 +47,8 @@ local alsabar = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_current_level = 0,
|
_current_level = 0,
|
||||||
_muted = false
|
_muted = false,
|
||||||
|
_status = "off"
|
||||||
}
|
}
|
||||||
|
|
||||||
function alsabar.notify()
|
function alsabar.notify()
|
||||||
|
@ -56,7 +57,7 @@ function alsabar.notify()
|
||||||
local preset = {
|
local preset = {
|
||||||
title = "",
|
title = "",
|
||||||
text = "",
|
text = "",
|
||||||
timeout = 5,
|
timeout = 1,
|
||||||
screen = alsabar.notifications.screen,
|
screen = alsabar.notifications.screen,
|
||||||
font = alsabar.notifications.font .. " " ..
|
font = alsabar.notifications.font .. " " ..
|
||||||
alsabar.notifications.font_size,
|
alsabar.notifications.font_size,
|
||||||
|
@ -94,7 +95,7 @@ end
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 1
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
local width = args.width or 63
|
local width = args.width or 63
|
||||||
local height = args.heigth or 1
|
local height = args.heigth or 1
|
||||||
|
@ -127,28 +128,33 @@ local function worker(args)
|
||||||
-- Capture mixer control state: [5%] ... ... [on]
|
-- Capture mixer control state: [5%] ... ... [on]
|
||||||
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
||||||
|
|
||||||
if volu == nil then
|
volu = tonumber(volu) or 0
|
||||||
volu = 0
|
if mute == "" then mute = "off"
|
||||||
mute = "off"
|
|
||||||
end
|
|
||||||
|
|
||||||
alsabar._current_level = tonumber(volu)
|
if alsabar._current_level ~= volu or alsabar._status ~= mute then
|
||||||
alsabar.bar:set_value(alsabar._current_level / 100)
|
|
||||||
if not mute and tonumber(volu) == 0 or mute == "off"
|
|
||||||
then
|
|
||||||
alsabar._muted = true
|
|
||||||
alsabar.tooltip:set_text (" [Muted] ")
|
|
||||||
alsabar.bar:set_color(alsabar.colors.mute)
|
|
||||||
else
|
|
||||||
alsabar._muted = false
|
|
||||||
alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
|
|
||||||
alsabar.bar:set_color(alsabar.colors.unmute)
|
|
||||||
end
|
|
||||||
|
|
||||||
volume_now = {}
|
alsabar._current_level = volu
|
||||||
volume_now.level = tonumber(volu)
|
alsabar._status = mute
|
||||||
volume_now.status = mute
|
|
||||||
settings()
|
alsabar.bar:set_value(alsabar._current_level / 100)
|
||||||
|
|
||||||
|
if not mute and volu == 0 or mute == "off"
|
||||||
|
then
|
||||||
|
alsabar._muted = true
|
||||||
|
alsabar.tooltip:set_text (" [Muted] ")
|
||||||
|
alsabar.bar:set_color(alsabar.colors.mute)
|
||||||
|
else
|
||||||
|
alsabar._muted = false
|
||||||
|
alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
|
||||||
|
alsabar.bar:set_color(alsabar.colors.unmute)
|
||||||
|
end
|
||||||
|
|
||||||
|
volume_now = {}
|
||||||
|
volume_now.level = volu
|
||||||
|
volume_now.status = mute
|
||||||
|
|
||||||
|
settings()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alsabar.bar:buttons (awful.util.table.join (
|
alsabar.bar:buttons (awful.util.table.join (
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
@ -19,19 +17,24 @@ local setmetatable = setmetatable
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local base = {}
|
local base = {}
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 1
|
||||||
local cmd = args.cmd or ""
|
local cmd = args.cmd or ""
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
base.widget = wibox.widget.textbox('')
|
base.widget = wibox.widget.textbox('')
|
||||||
|
helpers.set_map(cmd, '')
|
||||||
|
|
||||||
function base.update()
|
function base.update()
|
||||||
output = read_pipe(cmd)
|
output = helpers.read_pipe(cmd)
|
||||||
widget = base.widget
|
|
||||||
settings()
|
if helpers.get_map(cmd) ~= output then
|
||||||
|
widget = base.widget
|
||||||
|
settings()
|
||||||
|
helpers.set_map(cmd, output)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(cmd, timeout, base.update)
|
helpers.newtimer(cmd, timeout, base.update)
|
||||||
|
|
||||||
return setmetatable(base, { __index = base.widget })
|
return setmetatable(base, { __index = base.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local first_line = require("lain.helpers").first_line
|
|
||||||
|
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
|
@ -48,6 +46,11 @@ local function worker(args)
|
||||||
bg = "#FFFFFF"
|
bg = "#FFFFFF"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helpers.set_map(battery .. "status", "N/A")
|
||||||
|
helpers.set_map(battery .. "perc", "N/A")
|
||||||
|
helpers.set_map(battery .. "time", "N/A")
|
||||||
|
helpers.set_map(battery .. "watt", "N/A")
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
bat_now = {
|
bat_now = {
|
||||||
status = "Not present",
|
status = "Not present",
|
||||||
|
@ -58,22 +61,22 @@ local function worker(args)
|
||||||
|
|
||||||
local bstr = "/sys/class/power_supply/" .. battery
|
local bstr = "/sys/class/power_supply/" .. battery
|
||||||
|
|
||||||
local present = first_line(bstr .. "/present")
|
local present = helpers.first_line(bstr .. "/present")
|
||||||
|
|
||||||
if present == "1"
|
if present == "1"
|
||||||
then
|
then
|
||||||
local rate = first_line(bstr .. "/power_now") or
|
local rate = helpers.first_line(bstr .. "/power_now") or
|
||||||
first_line(bstr .. "/current_now")
|
helpers.first_line(bstr .. "/current_now")
|
||||||
|
|
||||||
local ratev = first_line(bstr .. "/voltage_now")
|
local ratev = helpers.first_line(bstr .. "/voltage_now")
|
||||||
|
|
||||||
local rem = first_line(bstr .. "/energy_now") or
|
local rem = helpers.first_line(bstr .. "/energy_now") or
|
||||||
first_line(bstr .. "/charge_now")
|
helpers.first_line(bstr .. "/charge_now")
|
||||||
|
|
||||||
local tot = first_line(bstr .. "/energy_full") or
|
local tot = helpers.first_line(bstr .. "/energy_full") or
|
||||||
first_line(bstr .. "/charge_full")
|
helpers.first_line(bstr .. "/charge_full")
|
||||||
|
|
||||||
bat_now.status = first_line(bstr .. "/status") or "N/A"
|
bat_now.status = helpers.first_line(bstr .. "/status") or "N/A"
|
||||||
|
|
||||||
rate = tonumber(rate) or 1
|
rate = tonumber(rate) or 1
|
||||||
ratev = tonumber(ratev)
|
ratev = tonumber(ratev)
|
||||||
|
@ -97,7 +100,7 @@ local function worker(args)
|
||||||
|
|
||||||
bat_now.time = string.format("%02d:%02d", hrs, min)
|
bat_now.time = string.format("%02d:%02d", hrs, min)
|
||||||
|
|
||||||
bat_now.perc = first_line(bstr .. "/capacity")
|
bat_now.perc = helpers.first_line(bstr .. "/capacity")
|
||||||
|
|
||||||
if not bat_now.perc then
|
if not bat_now.perc then
|
||||||
local perc = (rem / tot) * 100
|
local perc = (rem / tot) * 100
|
||||||
|
@ -115,11 +118,21 @@ local function worker(args)
|
||||||
else
|
else
|
||||||
bat_now.watt = "N/A"
|
bat_now.watt = "N/A"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
widget = bat.widget
|
if bat_now.status ~= helpers.get_map(battery .. "status")
|
||||||
settings()
|
or bat_now.perc ~= helpers.get_map(battery .. "perc")
|
||||||
|
or bat_now.time ~= helpers.get_map(battery .. "time")
|
||||||
|
or bat_now.watt ~= helpers.get_map(battery .. "watt")
|
||||||
|
then
|
||||||
|
widget = bat.widget
|
||||||
|
settings()
|
||||||
|
|
||||||
|
helpers.set_map(battery .. "status", bat_now.status)
|
||||||
|
helpers.set_map(battery .. "perc", bat_now.perc)
|
||||||
|
helpers.set_map(battery .. "time", bat_now.time)
|
||||||
|
helpers.set_map(battery .. "watt", bat_now.watt)
|
||||||
|
end
|
||||||
|
|
||||||
-- notifications for low and critical states
|
-- notifications for low and critical states
|
||||||
if bat_now.status == "Discharging" and notify == "on" and bat_now.perc ~= nil
|
if bat_now.status == "Discharging" and notify == "on" and bat_now.perc ~= nil
|
||||||
|
@ -141,9 +154,9 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(battery, timeout, update)
|
helpers.newtimer(battery, timeout, update)
|
||||||
|
|
||||||
return setmetatable(bat, { __index = bat.widget })
|
return bat.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(bat, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -7,16 +7,13 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local first_line = require("lain.helpers").first_line
|
local helpers = require("lain.helpers")
|
||||||
local newtimer = require("lain.helpers").newtimer
|
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local math = { ceil = math.ceil }
|
local math = { ceil = math.ceil }
|
||||||
local string = { format = string.format,
|
local string = { format = string.format,
|
||||||
gmatch = string.gmatch }
|
gmatch = string.gmatch }
|
||||||
local tostring = tostring
|
local tostring = tostring
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- CPU usage
|
-- CPU usage
|
||||||
|
@ -28,16 +25,18 @@ local cpu = {
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 2
|
local timeout = args.timeout or 1
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
cpu.widget = wibox.widget.textbox('')
|
cpu.widget = wibox.widget.textbox('')
|
||||||
|
helpers.set_map("cpuactive", 0)
|
||||||
|
helpers.set_map("cputotal", 0)
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
-- Read the amount of time the CPUs have spent performing
|
-- Read the amount of time the CPUs have spent performing
|
||||||
-- different kinds of work. Read the first line of /proc/stat
|
-- different kinds of work. Read the first line of /proc/stat
|
||||||
-- which is the sum of all CPUs.
|
-- which is the sum of all CPUs.
|
||||||
local times = first_line("/proc/stat")
|
local times = helpers.first_line("/proc/stat")
|
||||||
local at = 1
|
local at = 1
|
||||||
local idle = 0
|
local idle = 0
|
||||||
local total = 0
|
local total = 0
|
||||||
|
@ -54,22 +53,26 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
local active = total - idle
|
local active = total - idle
|
||||||
|
|
||||||
-- Read current data and calculate relative values.
|
if helpers.get_map("cpuactive") ~= active
|
||||||
local dactive = active - cpu.last_active
|
or helpers.get_map("cputotal") ~= total
|
||||||
local dtotal = total - cpu.last_total
|
then
|
||||||
|
-- Read current data and calculate relative values.
|
||||||
|
local dactive = active - cpu.last_active
|
||||||
|
local dtotal = total - cpu.last_total
|
||||||
|
|
||||||
cpu_now = {}
|
cpu_now = {}
|
||||||
cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100))
|
cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100))
|
||||||
|
|
||||||
widget = cpu.widget
|
widget = cpu.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
-- Save current data for the next run.
|
-- Save current data for the next run.
|
||||||
cpu.last_active = active
|
helpers.set_map("cpuactive", active)
|
||||||
cpu.last_total = total
|
helpers.set_map("cputotal", total)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("cpu", timeout, update)
|
helpers.newtimer("cpu", timeout, update)
|
||||||
|
|
||||||
return cpu.widget
|
return cpu.widget
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,8 @@ local setmetatable = setmetatable
|
||||||
-- File system disk space usage
|
-- File system disk space usage
|
||||||
-- lain.widgets.fs
|
-- lain.widgets.fs
|
||||||
local fs = {}
|
local fs = {}
|
||||||
local fs_notification = nil
|
|
||||||
|
local fs_notification = nil
|
||||||
|
|
||||||
function fs:hide()
|
function fs:hide()
|
||||||
if fs_notification ~= nil then
|
if fs_notification ~= nil then
|
||||||
|
@ -41,11 +42,11 @@ function fs:show(t_out)
|
||||||
local ws = helpers.read_pipe(helpers.scripts_dir .. "dfs"):gsub("\n*$", "")
|
local ws = helpers.read_pipe(helpers.scripts_dir .. "dfs"):gsub("\n*$", "")
|
||||||
|
|
||||||
if fs.followmouse then
|
if fs.followmouse then
|
||||||
fs.notification_preset.screen = mouse.screen
|
fs_notification_preset.screen = mouse.screen
|
||||||
end
|
end
|
||||||
|
|
||||||
fs_notification = naughty.notify({
|
fs_notification = naughty.notify({
|
||||||
preset = fs.notification_preset,
|
preset = fs_notification_preset,
|
||||||
text = ws,
|
text = ws,
|
||||||
timeout = t_out
|
timeout = t_out
|
||||||
})
|
})
|
||||||
|
@ -66,6 +67,7 @@ local function worker(args)
|
||||||
fs.widget = wibox.widget.textbox('')
|
fs.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
helpers.set_map(partition, false)
|
helpers.set_map(partition, false)
|
||||||
|
helpers.set_map("fsused", 0)
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
fs_info = {}
|
fs_info = {}
|
||||||
|
@ -92,8 +94,11 @@ local function worker(args)
|
||||||
fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0
|
fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0
|
||||||
fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0
|
fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0
|
||||||
|
|
||||||
widget = fs.widget
|
if helpers.get_map("fsused") ~= fs_now.used then
|
||||||
settings()
|
widget = fs.widget
|
||||||
|
settings()
|
||||||
|
helpers.set_map("fsused", fs_now.used)
|
||||||
|
end
|
||||||
|
|
||||||
if fs_now.used >= 99 and not helpers.get_map(partition)
|
if fs_now.used >= 99 and not helpers.get_map(partition)
|
||||||
then
|
then
|
||||||
|
|
|
@ -65,8 +65,10 @@ local function worker(args)
|
||||||
_, mailcount = string.gsub(f, "%d+", "")
|
_, mailcount = string.gsub(f, "%d+", "")
|
||||||
_ = nil
|
_ = nil
|
||||||
|
|
||||||
widget = imap.widget
|
if mailcount ~= helpers.get_map(mail) then
|
||||||
settings()
|
widget = imap.widget
|
||||||
|
settings()
|
||||||
|
end
|
||||||
|
|
||||||
if mailcount >= 1 and mailcount > helpers.get_map(mail)
|
if mailcount >= 1 and mailcount > helpers.get_map(mail)
|
||||||
then
|
then
|
||||||
|
|
|
@ -25,7 +25,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Maildir check
|
-- Maildir check
|
||||||
-- lain.widgets.maildir
|
-- lain.widgets.maildir
|
||||||
local maildir = {}
|
local maildir = { total = 0 }
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -65,7 +65,7 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
until line == nil
|
until line == nil
|
||||||
|
|
||||||
p:close()
|
p:close()
|
||||||
table.sort(boxes)
|
table.sort(boxes)
|
||||||
|
|
||||||
newmail = "no mail"
|
newmail = "no mail"
|
||||||
|
@ -88,8 +88,10 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
widget = maildir.widget
|
if maildir.total ~= total then
|
||||||
settings()
|
widget = maildir.widget
|
||||||
|
settings()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(mailpath, timeout, update, true)
|
newtimer(mailpath, timeout, update, true)
|
||||||
|
|
|
@ -7,27 +7,33 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local io = { lines = io.lines }
|
||||||
|
local math = { floor = math.floor }
|
||||||
|
local string = { gmatch = string.gmatch }
|
||||||
|
|
||||||
local io = { lines = io.lines }
|
local setmetatable = setmetatable
|
||||||
local math = { floor = math.floor }
|
|
||||||
local string = { gmatch = string.gmatch }
|
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
-- Memory usage
|
||||||
|
|
||||||
-- Memory usage (ignoring caches)
|
|
||||||
-- lain.widgets.mem
|
-- lain.widgets.mem
|
||||||
local mem = {}
|
local mem = {}
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 2
|
local timeout = args.timeout or 1
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
mem.widget = wibox.widget.textbox('')
|
mem.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
|
helpers.set_map("mem_last_total", 0)
|
||||||
|
helpers.set_map("mem_last_free", 0)
|
||||||
|
helpers.set_map("mem_last_buf", 0)
|
||||||
|
helpers.set_map("mem_last_cache", 0)
|
||||||
|
helpers.set_map("mem_last_swap", 0)
|
||||||
|
helpers.set_map("mem_last_swapf", 0)
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
mem_now = {}
|
mem_now = {}
|
||||||
for line in io.lines("/proc/meminfo")
|
for line in io.lines("/proc/meminfo")
|
||||||
|
@ -44,14 +50,29 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache)
|
if mem_now.total ~= helpers.set_map("mem_last_total")
|
||||||
mem_now.swapused = mem_now.swap - mem_now.swapf
|
or mem_now.free ~= helpers.set_map("mem_last_free")
|
||||||
|
or mem_now.buf ~= helpers.set_map("mem_last_buf")
|
||||||
|
or mem_now.cache ~= helpers.set_map("mem_last_cache")
|
||||||
|
or mem_now.swap ~= helpers.set_map("mem_last_swap")
|
||||||
|
or mem_now.swapf ~= helpers.set_map("mem_last_swapf")
|
||||||
|
then
|
||||||
|
mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache)
|
||||||
|
mem_now.swapused = mem_now.swap - mem_now.swapf
|
||||||
|
|
||||||
widget = mem.widget
|
widget = mem.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
|
helpers.set_map("mem_last_total", mem_now.total)
|
||||||
|
helpers.set_map("mem_last_free", mem_now.free)
|
||||||
|
helpers.set_map("mem_last_buf", mem_now.buf)
|
||||||
|
helpers.set_map("mem_last_cache", mem_now.cache)
|
||||||
|
helpers.set_map("mem_last_swap", mem_now.swap)
|
||||||
|
helpers.set_map("mem_last_swapf", mem_now.swapf)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("mem", timeout, update)
|
helpers.newtimer("mem", timeout, update)
|
||||||
|
|
||||||
return mem.widget
|
return mem.widget
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,7 +30,7 @@ local mpd = {}
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 2
|
local timeout = args.timeout or 1
|
||||||
local password = args.password or ""
|
local password = args.password or ""
|
||||||
local host = args.host or "127.0.0.1"
|
local host = args.host or "127.0.0.1"
|
||||||
local port = args.port or "6600"
|
local port = args.port or "6600"
|
||||||
|
@ -49,10 +49,11 @@ local function worker(args)
|
||||||
|
|
||||||
mpd_notification_preset = {
|
mpd_notification_preset = {
|
||||||
title = "Now playing",
|
title = "Now playing",
|
||||||
timeout = 6
|
timeout = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
helpers.set_map("current mpd track", nil)
|
helpers.set_map("current mpd track", "")
|
||||||
|
helpers.set_map("current mpd file", "")
|
||||||
|
|
||||||
function mpd.update()
|
function mpd.update()
|
||||||
async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f)
|
async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f)
|
||||||
|
@ -84,8 +85,13 @@ local function worker(args)
|
||||||
|
|
||||||
mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
|
mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
|
||||||
mpd_now.album, mpd_now.date, mpd_now.title)
|
mpd_now.album, mpd_now.date, mpd_now.title)
|
||||||
widget = mpd.widget
|
|
||||||
settings()
|
if mpd_now.file ~= helpers.get_map("current mpd file")
|
||||||
|
then
|
||||||
|
widget = mpd.widget
|
||||||
|
settings()
|
||||||
|
helpers.set_map("current mpd file", mpd_now.file)
|
||||||
|
end
|
||||||
|
|
||||||
if mpd_now.state == "play"
|
if mpd_now.state == "play"
|
||||||
then
|
then
|
||||||
|
|
|
@ -21,10 +21,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Network infos
|
-- Network infos
|
||||||
-- lain.widgets.net
|
-- lain.widgets.net
|
||||||
local net = {
|
local net = {}
|
||||||
last_t = 0,
|
|
||||||
last_r = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function net.get_device()
|
function net.get_device()
|
||||||
local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
|
local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
|
||||||
|
@ -38,7 +35,7 @@ end
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 2
|
local timeout = args.timeout or 1
|
||||||
local units = args.units or 1024 --kb
|
local units = args.units or 1024 --kb
|
||||||
local notify = args.notify or "on"
|
local notify = args.notify or "on"
|
||||||
local screen = args.screen or 1
|
local screen = args.screen or 1
|
||||||
|
@ -49,35 +46,44 @@ local function worker(args)
|
||||||
net.widget = wibox.widget.textbox('')
|
net.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
helpers.set_map(iface, true)
|
helpers.set_map(iface, true)
|
||||||
|
helpers.set_map("net_t", 0)
|
||||||
|
helpers.set_map("net_r", 0)
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
net_now = {}
|
net_now = {
|
||||||
|
sent = "0.0",
|
||||||
|
received = "0.0"
|
||||||
|
}
|
||||||
|
|
||||||
if iface == "" or string.match(iface, "network off")
|
if iface == "" or string.match(iface, "network off")
|
||||||
then
|
then
|
||||||
iface = net.get_device()
|
iface = net.get_device()
|
||||||
end
|
end
|
||||||
|
|
||||||
net_now.carrier = helpers.first_line('/sys/class/net/' .. iface ..
|
|
||||||
'/carrier') or "0"
|
|
||||||
net_now.state = helpers.first_line('/sys/class/net/' .. iface ..
|
|
||||||
'/operstate') or "down"
|
|
||||||
local now_t = helpers.first_line('/sys/class/net/' .. iface ..
|
local now_t = helpers.first_line('/sys/class/net/' .. iface ..
|
||||||
'/statistics/tx_bytes') or 0
|
'/statistics/tx_bytes') or 0
|
||||||
local now_r = helpers.first_line('/sys/class/net/' .. iface ..
|
local now_r = helpers.first_line('/sys/class/net/' .. iface ..
|
||||||
'/statistics/rx_bytes') or 0
|
'/statistics/rx_bytes') or 0
|
||||||
|
|
||||||
net_now.sent = (now_t - net.last_t) / timeout / units
|
if now_t ~= helpers.get_map("net_t")
|
||||||
net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".")
|
or now_r ~= helpers.get_map("net_r") then
|
||||||
|
net_now.carrier = helpers.first_line('/sys/class/net/' .. iface ..
|
||||||
|
'/carrier') or "0"
|
||||||
|
net_now.state = helpers.first_line('/sys/class/net/' .. iface ..
|
||||||
|
'/operstate') or "down"
|
||||||
|
|
||||||
net_now.received = (now_r - net.last_r) / timeout / units
|
net_now.sent = (now_t - net.last_t) / timeout / units
|
||||||
net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".")
|
net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".")
|
||||||
|
|
||||||
widget = net.widget
|
net_now.received = (now_r - net.last_r) / timeout / units
|
||||||
settings()
|
net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".")
|
||||||
|
|
||||||
net.last_t = now_t
|
widget = net.widget
|
||||||
net.last_r = now_r
|
settings()
|
||||||
|
|
||||||
|
helpers.set_map("net_t", now_t)
|
||||||
|
helpers.set_map("net_r", now_r)
|
||||||
|
end
|
||||||
|
|
||||||
if net_now.carrier ~= "1" and notify == "on"
|
if net_now.carrier ~= "1" and notify == "on"
|
||||||
then
|
then
|
||||||
|
@ -99,7 +105,8 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(iface, timeout, update)
|
helpers.newtimer(iface, timeout, update, false)
|
||||||
|
|
||||||
return net.widget
|
return net.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
|
@ -22,10 +21,13 @@ local sysload = {}
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 2
|
local timeout = args.timeout or 1
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
sysload.widget = wibox.widget.textbox('')
|
sysload.widget = wibox.widget.textbox('')
|
||||||
|
helpers.set_map("load_1", 0)
|
||||||
|
helpers.set_map("load_5", 0)
|
||||||
|
helpers.set_map("load_15", 0)
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
local f = io.open("/proc/loadavg")
|
local f = io.open("/proc/loadavg")
|
||||||
|
@ -34,11 +36,21 @@ local function worker(args)
|
||||||
|
|
||||||
load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
|
load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
|
||||||
|
|
||||||
widget = sysload.widget
|
if load_1 ~= helpers.get_map("load_1")
|
||||||
settings()
|
or load_5 ~= helpers.get_map("load_5")
|
||||||
|
or load_15 ~= helpers.get_map("load_15")
|
||||||
|
then
|
||||||
|
widget = sysload.widget
|
||||||
|
settings()
|
||||||
|
|
||||||
|
helpers.set_map("load_1", load_1)
|
||||||
|
helpers.set_map("load_5", load_5)
|
||||||
|
helpers.set_map("load_15", load_15)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("sysload", timeout, update)
|
helpers.newtimer("sysload", timeout, update)
|
||||||
|
|
||||||
return sysload.widget
|
return sysload.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
|
@ -21,11 +20,12 @@ local temp = {}
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 2
|
local timeout = args.timeout or 1
|
||||||
local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp"
|
local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp"
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
temp.widget = wibox.widget.textbox('')
|
temp.widget = wibox.widget.textbox('')
|
||||||
|
helpers.set_map("temp_last", 0)
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
local f = io.open(tempfile)
|
local f = io.open(tempfile)
|
||||||
|
@ -37,11 +37,15 @@ local function worker(args)
|
||||||
coretemp_now = "N/A"
|
coretemp_now = "N/A"
|
||||||
end
|
end
|
||||||
|
|
||||||
widget = temp.widget
|
if helpers.get_map("temp_last") ~= coretemp_now then
|
||||||
settings()
|
widget = temp.widget
|
||||||
|
settings()
|
||||||
|
helpers.set_map("temp_last", coretemp_now)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("coretemp", timeout, update)
|
helpers.newtimer("coretemp", timeout, update)
|
||||||
|
|
||||||
return temp.widget
|
return temp.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit d7aa1a7b8428211a1c4c71865fd64302e013d62b
|
Subproject commit 78879bd1208d713dcbb9216f226a34b51f886421
|
Loading…
Reference in New Issue