summaryrefslogtreecommitdiff
path: root/cpu-widget/cpu-widget.lua
diff options
context:
space:
mode:
Diffstat (limited to 'cpu-widget/cpu-widget.lua')
-rw-r--r--cpu-widget/cpu-widget.lua136
1 files changed, 93 insertions, 43 deletions
diff --git a/cpu-widget/cpu-widget.lua b/cpu-widget/cpu-widget.lua
index d256147..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,17 +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 = 4,
+ spacing = 8,
layout = wibox.layout.fixed.vertical,
+ }
+ 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>%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
}
local popup = awful.popup{
@@ -60,6 +99,9 @@ local function worker(args)
widget = {}
}
+ popup:connect_signal("mouse::enter", function(c) is_update = false end)
+ popup:connect_signal("mouse::leave", function(c) is_update = true end)
+
cpugraph_widget:buttons(
awful.util.table.join(
awful.button({}, 1, function()
@@ -77,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 --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
@@ -141,56 +179,67 @@ local function worker(args)
cpu_rows[i] = row
i = i + 1
else
- local pid, cmd, cpu, mem = line:match('(%d+)%s+(%w+)%s+([%d.]+)%s+([%d.]+)')
-
- if pid == nil then
- pid = 'PID'
- cmd = 'Name'
- cpu = '%CPU'
- mem = '%MEM'
+ if is_update == true then
- end
+ local columns = split(line, '|')
+ local pid = columns[1]
+ local comm = columns[2]
+ local cpu = columns[3]
+ local mem = columns[4]
+ local cmd = columns[5]
- local row = wibox.widget {
- {
- {
- text = pid,
- forced_width = 40,
- widget = wibox.widget.textbox
- },
- {
- text = cmd,
- forced_width = 40,
- widget = wibox.widget.textbox
- },
+ local row = wibox.widget {
{
{
- text = cpu,
+ text = pid,
forced_width = 40,
widget = wibox.widget.textbox
},
{
- text = mem,
+ text = comm,
forced_width = 40,
widget = wibox.widget.textbox
},
+ {
+ {
+ text = cpu,
+ forced_width = 40,
+ widget = wibox.widget.textbox
+ },
+ {
+ text = mem,
+ forced_width = 40,
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.align.horizontal
+ },
layout = wibox.layout.align.horizontal
},
- layout = wibox.layout.align.horizontal
- },
- widget = wibox.container.background
- }
-
- 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)
-
-
- process_rows[j] = row
+ 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)
+
+ awful.tooltip {
+ objects = { row },
+ mode = 'outside',
+ preferred_positions = {'bottom'},
+ timer_function = function()
+ return cmd
+ :gsub('%s%-', '\n\t-') -- put arguments on a new line
+ :gsub(':/', '\n\t\t:/') -- java classpath uses : to separate jars
+ end,
+ }
+
+ process_rows[j] = row
+
+ j = j + 1
+ end
- j = j + 1
end
-
end
popup:setup {
{
@@ -201,6 +250,7 @@ local function worker(args)
color = beautiful.bg_focus,
widget = wibox.widget.separator
},
+ process_header,
process_rows,
layout = wibox.layout.fixed.vertical,
},