From 19e1bebdb92e3378b68be22cea173b02f6c65093 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 29 Oct 2009 22:24:24 +0100 Subject: [PATCH] have one cpu "icon" per CPU + one global. Signed-off-by: Pierre Habouzit --- config/awesome/icons/cpu.png | Bin 282 -> 0 bytes config/awesome/rc.lua | 62 +++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 7 deletions(-) delete mode 100644 config/awesome/icons/cpu.png diff --git a/config/awesome/icons/cpu.png b/config/awesome/icons/cpu.png deleted file mode 100644 index 976b867a1b3338c0770b6f47031f5da591df9c6b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqY)RhkE)4%caKYZ?lYt_f1s;*b zK-vS0-A-oPfdtD69Mgd`SU-bd#MT@j$Jx`xF+}2W@}Gk8gY|422`LE)2NH}GIS*u{ zm@#utV(>9%-jt-KBXr_{y)ZN5ftD0jvjZoXwl)d2JM9qtKM|yg;oW?`CJ*)YJwW4B zOI#yLQW8s2t&)pUffR$0fq|v2p@FWEd5Dpbm655Hv4ysQp%qXxqjN2ahTQy=%(P07 m1`AySBV7Z-5F-OCLsKh5V~B==|AHMr4Gf;HelF{r5}E+Sf=lNB diff --git a/config/awesome/rc.lua b/config/awesome/rc.lua index 8df6ac9..2f0f578 100644 --- a/config/awesome/rc.lua +++ b/config/awesome/rc.lua @@ -196,6 +196,19 @@ function make_icon(fname, left, right, h, bg) return ib end +function draw_dashes_h(img, x, y, on, off, len, color) + for i = 0, len, on + off do + img:draw_line(x + i, y, x + i + on - 1, y, color) + end +end + +function draw_dashes_v(img, x, y, on, off, len, color) + for i = 0, len, on + off do + img:draw_line(x, y + i, x, y + i + on - 1, color) + end +end + + local mywidgets = {} -- {{{ Taglist @@ -217,25 +230,60 @@ mypromptbox = awful.widget.prompt{ -- }}} -- {{{ CPU Widgets -table.insert(mywidgets, make_icon('cpu.png', 16, 4, 16)) +local cpuwidgets = {} +for i = 1, io.popen("grep -c ^cpu /proc/stat"):read("*n") do + local cpu = {} + + cpu.widget = widget{ type = 'imagebox' } + cpu.update = function(cpu, value) + local color + + if value < 25 then + color = beautiful.fg_focus + elseif value < 50 then + color = 'yellow' + elseif value < 75 then + color = 'orange' + else + color = 'red' + end + + if cpu.color == color then return end + local img = image.argb32(11, 16, nil) + draw_dashes_h(img, 0, 4, 2, 1, 7, color) + draw_dashes_h(img, 0, 11, 2, 1, 7, color) + draw_dashes_v(img, 0, 4, 2, 1, 7, color) + draw_dashes_v(img, 7, 4, 2, 1, 7, color) + img:draw_rectangle(2, 6, 4, 4, true, color) + cpu.widget.image = img + cpu.percent = value + end + table.insert(mywidgets, cpu.widget) + cpuwidgets[i] = cpu +end -cputextwidget = widget({ type = 'textbox' }) +cputextwidget = widget{ type = 'textbox' } vicious.register(cputextwidget, vicious.widgets.cpu, function (widget, args) local r = tonumber(args[1]) local percent = args[1]..'%' + + for i = 1, #args do + cpuwidgets[i]:update(args[i]) + end + if r < 10 then percent = '0'..percent end if r < 25 then - percent = fg(theme.fg_focus, percent) + percent = fg(beautiful.fg_focus, percent) elseif r < 50 then percent = fg('yellow', percent) elseif r < 75 then percent = fg('orange', percent) else - percent = fg('#ff4040', percent) + percent = fg('red', percent) end return percent..' ' end, 2) @@ -247,7 +295,7 @@ table.insert(mywidgets, cputextwidget) table.insert(mywidgets, make_icon('mem.png', 16, 4, 16)) -memtextwidget = widget({ type = 'textbox' }) +memtextwidget = widget{ type = 'textbox' } vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args) -- Add extra preceding zeroes when needed @@ -257,7 +305,7 @@ vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args) percent = '0'..percent end if r < 50 then - percent = fg(theme.fg_focus, percent) + percent = fg(beautiful.fg_focus, percent) elseif r < 80 then percent = fg('orange', percent) else @@ -273,7 +321,7 @@ table.insert(mywidgets, memtextwidget) table.insert(mywidgets, make_icon('clock.png', 16, 4, 16)) -clockwidget = widget({ type = "textbox" }) +clockwidget = widget{ type = "textbox" } vicious.register(clockwidget, vicious.widgets.date, fg(theme.fg_focus, "%H:%M") .. " %a %d %b ", 10) -- 2.20.1