externalize config for ram-widget
This commit is contained in:
parent
434cdae5e2
commit
54500cf15d
|
@ -2,8 +2,14 @@ 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 {
|
||||
local ramgraph_widget = {}
|
||||
|
||||
local function worker(args)
|
||||
|
||||
local args = args or {}
|
||||
|
||||
--- Main ram widget shown on wibar
|
||||
ramgraph_widget = wibox.widget {
|
||||
border_width = 0,
|
||||
colors = {
|
||||
'#74aeab', '#26403f'
|
||||
|
@ -11,19 +17,19 @@ local ramgraph_widget = wibox.widget {
|
|||
display_labels = false,
|
||||
forced_width = 25,
|
||||
widget = wibox.widget.piechart
|
||||
}
|
||||
}
|
||||
|
||||
--- Widget which is shown when user clicks on the ram widget
|
||||
local w = wibox {
|
||||
--- 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 {
|
||||
w:setup {
|
||||
border_width = 0,
|
||||
colors = {
|
||||
'#5ea19d',
|
||||
|
@ -34,15 +40,15 @@ w:setup {
|
|||
forced_width = 25,
|
||||
id = 'pie',
|
||||
widget = wibox.widget.piechart
|
||||
}
|
||||
}
|
||||
|
||||
local total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap
|
||||
local total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap
|
||||
|
||||
local function getPercentage(value)
|
||||
local function getPercentage(value)
|
||||
return math.floor(value / (total+total_swap) * 100 + 0.5) .. '%'
|
||||
end
|
||||
end
|
||||
|
||||
watch('bash -c "free | grep -z Mem.*Swap.*"', 1,
|
||||
watch('bash -c "free | grep -z Mem.*Swap.*"', 1,
|
||||
function(widget, stdout, stderr, exitreason, exitcode)
|
||||
total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap =
|
||||
stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*Swap:%s*(%d+)%s*(%d+)%s*(%d+)')
|
||||
|
@ -58,9 +64,9 @@ watch('bash -c "free | grep -z Mem.*Swap.*"', 1,
|
|||
end
|
||||
end,
|
||||
ramgraph_widget
|
||||
)
|
||||
)
|
||||
|
||||
ramgraph_widget:buttons(
|
||||
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() })
|
||||
|
@ -73,6 +79,12 @@ ramgraph_widget:buttons(
|
|||
w.visible = not w.visible
|
||||
end)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return ramgraph_widget
|
||||
|
||||
return ramgraph_widget
|
||||
end
|
||||
|
||||
return setmetatable(ramgraph_widget, { __call = function(_, ...)
|
||||
return worker(...)
|
||||
end })
|
||||
|
|
Loading…
Reference in New Issue