local channel = args.channel or "Master"
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 mixer = f:read("*all")
f:close()
settings()
end
- newtimer("alsa", timeout, update)
+ newtimer("alsa", timeout, alsa.update)
- output = { widget = widget, notify = update }
-
- return setmetatable(output, { __index = output.widget })
+ return setmetatable(alsa, { __index = alsa.widget })
end
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
-- Battery infos
-- lain.widgets.bat
-local bat = { id = nil }
+local bat = {}
local function worker(args)
local args = args or {}
local battery = args.battery or "BAT0"
local settings = args.settings or function() end
+ bat.widget = wibox.widget.textbox('')
+
bat_now = {
status = "not present",
perc = "N/A",
watt = "N/A"
}
- widget = wibox.widget.textbox('')
-
- function update()
+ function bat.update()
local present = first_line("/sys/class/power_supply/"
.. battery
.. "/present")
bat_now.perc = string.format("%d", bat_now.perc)
end
+ widget = bat.widget
settings()
end
- newtimer("bat", timeout, update)
+ newtimer("bat", timeout, bat.update)
- return widget
+ return bat.widget
end
return setmetatable(bat, { __call = function(_, ...) return worker(...) end })
local timeout = args.timeout or 5
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
-- different kinds of work. Read the first line of /proc/stat
-- which is the sum of all CPUs.
usage = tostring(math.ceil((dactive / dtotal) * 100))
+ widget = cpu.widget
settings()
-- Save current data for the next run.
cpu.last_total = total
end
- newtimer("cpu", timeout, update)
+ newtimer("cpu", timeout, cpu.update)
- return widget
+ return cpu.widget
end
return setmetatable(cpu, { __call = function(_, ...) return worker(...) end })
-- File system disk space usage
-- lain.widgets.fs
-local fs = { notification_preset = {} }
-local notification = nil
+local fs = {}
+
+local notification = nil
+notification_preset = { fg = beautiful.fg_normal }
function fs:hide()
if notification ~= nil then
f:close()
notification = naughty.notify({
- preset = fs.notification_preset,
+ preset = notification_preset,
text = ws,
timeout = t_out
})
local partition = args.partition or "/"
local settings = args.settings or function() end
- widget = wibox.widget.textbox('')
+ fs.widget = wibox.widget.textbox('')
helpers.set_map("fs", false)
- function update()
+ function fs.update()
fs_info = {}
local f = io.popen("LC_ALL=C df -kP")
-- chosen partition easy stuff
-- you can however check whatever partition else
- used = fs_info[partition .. " used_p"]
- available = fs_info[partition .. " avail_p"]
- size_mb = fs_info[partition .. " size_mb"]
- size_gb = fs_info[partition .. " size_gb"]
-
- notification_preset = { fg = beautiful.fg_normal }
+ used = tonumber(fs_info[partition .. " used_p"])
+ available = tonumber(fs_info[partition .. " avail_p"])
+ size_mb = tonumber(fs_info[partition .. " size_mb"])
+ size_gb = tonumber(fs_info[partition .. " size_gb"])
+ widget = fs.widget
settings()
- fs.notification_preset = notification_preset
-
if used >= 99 and not helpers.get_map("fs")
then
naughty.notify({
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::leave', function () fs:hide() end)
output = {
- widget = widget,
+ widget = fs.widget,
show = function(t_out)
- update()
- fs:show(t_out)
+ fs.update()
+ fs:show(t_out)
end
}
-- Mail IMAP check
-- lain.widgets.imap
-local imap = { stored = nil }
+local imap = {}
-function worker(args)
+local function worker(args)
local args = args or {}
local server = args.server
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",
checkmail, server, mail, password, port)
end
end
- notification_preset = {
- icon = helpers.icons_dir .. "mail.png",
- timeout = 8,
- position = "top_left"
- }
-
+ widget = imap.widget
settings()
-
if helpers.get_map(mail) and tonumber(mailcount) >= 1
then
notify_title = ws:match(mail .. " has %d new message.?")
end
end
- helpers.newtimer(mail, timeout, update, true)
+ helpers.newtimer(mail, timeout, imap.update, true)
- return widget
+ return imap.widget
end
return setmetatable(imap, { __call = function(_, ...) return worker(...) end })
-- lain.widgets.maildir
local maildir = {}
-function worker(args)
+local function worker(args)
local args = args or {}
local timeout = args.timeout or 60
local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
local ignore_boxes = args.ignore_boxes or {}
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.
local p = io.popen("find " .. mailpath ..
" -mindepth 1 -maxdepth 1 -type d" ..
end
end
+ widget = maildir.widget
settings()
end
- newtimer(mailpath, timeout, update, true)
+ newtimer(mailpath, timeout, maildir.update, true)
- return widget
+ return maildir.widget
end
return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })
-- lain.widgets.mem
local mem = {}
-function worker(args)
+local function worker(args)
local args = args or {}
local timeout = args.timeout or 3
local settings = args.settings or function() end
- widget = wibox.widget.textbox('')
+ mem.widget = wibox.widget.textbox('')
- function update()
+ function mem.update()
mem = {}
for line in io.lines("/proc/meminfo")
do
used = mem.total - (mem.free + mem.buf + mem.cache)
swapused = mem.swap - mem.swapf
+ widget = mem.widget
settings()
end
- newtimer("mem", timeout, update)
+ newtimer("mem", timeout, mem.update)
- return widget
+ return mem.widget
end
return setmetatable(mem, { __call = function(_, ...) return worker(...) end })
local helpers = require("lain.helpers")
local util = require("awful.util")
-local beautiful = require("beautiful")
local naughty = require("naughty")
local wibox = require("wibox")
-local io = io
+local io = { popen = io.popen }
local os = { execute = os.execute,
getenv = os.getenv }
-local string = { gmatch = string.gmatch }
+local string = { format = string.format,
+ gmatch = string.gmatch }
local setmetatable = setmetatable
-- MPD infos
-- lain.widgets.mpd
-local mpd = { id = nil }
+local mpd = {}
-function worker(args)
+local function worker(args)
local args = args or {}
- local timeout = args.timeout or 1
+ local timeout = args.timeout or 2
local password = args.password or ""
local host = args.host or "127.0.0.1"
local port = args.port or "6600"
local mpdh = "telnet://" .. host .. ":" .. port
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)
- function update()
+ function mpd.update()
mpd_now = {
state = "N/A",
file = "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 k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
f:close()
- notification_preset = {
- title = "Now playing",
- text = mpd_now.artist .. " (" ..
- mpd_now.album .. ") - " ..
- mpd_now.date .. "\n" ..
- mpd_now.title,
- fg = beautiful.fg_normal or "#FFFFFF",
- bg = beautiful.bg_normal or "#000000",
- timeout = 6
- }
-
+ notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
+ mpd_now.album, mpd_now.date, mpd_now.title)
+ widget = mpd.widget
settings()
if mpd_now.state == "play"
then
helpers.set_map("current mpd track", mpd_now.title)
- os.execute(mpdcover .. " '" .. music_dir .. "' '"
- .. mpd_now.file .. "'")
+ os.execute(string.format("%s %q %q", mpdcover, music_dir, mpd_now.file))
mpd.id = naughty.notify({
preset = notification_preset,
end
end
- helpers.newtimer("mpd", timeout, update)
-
- output = { widget = widget, notify = update }
+ helpers.newtimer("mpd", timeout, mpd.update)
- return setmetatable(output, { __index = output.widget })
+ return setmetatable(mpd, { __index = mpd.widget })
end
return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })
end
end
-function worker(args)
+local function worker(args)
local args = args or {}
local timeout = args.timeout or 2
local iface = args.iface or net.get_device()
local units = args.units or 1024 --kb
local settings = args.settings or function() end
- widget = wibox.widget.textbox('')
+ net.widget = wibox.widget.textbox('')
helpers.set_map(iface, true)
- function update()
+ function net.update()
if iface == "" then iface = net.get_device() end
carrier = helpers.first_line('/sys/class/net/' .. iface ..
received = tostring((now_r - net.last_r) / timeout / units)
received = string.gsub(string.format('%.1f', received), ",", ".")
+ widget = net.widget
settings()
net.last_t = now_t
end
end
- helpers.newtimer(iface, timeout, update)
+ helpers.newtimer(iface, timeout, net.update)
- return widget
+ return net.widget
end
return setmetatable(net, { __call = function(_, ...) return worker(...) end })
-- lain.widgets.sysload
local sysload = {}
-function worker(args)
+local function worker(args)
local args = args or {}
local timeout = args.timeout or 5
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 ret = f:read("*all")
f:close()
a, b, c = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
+ widget = sysload.widget
settings()
end
- newtimer("sysload", timeout, update)
+ newtimer("sysload", timeout, sysload.update)
- return widget
+ return sysload.widget
end
return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })
-- lain.widgets.temp
local temp = {}
-function worker(args)
+local function worker(args)
local args = args or {}
local timeout = args.timeout or 5
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")
coretemp_now = tonumber(f:read("*all")) / 1000
f:close()
+ widget = temp.widget
settings()
end
- newtimer("coretemp", timeout, update)
+ newtimer("coretemp", timeout, temp.update)
- return widget
+ return temp.widget
end
return setmetatable(temp, { __call = function(_, ...) return worker(...) end })
--- /dev/null
+Rain.png
\ No newline at end of file
-- lain.widgets.yawn
local yawn =
{
- icon = wibox.widget.imagebox(),
- widget = wibox.widget.textbox(''),
- notification_preset = {}
+ icon = wibox.widget.imagebox(),
+ widget = wibox.widget.textbox('')
}
-local project_path = debug.getinfo(1, 'S').source:match[[^@(.*/).*$]]
-local localizations_path = project_path .. 'localizations/'
-local icon_path = project_path .. 'icons/'
-local api_url = 'http://weather.yahooapis.com/forecastrss'
-local units_set = '?u=c&w=' -- Default is Celsius
-local language = string.match(os.getenv("LANG"), "(%S*$*)[.]")
-local weather_data = nil
-local notification = nil
-local city_id = nil
-local sky = nil
-local settings = function() end
+local project_path = debug.getinfo(1, 'S').source:match[[^@(.*/).*$]]
+local localizations_path = project_path .. 'localizations/'
+local icon_path = project_path .. 'icons/'
+local api_url = 'http://weather.yahooapis.com/forecastrss'
+local units_set = '?u=c&w=' -- Default is Celsius
+local language = string.match(os.getenv("LANG"), "(%S*$*)[.]")
+local weather_data = nil
+local notification = nil
+local city_id = nil
+local sky = nil
+local settings = function() end
+
+notification_preset = {}
local function fetch_weather()
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 .. "'" )
local text = f:read("*all")
f:close()
- -- handle no suitable icon found
- yawn.icon:set_image(icon_path .. "na.png")
-
-- In case of no connection or invalid city ID
-- widgets won't display
if text == "" or text:match("City not found")
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
local f = io.open(localizations_path .. language, "r")
if language:find("en_") == nil and f ~= nil
-- Finally setting infos
yawn.icon:set_image(sky)
- widget = wibox.widget.textbox()
+ widget = yawn.widget
forecast = weather_data:match(": %S+.-,"):gsub(": ", ""):gsub(",", "\n")
units = units:gsub(" ", "")
- notification_preset = {}
- -- anche notification preset, con fg, bg e position
+ -- notification_preset = {}
settings()
-
- yawn.widget = widget
- yawn.notification_preset = notification_preset
end
function yawn.hide()
yawn.hide()
notification = naughty.notify({
- preset = yawn.notification_preset,
+ preset = notification_preset,
text = weather_data,
icon = sky,
timeout = t_out
yawn.hide()
end)
- return { icon = yawn.icon, widget = yawn.widget }
+ return yawn
end
function yawn.attach(widget, id, args)