diff options
author | Pavel Makhov <pmakhov@theoctavegroup.com> | 2019-09-17 15:29:36 -0400 |
---|---|---|
committer | Pavel Makhov <pmakhov@theoctavegroup.com> | 2019-09-17 15:29:36 -0400 |
commit | 6fd76c254b296da86619b43db619ccebcd521853 (patch) | |
tree | a005c8045bbee2998642c55fd5edadb258ea87de /ram-widget | |
parent | 372ae3c9e7cab4b64b8dcaf31d9d2d921a723585 (diff) | |
parent | 2e211937a116102c3647b85070718102192ddc54 (diff) |
Merge branch '74-externalize-config'
Note: breaking change, now widgets should be created with parentheses, i.e. battery(), instead of battery. Read more in README of the widget.
Diffstat (limited to 'ram-widget')
-rw-r--r-- | ram-widget/ram-widget.lua | 140 |
1 files changed, 76 insertions, 64 deletions
diff --git a/ram-widget/ram-widget.lua b/ram-widget/ram-widget.lua index 3072068..d8cb11f 100644 --- a/ram-widget/ram-widget.lua +++ b/ram-widget/ram-widget.lua @@ -2,77 +2,89 @@ 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 -} +local ramgraph_widget = {} ---- 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 -} +local function worker(args) -w:setup { - border_width = 0, - colors = { - '#5ea19d', - '#55918e', - '#4b817e', - }, - display_labels = false, - forced_width = 25, - id = 'pie', - widget = wibox.widget.piechart -} + local args = args or {} -local total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap + --- Main ram widget shown on wibar + ramgraph_widget = wibox.widget { + border_width = 0, + colors = { + '#74aeab', '#26403f' + }, + display_labels = false, + forced_width = 25, + widget = wibox.widget.piechart + } -local function getPercentage(value) - return math.floor(value / (total+total_swap) * 100 + 0.5) .. '%' -end + --- 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 + } + + local total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap + + local function getPercentage(value) + return math.floor(value / (total+total_swap) * 100 + 0.5) .. '%' + end -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+)') + watch('bash -c "LANGUAGE=en_US.UTF-8 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+)') - widget.data = { used, total-used } widget.data = { used, total-used } + widget.data = { used, total-used } widget.data = { used, total-used } - if w.visible then - w.pie.data_list = { - {'used ' .. getPercentage(used + used_swap), used + used_swap}, - {'free ' .. getPercentage(free + free_swap), free + free_swap}, - {'buff_cache ' .. getPercentage(buff_cache), buff_cache} - } - end - end, - ramgraph_widget -) + if w.visible then + w.pie.data_list = { + {'used ' .. getPercentage(used + used_swap), used + used_swap}, + {'free ' .. getPercentage(free + free_swap), free + free_swap}, + {'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 = { - {'used ' .. getPercentage(used + used_swap), used + used_swap}, - {'free ' .. getPercentage(free + free_swap), free + free_swap}, - {'buff_cache ' .. getPercentage(buff_cache), buff_cache} - } - w.pie.display_labels = true - w.visible = not w.visible - end) + 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 = { + {'used ' .. getPercentage(used + used_swap), used + used_swap}, + {'free ' .. getPercentage(free + free_swap), free + free_swap}, + {'buff_cache ' .. getPercentage(buff_cache), buff_cache} + } + w.pie.display_labels = true + w.visible = not w.visible + end) + ) ) -) -return ramgraph_widget + + return ramgraph_widget +end + +return setmetatable(ramgraph_widget, { __call = function(_, ...) + return worker(...) +end }) |