From ddbf283f0ebbc6772d485fe76c5dccf338d3b837 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 17:13:14 +0100 Subject: [PATCH] fix #288 --- widgets/abase.lua | 2 +- widgets/alsa.lua | 2 +- widgets/base.lua | 4 +--- widgets/bat.lua | 2 +- widgets/contrib/gpmdp.lua | 6 ++---- widgets/contrib/kbdlayout.lua | 2 +- widgets/contrib/moc.lua | 2 +- widgets/contrib/tpbat/init.lua | 7 ++----- widgets/cpu.lua | 13 ++++++------- widgets/fs.lua | 2 +- widgets/imap.lua | 4 ++-- widgets/maildir.lua | 10 ++++------ widgets/mem.lua | 10 ++++------ widgets/mpd.lua | 2 +- widgets/net.lua | 2 +- widgets/pulseaudio.lua | 5 ++--- widgets/sysload.lua | 14 ++++++-------- widgets/temp.lua | 10 ++++------ widgets/weather.lua | 22 ++++++++++------------ wiki | 2 +- 20 files changed, 52 insertions(+), 71 deletions(-) diff --git a/widgets/abase.lua b/widgets/abase.lua index 7eef754..1214151 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -35,7 +35,7 @@ local function worker(args) abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable) - return setmetatable(abase, { __index = abase.widget }) + return abase end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 93c74cc..8139d42 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -50,7 +50,7 @@ local function worker(args) helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update) - return setmetatable(alsa, { __index = alsa.widget }) + return alsa end return setmetatable(alsa, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/base.lua b/widgets/base.lua index 87b0c85..9d7b710 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -22,8 +22,6 @@ local function worker(args) local cmd = args.cmd or "" local settings = args.settings or function() end - base.widget = wibox.widget.textbox() - function base.update() output = helpers.read_pipe(cmd) if output ~= base.prev then @@ -35,7 +33,7 @@ local function worker(args) base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable) - return setmetatable(base, { __index = base.widget }) + return base end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/bat.lua b/widgets/bat.lua index 8b62790..503c56e 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -177,7 +177,7 @@ local function worker(args) newtimer("batteries", timeout, bat.update) - return setmetatable(bat, { __index = bat.widget }) + return bat end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/contrib/gpmdp.lua b/widgets/contrib/gpmdp.lua index 21776ac..37da43d 100644 --- a/widgets/contrib/gpmdp.lua +++ b/widgets/contrib/gpmdp.lua @@ -19,7 +19,7 @@ local setmetatable = setmetatable -- Google Play Music Desktop infos -- lain.widget.contrib.gpmdp -local gpmdp = {} +local gpmdp = helpers.make_widget_textbox() local function worker(args) 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" local settings = args.settings or function() end - gpmdp.widget = wibox.widget.textbox('') - gpmdp_notification_preset = { title = "Now playing", timeout = 6 @@ -86,7 +84,7 @@ local function worker(args) gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true) - return setmetatable(gpmdp, { __index = gpmdp.widget }) + return gpmdp end return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/contrib/kbdlayout.lua b/widgets/contrib/kbdlayout.lua index da3084c..8132c77 100644 --- a/widgets/contrib/kbdlayout.lua +++ b/widgets/contrib/kbdlayout.lua @@ -72,7 +72,7 @@ local function worker(args) helpers.newtimer("kbdlayout", timeout, kbdlayout.update) - return setmetatable(kbdlayout, { __index = kbdlayout.widget }) + return kbdlayout end return setmetatable({}, { __call = function (_, ...) return worker(...) end }) diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index 6190f5f..3566985 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -93,7 +93,7 @@ local function worker(args) moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true) - return setmetatable(moc, { __index = moc.widget }) + return moc end return setmetatable(moc, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index d96c2d8..3342e02 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -19,19 +19,16 @@ local newtimer = require("lain.helpers").newtimer local first_line = require("lain.helpers").first_line local naughty = require("naughty") local wibox = require("wibox") - local string = { format = string.format } local math = { floor = math.floor } local tostring = tostring local setmetatable = setmetatable - package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .. "?.lua;" .. package.path local smapi = require("smapi") -- ThinkPad SMAPI-enabled battery info widget -- lain.widgets.contrib.tpbat local tpbat = { } -local tpbat_notification = nil function tpbat.hide() 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) .. string.format("\n%s \t\t\t %s", status:upper(), msg) - tpbat_notification = naughty.notify({ + tpbat.notification = naughty.notify({ preset = naughty.config.defaults, text = str, timeout = t_out, @@ -86,7 +83,7 @@ function tpbat.register(args) tpbat.bat = smapi:battery(battery) -- Create a new battery local bat = tpbat.bat - tpbat.widget = wibox.widget.textbox('') + tpbat.widget = wibox.widget.textbox() bat_notification_low_preset = { title = "Battery low", diff --git a/widgets/cpu.lua b/widgets/cpu.lua index f7fb087..f61e2cc 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -7,8 +7,7 @@ --]] -local lines_match = require("lain.helpers").lines_match -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local math = { ceil = math.ceil } local string = { format = string.format, @@ -18,20 +17,20 @@ local setmetatable = setmetatable -- CPU usage -- lain.widgets.cpu -local cpu = { core = {} } +local cpu = helpers.make_widget_textbox() local function worker(args) local args = args or {} local timeout = args.timeout or 2 local settings = args.settings or function() end - cpu.widget = wibox.widget.textbox() + cpu.core = {} function update() -- Read the amount of time the CPUs have spent performing -- different kinds of work. Read the first line of /proc/stat -- 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 local coreid = index - 1 @@ -75,9 +74,9 @@ local function worker(args) settings() end - newtimer("cpu", timeout, update) + helpers.newtimer("cpu", timeout, update) - return setmetatable(cpu, { __index = cpu.widget }) + return cpu end return setmetatable(cpu, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/fs.lua b/widgets/fs.lua index 4e9f04b..e01aab8 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -124,7 +124,7 @@ local function worker(args) helpers.newtimer(partition, timeout, fs.update) - return setmetatable(fs, { __index = fs.widget }) + return fs end return setmetatable(fs, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/imap.lua b/widgets/imap.lua index 5896ae1..4be63dd 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -17,7 +17,7 @@ local setmetatable = setmetatable -- Mail IMAP check -- lain.widgets.imap -local function worker(args ) +local function worker(args) local imap = helpers.make_widget_textbox() local args = args or {} local server = args.server @@ -76,7 +76,7 @@ local function worker(args ) imap.timer = helpers.newtimer(mail, timeout, update, true, true) - return setmetatable(imap, { __index = imap.widget }) + return imap end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 1f4cd45..7e7b246 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -18,7 +18,7 @@ local setmetatable = setmetatable -- Maildir check (synchronous) -- lain.widgets.maildir -local maildir = {} +local maildir = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -26,12 +26,10 @@ local function worker(args) local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail" local ignore_boxes = args.ignore_boxes or {} local settings = args.settings or function() end - local ext_mail_cmd = args.external_mail_cmd - - maildir.widget = wibox.widget.textbox() + local cmd = args.cmd 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. 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) - return setmetatable(maildir, { __index = maildir.widget }) + return maildir end return setmetatable(maildir, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mem.lua b/widgets/mem.lua index e96dc1b..ff5816c 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -7,7 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local gmatch = string.gmatch local lines = io.lines @@ -16,15 +16,13 @@ local setmetatable = setmetatable -- Memory usage (ignoring caches) -- lain.widgets.mem -local mem = {} +local mem = helpers.make_widget_textbox() local function worker(args) local args = args or {} local timeout = args.timeout or 2 local settings = args.settings or function() end - mem.widget = wibox.widget.textbox() - function update() mem_now = {} for line in lines("/proc/meminfo") do @@ -48,9 +46,9 @@ local function worker(args) settings() end - newtimer("mem", timeout, update) + helpers.newtimer("mem", timeout, update) - return setmetatable(mem, { __index = mem.widget }) + return mem end return setmetatable(mem, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index aad4dc8..d92c78f 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -129,7 +129,7 @@ local function worker(args) mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true) - return setmetatable(mpd, { __index = mpd.widget }) + return mpd end return setmetatable(mpd, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/net.lua b/widgets/net.lua index 0b19f0b..302559a 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -119,7 +119,7 @@ local function worker(args) helpers.newtimer("network", timeout, update) - return setmetatable(net, { __index = net.widget }) + return net end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index 3178dcf..8e89ffd 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -16,7 +16,7 @@ local setmetatable = setmetatable -- PulseAudio volume -- lain.widgets.pulseaudio -local pulseaudio = {} +local pulseaudio = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -25,7 +25,6 @@ local function worker(args) 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.widget = wibox.widget.textbox() function pulseaudio.update() if scallback then pulseaudio.cmd = scallback() end @@ -54,7 +53,7 @@ local function worker(args) helpers.newtimer("pulseaudio", timeout, pulseaudio.update) - return setmetatable(pulseaudio, { __index = pulseaudio.widget }) + return pulseaudio end return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 041feb1..148319d 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -7,7 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local io = { open = io.open } local string = { match = string.match } @@ -15,15 +15,13 @@ local setmetatable = setmetatable -- System load -- lain.widgets.sysload -local sysload = {} +local sysload = helpers.make_widget_textbox() local function worker(args) - local args = args or {} - local timeout = args.timeout or 2 + local args = args or {} + local timeout = args.timeout or 2 local settings = args.settings or function() end - sysload.widget = wibox.widget.textbox() - function update() local f = io.open("/proc/loadavg") local ret = f:read("*all") @@ -35,9 +33,9 @@ local function worker(args) settings() end - newtimer("sysload", timeout, update) + helpers.newtimer("sysload", timeout, update) - return setmetatable(sysload, { __index = sysload.widget }) + return sysload end return setmetatable(sysload, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/temp.lua b/widgets/temp.lua index e769b25..4d8a727 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -6,7 +6,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local io = { open = io.open } local tonumber = tonumber @@ -14,7 +14,7 @@ local setmetatable = setmetatable -- coretemp -- lain.widgets.temp -local temp = {} +local temp = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -22,8 +22,6 @@ local function worker(args) local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp" local settings = args.settings or function() end - temp.widget = wibox.widget.textbox() - function update() local f = io.open(tempfile) if f then @@ -37,9 +35,9 @@ local function worker(args) settings() end - newtimer("coretemp", timeout, update) + helpers.newtimer("coretemp", timeout, update) - return setmetatable(temp, { __index = temp.widget }) + return temp end return setmetatable(temp, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/weather.lua b/widgets/weather.lua index ff86d7e..9f83dc8 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -6,9 +6,7 @@ --]] -local async = require("lain.helpers").async -local newtimer = require("lain.helpers").newtimer -local lain_icons = require("lain.helpers").icons_dir +local helpers = require("lain.helpers") local json = require("lain.util").dkjson local focused = require("awful.screen").focused local naughty = require("naughty") @@ -27,7 +25,7 @@ local setmetatable = setmetatable -- lain.widgets.weather local function worker(args) - local weather = {} + local weather = helpers.make_widget_textbox() local args = args or {} local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default local timeout = args.timeout or 900 -- 15 min @@ -44,7 +42,7 @@ local function worker(args) local lang = args.lang or "en" local cnt = args.cnt or 5 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_text_fun = args.notification_text_fun or function (wn) @@ -58,9 +56,9 @@ local function worker(args) local followtag = args.followtag or false 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 = wibox.widget.imagebox(weather.icon_path) + weather.icon = wibox.widget.imagebox(weather.icon_path) function weather.show(t_out) weather.hide() @@ -99,7 +97,7 @@ local function worker(args) function weather.forecast_update() local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID) - async(cmd, function(f) + helpers.async(cmd, function(f) local pos, err weather_now, pos, err = json.decode(f, 1, nil) @@ -119,7 +117,7 @@ local function worker(args) function weather.update() local cmd = string.format(current_call, city_id, units, lang, APPID) - async(cmd, function(f) + helpers.async(cmd, function(f) local pos, err, icon weather_now, pos, err = json.decode(f, 1, nil) @@ -160,10 +158,10 @@ local function worker(args) weather.attach(weather.widget) - weather.timer = 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 = helpers.newtimer("weather-" .. city_id, timeout, weather.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 return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/wiki b/wiki index 7e48658..6d6fb0e 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 7e4865822c669a86007d88bf6ae846a95c5eed5f +Subproject commit 6d6fb0eb073e204c154e4d94b60472d858fc870d -- 2.39.2