From: luke bonham Date: Wed, 11 Sep 2013 17:39:14 +0000 (+0200) Subject: refresh widget fix X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/e73a70c2ab26caf981d356756d4f83ad8bfbdb5a refresh widget fix --- diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 8571ec6..887f398 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -26,9 +26,9 @@ local function worker(args) 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() @@ -56,11 +56,9 @@ local function worker(args) 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 }) diff --git a/widgets/bat.lua b/widgets/bat.lua index 5a811f0..fa61c34 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -20,7 +20,7 @@ local setmetatable = setmetatable -- Battery infos -- lain.widgets.bat -local bat = { id = nil } +local bat = {} local function worker(args) local args = args or {} @@ -28,6 +28,8 @@ local function worker(args) 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", @@ -35,9 +37,7 @@ local function worker(args) watt = "N/A" } - widget = wibox.widget.textbox('') - - function update() + function bat.update() local present = first_line("/sys/class/power_supply/" .. battery .. "/present") @@ -106,12 +106,13 @@ local function worker(args) 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 }) diff --git a/widgets/cpu.lua b/widgets/cpu.lua index f9bbe72..f307b26 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -31,9 +31,9 @@ local function worker(args) 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. @@ -60,6 +60,7 @@ local function worker(args) usage = tostring(math.ceil((dactive / dtotal) * 100)) + widget = cpu.widget settings() -- Save current data for the next run. @@ -67,9 +68,9 @@ local function worker(args) 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 }) diff --git a/widgets/fs.lua b/widgets/fs.lua index 3a36bf3..b580010 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -24,8 +24,10 @@ local setmetatable = setmetatable -- 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 @@ -42,7 +44,7 @@ function fs:show(t_out) f:close() notification = naughty.notify({ - preset = fs.notification_preset, + preset = notification_preset, text = ws, timeout = t_out }) @@ -57,11 +59,11 @@ local function worker(args) 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") @@ -83,17 +85,14 @@ local function worker(args) -- 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({ @@ -109,16 +108,16 @@ local function worker(args) 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 } diff --git a/widgets/imap.lua b/widgets/imap.lua index 2c7067c..9821cb3 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -20,9 +20,9 @@ local setmetatable = setmetatable -- 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 @@ -54,9 +54,15 @@ function worker(args) 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) @@ -88,15 +94,9 @@ function worker(args) 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.?") @@ -123,9 +123,9 @@ function worker(args) 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 }) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 00ab771..4ac34bc 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -24,16 +24,16 @@ local setmetatable = setmetatable -- 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" .. @@ -84,12 +84,13 @@ function worker(args) 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 }) diff --git a/widgets/mem.lua b/widgets/mem.lua index d0ff223..f014149 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -25,14 +25,14 @@ local setmetatable = setmetatable -- 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 @@ -51,12 +51,13 @@ function worker(args) 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 }) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 8ba1cde..016f2a3 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -10,24 +10,24 @@ 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" @@ -38,11 +38,16 @@ function worker(args) 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", @@ -52,7 +57,7 @@ function worker(args) 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 @@ -68,17 +73,9 @@ function worker(args) 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" @@ -87,8 +84,7 @@ function worker(args) 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, @@ -102,11 +98,9 @@ function worker(args) 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 }) diff --git a/widgets/net.lua b/widgets/net.lua index e086c4b..d692df1 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -39,18 +39,18 @@ function net.get_device() 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 .. @@ -68,6 +68,7 @@ function worker(args) 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 @@ -94,9 +95,9 @@ function worker(args) 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 }) diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 6167d82..90bdedf 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -21,26 +21,27 @@ local setmetatable = setmetatable -- 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 }) diff --git a/widgets/temp.lua b/widgets/temp.lua index 5b1ebf5..e568138 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -19,23 +19,24 @@ local setmetatable = setmetatable -- 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 }) diff --git a/widgets/yawn/icons/LightRain.png b/widgets/yawn/icons/LightRain.png new file mode 120000 index 0000000..df34463 --- /dev/null +++ b/widgets/yawn/icons/LightRain.png @@ -0,0 +1 @@ +Rain.png \ No newline at end of file diff --git a/widgets/yawn/init.lua b/widgets/yawn/init.lua index 9bed983..e0e6f68 100644 --- a/widgets/yawn/init.lua +++ b/widgets/yawn/init.lua @@ -27,33 +27,31 @@ local setmetatable = setmetatable -- 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") @@ -107,6 +105,14 @@ local function fetch_weather() 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 @@ -122,17 +128,13 @@ local function fetch_weather() -- 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() @@ -151,7 +153,7 @@ function yawn.show(t_out) yawn.hide() notification = naughty.notify({ - preset = yawn.notification_preset, + preset = notification_preset, text = weather_data, icon = sky, timeout = t_out @@ -176,7 +178,7 @@ function yawn.register(id, args) yawn.hide() end) - return { icon = yawn.icon, widget = yawn.widget } + return yawn end function yawn.attach(widget, id, args)