mirror of https://github.com/lcpz/lain.git
refresh widget fix
This commit is contained in:
parent
68aa86654d
commit
e73a70c2ab
|
@ -26,9 +26,9 @@ local function worker(args)
|
||||||
local channel = args.channel or "Master"
|
local channel = args.channel or "Master"
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
alsa.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function alsa.update()
|
||||||
local f = io.popen('amixer get ' .. channel)
|
local f = io.popen('amixer get ' .. channel)
|
||||||
local mixer = f:read("*all")
|
local mixer = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
|
@ -56,11 +56,9 @@ local function worker(args)
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("alsa", timeout, update)
|
newtimer("alsa", timeout, alsa.update)
|
||||||
|
|
||||||
output = { widget = widget, notify = update }
|
return setmetatable(alsa, { __index = alsa.widget })
|
||||||
|
|
||||||
return setmetatable(output, { __index = output.widget })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -20,7 +20,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Battery infos
|
-- Battery infos
|
||||||
-- lain.widgets.bat
|
-- lain.widgets.bat
|
||||||
local bat = { id = nil }
|
local bat = {}
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -28,6 +28,8 @@ local function worker(args)
|
||||||
local battery = args.battery or "BAT0"
|
local battery = args.battery or "BAT0"
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
|
bat.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
bat_now = {
|
bat_now = {
|
||||||
status = "not present",
|
status = "not present",
|
||||||
perc = "N/A",
|
perc = "N/A",
|
||||||
|
@ -35,9 +37,7 @@ local function worker(args)
|
||||||
watt = "N/A"
|
watt = "N/A"
|
||||||
}
|
}
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
function bat.update()
|
||||||
|
|
||||||
function update()
|
|
||||||
local present = first_line("/sys/class/power_supply/"
|
local present = first_line("/sys/class/power_supply/"
|
||||||
.. battery
|
.. battery
|
||||||
.. "/present")
|
.. "/present")
|
||||||
|
@ -106,12 +106,13 @@ local function worker(args)
|
||||||
bat_now.perc = string.format("%d", bat_now.perc)
|
bat_now.perc = string.format("%d", bat_now.perc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
widget = bat.widget
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("bat", timeout, update)
|
newtimer("bat", timeout, bat.update)
|
||||||
|
|
||||||
return widget
|
return bat.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(bat, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(bat, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -31,9 +31,9 @@ local function worker(args)
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 5
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
cpu.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function cpu.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.
|
||||||
|
@ -60,6 +60,7 @@ local function worker(args)
|
||||||
|
|
||||||
usage = tostring(math.ceil((dactive / dtotal) * 100))
|
usage = tostring(math.ceil((dactive / dtotal) * 100))
|
||||||
|
|
||||||
|
widget = cpu.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
-- Save current data for the next run.
|
-- Save current data for the next run.
|
||||||
|
@ -67,9 +68,9 @@ local function worker(args)
|
||||||
cpu.last_total = total
|
cpu.last_total = total
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("cpu", timeout, update)
|
newtimer("cpu", timeout, cpu.update)
|
||||||
|
|
||||||
return widget
|
return cpu.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(cpu, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(cpu, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -24,8 +24,10 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- File system disk space usage
|
-- File system disk space usage
|
||||||
-- lain.widgets.fs
|
-- lain.widgets.fs
|
||||||
local fs = { notification_preset = {} }
|
local fs = {}
|
||||||
|
|
||||||
local notification = nil
|
local notification = nil
|
||||||
|
notification_preset = { fg = beautiful.fg_normal }
|
||||||
|
|
||||||
function fs:hide()
|
function fs:hide()
|
||||||
if notification ~= nil then
|
if notification ~= nil then
|
||||||
|
@ -42,7 +44,7 @@ function fs:show(t_out)
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
notification = naughty.notify({
|
notification = naughty.notify({
|
||||||
preset = fs.notification_preset,
|
preset = notification_preset,
|
||||||
text = ws,
|
text = ws,
|
||||||
timeout = t_out
|
timeout = t_out
|
||||||
})
|
})
|
||||||
|
@ -57,11 +59,11 @@ local function worker(args)
|
||||||
local partition = args.partition or "/"
|
local partition = args.partition or "/"
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
fs.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
helpers.set_map("fs", false)
|
helpers.set_map("fs", false)
|
||||||
|
|
||||||
function update()
|
function fs.update()
|
||||||
fs_info = {}
|
fs_info = {}
|
||||||
|
|
||||||
local f = io.popen("LC_ALL=C df -kP")
|
local f = io.popen("LC_ALL=C df -kP")
|
||||||
|
@ -83,17 +85,14 @@ local function worker(args)
|
||||||
|
|
||||||
-- chosen partition easy stuff
|
-- chosen partition easy stuff
|
||||||
-- you can however check whatever partition else
|
-- you can however check whatever partition else
|
||||||
used = fs_info[partition .. " used_p"]
|
used = tonumber(fs_info[partition .. " used_p"])
|
||||||
available = fs_info[partition .. " avail_p"]
|
available = tonumber(fs_info[partition .. " avail_p"])
|
||||||
size_mb = fs_info[partition .. " size_mb"]
|
size_mb = tonumber(fs_info[partition .. " size_mb"])
|
||||||
size_gb = fs_info[partition .. " size_gb"]
|
size_gb = tonumber(fs_info[partition .. " size_gb"])
|
||||||
|
|
||||||
notification_preset = { fg = beautiful.fg_normal }
|
|
||||||
|
|
||||||
|
widget = fs.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
fs.notification_preset = notification_preset
|
|
||||||
|
|
||||||
if used >= 99 and not helpers.get_map("fs")
|
if used >= 99 and not helpers.get_map("fs")
|
||||||
then
|
then
|
||||||
naughty.notify({
|
naughty.notify({
|
||||||
|
@ -109,15 +108,15 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer("fs " .. partition, timeout, update)
|
helpers.newtimer(partition, timeout, fs.update)
|
||||||
|
|
||||||
widget:connect_signal('mouse::enter', function () fs:show(0) end)
|
widget:connect_signal('mouse::enter', function () fs:show(0) end)
|
||||||
widget:connect_signal('mouse::leave', function () fs:hide() end)
|
widget:connect_signal('mouse::leave', function () fs:hide() end)
|
||||||
|
|
||||||
output = {
|
output = {
|
||||||
widget = widget,
|
widget = fs.widget,
|
||||||
show = function(t_out)
|
show = function(t_out)
|
||||||
update()
|
fs.update()
|
||||||
fs:show(t_out)
|
fs:show(t_out)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Mail IMAP check
|
-- Mail IMAP check
|
||||||
-- lain.widgets.imap
|
-- lain.widgets.imap
|
||||||
local imap = { stored = nil }
|
local imap = {}
|
||||||
|
|
||||||
function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
|
||||||
local server = args.server
|
local server = args.server
|
||||||
|
@ -54,9 +54,15 @@ function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
imap.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
notification_preset = {
|
||||||
|
icon = helpers.icons_dir .. "mail.png",
|
||||||
|
timeout = 8,
|
||||||
|
position = "top_left"
|
||||||
|
}
|
||||||
|
|
||||||
|
function imap.update()
|
||||||
to_execute = string.format("%s -s %s -u %s -p %s --port %s",
|
to_execute = string.format("%s -s %s -u %s -p %s --port %s",
|
||||||
checkmail, server, mail, password, port)
|
checkmail, server, mail, password, port)
|
||||||
|
|
||||||
|
@ -88,15 +94,9 @@ function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
notification_preset = {
|
widget = imap.widget
|
||||||
icon = helpers.icons_dir .. "mail.png",
|
|
||||||
timeout = 8,
|
|
||||||
position = "top_left"
|
|
||||||
}
|
|
||||||
|
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
|
|
||||||
if helpers.get_map(mail) and tonumber(mailcount) >= 1
|
if helpers.get_map(mail) and tonumber(mailcount) >= 1
|
||||||
then
|
then
|
||||||
notify_title = ws:match(mail .. " has %d new message.?")
|
notify_title = ws:match(mail .. " has %d new message.?")
|
||||||
|
@ -123,9 +123,9 @@ function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(mail, timeout, update, true)
|
helpers.newtimer(mail, timeout, imap.update, true)
|
||||||
|
|
||||||
return widget
|
return imap.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(imap, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(imap, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -24,16 +24,16 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.maildir
|
-- lain.widgets.maildir
|
||||||
local maildir = {}
|
local maildir = {}
|
||||||
|
|
||||||
function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 60
|
local timeout = args.timeout or 60
|
||||||
local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
|
local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
|
||||||
local ignore_boxes = args.ignore_boxes or {}
|
local ignore_boxes = args.ignore_boxes or {}
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
maildir.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function maildir.update()
|
||||||
-- Find pathes to mailboxes.
|
-- Find pathes to mailboxes.
|
||||||
local p = io.popen("find " .. mailpath ..
|
local p = io.popen("find " .. mailpath ..
|
||||||
" -mindepth 1 -maxdepth 1 -type d" ..
|
" -mindepth 1 -maxdepth 1 -type d" ..
|
||||||
|
@ -84,12 +84,13 @@ function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
widget = maildir.widget
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(mailpath, timeout, update, true)
|
newtimer(mailpath, timeout, maildir.update, true)
|
||||||
|
|
||||||
return widget
|
return maildir.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -25,14 +25,14 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.mem
|
-- lain.widgets.mem
|
||||||
local mem = {}
|
local mem = {}
|
||||||
|
|
||||||
function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 3
|
local timeout = args.timeout or 3
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
mem.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function mem.update()
|
||||||
mem = {}
|
mem = {}
|
||||||
for line in io.lines("/proc/meminfo")
|
for line in io.lines("/proc/meminfo")
|
||||||
do
|
do
|
||||||
|
@ -51,12 +51,13 @@ function worker(args)
|
||||||
used = mem.total - (mem.free + mem.buf + mem.cache)
|
used = mem.total - (mem.free + mem.buf + mem.cache)
|
||||||
swapused = mem.swap - mem.swapf
|
swapused = mem.swap - mem.swapf
|
||||||
|
|
||||||
|
widget = mem.widget
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("mem", timeout, update)
|
newtimer("mem", timeout, mem.update)
|
||||||
|
|
||||||
return widget
|
return mem.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(mem, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(mem, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -10,24 +10,24 @@
|
||||||
local helpers = require("lain.helpers")
|
local helpers = require("lain.helpers")
|
||||||
|
|
||||||
local util = require("awful.util")
|
local util = require("awful.util")
|
||||||
local beautiful = require("beautiful")
|
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local io = io
|
local io = { popen = io.popen }
|
||||||
local os = { execute = os.execute,
|
local os = { execute = os.execute,
|
||||||
getenv = os.getenv }
|
getenv = os.getenv }
|
||||||
local string = { gmatch = string.gmatch }
|
local string = { format = string.format,
|
||||||
|
gmatch = string.gmatch }
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- MPD infos
|
-- MPD infos
|
||||||
-- lain.widgets.mpd
|
-- lain.widgets.mpd
|
||||||
local mpd = { id = nil }
|
local mpd = {}
|
||||||
|
|
||||||
function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 1
|
local timeout = args.timeout or 2
|
||||||
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"
|
||||||
|
@ -38,11 +38,16 @@ function worker(args)
|
||||||
local mpdh = "telnet://" .. host .. ":" .. port
|
local mpdh = "telnet://" .. host .. ":" .. port
|
||||||
local echo = "echo 'password " .. password .. "\nstatus\ncurrentsong\nclose'"
|
local echo = "echo 'password " .. password .. "\nstatus\ncurrentsong\nclose'"
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
mpd.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
|
notification_preset = {
|
||||||
|
title = "Now playing",
|
||||||
|
timeout = 6
|
||||||
|
}
|
||||||
|
|
||||||
helpers.set_map("current mpd track", nil)
|
helpers.set_map("current mpd track", nil)
|
||||||
|
|
||||||
function update()
|
function mpd.update()
|
||||||
mpd_now = {
|
mpd_now = {
|
||||||
state = "N/A",
|
state = "N/A",
|
||||||
file = "N/A",
|
file = "N/A",
|
||||||
|
@ -52,7 +57,7 @@ function worker(args)
|
||||||
date = "N/A"
|
date = "N/A"
|
||||||
}
|
}
|
||||||
|
|
||||||
local f = io.popen(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh)
|
local f = io.popen(echo .. " | curl --connect-timeout 1 -fsm 1 " .. mpdh)
|
||||||
|
|
||||||
for line in f:lines() do
|
for line in f:lines() do
|
||||||
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
||||||
|
@ -68,17 +73,9 @@ function worker(args)
|
||||||
|
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
notification_preset = {
|
notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
|
||||||
title = "Now playing",
|
mpd_now.album, mpd_now.date, mpd_now.title)
|
||||||
text = mpd_now.artist .. " (" ..
|
widget = mpd.widget
|
||||||
mpd_now.album .. ") - " ..
|
|
||||||
mpd_now.date .. "\n" ..
|
|
||||||
mpd_now.title,
|
|
||||||
fg = beautiful.fg_normal or "#FFFFFF",
|
|
||||||
bg = beautiful.bg_normal or "#000000",
|
|
||||||
timeout = 6
|
|
||||||
}
|
|
||||||
|
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
if mpd_now.state == "play"
|
if mpd_now.state == "play"
|
||||||
|
@ -87,8 +84,7 @@ function worker(args)
|
||||||
then
|
then
|
||||||
helpers.set_map("current mpd track", mpd_now.title)
|
helpers.set_map("current mpd track", mpd_now.title)
|
||||||
|
|
||||||
os.execute(mpdcover .. " '" .. music_dir .. "' '"
|
os.execute(string.format("%s %q %q", mpdcover, music_dir, mpd_now.file))
|
||||||
.. mpd_now.file .. "'")
|
|
||||||
|
|
||||||
mpd.id = naughty.notify({
|
mpd.id = naughty.notify({
|
||||||
preset = notification_preset,
|
preset = notification_preset,
|
||||||
|
@ -102,11 +98,9 @@ function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer("mpd", timeout, update)
|
helpers.newtimer("mpd", timeout, mpd.update)
|
||||||
|
|
||||||
output = { widget = widget, notify = update }
|
return setmetatable(mpd, { __index = mpd.widget })
|
||||||
|
|
||||||
return setmetatable(output, { __index = output.widget })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -39,18 +39,18 @@ function net.get_device()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
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 2
|
||||||
local iface = args.iface or net.get_device()
|
local iface = args.iface or net.get_device()
|
||||||
local units = args.units or 1024 --kb
|
local units = args.units or 1024 --kb
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
net.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
helpers.set_map(iface, true)
|
helpers.set_map(iface, true)
|
||||||
|
|
||||||
function update()
|
function net.update()
|
||||||
if iface == "" then iface = net.get_device() end
|
if iface == "" then iface = net.get_device() end
|
||||||
|
|
||||||
carrier = helpers.first_line('/sys/class/net/' .. iface ..
|
carrier = helpers.first_line('/sys/class/net/' .. iface ..
|
||||||
|
@ -68,6 +68,7 @@ function worker(args)
|
||||||
received = tostring((now_r - net.last_r) / timeout / units)
|
received = tostring((now_r - net.last_r) / timeout / units)
|
||||||
received = string.gsub(string.format('%.1f', received), ",", ".")
|
received = string.gsub(string.format('%.1f', received), ",", ".")
|
||||||
|
|
||||||
|
widget = net.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
net.last_t = now_t
|
net.last_t = now_t
|
||||||
|
@ -94,9 +95,9 @@ function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(iface, timeout, update)
|
helpers.newtimer(iface, timeout, net.update)
|
||||||
|
|
||||||
return widget
|
return net.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(net, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(net, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -21,26 +21,27 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.sysload
|
-- lain.widgets.sysload
|
||||||
local sysload = {}
|
local sysload = {}
|
||||||
|
|
||||||
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 5
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
sysload.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function sysload.update()
|
||||||
local f = io.open("/proc/loadavg")
|
local f = io.open("/proc/loadavg")
|
||||||
local ret = f:read("*all")
|
local ret = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
a, b, c = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
|
a, b, c = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
|
||||||
|
|
||||||
|
widget = sysload.widget
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("sysload", timeout, update)
|
newtimer("sysload", timeout, sysload.update)
|
||||||
|
|
||||||
return widget
|
return sysload.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -19,23 +19,24 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.temp
|
-- lain.widgets.temp
|
||||||
local temp = {}
|
local temp = {}
|
||||||
|
|
||||||
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 5
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
widget = wibox.widget.textbox('')
|
temp.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function temp.update()
|
||||||
local f = io.open("/sys/class/thermal/thermal_zone0/temp")
|
local f = io.open("/sys/class/thermal/thermal_zone0/temp")
|
||||||
coretemp_now = tonumber(f:read("*all")) / 1000
|
coretemp_now = tonumber(f:read("*all")) / 1000
|
||||||
f:close()
|
f:close()
|
||||||
|
widget = temp.widget
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("coretemp", timeout, update)
|
newtimer("coretemp", timeout, temp.update)
|
||||||
|
|
||||||
return widget
|
return temp.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(temp, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(temp, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Rain.png
|
|
@ -28,8 +28,7 @@ local setmetatable = setmetatable
|
||||||
local yawn =
|
local yawn =
|
||||||
{
|
{
|
||||||
icon = wibox.widget.imagebox(),
|
icon = wibox.widget.imagebox(),
|
||||||
widget = wibox.widget.textbox(''),
|
widget = wibox.widget.textbox('')
|
||||||
notification_preset = {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local project_path = debug.getinfo(1, 'S').source:match[[^@(.*/).*$]]
|
local project_path = debug.getinfo(1, 'S').source:match[[^@(.*/).*$]]
|
||||||
|
@ -44,16 +43,15 @@ local city_id = nil
|
||||||
local sky = nil
|
local sky = nil
|
||||||
local settings = function() end
|
local settings = function() end
|
||||||
|
|
||||||
|
notification_preset = {}
|
||||||
|
|
||||||
local function fetch_weather()
|
local function fetch_weather()
|
||||||
local url = api_url .. units_set .. city_id
|
local url = api_url .. units_set .. city_id
|
||||||
local f = io.popen("curl --connect-timeout 1 -fsm 2 '"
|
local f = io.popen("curl --connect-timeout 1 -fsm 1 '"
|
||||||
.. url .. "'" )
|
.. url .. "'" )
|
||||||
local text = f:read("*all")
|
local text = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
-- handle no suitable icon found
|
|
||||||
yawn.icon:set_image(icon_path .. "na.png")
|
|
||||||
|
|
||||||
-- In case of no connection or invalid city ID
|
-- In case of no connection or invalid city ID
|
||||||
-- widgets won't display
|
-- widgets won't display
|
||||||
if text == "" or text:match("City not found")
|
if text == "" or text:match("City not found")
|
||||||
|
@ -107,6 +105,14 @@ local function fetch_weather()
|
||||||
|
|
||||||
sky = sky .. forecast:gsub(" ", ""):gsub("/", "") .. ".png"
|
sky = sky .. forecast:gsub(" ", ""):gsub("/", "") .. ".png"
|
||||||
|
|
||||||
|
-- In case there's no defined icon for current forecast
|
||||||
|
f = io.popen(sky)
|
||||||
|
if f == nil then
|
||||||
|
sky = icon_path .. "na.png"
|
||||||
|
else
|
||||||
|
io.close(f)
|
||||||
|
end
|
||||||
|
|
||||||
-- Localization
|
-- Localization
|
||||||
local f = io.open(localizations_path .. language, "r")
|
local f = io.open(localizations_path .. language, "r")
|
||||||
if language:find("en_") == nil and f ~= nil
|
if language:find("en_") == nil and f ~= nil
|
||||||
|
@ -122,17 +128,13 @@ local function fetch_weather()
|
||||||
|
|
||||||
-- Finally setting infos
|
-- Finally setting infos
|
||||||
yawn.icon:set_image(sky)
|
yawn.icon:set_image(sky)
|
||||||
widget = wibox.widget.textbox()
|
widget = yawn.widget
|
||||||
|
|
||||||
forecast = weather_data:match(": %S+.-,"):gsub(": ", ""):gsub(",", "\n")
|
forecast = weather_data:match(": %S+.-,"):gsub(": ", ""):gsub(",", "\n")
|
||||||
units = units:gsub(" ", "")
|
units = units:gsub(" ", "")
|
||||||
notification_preset = {}
|
-- notification_preset = {}
|
||||||
-- anche notification preset, con fg, bg e position
|
|
||||||
|
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
yawn.widget = widget
|
|
||||||
yawn.notification_preset = notification_preset
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function yawn.hide()
|
function yawn.hide()
|
||||||
|
@ -151,7 +153,7 @@ function yawn.show(t_out)
|
||||||
yawn.hide()
|
yawn.hide()
|
||||||
|
|
||||||
notification = naughty.notify({
|
notification = naughty.notify({
|
||||||
preset = yawn.notification_preset,
|
preset = notification_preset,
|
||||||
text = weather_data,
|
text = weather_data,
|
||||||
icon = sky,
|
icon = sky,
|
||||||
timeout = t_out
|
timeout = t_out
|
||||||
|
@ -176,7 +178,7 @@ function yawn.register(id, args)
|
||||||
yawn.hide()
|
yawn.hide()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return { icon = yawn.icon, widget = yawn.widget }
|
return yawn
|
||||||
end
|
end
|
||||||
|
|
||||||
function yawn.attach(widget, id, args)
|
function yawn.attach(widget, id, args)
|
||||||
|
|
Loading…
Reference in New Issue