mirror of https://github.com/lcpz/lain.git
some cpu usage improvements
This commit is contained in:
parent
42505f946e
commit
f63a7fd098
|
@ -28,8 +28,11 @@ local function worker(args)
|
||||||
function abase.update()
|
function abase.update()
|
||||||
async.request(cmd, function(f)
|
async.request(cmd, function(f)
|
||||||
output = f
|
output = f
|
||||||
widget = abase.widget
|
if output ~= abase.prev then
|
||||||
settings()
|
widget = abase.widget
|
||||||
|
settings()
|
||||||
|
abase.prev = output
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- ALSA volume
|
-- ALSA volume
|
||||||
-- lain.widgets.alsa
|
-- lain.widgets.alsa
|
||||||
local alsa = {}
|
local alsa = { last_level = "0", last_status = "off" }
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -28,34 +28,20 @@ local function worker(args)
|
||||||
|
|
||||||
alsa.cmd = args.cmd or "amixer"
|
alsa.cmd = args.cmd or "amixer"
|
||||||
alsa.channel = args.channel or "Master"
|
alsa.channel = args.channel or "Master"
|
||||||
|
alsa.widget = wibox.widget.textbox('')
|
||||||
alsa.widget = wibox.widget.textbox('')
|
|
||||||
|
|
||||||
function alsa.update()
|
function alsa.update()
|
||||||
local mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
|
mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
|
||||||
|
l, s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
||||||
|
|
||||||
volume_now = {}
|
if alsa.last_level ~= l or alsa.last_status ~= s then
|
||||||
|
volume_now = { level = l, status = s }
|
||||||
|
alsa.last_level = l
|
||||||
|
alsa.last_status = s
|
||||||
|
|
||||||
volume_now.level, volume_now.status = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
widget = alsa.widget
|
||||||
|
settings()
|
||||||
if volume_now.level == nil
|
|
||||||
then
|
|
||||||
volume_now.level = "0"
|
|
||||||
volume_now.status = "off"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if volume_now.status == ""
|
|
||||||
then
|
|
||||||
if volume_now.level == "0"
|
|
||||||
then
|
|
||||||
volume_now.status = "off"
|
|
||||||
else
|
|
||||||
volume_now.status = "on"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
widget = alsa.widget
|
|
||||||
settings()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
||||||
|
|
|
@ -127,28 +127,26 @@ local function worker(args)
|
||||||
-- Capture mixer control state: [5%] ... ... [on]
|
-- Capture mixer control state: [5%] ... ... [on]
|
||||||
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
||||||
|
|
||||||
if volu == nil then
|
if tonumber(volu) ~= alsabar._current_level or string.match(mute, "on") ~= alsabar._muted
|
||||||
volu = 0
|
|
||||||
mute = "off"
|
|
||||||
end
|
|
||||||
|
|
||||||
alsabar._current_level = tonumber(volu)
|
|
||||||
alsabar.bar:set_value(alsabar._current_level / 100)
|
|
||||||
if not mute and tonumber(volu) == 0 or mute == "off"
|
|
||||||
then
|
then
|
||||||
alsabar._muted = true
|
alsabar._current_level = tonumber(volu)
|
||||||
alsabar.tooltip:set_text (" [Muted] ")
|
alsabar.bar:set_value(alsabar._current_level / 100)
|
||||||
alsabar.bar:set_color(alsabar.colors.mute)
|
if not mute and tonumber(volu) == 0 or mute == "off"
|
||||||
else
|
then
|
||||||
alsabar._muted = false
|
alsabar._muted = true
|
||||||
alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
|
alsabar.tooltip:set_text (" [Muted] ")
|
||||||
alsabar.bar:set_color(alsabar.colors.unmute)
|
alsabar.bar:set_color(alsabar.colors.mute)
|
||||||
end
|
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 = {}
|
||||||
volume_now.level = tonumber(volu)
|
volume_now.level = tonumber(volu)
|
||||||
volume_now.status = mute
|
volume_now.status = mute
|
||||||
settings()
|
settings()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alsabar.bar:buttons (awful.util.table.join (
|
alsabar.bar:buttons (awful.util.table.join (
|
||||||
|
|
|
@ -26,9 +26,12 @@ local function worker(args)
|
||||||
base.widget = wibox.widget.textbox('')
|
base.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function base.update()
|
function base.update()
|
||||||
output = read_pipe(cmd)
|
if output ~= abase.prev then
|
||||||
widget = base.widget
|
output = read_pipe(cmd)
|
||||||
settings()
|
widget = base.widget
|
||||||
|
settings()
|
||||||
|
abase.prev = output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(cmd, timeout, base.update)
|
newtimer(cmd, timeout, base.update)
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local wibox = require("awful.wibox")
|
local wibox = require("awful.wibox")
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Creates a thin wibox at a position relative to another wibox
|
-- Creates a thin wibox at a position relative to another wibox
|
||||||
|
|
|
@ -21,10 +21,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- CPU usage
|
-- CPU usage
|
||||||
-- lain.widgets.cpu
|
-- lain.widgets.cpu
|
||||||
local cpu = {
|
local cpu = { last_total = 0, last_active = 0 }
|
||||||
last_total = 0,
|
|
||||||
last_active = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -53,20 +50,22 @@ local function worker(args)
|
||||||
at = at + 1
|
at = at + 1
|
||||||
end
|
end
|
||||||
local active = total - idle
|
local active = total - idle
|
||||||
|
|
||||||
|
if cpu.last_active ~= active or cpu.last_total ~= 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.
|
cpu_now = {}
|
||||||
local dactive = active - cpu.last_active
|
cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100))
|
||||||
local dtotal = total - cpu.last_total
|
|
||||||
|
|
||||||
cpu_now = {}
|
widget = cpu.widget
|
||||||
cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100))
|
settings()
|
||||||
|
|
||||||
widget = cpu.widget
|
-- Save current data for the next run.
|
||||||
settings()
|
cpu.last_active = active
|
||||||
|
cpu.last_total = total
|
||||||
-- Save current data for the next run.
|
end
|
||||||
cpu.last_active = active
|
|
||||||
cpu.last_total = total
|
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("cpu", timeout, update)
|
newtimer("cpu", timeout, update)
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local helpers = require("lain.helpers")
|
local helpers = require("lain.helpers")
|
||||||
|
|
||||||
local notify_fg = require("beautiful").fg_focus
|
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
|
@ -28,11 +26,8 @@ local function worker(args)
|
||||||
function net.get_device()
|
function net.get_device()
|
||||||
local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
|
local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
|
||||||
ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
|
ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
|
||||||
if ws ~= nil then
|
if ws then return ws:match("(%w+):")
|
||||||
return ws:match("(%w+):")
|
else return "network off" end
|
||||||
else
|
|
||||||
return "network off"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -55,38 +50,33 @@ local function worker(args)
|
||||||
iface = net.get_device()
|
iface = net.get_device()
|
||||||
end
|
end
|
||||||
|
|
||||||
net_now.carrier = helpers.first_line('/sys/class/net/' .. iface ..
|
net_now.carrier = helpers.first_line(string.format('/sys/class/net/%s/carrier', iface)) or '0'
|
||||||
'/carrier') or "0"
|
net_now.state = helpers.first_line(string.format('/sys/class/net/%s/operstate', iface)) or 'down'
|
||||||
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
|
local now_t = helpers.first_line(string.format('/sys/class/net/%s/statistics/tx_bytes', iface)) or 0
|
||||||
net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".")
|
local now_r = helpers.first_line(string.format('/sys/class/net/%s/statistics/rx_bytes', iface)) or 0
|
||||||
|
|
||||||
net_now.received = (now_r - net.last_r) / timeout / units
|
if now_t ~= net.last_t or now_r ~= net.last_r then
|
||||||
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), ',', '.')
|
||||||
|
net_now.received = (now_r - net.last_r) / timeout / units
|
||||||
|
net_now.received = string.gsub(string.format('%.1f', net_now.received), ',', '.')
|
||||||
|
|
||||||
widget = net.widget
|
widget = net.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
net.last_t = now_t
|
net.last_t = now_t
|
||||||
net.last_r = now_r
|
net.last_r = now_r
|
||||||
|
end
|
||||||
|
|
||||||
if net_now.carrier ~= "1" and notify == "on"
|
if not string.match(net_now.carrier, "1") and notify == "on"
|
||||||
then
|
then
|
||||||
if helpers.get_map(iface)
|
if helpers.get_map(iface)
|
||||||
then
|
then
|
||||||
naughty.notify({
|
naughty.notify({
|
||||||
title = iface,
|
title = iface,
|
||||||
text = "no carrier",
|
text = "no carrier",
|
||||||
timeout = 7,
|
|
||||||
position = "top_left",
|
|
||||||
icon = helpers.icons_dir .. "no_net.png",
|
icon = helpers.icons_dir .. "no_net.png",
|
||||||
fg = notify_fg or "#FFFFFF",
|
|
||||||
screen = screen
|
screen = screen
|
||||||
})
|
})
|
||||||
helpers.set_map(iface, false)
|
helpers.set_map(iface, false)
|
||||||
|
|
|
@ -42,6 +42,7 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("coretemp", timeout, update)
|
newtimer("coretemp", timeout, update)
|
||||||
|
|
||||||
return temp.widget
|
return temp.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue