few improvements
This commit is contained in:
parent
1aefb814ef
commit
443df3e6d8
|
@ -2,6 +2,7 @@ local awful = require("awful")
|
||||||
local watch = require("awful.widget.watch")
|
local watch = require("awful.widget.watch")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
|
--- Main ram widget shown on wibar
|
||||||
local ramgraph_widget = wibox.widget {
|
local ramgraph_widget = wibox.widget {
|
||||||
border_width = 0,
|
border_width = 0,
|
||||||
colors = {
|
colors = {
|
||||||
|
@ -12,20 +13,10 @@ local ramgraph_widget = wibox.widget {
|
||||||
widget = wibox.widget.piechart
|
widget = wibox.widget.piechart
|
||||||
}
|
}
|
||||||
|
|
||||||
local total, used, free, shared, buff_cache, available
|
--- Widget which is shown when user clicks on the ram widget
|
||||||
|
|
||||||
watch('bash -c "free | grep Mem"', 1,
|
|
||||||
function(widget, stdout, stderr, exitreason, exitcode)
|
|
||||||
total, used, free, shared, buff_cache, available = stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)')
|
|
||||||
|
|
||||||
widget.data = {used, total-used}
|
|
||||||
end,
|
|
||||||
ramgraph_widget
|
|
||||||
)
|
|
||||||
|
|
||||||
local w = wibox {
|
local w = wibox {
|
||||||
height = 200,
|
height = 200,
|
||||||
width = 350,
|
width = 400,
|
||||||
ontop = true,
|
ontop = true,
|
||||||
screen = mouse.screen,
|
screen = mouse.screen,
|
||||||
expand = true,
|
expand = true,
|
||||||
|
@ -34,50 +25,55 @@ local w = wibox {
|
||||||
}
|
}
|
||||||
|
|
||||||
w:setup {
|
w:setup {
|
||||||
{
|
border_width = 0,
|
||||||
border_width = 0,
|
colors = {
|
||||||
colors = {
|
-- '#74aeab',
|
||||||
'#74aeab',
|
-- '#6eaaa7',
|
||||||
'#6eaaa7',
|
'#5ea19d',
|
||||||
'#5ea19d',
|
'#55918e',
|
||||||
'#55918e',
|
'#4b817e',
|
||||||
'#4b817e',
|
|
||||||
},
|
|
||||||
display_labels = false,
|
|
||||||
forced_width = 25,
|
|
||||||
id = 'pie',
|
|
||||||
widget = wibox.widget.piechart
|
|
||||||
},
|
},
|
||||||
{
|
display_labels = false,
|
||||||
text = 'Hello',
|
forced_width = 25,
|
||||||
widget = wibox.widget.textbox
|
id = 'pie',
|
||||||
},
|
widget = wibox.widget.piechart
|
||||||
id = 'popup',
|
|
||||||
layout = wibox.layout.stack
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local total, used, free, shared, buff_cache, available
|
||||||
|
|
||||||
local function getPercentage(value)
|
local function getPercentage(value)
|
||||||
return math.floor(value / total * 100 + 0.5) .. '%'
|
return math.floor(value / total * 100 + 0.5) .. '%'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
watch('bash -c "free | grep Mem"', 1,
|
||||||
|
function(widget, stdout, stderr, exitreason, exitcode)
|
||||||
|
total, used, free, shared, buff_cache, available = stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)')
|
||||||
|
widget.data = { used, total-used }
|
||||||
|
|
||||||
|
if w.visible then
|
||||||
|
w.pie.data_list = {
|
||||||
|
{'used ' .. getPercentage(used), used},
|
||||||
|
{'free ' .. getPercentage(free), free},
|
||||||
|
{'buff_cache ' .. getPercentage(buff_cache), buff_cache}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
ramgraph_widget
|
||||||
|
)
|
||||||
|
|
||||||
ramgraph_widget:buttons(
|
ramgraph_widget:buttons(
|
||||||
awful.util.table.join(
|
awful.util.table.join(
|
||||||
awful.button({}, 1, function()
|
awful.button({}, 1, function()
|
||||||
awful.placement.top_right(w, { margins = {top = 25, right = 10}})
|
awful.placement.top_right(w, { margins = {top = 25, right = 10}})
|
||||||
w.popup.pie.data_list = {
|
w.pie.data_list = {
|
||||||
{'used ' .. getPercentage(used), used},
|
{'used ' .. getPercentage(used), used},
|
||||||
{'free ' .. getPercentage(free), free},
|
{'free ' .. getPercentage(free), free},
|
||||||
-- {'shared ' .. getPercentage(shared), shared},
|
{'buff_cache ' .. getPercentage(buff_cache), buff_cache}
|
||||||
{'buff_cache ' .. getPercentage(buff_cache), buff_cache},
|
|
||||||
-- {'available ' .. getPercentage(available), available}
|
|
||||||
}
|
}
|
||||||
w.popup.pie.display_labels = true
|
w.pie.display_labels = true
|
||||||
w.visible = true
|
w.visible = not w.visible
|
||||||
end),
|
|
||||||
awful.button({}, 3, function()
|
|
||||||
w.visible = false;
|
|
||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return ramgraph_widget
|
return ramgraph_widget
|
Loading…
Reference in New Issue