From 912bd26ede8901c98fd8d7a35f8493ee448109ad Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 12 Oct 2015 12:09:44 +0200 Subject: [PATCH 01/16] merge and resolve conflicts from #134; #114 --- helpers.lua | 12 ++++++++--- widgets/abase.lua | 19 +++++++++++------ widgets/alsa.lua | 17 +++++++++++---- widgets/alsabar.lua | 52 +++++++++++++++++++++++++-------------------- widgets/base.lua | 19 ++++++++++------- widgets/bat.lua | 51 +++++++++++++++++++++++++++----------------- widgets/cpu.lua | 37 +++++++++++++++++--------------- widgets/fs.lua | 15 ++++++++----- widgets/imap.lua | 6 ++++-- widgets/maildir.lua | 10 +++++---- widgets/mem.lua | 49 ++++++++++++++++++++++++++++++------------ widgets/mpd.lua | 16 +++++++++----- widgets/net.lua | 45 ++++++++++++++++++++++----------------- widgets/sysload.lua | 24 +++++++++++++++------ widgets/temp.lua | 16 ++++++++------ wiki | 2 +- 16 files changed, 247 insertions(+), 143 deletions(-) diff --git a/helpers.lua b/helpers.lua index 4e90e16..503c40e 100644 --- a/helpers.lua +++ b/helpers.lua @@ -76,10 +76,16 @@ end helpers.timer_table = {} -function helpers.newtimer(name, timeout, fun, nostart) - helpers.timer_table[name] = capi.timer({ timeout = timeout }) +function helpers.newtimer(_name, timeout, fun, nostart) + local name = timeout + + if not helpers.timer_table[name] then + helpers.timer_table[name] = capi.timer({ timeout = timeout }) + helpers.timer_table[name]:start() + end + helpers.timer_table[name]:connect_signal("timeout", fun) - helpers.timer_table[name]:start() + if not nostart then helpers.timer_table[name]:emit_signal("timeout") end diff --git a/widgets/abase.lua b/widgets/abase.lua index 98f7818..87af872 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -6,9 +6,9 @@ --]] -local newtimer = require("lain.helpers").newtimer -local async = require("lain.asyncshell") -local wibox = require("wibox") +local helpers = require("lain.helpers") +local async = require("lain.asyncshell") +local wibox = require("wibox") local setmetatable = setmetatable @@ -19,21 +19,26 @@ local setmetatable = setmetatable local function worker(args) local abase = {} local args = args or {} - local timeout = args.timeout or 5 + local timeout = args.timeout or 1 local cmd = args.cmd or "" local settings = args.settings or function() end abase.widget = wibox.widget.textbox('') + helpers.set_map(cmd, '') function abase.update() async.request(cmd, function(f) output = f - widget = abase.widget - settings() + + if helpers.get_map(cmd) ~= output then + widget = abase.widget + settings() + helpers.set_map(cmd, output) + end end) end - newtimer(cmd, timeout, abase.update) + helpers.newtimer(cmd, timeout, abase.update) return setmetatable(abase, { __index = abase.widget }) end diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 85d5311..0bb2059 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -19,11 +19,14 @@ local setmetatable = setmetatable -- ALSA volume -- lain.widgets.alsa -local alsa = {} +local alsa = { + level = "0", + status = "off", +} local function worker(args) local args = args or {} - local timeout = args.timeout or 5 + local timeout = args.timeout or 1 local settings = args.settings or function() end alsa.cmd = args.cmd or "amixer" @@ -54,8 +57,14 @@ local function worker(args) end end - widget = alsa.widget - settings() + if alsa.level ~= volume_now.level or alsa.status ~= volume_now.status + then + widget = alsa.widget + settings() + + alsa.level = volume_now.level + alsa.status = volume_now.status + end end timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index c7498d2..fc45c72 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -47,7 +47,8 @@ local alsabar = { }, _current_level = 0, - _muted = false + _muted = false, + _status = "off" } function alsabar.notify() @@ -56,7 +57,7 @@ function alsabar.notify() local preset = { title = "", text = "", - timeout = 5, + timeout = 1, screen = alsabar.notifications.screen, font = alsabar.notifications.font .. " " .. alsabar.notifications.font_size, @@ -94,7 +95,7 @@ end local function worker(args) local args = args or {} - local timeout = args.timeout or 5 + local timeout = args.timeout or 1 local settings = args.settings or function() end local width = args.width or 63 local height = args.heigth or 1 @@ -127,28 +128,33 @@ local function worker(args) -- Capture mixer control state: [5%] ... ... [on] local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") - if volu == nil then - volu = 0 - mute = "off" - end + volu = tonumber(volu) or 0 + if mute == "" then mute = "off" - alsabar._current_level = tonumber(volu) - alsabar.bar:set_value(alsabar._current_level / 100) - if not mute and tonumber(volu) == 0 or mute == "off" - then - alsabar._muted = true - alsabar.tooltip:set_text (" [Muted] ") - alsabar.bar:set_color(alsabar.colors.mute) - else - alsabar._muted = false - alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu)) - alsabar.bar:set_color(alsabar.colors.unmute) - end + if alsabar._current_level ~= volu or alsabar._status ~= mute then + + alsabar._current_level = volu + alsabar._status = mute + + alsabar.bar:set_value(alsabar._current_level / 100) - volume_now = {} - volume_now.level = tonumber(volu) - volume_now.status = mute - settings() + if not mute and volu == 0 or mute == "off" + then + alsabar._muted = true + alsabar.tooltip:set_text (" [Muted] ") + alsabar.bar:set_color(alsabar.colors.mute) + else + alsabar._muted = false + alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu)) + alsabar.bar:set_color(alsabar.colors.unmute) + end + + volume_now = {} + volume_now.level = volu + volume_now.status = mute + + settings() + end end alsabar.bar:buttons (awful.util.table.join ( diff --git a/widgets/base.lua b/widgets/base.lua index 2f377f7..88478b0 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -6,9 +6,7 @@ --]] -local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe - +local helpers = require("lain.helpers") local wibox = require("wibox") local setmetatable = setmetatable @@ -19,19 +17,24 @@ local setmetatable = setmetatable local function worker(args) local base = {} local args = args or {} - local timeout = args.timeout or 5 + local timeout = args.timeout or 1 local cmd = args.cmd or "" local settings = args.settings or function() end base.widget = wibox.widget.textbox('') + helpers.set_map(cmd, '') function base.update() - output = read_pipe(cmd) - widget = base.widget - settings() + output = helpers.read_pipe(cmd) + + if helpers.get_map(cmd) ~= output then + widget = base.widget + settings() + helpers.set_map(cmd, output) + end end - newtimer(cmd, timeout, base.update) + helpers.newtimer(cmd, timeout, base.update) return setmetatable(base, { __index = base.widget }) end diff --git a/widgets/bat.lua b/widgets/bat.lua index 61828ec..d18af87 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -7,9 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer -local first_line = require("lain.helpers").first_line - +local helpers = require("lain.helpers") local naughty = require("naughty") local wibox = require("wibox") @@ -48,6 +46,11 @@ local function worker(args) bg = "#FFFFFF" } + helpers.set_map(battery .. "status", "N/A") + helpers.set_map(battery .. "perc", "N/A") + helpers.set_map(battery .. "time", "N/A") + helpers.set_map(battery .. "watt", "N/A") + function update() bat_now = { status = "Not present", @@ -58,22 +61,22 @@ local function worker(args) local bstr = "/sys/class/power_supply/" .. battery - local present = first_line(bstr .. "/present") + local present = helpers.first_line(bstr .. "/present") if present == "1" then - local rate = first_line(bstr .. "/power_now") or - first_line(bstr .. "/current_now") + local rate = helpers.first_line(bstr .. "/power_now") or + helpers.first_line(bstr .. "/current_now") - local ratev = first_line(bstr .. "/voltage_now") + local ratev = helpers.first_line(bstr .. "/voltage_now") - local rem = first_line(bstr .. "/energy_now") or - first_line(bstr .. "/charge_now") + local rem = helpers.first_line(bstr .. "/energy_now") or + helpers.first_line(bstr .. "/charge_now") - local tot = first_line(bstr .. "/energy_full") or - first_line(bstr .. "/charge_full") + local tot = helpers.first_line(bstr .. "/energy_full") or + helpers.first_line(bstr .. "/charge_full") - bat_now.status = first_line(bstr .. "/status") or "N/A" + bat_now.status = helpers.first_line(bstr .. "/status") or "N/A" rate = tonumber(rate) or 1 ratev = tonumber(ratev) @@ -97,7 +100,7 @@ local function worker(args) bat_now.time = string.format("%02d:%02d", hrs, min) - bat_now.perc = first_line(bstr .. "/capacity") + bat_now.perc = helpers.first_line(bstr .. "/capacity") if not bat_now.perc then local perc = (rem / tot) * 100 @@ -115,11 +118,21 @@ local function worker(args) else bat_now.watt = "N/A" end - end - widget = bat.widget - settings() + if bat_now.status ~= helpers.get_map(battery .. "status") + or bat_now.perc ~= helpers.get_map(battery .. "perc") + or bat_now.time ~= helpers.get_map(battery .. "time") + or bat_now.watt ~= helpers.get_map(battery .. "watt") + then + widget = bat.widget + settings() + + helpers.set_map(battery .. "status", bat_now.status) + helpers.set_map(battery .. "perc", bat_now.perc) + helpers.set_map(battery .. "time", bat_now.time) + helpers.set_map(battery .. "watt", bat_now.watt) + end -- notifications for low and critical states if bat_now.status == "Discharging" and notify == "on" and bat_now.perc ~= nil @@ -141,9 +154,9 @@ local function worker(args) end end - newtimer(battery, timeout, update) + helpers.newtimer(battery, timeout, update) - return setmetatable(bat, { __index = bat.widget }) + return bat.widget end -return setmetatable({}, { __call = function(_, ...) return worker(...) end }) +return setmetatable(bat, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpu.lua b/widgets/cpu.lua index ec84101..1554443 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -7,16 +7,13 @@ --]] -local first_line = require("lain.helpers").first_line -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, gmatch = string.gmatch } local tostring = tostring - local setmetatable = setmetatable -- CPU usage @@ -28,16 +25,18 @@ local cpu = { local function worker(args) local args = args or {} - local timeout = args.timeout or 2 + local timeout = args.timeout or 1 local settings = args.settings or function() end cpu.widget = wibox.widget.textbox('') + helpers.set_map("cpuactive", 0) + helpers.set_map("cputotal", 0) 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 = first_line("/proc/stat") + local times = helpers.first_line("/proc/stat") local at = 1 local idle = 0 local total = 0 @@ -54,22 +53,26 @@ local function worker(args) end local active = total - idle - -- Read current data and calculate relative values. - local dactive = active - cpu.last_active - local dtotal = total - cpu.last_total + if helpers.get_map("cpuactive") ~= active + or helpers.get_map("cputotal") ~= total + then + -- Read current data and calculate relative values. + local dactive = active - cpu.last_active + local dtotal = total - cpu.last_total - cpu_now = {} - cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100)) + cpu_now = {} + cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100)) - widget = cpu.widget - settings() + widget = cpu.widget + settings() - -- Save current data for the next run. - cpu.last_active = active - cpu.last_total = total + -- Save current data for the next run. + helpers.set_map("cpuactive", active) + helpers.set_map("cputotal", total) + end end - newtimer("cpu", timeout, update) + helpers.newtimer("cpu", timeout, update) return cpu.widget end diff --git a/widgets/fs.lua b/widgets/fs.lua index a1d5d95..8b2886b 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -26,7 +26,8 @@ local setmetatable = setmetatable -- File system disk space usage -- lain.widgets.fs local fs = {} -local fs_notification = nil + +local fs_notification = nil function fs:hide() if fs_notification ~= nil then @@ -41,11 +42,11 @@ function fs:show(t_out) local ws = helpers.read_pipe(helpers.scripts_dir .. "dfs"):gsub("\n*$", "") if fs.followmouse then - fs.notification_preset.screen = mouse.screen + fs_notification_preset.screen = mouse.screen end fs_notification = naughty.notify({ - preset = fs.notification_preset, + preset = fs_notification_preset, text = ws, timeout = t_out }) @@ -66,6 +67,7 @@ local function worker(args) fs.widget = wibox.widget.textbox('') helpers.set_map(partition, false) + helpers.set_map("fsused", 0) function update() fs_info = {} @@ -92,8 +94,11 @@ local function worker(args) fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0 fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0 - widget = fs.widget - settings() + if helpers.get_map("fsused") ~= fs_now.used then + widget = fs.widget + settings() + helpers.set_map("fsused", fs_now.used) + end if fs_now.used >= 99 and not helpers.get_map(partition) then diff --git a/widgets/imap.lua b/widgets/imap.lua index ea763df..350e1ad 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -65,8 +65,10 @@ local function worker(args) _, mailcount = string.gsub(f, "%d+", "") _ = nil - widget = imap.widget - settings() + if mailcount ~= helpers.get_map(mail) then + widget = imap.widget + settings() + end if mailcount >= 1 and mailcount > helpers.get_map(mail) then diff --git a/widgets/maildir.lua b/widgets/maildir.lua index eed6138..8cb821d 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -25,7 +25,7 @@ local setmetatable = setmetatable -- Maildir check -- lain.widgets.maildir -local maildir = {} +local maildir = { total = 0 } local function worker(args) local args = args or {} @@ -65,7 +65,7 @@ local function worker(args) end until line == nil - p:close() + p:close() table.sort(boxes) newmail = "no mail" @@ -88,8 +88,10 @@ local function worker(args) end end - widget = maildir.widget - settings() + if maildir.total ~= total then + widget = maildir.widget + settings() + end end newtimer(mailpath, timeout, update, true) diff --git a/widgets/mem.lua b/widgets/mem.lua index f6213b2..dc72279 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -7,27 +7,33 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") +local wibox = require("wibox") -local wibox = require("wibox") +local io = { lines = io.lines } +local math = { floor = math.floor } +local string = { gmatch = string.gmatch } -local io = { lines = io.lines } -local math = { floor = math.floor } -local string = { gmatch = string.gmatch } +local setmetatable = setmetatable -local setmetatable = setmetatable - --- Memory usage (ignoring caches) +-- Memory usage -- lain.widgets.mem local mem = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 2 + local timeout = args.timeout or 1 local settings = args.settings or function() end mem.widget = wibox.widget.textbox('') + helpers.set_map("mem_last_total", 0) + helpers.set_map("mem_last_free", 0) + helpers.set_map("mem_last_buf", 0) + helpers.set_map("mem_last_cache", 0) + helpers.set_map("mem_last_swap", 0) + helpers.set_map("mem_last_swapf", 0) + function update() mem_now = {} for line in io.lines("/proc/meminfo") @@ -44,14 +50,29 @@ local function worker(args) end end - mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache) - mem_now.swapused = mem_now.swap - mem_now.swapf + if mem_now.total ~= helpers.set_map("mem_last_total") + or mem_now.free ~= helpers.set_map("mem_last_free") + or mem_now.buf ~= helpers.set_map("mem_last_buf") + or mem_now.cache ~= helpers.set_map("mem_last_cache") + or mem_now.swap ~= helpers.set_map("mem_last_swap") + or mem_now.swapf ~= helpers.set_map("mem_last_swapf") + then + mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache) + mem_now.swapused = mem_now.swap - mem_now.swapf - widget = mem.widget - settings() + widget = mem.widget + settings() + + helpers.set_map("mem_last_total", mem_now.total) + helpers.set_map("mem_last_free", mem_now.free) + helpers.set_map("mem_last_buf", mem_now.buf) + helpers.set_map("mem_last_cache", mem_now.cache) + helpers.set_map("mem_last_swap", mem_now.swap) + helpers.set_map("mem_last_swapf", mem_now.swapf) + end end - newtimer("mem", timeout, update) + helpers.newtimer("mem", timeout, update) return mem.widget end diff --git a/widgets/mpd.lua b/widgets/mpd.lua index c437347..1d2c617 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -30,7 +30,7 @@ local mpd = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 2 + local timeout = args.timeout or 1 local password = args.password or "" local host = args.host or "127.0.0.1" local port = args.port or "6600" @@ -49,10 +49,11 @@ local function worker(args) mpd_notification_preset = { title = "Now playing", - timeout = 6 + timeout = 5 } - helpers.set_map("current mpd track", nil) + helpers.set_map("current mpd track", "") + helpers.set_map("current mpd file", "") function mpd.update() async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f) @@ -84,8 +85,13 @@ local function worker(args) mpd_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.file ~= helpers.get_map("current mpd file") + then + widget = mpd.widget + settings() + helpers.set_map("current mpd file", mpd_now.file) + end if mpd_now.state == "play" then diff --git a/widgets/net.lua b/widgets/net.lua index a578ae4..983da41 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -21,10 +21,7 @@ local setmetatable = setmetatable -- Network infos -- lain.widgets.net -local net = { - last_t = 0, - last_r = 0 -} +local net = {} function net.get_device() local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") @@ -38,7 +35,7 @@ end local function worker(args) local args = args or {} - local timeout = args.timeout or 2 + local timeout = args.timeout or 1 local units = args.units or 1024 --kb local notify = args.notify or "on" local screen = args.screen or 1 @@ -49,35 +46,44 @@ local function worker(args) net.widget = wibox.widget.textbox('') helpers.set_map(iface, true) + helpers.set_map("net_t", 0) + helpers.set_map("net_r", 0) function update() - net_now = {} + net_now = { + sent = "0.0", + received = "0.0" + } if iface == "" or string.match(iface, "network off") then iface = net.get_device() end - net_now.carrier = helpers.first_line('/sys/class/net/' .. iface .. - '/carrier') or "0" - net_now.state = helpers.first_line('/sys/class/net/' .. iface .. - '/operstate') or "down" local now_t = helpers.first_line('/sys/class/net/' .. iface .. '/statistics/tx_bytes') or 0 local now_r = helpers.first_line('/sys/class/net/' .. iface .. '/statistics/rx_bytes') or 0 - net_now.sent = (now_t - net.last_t) / timeout / units - net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".") + if now_t ~= helpers.get_map("net_t") + or now_r ~= helpers.get_map("net_r") then + net_now.carrier = helpers.first_line('/sys/class/net/' .. iface .. + '/carrier') or "0" + net_now.state = helpers.first_line('/sys/class/net/' .. iface .. + '/operstate') or "down" - net_now.received = (now_r - net.last_r) / timeout / units - net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".") + net_now.sent = (now_t - net.last_t) / timeout / units + net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".") - widget = net.widget - settings() + net_now.received = (now_r - net.last_r) / timeout / units + net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".") - net.last_t = now_t - net.last_r = now_r + widget = net.widget + settings() + + helpers.set_map("net_t", now_t) + helpers.set_map("net_r", now_r) + end if net_now.carrier ~= "1" and notify == "on" then @@ -99,7 +105,8 @@ local function worker(args) end end - helpers.newtimer(iface, timeout, update) + helpers.newtimer(iface, timeout, update, false) + return net.widget end diff --git a/widgets/sysload.lua b/widgets/sysload.lua index d8e4713..9472235 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -7,8 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer - +local helpers = require("lain.helpers") local wibox = require("wibox") local io = { open = io.open } @@ -22,10 +21,13 @@ local sysload = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 2 + local timeout = args.timeout or 1 local settings = args.settings or function() end sysload.widget = wibox.widget.textbox('') + helpers.set_map("load_1", 0) + helpers.set_map("load_5", 0) + helpers.set_map("load_15", 0) function update() local f = io.open("/proc/loadavg") @@ -34,11 +36,21 @@ local function worker(args) load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)") - widget = sysload.widget - settings() + if load_1 ~= helpers.get_map("load_1") + or load_5 ~= helpers.get_map("load_5") + or load_15 ~= helpers.get_map("load_15") + then + widget = sysload.widget + settings() + + helpers.set_map("load_1", load_1) + helpers.set_map("load_5", load_5) + helpers.set_map("load_15", load_15) + end end - newtimer("sysload", timeout, update) + helpers.newtimer("sysload", timeout, update) + return sysload.widget end diff --git a/widgets/temp.lua b/widgets/temp.lua index 67c9456..6831588 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -6,8 +6,7 @@ --]] -local newtimer = require("lain.helpers").newtimer - +local helpers = require("lain.helpers") local wibox = require("wibox") local io = { open = io.open } @@ -21,11 +20,12 @@ local temp = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 2 + local timeout = args.timeout or 1 local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp" local settings = args.settings or function() end temp.widget = wibox.widget.textbox('') + helpers.set_map("temp_last", 0) function update() local f = io.open(tempfile) @@ -37,11 +37,15 @@ local function worker(args) coretemp_now = "N/A" end - widget = temp.widget - settings() + if helpers.get_map("temp_last") ~= coretemp_now then + widget = temp.widget + settings() + helpers.set_map("temp_last", coretemp_now) + end end - newtimer("coretemp", timeout, update) + helpers.newtimer("coretemp", timeout, update) + return temp.widget end diff --git a/wiki b/wiki index d7aa1a7..78879bd 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit d7aa1a7b8428211a1c4c71865fd64302e013d62b +Subproject commit 78879bd1208d713dcbb9216f226a34b51f886421 -- 2.39.5 From 7de62e4d9fe0d3a7521fc72a66c905d6f343c27b Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 12 Oct 2015 12:24:30 +0200 Subject: [PATCH 02/16] wiki updated --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 78879bd..35cc75d 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 78879bd1208d713dcbb9216f226a34b51f886421 +Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f -- 2.39.5 From 554d206f5fbc1e04e8863b07b7e2448163857050 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 13 Oct 2015 15:32:29 +0200 Subject: [PATCH 03/16] project was added to OWM FOSS keys list; #146 --- widgets/weather.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index 68abae9..baf82d7 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -30,7 +30,7 @@ local setmetatable = setmetatable local function worker(args) local weather = {} local args = args or {} - local APPID = args.APPID or 1 -- mandatory + local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default local timeout = args.timeout or 900 -- 15 min local timeout_forecast = args.timeout or 86400 -- 24 hrs local current_call = "curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'" -- 2.39.5 From 69ec77e16aa8188062f74ceae785e9f9460006e6 Mon Sep 17 00:00:00 2001 From: Luke Bonham Date: Mon, 19 Oct 2015 08:48:14 +0200 Subject: [PATCH 04/16] wiki updated! --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index d7aa1a7..35cc75d 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit d7aa1a7b8428211a1c4c71865fd64302e013d62b +Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f -- 2.39.5 From 0b80b45bc9bca17f08e8055d364bac17f96129bd Mon Sep 17 00:00:00 2001 From: Luke Bonham Date: Tue, 20 Oct 2015 15:17:44 +0200 Subject: [PATCH 05/16] revert to previous stable --- helpers.lua | 12 +++-------- widgets/abase.lua | 19 ++++++----------- widgets/alsa.lua | 17 ++++----------- widgets/alsabar.lua | 52 ++++++++++++++++++++------------------------- widgets/base.lua | 19 +++++++---------- widgets/bat.lua | 49 ++++++++++++++++-------------------------- widgets/cpu.lua | 37 +++++++++++++++----------------- widgets/fs.lua | 15 +++++-------- widgets/imap.lua | 6 ++---- widgets/maildir.lua | 10 ++++----- widgets/mem.lua | 49 ++++++++++++------------------------------ widgets/mpd.lua | 17 +++++---------- widgets/net.lua | 45 +++++++++++++++++---------------------- widgets/sysload.lua | 24 ++++++--------------- widgets/temp.lua | 16 ++++++-------- 15 files changed, 141 insertions(+), 246 deletions(-) diff --git a/helpers.lua b/helpers.lua index 503c40e..4e90e16 100644 --- a/helpers.lua +++ b/helpers.lua @@ -76,16 +76,10 @@ end helpers.timer_table = {} -function helpers.newtimer(_name, timeout, fun, nostart) - local name = timeout - - if not helpers.timer_table[name] then - helpers.timer_table[name] = capi.timer({ timeout = timeout }) - helpers.timer_table[name]:start() - end - +function helpers.newtimer(name, timeout, fun, nostart) + helpers.timer_table[name] = capi.timer({ timeout = timeout }) helpers.timer_table[name]:connect_signal("timeout", fun) - + helpers.timer_table[name]:start() if not nostart then helpers.timer_table[name]:emit_signal("timeout") end diff --git a/widgets/abase.lua b/widgets/abase.lua index 87af872..98f7818 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -6,9 +6,9 @@ --]] -local helpers = require("lain.helpers") -local async = require("lain.asyncshell") -local wibox = require("wibox") +local newtimer = require("lain.helpers").newtimer +local async = require("lain.asyncshell") +local wibox = require("wibox") local setmetatable = setmetatable @@ -19,26 +19,21 @@ local setmetatable = setmetatable local function worker(args) local abase = {} local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 5 local cmd = args.cmd or "" local settings = args.settings or function() end abase.widget = wibox.widget.textbox('') - helpers.set_map(cmd, '') function abase.update() async.request(cmd, function(f) output = f - - if helpers.get_map(cmd) ~= output then - widget = abase.widget - settings() - helpers.set_map(cmd, output) - end + widget = abase.widget + settings() end) end - helpers.newtimer(cmd, timeout, abase.update) + newtimer(cmd, timeout, abase.update) return setmetatable(abase, { __index = abase.widget }) end diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 0bb2059..85d5311 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -19,14 +19,11 @@ local setmetatable = setmetatable -- ALSA volume -- lain.widgets.alsa -local alsa = { - level = "0", - status = "off", -} +local alsa = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 5 local settings = args.settings or function() end alsa.cmd = args.cmd or "amixer" @@ -57,14 +54,8 @@ local function worker(args) end end - if alsa.level ~= volume_now.level or alsa.status ~= volume_now.status - then - widget = alsa.widget - settings() - - alsa.level = volume_now.level - alsa.status = volume_now.status - end + widget = alsa.widget + settings() end timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index fc45c72..c7498d2 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -47,8 +47,7 @@ local alsabar = { }, _current_level = 0, - _muted = false, - _status = "off" + _muted = false } function alsabar.notify() @@ -57,7 +56,7 @@ function alsabar.notify() local preset = { title = "", text = "", - timeout = 1, + timeout = 5, screen = alsabar.notifications.screen, font = alsabar.notifications.font .. " " .. alsabar.notifications.font_size, @@ -95,7 +94,7 @@ end local function worker(args) local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 5 local settings = args.settings or function() end local width = args.width or 63 local height = args.heigth or 1 @@ -128,33 +127,28 @@ local function worker(args) -- Capture mixer control state: [5%] ... ... [on] local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") - volu = tonumber(volu) or 0 - if mute == "" then mute = "off" - - if alsabar._current_level ~= volu or alsabar._status ~= mute then - - alsabar._current_level = volu - alsabar._status = mute - - alsabar.bar:set_value(alsabar._current_level / 100) - - if not mute and volu == 0 or mute == "off" - then - alsabar._muted = true - alsabar.tooltip:set_text (" [Muted] ") - alsabar.bar:set_color(alsabar.colors.mute) - else - alsabar._muted = false - alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu)) - alsabar.bar:set_color(alsabar.colors.unmute) - end - - volume_now = {} - volume_now.level = volu - volume_now.status = mute + if volu == nil then + volu = 0 + mute = "off" + end - settings() + alsabar._current_level = tonumber(volu) + alsabar.bar:set_value(alsabar._current_level / 100) + if not mute and tonumber(volu) == 0 or mute == "off" + then + alsabar._muted = true + alsabar.tooltip:set_text (" [Muted] ") + alsabar.bar:set_color(alsabar.colors.mute) + else + alsabar._muted = false + alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu)) + alsabar.bar:set_color(alsabar.colors.unmute) end + + volume_now = {} + volume_now.level = tonumber(volu) + volume_now.status = mute + settings() end alsabar.bar:buttons (awful.util.table.join ( diff --git a/widgets/base.lua b/widgets/base.lua index 88478b0..2f377f7 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -6,7 +6,9 @@ --]] -local helpers = require("lain.helpers") +local newtimer = require("lain.helpers").newtimer +local read_pipe = require("lain.helpers").read_pipe + local wibox = require("wibox") local setmetatable = setmetatable @@ -17,24 +19,19 @@ local setmetatable = setmetatable local function worker(args) local base = {} local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 5 local cmd = args.cmd or "" local settings = args.settings or function() end base.widget = wibox.widget.textbox('') - helpers.set_map(cmd, '') function base.update() - output = helpers.read_pipe(cmd) - - if helpers.get_map(cmd) ~= output then - widget = base.widget - settings() - helpers.set_map(cmd, output) - end + output = read_pipe(cmd) + widget = base.widget + settings() end - helpers.newtimer(cmd, timeout, base.update) + newtimer(cmd, timeout, base.update) return setmetatable(base, { __index = base.widget }) end diff --git a/widgets/bat.lua b/widgets/bat.lua index d18af87..626239b 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -7,7 +7,9 @@ --]] -local helpers = require("lain.helpers") +local newtimer = require("lain.helpers").newtimer +local first_line = require("lain.helpers").first_line + local naughty = require("naughty") local wibox = require("wibox") @@ -19,9 +21,9 @@ local setmetatable = setmetatable -- Battery infos -- lain.widgets.bat +local bat = {} local function worker(args) - local bat = {} local args = args or {} local timeout = args.timeout or 30 local battery = args.battery or "BAT0" @@ -46,11 +48,6 @@ local function worker(args) bg = "#FFFFFF" } - helpers.set_map(battery .. "status", "N/A") - helpers.set_map(battery .. "perc", "N/A") - helpers.set_map(battery .. "time", "N/A") - helpers.set_map(battery .. "watt", "N/A") - function update() bat_now = { status = "Not present", @@ -61,22 +58,22 @@ local function worker(args) local bstr = "/sys/class/power_supply/" .. battery - local present = helpers.first_line(bstr .. "/present") + local present = first_line(bstr .. "/present") if present == "1" then - local rate = helpers.first_line(bstr .. "/power_now") or - helpers.first_line(bstr .. "/current_now") + local rate = first_line(bstr .. "/power_now") or + first_line(bstr .. "/current_now") - local ratev = helpers.first_line(bstr .. "/voltage_now") + local ratev = first_line(bstr .. "/voltage_now") - local rem = helpers.first_line(bstr .. "/energy_now") or - helpers.first_line(bstr .. "/charge_now") + local rem = first_line(bstr .. "/energy_now") or + first_line(bstr .. "/charge_now") - local tot = helpers.first_line(bstr .. "/energy_full") or - helpers.first_line(bstr .. "/charge_full") + local tot = first_line(bstr .. "/energy_full") or + first_line(bstr .. "/charge_full") - bat_now.status = helpers.first_line(bstr .. "/status") or "N/A" + bat_now.status = first_line(bstr .. "/status") or "N/A" rate = tonumber(rate) or 1 ratev = tonumber(ratev) @@ -100,7 +97,7 @@ local function worker(args) bat_now.time = string.format("%02d:%02d", hrs, min) - bat_now.perc = helpers.first_line(bstr .. "/capacity") + bat_now.perc = first_line(bstr .. "/capacity") if not bat_now.perc then local perc = (rem / tot) * 100 @@ -118,22 +115,12 @@ local function worker(args) else bat_now.watt = "N/A" end - end - if bat_now.status ~= helpers.get_map(battery .. "status") - or bat_now.perc ~= helpers.get_map(battery .. "perc") - or bat_now.time ~= helpers.get_map(battery .. "time") - or bat_now.watt ~= helpers.get_map(battery .. "watt") - then - widget = bat.widget - settings() - - helpers.set_map(battery .. "status", bat_now.status) - helpers.set_map(battery .. "perc", bat_now.perc) - helpers.set_map(battery .. "time", bat_now.time) - helpers.set_map(battery .. "watt", bat_now.watt) end + widget = bat.widget + settings() + -- notifications for low and critical states if bat_now.status == "Discharging" and notify == "on" and bat_now.perc ~= nil then @@ -154,7 +141,7 @@ local function worker(args) end end - helpers.newtimer(battery, timeout, update) + newtimer(battery, timeout, update) return bat.widget end diff --git a/widgets/cpu.lua b/widgets/cpu.lua index 1554443..ec84101 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -7,13 +7,16 @@ --]] -local helpers = require("lain.helpers") +local first_line = require("lain.helpers").first_line +local newtimer = require("lain.helpers").newtimer + local wibox = require("wibox") local math = { ceil = math.ceil } local string = { format = string.format, gmatch = string.gmatch } local tostring = tostring + local setmetatable = setmetatable -- CPU usage @@ -25,18 +28,16 @@ local cpu = { local function worker(args) local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 2 local settings = args.settings or function() end cpu.widget = wibox.widget.textbox('') - helpers.set_map("cpuactive", 0) - helpers.set_map("cputotal", 0) 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 = helpers.first_line("/proc/stat") + local times = first_line("/proc/stat") local at = 1 local idle = 0 local total = 0 @@ -53,26 +54,22 @@ local function worker(args) end local active = total - idle - if helpers.get_map("cpuactive") ~= active - or helpers.get_map("cputotal") ~= total - then - -- Read current data and calculate relative values. - local dactive = active - cpu.last_active - local dtotal = total - cpu.last_total + -- Read current data and calculate relative values. + local dactive = active - cpu.last_active + local dtotal = total - cpu.last_total - cpu_now = {} - cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100)) + cpu_now = {} + cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100)) - widget = cpu.widget - settings() + widget = cpu.widget + settings() - -- Save current data for the next run. - helpers.set_map("cpuactive", active) - helpers.set_map("cputotal", total) - end + -- Save current data for the next run. + cpu.last_active = active + cpu.last_total = total end - helpers.newtimer("cpu", timeout, update) + newtimer("cpu", timeout, update) return cpu.widget end diff --git a/widgets/fs.lua b/widgets/fs.lua index 8b2886b..a1d5d95 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -26,8 +26,7 @@ local setmetatable = setmetatable -- File system disk space usage -- lain.widgets.fs local fs = {} - -local fs_notification = nil +local fs_notification = nil function fs:hide() if fs_notification ~= nil then @@ -42,11 +41,11 @@ function fs:show(t_out) local ws = helpers.read_pipe(helpers.scripts_dir .. "dfs"):gsub("\n*$", "") if fs.followmouse then - fs_notification_preset.screen = mouse.screen + fs.notification_preset.screen = mouse.screen end fs_notification = naughty.notify({ - preset = fs_notification_preset, + preset = fs.notification_preset, text = ws, timeout = t_out }) @@ -67,7 +66,6 @@ local function worker(args) fs.widget = wibox.widget.textbox('') helpers.set_map(partition, false) - helpers.set_map("fsused", 0) function update() fs_info = {} @@ -94,11 +92,8 @@ local function worker(args) fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0 fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0 - if helpers.get_map("fsused") ~= fs_now.used then - widget = fs.widget - settings() - helpers.set_map("fsused", fs_now.used) - end + widget = fs.widget + settings() if fs_now.used >= 99 and not helpers.get_map(partition) then diff --git a/widgets/imap.lua b/widgets/imap.lua index 350e1ad..ea763df 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -65,10 +65,8 @@ local function worker(args) _, mailcount = string.gsub(f, "%d+", "") _ = nil - if mailcount ~= helpers.get_map(mail) then - widget = imap.widget - settings() - end + widget = imap.widget + settings() if mailcount >= 1 and mailcount > helpers.get_map(mail) then diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 8cb821d..eed6138 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -25,7 +25,7 @@ local setmetatable = setmetatable -- Maildir check -- lain.widgets.maildir -local maildir = { total = 0 } +local maildir = {} local function worker(args) local args = args or {} @@ -65,7 +65,7 @@ local function worker(args) end until line == nil - p:close() + p:close() table.sort(boxes) newmail = "no mail" @@ -88,10 +88,8 @@ local function worker(args) end end - if maildir.total ~= total then - widget = maildir.widget - settings() - end + widget = maildir.widget + settings() end newtimer(mailpath, timeout, update, true) diff --git a/widgets/mem.lua b/widgets/mem.lua index dc72279..f6213b2 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -7,33 +7,27 @@ --]] -local helpers = require("lain.helpers") -local wibox = require("wibox") +local newtimer = require("lain.helpers").newtimer -local io = { lines = io.lines } -local math = { floor = math.floor } -local string = { gmatch = string.gmatch } +local wibox = require("wibox") -local setmetatable = setmetatable +local io = { lines = io.lines } +local math = { floor = math.floor } +local string = { gmatch = string.gmatch } --- Memory usage +local setmetatable = setmetatable + +-- Memory usage (ignoring caches) -- lain.widgets.mem local mem = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 2 local settings = args.settings or function() end mem.widget = wibox.widget.textbox('') - helpers.set_map("mem_last_total", 0) - helpers.set_map("mem_last_free", 0) - helpers.set_map("mem_last_buf", 0) - helpers.set_map("mem_last_cache", 0) - helpers.set_map("mem_last_swap", 0) - helpers.set_map("mem_last_swapf", 0) - function update() mem_now = {} for line in io.lines("/proc/meminfo") @@ -50,29 +44,14 @@ local function worker(args) end end - if mem_now.total ~= helpers.set_map("mem_last_total") - or mem_now.free ~= helpers.set_map("mem_last_free") - or mem_now.buf ~= helpers.set_map("mem_last_buf") - or mem_now.cache ~= helpers.set_map("mem_last_cache") - or mem_now.swap ~= helpers.set_map("mem_last_swap") - or mem_now.swapf ~= helpers.set_map("mem_last_swapf") - then - mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache) - mem_now.swapused = mem_now.swap - mem_now.swapf + mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache) + mem_now.swapused = mem_now.swap - mem_now.swapf - widget = mem.widget - settings() - - helpers.set_map("mem_last_total", mem_now.total) - helpers.set_map("mem_last_free", mem_now.free) - helpers.set_map("mem_last_buf", mem_now.buf) - helpers.set_map("mem_last_cache", mem_now.cache) - helpers.set_map("mem_last_swap", mem_now.swap) - helpers.set_map("mem_last_swapf", mem_now.swapf) - end + widget = mem.widget + settings() end - helpers.newtimer("mem", timeout, update) + newtimer("mem", timeout, update) return mem.widget end diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 1d2c617..5af898b 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -30,7 +30,7 @@ local mpd = {} 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" @@ -49,11 +49,10 @@ local function worker(args) mpd_notification_preset = { title = "Now playing", - timeout = 5 + timeout = 6 } - helpers.set_map("current mpd track", "") - helpers.set_map("current mpd file", "") + helpers.set_map("current mpd track", nil) function mpd.update() async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f) @@ -72,7 +71,6 @@ local function worker(args) for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do if k == "state" then mpd_now.state = v elseif k == "file" then mpd_now.file = v - elseif k == "Name" then mpd_now.name = escape_f(v) elseif k == "Artist" then mpd_now.artist = escape_f(v) elseif k == "Title" then mpd_now.title = escape_f(v) elseif k == "Album" then mpd_now.album = escape_f(v) @@ -85,13 +83,8 @@ local function worker(args) mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist, mpd_now.album, mpd_now.date, mpd_now.title) - - if mpd_now.file ~= helpers.get_map("current mpd file") - then - widget = mpd.widget - settings() - helpers.set_map("current mpd file", mpd_now.file) - end + widget = mpd.widget + settings() if mpd_now.state == "play" then diff --git a/widgets/net.lua b/widgets/net.lua index 983da41..a578ae4 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -21,7 +21,10 @@ local setmetatable = setmetatable -- Network infos -- lain.widgets.net -local net = {} +local net = { + last_t = 0, + last_r = 0 +} function net.get_device() local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") @@ -35,7 +38,7 @@ end local function worker(args) local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 2 local units = args.units or 1024 --kb local notify = args.notify or "on" local screen = args.screen or 1 @@ -46,44 +49,35 @@ local function worker(args) net.widget = wibox.widget.textbox('') helpers.set_map(iface, true) - helpers.set_map("net_t", 0) - helpers.set_map("net_r", 0) function update() - net_now = { - sent = "0.0", - received = "0.0" - } + net_now = {} if iface == "" or string.match(iface, "network off") then iface = net.get_device() end + net_now.carrier = helpers.first_line('/sys/class/net/' .. iface .. + '/carrier') or "0" + net_now.state = helpers.first_line('/sys/class/net/' .. iface .. + '/operstate') or "down" local now_t = helpers.first_line('/sys/class/net/' .. iface .. '/statistics/tx_bytes') or 0 local now_r = helpers.first_line('/sys/class/net/' .. iface .. '/statistics/rx_bytes') or 0 - if now_t ~= helpers.get_map("net_t") - or now_r ~= helpers.get_map("net_r") then - net_now.carrier = helpers.first_line('/sys/class/net/' .. iface .. - '/carrier') or "0" - net_now.state = helpers.first_line('/sys/class/net/' .. iface .. - '/operstate') or "down" + net_now.sent = (now_t - net.last_t) / timeout / units + net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".") - net_now.sent = (now_t - net.last_t) / timeout / units - net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".") + net_now.received = (now_r - net.last_r) / timeout / units + net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".") - net_now.received = (now_r - net.last_r) / timeout / units - net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".") + widget = net.widget + settings() - widget = net.widget - settings() - - helpers.set_map("net_t", now_t) - helpers.set_map("net_r", now_r) - end + net.last_t = now_t + net.last_r = now_r if net_now.carrier ~= "1" and notify == "on" then @@ -105,8 +99,7 @@ local function worker(args) end end - helpers.newtimer(iface, timeout, update, false) - + helpers.newtimer(iface, timeout, update) return net.widget end diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 9472235..d8e4713 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -7,7 +7,8 @@ --]] -local helpers = require("lain.helpers") +local newtimer = require("lain.helpers").newtimer + local wibox = require("wibox") local io = { open = io.open } @@ -21,13 +22,10 @@ local sysload = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 2 local settings = args.settings or function() end sysload.widget = wibox.widget.textbox('') - helpers.set_map("load_1", 0) - helpers.set_map("load_5", 0) - helpers.set_map("load_15", 0) function update() local f = io.open("/proc/loadavg") @@ -36,21 +34,11 @@ local function worker(args) load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)") - if load_1 ~= helpers.get_map("load_1") - or load_5 ~= helpers.get_map("load_5") - or load_15 ~= helpers.get_map("load_15") - then - widget = sysload.widget - settings() - - helpers.set_map("load_1", load_1) - helpers.set_map("load_5", load_5) - helpers.set_map("load_15", load_15) - end + widget = sysload.widget + settings() end - helpers.newtimer("sysload", timeout, update) - + newtimer("sysload", timeout, update) return sysload.widget end diff --git a/widgets/temp.lua b/widgets/temp.lua index 6831588..67c9456 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -6,7 +6,8 @@ --]] -local helpers = require("lain.helpers") +local newtimer = require("lain.helpers").newtimer + local wibox = require("wibox") local io = { open = io.open } @@ -20,12 +21,11 @@ local temp = {} local function worker(args) local args = args or {} - local timeout = args.timeout or 1 + local timeout = args.timeout or 2 local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp" local settings = args.settings or function() end temp.widget = wibox.widget.textbox('') - helpers.set_map("temp_last", 0) function update() local f = io.open(tempfile) @@ -37,15 +37,11 @@ local function worker(args) coretemp_now = "N/A" end - if helpers.get_map("temp_last") ~= coretemp_now then - widget = temp.widget - settings() - helpers.set_map("temp_last", coretemp_now) - end + widget = temp.widget + settings() end - helpers.newtimer("coretemp", timeout, update) - + newtimer("coretemp", timeout, update) return temp.widget end -- 2.39.5 From 2b8a2bc2ae974072cb48e293db0c05e9517cff06 Mon Sep 17 00:00:00 2001 From: Luke Bonham Date: Sun, 25 Oct 2015 10:02:40 +0100 Subject: [PATCH 06/16] forgot to refix #141 --- widgets/bat.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/widgets/bat.lua b/widgets/bat.lua index 626239b..61828ec 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -21,9 +21,9 @@ local setmetatable = setmetatable -- Battery infos -- lain.widgets.bat -local bat = {} local function worker(args) + local bat = {} local args = args or {} local timeout = args.timeout or 30 local battery = args.battery or "BAT0" @@ -143,7 +143,7 @@ local function worker(args) newtimer(battery, timeout, update) - return bat.widget + return setmetatable(bat, { __index = bat.widget }) end -return setmetatable(bat, { __call = function(_, ...) return worker(...) end }) +return setmetatable({}, { __call = function(_, ...) return worker(...) end }) -- 2.39.5 From 305e0e57b20e324f30758fd2c8202180dd8908d6 Mon Sep 17 00:00:00 2001 From: Dario Gjorgjevski Date: Mon, 2 Nov 2015 22:50:32 +0100 Subject: [PATCH 07/16] improve icon and notification text handling --- widgets/weather.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index baf82d7..ab87ff8 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -46,11 +46,13 @@ local function worker(args) function (day, desc, tmin, tmax) return string.format("%s: %s, %d - %d ", day, desc, tmin, tmax) end + local weather_na_markup = args.weather_na_markup or " N/A " local followmouse = args.followmouse or false local settings = args.settings or function() end - weather.widget = wibox.widget.textbox('') - weather.icon = wibox.widget.imagebox() + weather.widget = wibox.widget.textbox(weather_na_text) + weather.icon_path = icons_path .. "na.png" + weather.icon = wibox.widget.imagebox(weather.icon_path) function weather.show(t_out) weather.hide() @@ -60,7 +62,8 @@ local function worker(args) end weather.notification = naughty.notify({ - text = weather.notification_text, + text = weather.notification_text + or "Waiting for the server to respond...", icon = weather.icon_path, timeout = t_out, preset = notification_preset @@ -106,7 +109,6 @@ local function worker(args) end end else - weather.icon_path = icons_path .. "na.png" weather.notification_text = "API/connection error or bad/not set city ID" end end) @@ -120,13 +122,14 @@ local function worker(args) if not err and weather_now ~= nil and tonumber(weather_now["cod"]) == 200 then weather.icon_path = icons_path .. weather_now["weather"][1]["icon"] .. ".png" - weather.icon:set_image(weather.icon_path) widget = weather.widget settings() else - weather.widget._layout.text = " N/A " -- tries to avoid textbox bugs - weather.icon:set_image(icons_path .. "na.png") + weather.icon_path = icons_path .. "na.png" + weather.widget:set_markup(weather_na_markup) end + + weather.icon:set_image(weather.icon_path) end) end -- 2.39.5 From 9f8eb5d0a2fa32b81df9bd70cd0761773955b724 Mon Sep 17 00:00:00 2001 From: Dario Gjorgjevski Date: Mon, 2 Nov 2015 22:51:57 +0100 Subject: [PATCH 08/16] fix variable name --- widgets/weather.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index ab87ff8..173601a 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -50,7 +50,7 @@ local function worker(args) local followmouse = args.followmouse or false local settings = args.settings or function() end - weather.widget = wibox.widget.textbox(weather_na_text) + weather.widget = wibox.widget.textbox(weather_na_markup) weather.icon_path = icons_path .. "na.png" weather.icon = wibox.widget.imagebox(weather.icon_path) -- 2.39.5 From d659c34974ee8e2c136bbac2424c5d95b889492d Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 11 Nov 2015 18:25:51 +0100 Subject: [PATCH 09/16] #150 fix; wiki updated --- widgets/net.lua | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/widgets/net.lua b/widgets/net.lua index a578ae4..702937c 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -21,22 +21,20 @@ local setmetatable = setmetatable -- Network infos -- lain.widgets.net -local net = { - last_t = 0, - last_r = 0 -} - -function net.get_device() - local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") - ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN") - if ws ~= nil then - return ws:match("(%w+):") - else - return "network off" - end -end local function worker(args) + local net = { last_t = 0, last_r = 0 } + + function net.get_device() + local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") + ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN") + if ws ~= nil then + return ws:match("(%w+):") + else + return "network off" + end + end + local args = args or {} local timeout = args.timeout or 2 local units = args.units or 1024 --kb @@ -100,7 +98,8 @@ local function worker(args) end helpers.newtimer(iface, timeout, update) - return net.widget + + return setmetatable(net, { __index = net.widget }) end -return setmetatable(net, { __call = function(_, ...) return worker(...) end }) +return setmetatable({}, { __call = function(_, ...) return worker(...) end }) -- 2.39.5 From d58ac139b6198118314a4fe640abe18e3f816380 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 11 Nov 2015 18:30:59 +0100 Subject: [PATCH 10/16] wiki updated --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 35cc75d..cb5d545 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f +Subproject commit cb5d5455987533d08c37fd17fec7dfa757b7130a -- 2.39.5 From da1410677b338d57f4e4082587197b3a38985207 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 11 Nov 2015 18:52:40 +0100 Subject: [PATCH 11/16] #150 fix 2 --- widgets/net.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/widgets/net.lua b/widgets/net.lua index 702937c..af823a8 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -35,14 +35,13 @@ local function worker(args) end end - local args = args or {} - local timeout = args.timeout or 2 - local units = args.units or 1024 --kb - local notify = args.notify or "on" - local screen = args.screen or 1 + local args = args or {} + local timeout = args.timeout or 2 + local units = args.units or 1024 --kb + local notify = args.notify or "on" + local screen = args.screen or 1 local settings = args.settings or function() end - - iface = args.iface or net.get_device() + local iface = args.iface or net.get_device() net.widget = wibox.widget.textbox('') -- 2.39.5 From 11e448e5e2260fbbcb63f1303bbc00d0d8ddcbbd Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Nov 2015 11:51:53 +0100 Subject: [PATCH 12/16] (re)merged #142 --- widgets/mpd.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 5af898b..1972050 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -59,6 +59,7 @@ local function worker(args) mpd_now = { state = "N/A", file = "N/A", + name = "N/A", artist = "N/A", title = "N/A", album = "N/A", @@ -71,6 +72,7 @@ local function worker(args) for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do if k == "state" then mpd_now.state = v elseif k == "file" then mpd_now.file = v + elseif k == "Name" then mpd_now.name = escape_f(v) elseif k == "Artist" then mpd_now.artist = escape_f(v) elseif k == "Title" then mpd_now.title = escape_f(v) elseif k == "Album" then mpd_now.album = escape_f(v) -- 2.39.5 From 418e475b5b4eb8404e115d74fdb3756169877278 Mon Sep 17 00:00:00 2001 From: Sudo Nice Date: Wed, 18 Nov 2015 11:02:16 +0300 Subject: [PATCH 13/16] helpers: spairs() added --- helpers.lua | 20 ++++++++++++++++++++ widgets/maildir.lua | 7 +++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/helpers.lua b/helpers.lua index 4e90e16..4ece329 100644 --- a/helpers.lua +++ b/helpers.lua @@ -13,6 +13,7 @@ local io = { open = io.open, lines = io.lines, popen = io.popen } local rawget = rawget +local table = { sort = table.sort } -- Lain helper functions for internal use -- lain.helpers @@ -113,4 +114,23 @@ end -- }}} +--{{{ Iterate over table of records sorted by keys +function helpers.spairs(t) + -- collect the keys + local keys = {} + for k in pairs(t) do keys[#keys+1] = k end + + table.sort(keys) + + -- return the iterator function + local i = 0 + return function() + i = i + 1 + if keys[i] then + return keys[i], t[keys[i]] + end + end +end +--}}} + return helpers diff --git a/widgets/maildir.lua b/widgets/maildir.lua index eed6138..79d28b5 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -9,6 +9,7 @@ local newtimer = require("lain.helpers").newtimer local read_pipe = require("lain.helpers").read_pipe +local spairs = require("lain.helpers").spairs local wibox = require("wibox") @@ -19,7 +20,6 @@ local os = { getenv = os.getenv } local pairs = pairs local string = { len = string.len, match = string.match } -local table = { sort = table.sort } local setmetatable = setmetatable @@ -65,14 +65,13 @@ local function worker(args) end until line == nil - p:close() - table.sort(boxes) + p:close() newmail = "no mail" -- Count the total number of mails irrespective of where it was found total = 0 - for box, number in pairs(boxes) + for box, number in spairs(boxes) do -- Add this box only if it's not to be ignored. if not util.element_in_table(box, ignore_boxes) -- 2.39.5 From 1539a1b5d4394c6a397e3a68f36f9ba66d161a4b Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Sat, 21 Nov 2015 11:49:22 +0000 Subject: [PATCH 14/16] Add ability to run an external mail update command, and support multi-level maildirs containing multiple accounts. --- widgets/maildir.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 79d28b5..4f3fc79 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -33,14 +33,19 @@ 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('') function update() + if ext_mail_cmd ~= nil + then + awful.util.spawn(ext_mail_cmd) + end -- Find pathes to mailboxes. local p = io.popen("find " .. mailpath .. - " -mindepth 1 -maxdepth 1 -type d" .. - " -not -name .git") + " -mindepth 1 -maxdepth 2 -type d" .. + " -not -name .git") local boxes = {} repeat line = p:read("*l") @@ -56,7 +61,7 @@ local function worker(args) "-not -name '.*' -printf a") -- Strip off leading mailpath. - local box = string.match(line, mailpath .. "/*([^/]+)") + local box = string.match(line, mailpath .. "/(.*)") local nummails = string.len(mailstring) if nummails > 0 then -- 2.39.5 From 94204ac2dad82e8b9b206cb596b3a27fb8379640 Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Sat, 21 Nov 2015 11:53:19 +0000 Subject: [PATCH 15/16] Styling to match upstream --- widgets/maildir.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 4f3fc79..12f3545 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -44,8 +44,8 @@ local function worker(args) end -- Find pathes to mailboxes. local p = io.popen("find " .. mailpath .. - " -mindepth 1 -maxdepth 2 -type d" .. - " -not -name .git") + " -mindepth 1 -maxdepth 2 -type d" .. + " -not -name .git") local boxes = {} repeat line = p:read("*l") -- 2.39.5 From 35957f391460172500255ffe20cf1b34622d93f1 Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Sat, 21 Nov 2015 11:56:32 +0000 Subject: [PATCH 16/16] Fix missing awful --- widgets/maildir.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 12f3545..2476601 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -13,6 +13,7 @@ local spairs = require("lain.helpers").spairs local wibox = require("wibox") +local awful = require("awful") local util = require("lain.util") local io = { popen = io.popen } -- 2.39.5