diff options
| -rw-r--r-- | batteryarc-widget/README.md | 2 | ||||
| -rw-r--r-- | cpu-widget/cpu-png | bin | 0 -> 90688 bytes | |||
| -rw-r--r-- | cpu-widget/cpu-widget.lua | 82 | ||||
| -rw-r--r-- | cpu-widget/cpu.gif | bin | 4913 -> 261200 bytes | |||
| -rw-r--r-- | cpu-widget/out.gif | bin | 3505 -> 0 bytes | |||
| -rw-r--r-- | jira-widget/jira.lua | 4 | ||||
| -rw-r--r-- | storage-widget/README.md | 24 | ||||
| -rw-r--r-- | storage-widget/out.gif | bin | 0 -> 103946 bytes | |||
| -rw-r--r-- | storage-widget/storage-widget.lua | 156 | ||||
| -rw-r--r-- | weather-widget/weather.lua | 4 | 
10 files changed, 231 insertions, 41 deletions
| diff --git a/batteryarc-widget/README.md b/batteryarc-widget/README.md index ba65db7..300842f 100644 --- a/batteryarc-widget/README.md +++ b/batteryarc-widget/README.md @@ -49,7 +49,7 @@ s.mytasklist, -- Middle widget          --[[or customized]]          batteryarc_widget({              show_current_level = true, -            arc_thickness = '1', +            arc_thickness = 1,          }),  	}  	... diff --git a/cpu-widget/cpu-png b/cpu-widget/cpu-pngBinary files differ new file mode 100644 index 0000000..96ba29f --- /dev/null +++ b/cpu-widget/cpu-png diff --git a/cpu-widget/cpu-widget.lua b/cpu-widget/cpu-widget.lua index 5db1778..7dfc5a7 100644 --- a/cpu-widget/cpu-widget.lua +++ b/cpu-widget/cpu-widget.lua @@ -16,6 +16,21 @@ local gears = require("gears")  local widget = {} +local function split(string_to_split, separator) +    if separator == nil then separator = "%s" end +    local t={} + +    for str in string.gmatch(string_to_split, "([^".. separator .."]+)") do +        table.insert(t, str) +    end + +    return t +end + +local function starts_with(str, start) +    return str:sub(1, #start) == start +end +  local function worker(args)      local args = args or {} @@ -36,47 +51,41 @@ local function worker(args)      }      local cpu_rows = { -        { widget = wibox.widget.textbox },          spacing = 4,          layout = wibox.layout.fixed.vertical,      }      local is_update = true      local process_rows = { -        --{ widget = wibox.widget.textbox },          spacing = 8,          layout = wibox.layout.fixed.vertical, -      } -    local process_header =                         { -        --{ +    local process_header = { +        { +            markup = '<b>PID</b>', +            forced_width = 40, +            widget = wibox.widget.textbox +        }, +        { +            markup = '<b>Name</b>', +            forced_width = 40, +            widget = wibox.widget.textbox +        }, +        {              { -                markup = '<b>PID</b>', +                markup = '<b>%CPU</b>',                  forced_width = 40,                  widget = wibox.widget.textbox              },              { -                markup = '<b>Name</b>', +                markup = '<b>%MEM</b>',                  forced_width = 40,                  widget = wibox.widget.textbox              }, -            { -                { -                    markup = '<b>%CPU</b>', -                    forced_width = 40, -                    widget = wibox.widget.textbox -                }, -                { -                    markup = '<b>%MEM</b>', -                    forced_width = 40, -                    widget = wibox.widget.textbox -                }, -                layout = wibox.layout.fixed.horizontal -            }, -                layout = wibox.layout.align.horizontal -        --}, -        --widget = wibox.container.background +            layout = wibox.layout.fixed.horizontal +        }, +        layout = wibox.layout.align.horizontal      }      local popup = awful.popup{ @@ -89,6 +98,7 @@ local function worker(args)          offset = { y = 5 },          widget = {}      } +      popup:connect_signal("mouse::enter", function(c) is_update = false end)      popup:connect_signal("mouse::leave", function(c) is_update = true end) @@ -109,12 +119,8 @@ local function worker(args)      --- By default graph widget goes from left to right, so we mirror it and push up a bit      local cpu_widget = wibox.container.margin(wibox.container.mirror(cpugraph_widget, { horizontal = true }), 0, 0, 0, 2) -    local function starts_with(str, start) -        return str:sub(1, #start) == start -    end -      local cpus = {} -    watch([[bash -c "cat /proc/stat | grep '^cpu.' ; ps -eo pid=,comm=,%cpu=,%mem=,cmd= --sort=-%cpu | head"]], 1, +    watch([[bash -c "cat /proc/stat | grep '^cpu.' ; ps -eo '%p|%c|%C|' -o "%mem" -o '|%a' --sort=-%cpu | head -11 | tail -n +2"]], 1,              function(widget, stdout)                  local i = 1                  local j = 1 @@ -175,16 +181,13 @@ local function worker(args)                      else                          if is_update == true then -                            local pid, comm, cpu, mem, cmd = line:match('(%d+)%s+(%w+)%s+([%d.]+)%s+([%d.]+)%s+(.+)') -                            cmd = string.sub(cmd,0, 300) -                            cmd = cmd .. '...' -                            if pid == nil then -                                pid = 'PID' -                                comm = 'Name' -                                cpu = '%CPU' -                                mem = '%MEM' +                            local columns = split(line, '|') -                            end +                            local pid = columns[1] +                            local comm = columns[2] +                            local cpu = columns[3] +                            local mem = columns[4] +                            local cmd = columns[5]                              local row = wibox.widget {                                  { @@ -216,6 +219,7 @@ local function worker(args)                                  widget = wibox.container.background                              } +                            -- Do not update process rows when mouse cursor is over the widget                              row:connect_signal("mouse::enter", function(c) c:set_bg(beautiful.bg_focus) end)                              row:connect_signal("mouse::leave", function(c) c:set_bg(beautiful.bg_normal) end) @@ -224,7 +228,9 @@ local function worker(args)                                  mode = 'outside',                                  preferred_positions = {'bottom'},                                  timer_function = function() -                                    return cmd:gsub('%s', '\n\t') +                                    return cmd +                                            :gsub('%s%-', '\n\t-') -- put arguments on a new line +                                            :gsub(':/', '\n\t\t:/') -- java classpath uses : to separate jars                                  end,                              } diff --git a/cpu-widget/cpu.gif b/cpu-widget/cpu.gifBinary files differ index 086e618..cb97262 100644 --- a/cpu-widget/cpu.gif +++ b/cpu-widget/cpu.gif diff --git a/cpu-widget/out.gif b/cpu-widget/out.gifBinary files differ deleted file mode 100644 index ac7542d..0000000 --- a/cpu-widget/out.gif +++ /dev/null diff --git a/jira-widget/jira.lua b/jira-widget/jira.lua index 652767a..b876c0b 100644 --- a/jira-widget/jira.lua +++ b/jira-widget/jira.lua @@ -97,13 +97,13 @@ local function worker(args)          for i = 0, #rows do rows[i]=nil end          for _, issue in ipairs(result.issues) do -            local path_to_avatar = os.getenv("HOME") ..'/.cache/awmw/jira-widget/avatars/' .. issue.fields.assignee.key +            local path_to_avatar = os.getenv("HOME") ..'/.cache/awmw/jira-widget/avatars/' .. issue.fields.assignee.accountId              if not gfs.file_readable(path_to_avatar) then                  spawn.easy_async(string.format(                          DOWNLOAD_AVATAR_CMD,                          HOME_DIR, -                        issue.fields.assignee.key, +                        issue.fields.assignee.accountId,                          issue.fields.assignee.avatarUrls['48x48']))              end diff --git a/storage-widget/README.md b/storage-widget/README.md new file mode 100644 index 0000000..48d2ffe --- /dev/null +++ b/storage-widget/README.md @@ -0,0 +1,24 @@ +# Storage Widget + +This widget shows disk usage. When clicked another widget appears with more detailed information. By default it monitors the "/" mount. It can be configured with a +list of mounts to monitor though only the first will show in the wibar. To have +multiple mounts displayed on the wibar simply define multiple `storage_widgets` +with different mounts as arguments. + + +```lua +  local storage_widget = require("awesome-wm-widgets.storage-widget.storage-widget") +  ... +  s.mywibox:setup { +      s.mytasklist, -- Middle widget +      { -- Right widgets +      storage_widget(), --default +      wibox.widget.textbox(':'), +      storage_widget({ mounts = { '/', '/mnt/musicj' } }), -- multiple mounts +  ... + +``` + +## Installation + +Please refer to the [installation](https://github.com/streetturtle/awesome-wm-widgets#installation) section of the repo. diff --git a/storage-widget/out.gif b/storage-widget/out.gifBinary files differ new file mode 100644 index 0000000..736f894 --- /dev/null +++ b/storage-widget/out.gif diff --git a/storage-widget/storage-widget.lua b/storage-widget/storage-widget.lua new file mode 100644 index 0000000..d719f60 --- /dev/null +++ b/storage-widget/storage-widget.lua @@ -0,0 +1,156 @@ +local awful = require("awful") +local watch = require("awful.widget.watch") +local wibox = require("wibox") +local beautiful = require("beautiful") +local gears = require("gears") + +local storage_graph_widget = {} + +local function worker(args) +    local args = args or {} +    local mounts = args.mounts or {'/'} + +    storage_graph_widget = wibox.widget { +        max_value = 100, +        forced_height = 20, +        forced_width = 35, +        paddings = 1, +        margins = 4, +        border_width = 0.5, +        border_color = beautiful.fg_normal, +        background_color = beautiful.bg_normal, +        bar_border_width = 1, +        bar_border_color = beautiful.bg_focus, +        color = "linear:150,0:0,0:0," +          .. beautiful.fg_normal +          .. ":0.3," .. beautiful.bg_urgent .. ":0.6," +          .. beautiful.fg_normal, +        widget = wibox.widget.progressbar, +    } + +    local disk_rows = { +        { widget = wibox.widget.textbox }, +        spacing = 4, +        layout = wibox.layout.fixed.vertical, +    } + +    local disk_header = { +      { +        markup = '<b>Mount</b>', +        forced_width = 150, +        align  = 'left', +        widget = wibox.widget.textbox, +      }, +      { +        markup = '<b>Used</b>', +        align  = 'left', +        widget = wibox.widget.textbox, +      }, +      layout = wibox.layout.align.horizontal +    } + +    local popup = awful.popup{ +        ontop         = true, +        visible       = false, +        shape         = gears.shape.rounded_rect, +        border_width  = 1, +        border_color  = beautiful.bg_normal, +        bg            = beautiful.bg_focus, +        maximum_width = 400, +        offset        = { y = 5 }, +        widget        = {} +    } +    popup:connect_signal("mouse::enter", function(c) is_update = false end) +    popup:connect_signal("mouse::leave", function(c) is_update = true end) + +    storage_graph_widget:buttons( +      awful.util.table.join( +        awful.button({}, 1, function() +          if popup.visible then +            popup.visible = not popup.visible +          else +            popup:move_next_to(mouse.current_widget_geometry) +          end +        end) +        ) +      ) + +    local disk_widget = wibox.container.margin(wibox.container.mirror(storage_graph_widget, { horizontal = true }), 0, 0, 0, 2) + +    local disks = {} +    watch([[bash -c "df | tail -n +2"]], 60, +        function(widget, stdout) +          for line in stdout:gmatch("[^\r\n$]+") do +            local filesystem, size, used, avail, perc, mount = +              line:match('([%p%w]+)%s+([%d%w]+)%s+([%d%w]+)%s+([%d%w]+)%s+([%d]+)%%%s+([%p%w]+)') + +            disks[mount]            = {} +            disks[mount].filesystem = filesystem +            disks[mount].size       = size +            disks[mount].used       = used +            disks[mount].avail      = avail +            disks[mount].perc       = perc +            disks[mount].mount      = mount + +            if disks[mount].mount == mounts[1] then +              widget.value = tonumber(disks[mount].perc) +            end +          end + +          for k,v in ipairs(mounts) do + +            local row = wibox.widget{ +              { +                  text = disks[v].mount, +                  forced_width = 150, +                  widget = wibox.widget.textbox +              }, +              { +                  max_value = 100, +                  value = tonumber(disks[v].perc), +                  forced_height = 20, +                  paddings = 1, +                  margins = 4, +                  border_width = 1, +                  border_color = beautiful.bg_focus, +                  background_color = beautiful.bg_normal, +                  bar_border_width = 1, +                  bar_border_color = beautiful.bg_focus, +                  color = "linear:150,0:0,0:0," +                    .. beautiful.fg_normal +                    .. ":0.3," .. beautiful.bg_urgent .. ":0.6," +                    .. beautiful.fg_normal, +                  widget = wibox.widget.progressbar, + +              }, +              { +                  text = math.floor(disks[v].used/1024/1024) +                    .. '/' +                    .. math.floor(disks[v].size/1024/1024) .. 'GB(' +                    .. math.floor(disks[v].perc) .. '%)', +                  widget = wibox.widget.textbox +              }, +              layout = wibox.layout.align.horizontal +            } + +            disk_rows[k] = row +          end +          popup:setup { +              { +                  disk_header, +                  disk_rows, +                  layout = wibox.layout.fixed.vertical, +              }, +              margins = 8, +              widget = wibox.container.margin +          } +        end, +        storage_graph_widget +    ) + +    return disk_widget +end + +return setmetatable(storage_graph_widget, { __call = function(_, ...) +    return worker(...) +end }) diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index a1075f6..6fafa97 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -144,6 +144,8 @@ local function worker(args)      end      local function error_display(resp_json) +        weather_timer.timeout = math.min(15 * 60, weather_timer.timeout * 2) +        weather_timer:again()          local err_resp = json.decode(resp_json)          naughty.notify{              title = 'Weather Widget Error', @@ -185,6 +187,8 @@ local function worker(args)              resp = json.decode(resp_json)              icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]              temp_widget:set_text(gen_temperature_str(resp.main.temp, '%.0f', both_units_widget)) +            weather_timer.timeout = 60 +            weather_timer:again()          end      end)      weather_timer:start() | 
