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()
|
||||
async.request(cmd, function(f)
|
||||
output = f
|
||||
widget = abase.widget
|
||||
settings()
|
||||
if output ~= abase.prev then
|
||||
widget = abase.widget
|
||||
settings()
|
||||
abase.prev = output
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ local setmetatable = setmetatable
|
|||
|
||||
-- ALSA volume
|
||||
-- lain.widgets.alsa
|
||||
local alsa = {}
|
||||
local alsa = { last_level = "0", last_status = "off" }
|
||||
|
||||
local function worker(args)
|
||||
local args = args or {}
|
||||
|
@ -28,34 +28,20 @@ local function worker(args)
|
|||
|
||||
alsa.cmd = args.cmd or "amixer"
|
||||
alsa.channel = args.channel or "Master"
|
||||
|
||||
alsa.widget = wibox.widget.textbox('')
|
||||
alsa.widget = wibox.widget.textbox('')
|
||||
|
||||
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]*)")
|
||||
|
||||
if volume_now.level == nil
|
||||
then
|
||||
volume_now.level = "0"
|
||||
volume_now.status = "off"
|
||||
widget = alsa.widget
|
||||
settings()
|
||||
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
|
||||
|
||||
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]
|
||||
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
||||
|
||||
if volu == nil then
|
||||
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"
|
||||
if tonumber(volu) ~= alsabar._current_level or string.match(mute, "on") ~= alsabar._muted
|
||||
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
|
||||
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()
|
||||
volume_now = {}
|
||||
volume_now.level = tonumber(volu)
|
||||
volume_now.status = mute
|
||||
settings()
|
||||
end
|
||||
end
|
||||
|
||||
alsabar.bar:buttons (awful.util.table.join (
|
||||
|
|
|
@ -26,9 +26,12 @@ local function worker(args)
|
|||
base.widget = wibox.widget.textbox('')
|
||||
|
||||
function base.update()
|
||||
output = read_pipe(cmd)
|
||||
widget = base.widget
|
||||
settings()
|
||||
if output ~= abase.prev then
|
||||
output = read_pipe(cmd)
|
||||
widget = base.widget
|
||||
settings()
|
||||
abase.prev = output
|
||||
end
|
||||
end
|
||||
|
||||
newtimer(cmd, timeout, base.update)
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
--]]
|
||||
|
||||
local wibox = require("awful.wibox")
|
||||
|
||||
local wibox = require("awful.wibox")
|
||||
local setmetatable = setmetatable
|
||||
|
||||
-- Creates a thin wibox at a position relative to another wibox
|
||||
|
|
|
@ -21,10 +21,7 @@ local setmetatable = setmetatable
|
|||
|
||||
-- CPU usage
|
||||
-- lain.widgets.cpu
|
||||
local cpu = {
|
||||
last_total = 0,
|
||||
last_active = 0
|
||||
}
|
||||
local cpu = { last_total = 0, last_active = 0 }
|
||||
|
||||
local function worker(args)
|
||||
local args = args or {}
|
||||
|
@ -53,20 +50,22 @@ local function worker(args)
|
|||
at = at + 1
|
||||
end
|
||||
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.
|
||||
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.
|
||||
cpu.last_active = active
|
||||
cpu.last_total = total
|
||||
end
|
||||
end
|
||||
|
||||
newtimer("cpu", timeout, update)
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
--]]
|
||||
|
||||
local helpers = require("lain.helpers")
|
||||
|
||||
local notify_fg = require("beautiful").fg_focus
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
||||
|
@ -28,11 +26,8 @@ local function worker(args)
|
|||
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
|
||||
if ws then return ws:match("(%w+):")
|
||||
else return "network off" end
|
||||
end
|
||||
|
||||
local args = args or {}
|
||||
|
@ -55,38 +50,33 @@ local function worker(args)
|
|||
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.carrier = helpers.first_line(string.format('/sys/class/net/%s/carrier', iface)) or '0'
|
||||
net_now.state = helpers.first_line(string.format('/sys/class/net/%s/operstate', iface)) or 'down'
|
||||
|
||||
net_now.sent = (now_t - net.last_t) / timeout / units
|
||||
net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".")
|
||||
local now_t = helpers.first_line(string.format('/sys/class/net/%s/statistics/tx_bytes', iface)) or 0
|
||||
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
|
||||
net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".")
|
||||
if now_t ~= net.last_t or now_r ~= net.last_r then
|
||||
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
|
||||
settings()
|
||||
widget = net.widget
|
||||
settings()
|
||||
|
||||
net.last_t = now_t
|
||||
net.last_r = now_r
|
||||
net.last_t = now_t
|
||||
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
|
||||
if helpers.get_map(iface)
|
||||
then
|
||||
naughty.notify({
|
||||
title = iface,
|
||||
text = "no carrier",
|
||||
timeout = 7,
|
||||
position = "top_left",
|
||||
icon = helpers.icons_dir .. "no_net.png",
|
||||
fg = notify_fg or "#FFFFFF",
|
||||
screen = screen
|
||||
})
|
||||
helpers.set_map(iface, false)
|
||||
|
|
|
@ -42,6 +42,7 @@ local function worker(args)
|
|||
end
|
||||
|
||||
newtimer("coretemp", timeout, update)
|
||||
|
||||
return temp.widget
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue