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 })
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 })
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
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 })
newtimer("batteries", timeout, bat.update)
- return setmetatable(bat, { __index = bat.widget })
+ return bat
end
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
-- 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 {}
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
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 })
helpers.newtimer("kbdlayout", timeout, kbdlayout.update)
- return setmetatable(kbdlayout, { __index = kbdlayout.widget })
+ return kbdlayout
end
return setmetatable({}, { __call = function (_, ...) return worker(...) end })
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 })
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
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,
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",
--]]
-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,
-- 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
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 })
helpers.newtimer(partition, timeout, fs.update)
- return setmetatable(fs, { __index = fs.widget })
+ return fs
end
return setmetatable(fs, { __call = function(_, ...) return worker(...) end })
-- 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
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 })
-- Maildir check (synchronous)
-- lain.widgets.maildir
-local maildir = {}
+local maildir = helpers.make_widget_textbox()
local function worker(args)
local args = args or {}
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))
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 })
--]]
-local newtimer = require("lain.helpers").newtimer
+local helpers = require("lain.helpers")
local wibox = require("wibox")
local gmatch = string.gmatch
local lines = io.lines
-- 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
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 })
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 })
helpers.newtimer("network", timeout, update)
- return setmetatable(net, { __index = net.widget })
+ return net
end
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
-- PulseAudio volume
-- lain.widgets.pulseaudio
-local pulseaudio = {}
+local pulseaudio = helpers.make_widget_textbox()
local function worker(args)
local args = args or {}
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
helpers.newtimer("pulseaudio", timeout, pulseaudio.update)
- return setmetatable(pulseaudio, { __index = pulseaudio.widget })
+ return pulseaudio
end
return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end })
--]]
-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 }
-- 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")
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 })
--]]
-local newtimer = require("lain.helpers").newtimer
+local helpers = require("lain.helpers")
local wibox = require("wibox")
local io = { open = io.open }
local tonumber = tonumber
-- coretemp
-- lain.widgets.temp
-local temp = {}
+local temp = helpers.make_widget_textbox()
local function worker(args)
local args = args or {}
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
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 })
--]]
-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")
-- 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
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)
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()
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)
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)
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 })
-Subproject commit 7e4865822c669a86007d88bf6ae846a95c5eed5f
+Subproject commit 6d6fb0eb073e204c154e4d94b60472d858fc870d