mirror of https://github.com/lcpz/lain.git
fix #288
This commit is contained in:
parent
8c2e1df0c3
commit
ddbf283f0e
|
@ -35,7 +35,7 @@ local function worker(args)
|
||||||
|
|
||||||
abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable)
|
abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable)
|
||||||
|
|
||||||
return setmetatable(abase, { __index = abase.widget })
|
return abase
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -50,7 +50,7 @@ local function worker(args)
|
||||||
|
|
||||||
helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update)
|
helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update)
|
||||||
|
|
||||||
return setmetatable(alsa, { __index = alsa.widget })
|
return alsa
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -22,8 +22,6 @@ local function worker(args)
|
||||||
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()
|
|
||||||
|
|
||||||
function base.update()
|
function base.update()
|
||||||
output = helpers.read_pipe(cmd)
|
output = helpers.read_pipe(cmd)
|
||||||
if output ~= base.prev then
|
if output ~= base.prev then
|
||||||
|
@ -35,7 +33,7 @@ local function worker(args)
|
||||||
|
|
||||||
base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable)
|
base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable)
|
||||||
|
|
||||||
return setmetatable(base, { __index = base.widget })
|
return base
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -177,7 +177,7 @@ local function worker(args)
|
||||||
|
|
||||||
newtimer("batteries", timeout, bat.update)
|
newtimer("batteries", timeout, bat.update)
|
||||||
|
|
||||||
return setmetatable(bat, { __index = bat.widget })
|
return bat
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -19,7 +19,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Google Play Music Desktop infos
|
-- Google Play Music Desktop infos
|
||||||
-- lain.widget.contrib.gpmdp
|
-- lain.widget.contrib.gpmdp
|
||||||
local gpmdp = {}
|
local gpmdp = helpers.make_widget_textbox()
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -30,8 +30,6 @@ local function worker(args)
|
||||||
os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json"
|
os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json"
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
gpmdp.widget = wibox.widget.textbox('')
|
|
||||||
|
|
||||||
gpmdp_notification_preset = {
|
gpmdp_notification_preset = {
|
||||||
title = "Now playing",
|
title = "Now playing",
|
||||||
timeout = 6
|
timeout = 6
|
||||||
|
@ -86,7 +84,7 @@ local function worker(args)
|
||||||
|
|
||||||
gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true)
|
gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true)
|
||||||
|
|
||||||
return setmetatable(gpmdp, { __index = gpmdp.widget })
|
return gpmdp
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -72,7 +72,7 @@ local function worker(args)
|
||||||
|
|
||||||
helpers.newtimer("kbdlayout", timeout, kbdlayout.update)
|
helpers.newtimer("kbdlayout", timeout, kbdlayout.update)
|
||||||
|
|
||||||
return setmetatable(kbdlayout, { __index = kbdlayout.widget })
|
return kbdlayout
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function (_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function (_, ...) return worker(...) end })
|
||||||
|
|
|
@ -93,7 +93,7 @@ local function worker(args)
|
||||||
|
|
||||||
moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true)
|
moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true)
|
||||||
|
|
||||||
return setmetatable(moc, { __index = moc.widget })
|
return moc
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(moc, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(moc, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -19,19 +19,16 @@ local newtimer = require("lain.helpers").newtimer
|
||||||
local first_line = require("lain.helpers").first_line
|
local first_line = require("lain.helpers").first_line
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local string = { format = string.format }
|
local string = { format = string.format }
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local tostring = tostring
|
local tostring = tostring
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .. "?.lua;" .. package.path
|
package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .. "?.lua;" .. package.path
|
||||||
local smapi = require("smapi")
|
local smapi = require("smapi")
|
||||||
|
|
||||||
-- ThinkPad SMAPI-enabled battery info widget
|
-- ThinkPad SMAPI-enabled battery info widget
|
||||||
-- lain.widgets.contrib.tpbat
|
-- lain.widgets.contrib.tpbat
|
||||||
local tpbat = { }
|
local tpbat = { }
|
||||||
local tpbat_notification = nil
|
|
||||||
|
|
||||||
function tpbat.hide()
|
function tpbat.hide()
|
||||||
if not tpbat.notification then return end
|
if not tpbat.notification then return end
|
||||||
|
@ -69,7 +66,7 @@ function tpbat.show(t_out)
|
||||||
local str = string.format("%s : %s %s (%s)\n", bat.name, mfgr, model, chem)
|
local str = string.format("%s : %s %s (%s)\n", bat.name, mfgr, model, chem)
|
||||||
.. string.format("\n%s \t\t\t %s", status:upper(), msg)
|
.. string.format("\n%s \t\t\t %s", status:upper(), msg)
|
||||||
|
|
||||||
tpbat_notification = naughty.notify({
|
tpbat.notification = naughty.notify({
|
||||||
preset = naughty.config.defaults,
|
preset = naughty.config.defaults,
|
||||||
text = str,
|
text = str,
|
||||||
timeout = t_out,
|
timeout = t_out,
|
||||||
|
@ -86,7 +83,7 @@ function tpbat.register(args)
|
||||||
tpbat.bat = smapi:battery(battery) -- Create a new battery
|
tpbat.bat = smapi:battery(battery) -- Create a new battery
|
||||||
local bat = tpbat.bat
|
local bat = tpbat.bat
|
||||||
|
|
||||||
tpbat.widget = wibox.widget.textbox('')
|
tpbat.widget = wibox.widget.textbox()
|
||||||
|
|
||||||
bat_notification_low_preset = {
|
bat_notification_low_preset = {
|
||||||
title = "Battery low",
|
title = "Battery low",
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local lines_match = require("lain.helpers").lines_match
|
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,
|
||||||
|
@ -18,20 +17,20 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- CPU usage
|
-- CPU usage
|
||||||
-- lain.widgets.cpu
|
-- lain.widgets.cpu
|
||||||
local cpu = { core = {} }
|
local cpu = helpers.make_widget_textbox()
|
||||||
|
|
||||||
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 2
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
cpu.widget = wibox.widget.textbox()
|
cpu.core = {}
|
||||||
|
|
||||||
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 = lines_match("cpu","/proc/stat")
|
local times = helpers.lines_match("cpu","/proc/stat")
|
||||||
|
|
||||||
for index,time in pairs(times) do
|
for index,time in pairs(times) do
|
||||||
local coreid = index - 1
|
local coreid = index - 1
|
||||||
|
@ -75,9 +74,9 @@ local function worker(args)
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("cpu", timeout, update)
|
helpers.newtimer("cpu", timeout, update)
|
||||||
|
|
||||||
return setmetatable(cpu, { __index = cpu.widget })
|
return cpu
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(cpu, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(cpu, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -124,7 +124,7 @@ local function worker(args)
|
||||||
|
|
||||||
helpers.newtimer(partition, timeout, fs.update)
|
helpers.newtimer(partition, timeout, fs.update)
|
||||||
|
|
||||||
return setmetatable(fs, { __index = fs.widget })
|
return fs
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(fs, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(fs, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -17,7 +17,7 @@ local setmetatable = setmetatable
|
||||||
-- Mail IMAP check
|
-- Mail IMAP check
|
||||||
-- lain.widgets.imap
|
-- lain.widgets.imap
|
||||||
|
|
||||||
local function worker(args )
|
local function worker(args)
|
||||||
local imap = helpers.make_widget_textbox()
|
local imap = helpers.make_widget_textbox()
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local server = args.server
|
local server = args.server
|
||||||
|
@ -76,7 +76,7 @@ local function worker(args )
|
||||||
|
|
||||||
imap.timer = helpers.newtimer(mail, timeout, update, true, true)
|
imap.timer = helpers.newtimer(mail, timeout, update, true, true)
|
||||||
|
|
||||||
return setmetatable(imap, { __index = imap.widget })
|
return imap
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -18,7 +18,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Maildir check (synchronous)
|
-- Maildir check (synchronous)
|
||||||
-- lain.widgets.maildir
|
-- lain.widgets.maildir
|
||||||
local maildir = {}
|
local maildir = helpers.make_widget_textbox()
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -26,12 +26,10 @@ local function worker(args)
|
||||||
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
|
||||||
local ext_mail_cmd = args.external_mail_cmd
|
local cmd = args.cmd
|
||||||
|
|
||||||
maildir.widget = wibox.widget.textbox()
|
|
||||||
|
|
||||||
function maildir.update()
|
function maildir.update()
|
||||||
if ext_mail_cmd then awful.spawn(ext_mail_cmd) end
|
if cmd then helpers.async({ awful.util.shell, "-c", cmd }, function() end) end
|
||||||
|
|
||||||
-- Find pathes to mailboxes.
|
-- Find pathes to mailboxes.
|
||||||
local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath))
|
local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath))
|
||||||
|
@ -78,7 +76,7 @@ local function worker(args)
|
||||||
|
|
||||||
maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true)
|
maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true)
|
||||||
|
|
||||||
return setmetatable(maildir, { __index = maildir.widget })
|
return maildir
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local gmatch = string.gmatch
|
local gmatch = string.gmatch
|
||||||
local lines = io.lines
|
local lines = io.lines
|
||||||
|
@ -16,15 +16,13 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Memory usage (ignoring caches)
|
-- Memory usage (ignoring caches)
|
||||||
-- lain.widgets.mem
|
-- lain.widgets.mem
|
||||||
local mem = {}
|
local mem = helpers.make_widget_textbox()
|
||||||
|
|
||||||
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 2
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
mem.widget = wibox.widget.textbox()
|
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
mem_now = {}
|
mem_now = {}
|
||||||
for line in lines("/proc/meminfo") do
|
for line in lines("/proc/meminfo") do
|
||||||
|
@ -48,9 +46,9 @@ local function worker(args)
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("mem", timeout, update)
|
helpers.newtimer("mem", timeout, update)
|
||||||
|
|
||||||
return setmetatable(mem, { __index = mem.widget })
|
return mem
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(mem, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(mem, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -129,7 +129,7 @@ local function worker(args)
|
||||||
|
|
||||||
mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true)
|
mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true)
|
||||||
|
|
||||||
return setmetatable(mpd, { __index = mpd.widget })
|
return mpd
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -119,7 +119,7 @@ local function worker(args)
|
||||||
|
|
||||||
helpers.newtimer("network", timeout, update)
|
helpers.newtimer("network", timeout, update)
|
||||||
|
|
||||||
return setmetatable(net, { __index = net.widget })
|
return net
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -16,7 +16,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- PulseAudio volume
|
-- PulseAudio volume
|
||||||
-- lain.widgets.pulseaudio
|
-- lain.widgets.pulseaudio
|
||||||
local pulseaudio = {}
|
local pulseaudio = helpers.make_widget_textbox()
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -25,7 +25,6 @@ local function worker(args)
|
||||||
local scallback = args.scallback
|
local scallback = args.scallback
|
||||||
|
|
||||||
pulseaudio.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'"
|
pulseaudio.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'"
|
||||||
pulseaudio.widget = wibox.widget.textbox()
|
|
||||||
|
|
||||||
function pulseaudio.update()
|
function pulseaudio.update()
|
||||||
if scallback then pulseaudio.cmd = scallback() end
|
if scallback then pulseaudio.cmd = scallback() end
|
||||||
|
@ -54,7 +53,7 @@ local function worker(args)
|
||||||
|
|
||||||
helpers.newtimer("pulseaudio", timeout, pulseaudio.update)
|
helpers.newtimer("pulseaudio", timeout, pulseaudio.update)
|
||||||
|
|
||||||
return setmetatable(pulseaudio, { __index = pulseaudio.widget })
|
return pulseaudio
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -7,7 +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 }
|
||||||
local string = { match = string.match }
|
local string = { match = string.match }
|
||||||
|
@ -15,15 +15,13 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- System load
|
-- System load
|
||||||
-- lain.widgets.sysload
|
-- lain.widgets.sysload
|
||||||
local sysload = {}
|
local sysload = helpers.make_widget_textbox()
|
||||||
|
|
||||||
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 2
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
sysload.widget = wibox.widget.textbox()
|
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
local f = io.open("/proc/loadavg")
|
local f = io.open("/proc/loadavg")
|
||||||
local ret = f:read("*all")
|
local ret = f:read("*all")
|
||||||
|
@ -35,9 +33,9 @@ local function worker(args)
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("sysload", timeout, update)
|
helpers.newtimer("sysload", timeout, update)
|
||||||
|
|
||||||
return setmetatable(sysload, { __index = sysload.widget })
|
return sysload
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -6,7 +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 }
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
|
@ -14,7 +14,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- coretemp
|
-- coretemp
|
||||||
-- lain.widgets.temp
|
-- lain.widgets.temp
|
||||||
local temp = {}
|
local temp = helpers.make_widget_textbox()
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -22,8 +22,6 @@ local function worker(args)
|
||||||
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()
|
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
local f = io.open(tempfile)
|
local f = io.open(tempfile)
|
||||||
if f then
|
if f then
|
||||||
|
@ -37,9 +35,9 @@ local function worker(args)
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("coretemp", timeout, update)
|
helpers.newtimer("coretemp", timeout, update)
|
||||||
|
|
||||||
return setmetatable(temp, { __index = temp.widget })
|
return temp
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(temp, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(temp, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local async = require("lain.helpers").async
|
local helpers = require("lain.helpers")
|
||||||
local newtimer = require("lain.helpers").newtimer
|
|
||||||
local lain_icons = require("lain.helpers").icons_dir
|
|
||||||
local json = require("lain.util").dkjson
|
local json = require("lain.util").dkjson
|
||||||
local focused = require("awful.screen").focused
|
local focused = require("awful.screen").focused
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
|
@ -27,7 +25,7 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.weather
|
-- lain.widgets.weather
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local weather = {}
|
local weather = helpers.make_widget_textbox()
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default
|
local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default
|
||||||
local timeout = args.timeout or 900 -- 15 min
|
local timeout = args.timeout or 900 -- 15 min
|
||||||
|
@ -44,7 +42,7 @@ local function worker(args)
|
||||||
local lang = args.lang or "en"
|
local lang = args.lang or "en"
|
||||||
local cnt = args.cnt or 5
|
local cnt = args.cnt or 5
|
||||||
local date_cmd = args.date_cmd or "date -u -d @%d +'%%a %%d'"
|
local date_cmd = args.date_cmd or "date -u -d @%d +'%%a %%d'"
|
||||||
local icons_path = args.icons_path or lain_icons .. "openweathermap/"
|
local icons_path = args.icons_path or helpers.icons_dir .. "openweathermap/"
|
||||||
local notification_preset = args.notification_preset or {}
|
local notification_preset = args.notification_preset or {}
|
||||||
local notification_text_fun = args.notification_text_fun or
|
local notification_text_fun = args.notification_text_fun or
|
||||||
function (wn)
|
function (wn)
|
||||||
|
@ -58,9 +56,9 @@ local function worker(args)
|
||||||
local followtag = args.followtag or false
|
local followtag = args.followtag or false
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
weather.widget = wibox.widget.textbox(weather_na_markup)
|
weather.widget:set_markup(weather_na_markup)
|
||||||
weather.icon_path = icons_path .. "na.png"
|
weather.icon_path = icons_path .. "na.png"
|
||||||
weather.icon = wibox.widget.imagebox(weather.icon_path)
|
weather.icon = wibox.widget.imagebox(weather.icon_path)
|
||||||
|
|
||||||
function weather.show(t_out)
|
function weather.show(t_out)
|
||||||
weather.hide()
|
weather.hide()
|
||||||
|
@ -99,7 +97,7 @@ local function worker(args)
|
||||||
|
|
||||||
function weather.forecast_update()
|
function weather.forecast_update()
|
||||||
local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID)
|
local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID)
|
||||||
async(cmd, function(f)
|
helpers.async(cmd, function(f)
|
||||||
local pos, err
|
local pos, err
|
||||||
weather_now, pos, err = json.decode(f, 1, nil)
|
weather_now, pos, err = json.decode(f, 1, nil)
|
||||||
|
|
||||||
|
@ -119,7 +117,7 @@ local function worker(args)
|
||||||
|
|
||||||
function weather.update()
|
function weather.update()
|
||||||
local cmd = string.format(current_call, city_id, units, lang, APPID)
|
local cmd = string.format(current_call, city_id, units, lang, APPID)
|
||||||
async(cmd, function(f)
|
helpers.async(cmd, function(f)
|
||||||
local pos, err, icon
|
local pos, err, icon
|
||||||
weather_now, pos, err = json.decode(f, 1, nil)
|
weather_now, pos, err = json.decode(f, 1, nil)
|
||||||
|
|
||||||
|
@ -160,10 +158,10 @@ local function worker(args)
|
||||||
|
|
||||||
weather.attach(weather.widget)
|
weather.attach(weather.widget)
|
||||||
|
|
||||||
weather.timer = newtimer("weather-" .. city_id, timeout, weather.update, false, true)
|
weather.timer = helpers.newtimer("weather-" .. city_id, timeout, weather.update, false, true)
|
||||||
weather.timer_forecast = newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update, false, true)
|
weather.timer_forecast = helpers.newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update, false, true)
|
||||||
|
|
||||||
return setmetatable(weather, { __index = weather.widget })
|
return weather
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit 7e4865822c669a86007d88bf6ae846a95c5eed5f
|
Subproject commit 6d6fb0eb073e204c154e4d94b60472d858fc870d
|
Loading…
Reference in New Issue