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 markup = require("lain.util.markup")
11 local helpers = require("lain.helpers")
13 local awful = require("awful")
14 local beautiful = require("beautiful")
15 local wibox = require("wibox")
18 local tostring = tostring
19 local string = { format = string.format }
21 local setmetatable = setmetatable
39 function net.get_device()
40 f = io.popen("ip link show | cut -d' ' -f2,9")
43 ws = ws:match("%w+: UP")
45 return ws:gsub(": UP", "")
52 local args = args or {}
53 local iface = args.iface or net.get_device()
54 local delta = args.refresh_timeout or 2
55 local units = args.units or net.units["kb"]
56 local spr = args.spr or " "
57 local header = args.header or iface
58 local header_color = args.header_color or beautiful.fg_normal or "#FFFFFF"
59 local color_up = args.color_up or beautiful.fg_focus or "#FFFFFF"
60 local color_down = args.color_down or beautiful.fg_focus or "#FFFFFF"
61 local app = args.app or "sudo wifi-menu"
63 helpers.set_map(iface, true)
64 helpers.set_map("carrier", 0)
66 local mynet = wibox.widget.textbox()
68 local mynetupdate = function()
70 iface = net.get_device()
74 local carrier = helpers.first_line('/sys/class/net/' .. iface ..
76 local state = helpers.first_line('/sys/class/net/' .. iface ..
78 local now_t = helpers.first_line('/sys/class/net/' .. iface ..
79 '/statistics/tx_bytes')
80 local now_r = helpers.first_line('/sys/class/net/' .. iface ..
81 '/statistics/rx_bytes')
82 local text = '<span color="' .. header_color .. '">' .. header .. '</span> '
86 if helpers.get_map(iface)
93 naughty.notify({ title = n_title, text = "no carrier",
95 position = "top_left",
96 icon = beautiful.lain_no_net_notify or
97 helpers.icons_dir .. "no_net.png",
98 fg = beautiful.fg_focus or "#FFFFFF" })
100 mynet:set_markup(markup(header_color, header) .. markup(color_up, " Off"))
101 helpers.set_map(iface, false)
105 helpers.set_map(iface, true)
108 if state == 'down' or not now_t or not now_r
110 mynet:set_markup(' ' .. text .. '-' .. ' ')
114 if net.last_t[iface] and net.last_t[iface]
116 net.send = tostring((now_t - net.last_t[iface]) / delta / units)
117 net.recv = tostring((now_r - net.last_r[iface]) / delta / units)
120 .. '<span color="' .. color_up .. '">'
121 .. string.format('%.1f', net.send)
124 .. '<span color="' .. color_down .. '">'
125 .. string.format('%.1f', net.recv)
128 mynet:set_markup(' ' .. text .. ' ')
130 mynet:set_markup(' ' .. text .. '-' .. ' ')
133 net.last_t[iface] = now_t
134 net.last_r[iface] = now_r
137 local mynettimer = timer({ timeout = delta })
138 mynettimer:connect_signal("timeout", mynetupdate)
140 mynettimer:emit_signal("timeout")
142 mynet:buttons(awful.util.table.join(
143 awful.button({}, 0, function()
144 helpers.run_in_terminal(app)
150 return setmetatable(net, { __index = net.widget })
153 return setmetatable(net, { __call = function(_, ...) return worker(...) end })