diff options
| author | Florian Lindner <florian.lindner@xgm.de> | 2020-11-21 13:53:07 +0100 | 
|---|---|---|
| committer | Florian Lindner <florian.lindner@xgm.de> | 2020-11-21 13:53:07 +0100 | 
| commit | 1c7179431af1e160f6f9fab069074b6847733ec9 (patch) | |
| tree | eca19759fa1745d0c4a917d0ea14c4144e88dac8 /ram-widget | |
| parent | 207ad20d7233992a4ad11cb22f77fb76ba8c02a4 (diff) | |
Use popup widget and theme colors for ram-widget.
ram-widget now uses an awful.popup widget. This gives a more
consistent appearance with the other widget and displays the popup
next to the wibar widget, instead of always top right.
Instead of fixed colors, I selected appropriate symbolic colors from
beautiful themes. Therefore, the widget now reacts to
theming. Naturally, The selection of colors are a matter of taste.
Fixes #201.
Diffstat (limited to 'ram-widget')
| -rw-r--r-- | ram-widget/ram-widget.lua | 71 | 
1 files changed, 37 insertions, 34 deletions
diff --git a/ram-widget/ram-widget.lua b/ram-widget/ram-widget.lua index 55b6fd7..66863f5 100644 --- a/ram-widget/ram-widget.lua +++ b/ram-widget/ram-widget.lua @@ -1,11 +1,14 @@  local awful = require("awful") +local beautiful = require("beautiful") +local gears = require("gears")  local watch = require("awful.widget.watch")  local wibox = require("wibox") +  local ramgraph_widget = {} -local function worker(args) +local function worker(args)      local args = args or {}      local timeout = args.timeout or 1 @@ -13,7 +16,8 @@ local function worker(args)      ramgraph_widget = wibox.widget {          border_width = 0,          colors = { -            '#74aeab', '#26403f' +           beautiful.bg_urgent, -- used +           beautiful.fg_normal  -- free          },          display_labels = false,          forced_width = 25, @@ -21,26 +25,22 @@ local function worker(args)      }      --- 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 popup = awful.popup{ +       visible = false, +       widget = { +          widget = wibox.widget.piechart, +          forced_height = 200, +          forced_width = 400, +          colors = { +             beautiful.bg_urgent,           -- used +             beautiful.fg_normal,           -- free +             beautiful.border_color_active, -- buf_cache +          }, +       }, +       shape = gears.shape.rounded_rect, +       border_color = beautiful.border_color_active, +       border_width = 1, +       offset = { y = 5 },      }      local total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap @@ -54,13 +54,13 @@ local function worker(args)              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 } -            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} +            if popup.visible then +               popup:get_widget().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, @@ -69,23 +69,26 @@ local function worker(args)      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 = { +           awful.button({}, 1, function() +                 popup:get_widget().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 +                 +                if popup.visible then +                   popup.visible = not popup.visible +                else +                   popup:move_next_to(mouse.current_widget_geometry) +                end              end)          )      ) -      return ramgraph_widget  end +  return setmetatable(ramgraph_widget, { __call = function(_, ...)      return worker(...)  end })  | 
