All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010-2012, Peter Hofmann
10 local helpers = require("lain.helpers")
12 local notify_fg = require("beautiful").fg_focus
13 local naughty = require("naughty")
14 local wibox = require("wibox")
17 local tostring = tostring
18 local string = { format = string.format,
21 local setmetatable = setmetatable
30 function net.get_device()
31 f = io.popen("ip link show | cut -d' ' -f2,9")
34 ws = ws:match("%w+: UP")
36 return ws:gsub(": UP", "")
43 local args = args or {}
44 local iface = args.iface or net.get_device()
45 local units = args.units or 1024 --kb
46 local timeout = args.timeout or 2
47 local settings = args.settings or function() end
49 widget = wibox.widget.textbox('')
51 helpers.set_map(iface, true)
54 if iface == "" then iface = net.get_device() end
56 carrier = helpers.first_line('/sys/class/net/' .. iface ..
58 state = helpers.first_line('/sys/class/net/' .. iface ..
59 '/operstate') or "down"
60 local now_t = helpers.first_line('/sys/class/net/' .. iface ..
61 '/statistics/tx_bytes') or 0
62 local now_r = helpers.first_line('/sys/class/net/' .. iface ..
63 '/statistics/rx_bytes') or 0
65 sent = tostring((now_t - net.last_t) / timeout / units)
66 sent = string.gsub(string.format('%.1f', sent), ",", ".")
68 received = tostring((now_r - net.last_r) / timeout / units)
69 received = string.gsub(string.format('%.1f', received), ",", ".")
78 if helpers.get_map(iface)
81 if n_title == "" then n_title = "network" end
86 position = "top_left",
87 icon = helpers.icons_dir .. "no_net.png",
88 fg = notify_fg or "#FFFFFF"
90 helpers.set_map(iface, false)
93 helpers.set_map(iface, true)
97 helpers.newtimer(iface, timeout, update)
102 return setmetatable(net, { __call = function(_, ...) return worker(...) end })