2018-11-28 15:31:35 +01:00
|
|
|
local awful = require("awful")
|
|
|
|
local watch = require("awful.widget.watch")
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
|
|
|
--- Main ram widget shown on wibar
|
|
|
|
local ramgraph_widget = wibox.widget {
|
|
|
|
border_width = 0,
|
|
|
|
colors = {
|
|
|
|
'#74aeab', '#26403f'
|
|
|
|
},
|
|
|
|
display_labels = false,
|
|
|
|
forced_width = 25,
|
|
|
|
widget = wibox.widget.piechart
|
|
|
|
}
|
|
|
|
|
|
|
|
--- Widget which is shown when user clicks on the ram widget
|
|
|
|
local w = wibox {
|
|
|
|
height = 200,
|
|
|
|
width = 400,
|
|
|
|
ontop = true,
|
|
|
|
expand = true,
|
|
|
|
bg = '#1e252c',
|
|
|
|
max_widget_size = 500
|
|
|
|
}
|
|
|
|
|
|
|
|
w:setup {
|
|
|
|
border_width = 0,
|
|
|
|
colors = {
|
|
|
|
'#5ea19d',
|
|
|
|
'#55918e',
|
|
|
|
'#4b817e',
|
|
|
|
},
|
|
|
|
display_labels = false,
|
|
|
|
forced_width = 25,
|
|
|
|
id = 'pie',
|
|
|
|
widget = wibox.widget.piechart
|
|
|
|
}
|
|
|
|
|
2018-11-29 10:39:58 +01:00
|
|
|
local total, used, free, shared, buff_cache, available
|
2018-11-28 15:31:35 +01:00
|
|
|
|
|
|
|
local function getPercentage(value)
|
2018-11-29 10:39:58 +01:00
|
|
|
return math.floor(value / (total) * 100 + 0.5) .. '%'
|
2018-11-28 15:31:35 +01:00
|
|
|
end
|
|
|
|
|
2018-11-29 10:39:58 +01:00
|
|
|
watch('bash -c "free | grep -z Mem"', 1,
|
2018-11-28 15:31:35 +01:00
|
|
|
function(widget, stdout, stderr, exitreason, exitcode)
|
2018-11-29 10:39:58 +01:00
|
|
|
total, used, free, shared, buff_cache, available =
|
|
|
|
stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)')
|
2018-11-28 15:31:35 +01:00
|
|
|
|
|
|
|
widget.data = { used, total-used } widget.data = { used, total-used }
|
|
|
|
|
|
|
|
if w.visible then
|
|
|
|
w.pie.data_list = {
|
2018-11-29 10:39:58 +01:00
|
|
|
{'used ' .. getPercentage(used), used},
|
|
|
|
{'free ' .. getPercentage(free), free},
|
2018-11-28 15:31:35 +01:00
|
|
|
{'buff_cache ' .. getPercentage(buff_cache), buff_cache}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
ramgraph_widget
|
|
|
|
)
|
|
|
|
|
|
|
|
ramgraph_widget:buttons(
|
|
|
|
awful.util.table.join(
|
|
|
|
awful.button({}, 1, function()
|
|
|
|
awful.placement.top_right(w, { margins = {top = 25, right = 10}, parent = awful.screen.focused() })
|
|
|
|
w.pie.data_list = {
|
2018-11-29 10:39:58 +01:00
|
|
|
{'used ' .. getPercentage(used), used},
|
|
|
|
{'free ' .. getPercentage(free), free},
|
2018-11-28 15:31:35 +01:00
|
|
|
{'buff_cache ' .. getPercentage(buff_cache), buff_cache}
|
|
|
|
}
|
|
|
|
w.pie.display_labels = true
|
|
|
|
w.visible = not w.visible
|
|
|
|
end)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return ramgraph_widget
|