use gradient over cpu-widget, from main color to red

This commit is contained in:
streetturtle 2019-03-18 20:27:08 -04:00
parent f65a12034b
commit 94252c405a
1 changed files with 4 additions and 7 deletions

View File

@ -5,12 +5,11 @@
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/cpu-widget
-- @author Pavel Makhov
-- @copyright 2017 Pavel Makhov
-- @copyright 2019 Pavel Makhov
-------------------------------------------------
local watch = require("awful.widget.watch")
local wibox = require("wibox")
local beautiful = require("beautiful")
local cpugraph_widget = wibox.widget {
max_value = 100,
@ -18,7 +17,8 @@ local cpugraph_widget = wibox.widget {
forced_width = 50,
step_width = 2,
step_spacing = 1,
widget = wibox.widget.graph
widget = wibox.widget.graph,
color = "linear:0,0:0,22:0,#FF0000:0.3,#FFFF00:0.5,#74aeab"
}
--- By default graph widget goes from left to right, so we mirror it and push up a bit
@ -28,7 +28,7 @@ local total_prev = 0
local idle_prev = 0
watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1,
function(widget, stdout, stderr, exitreason, exitcode)
function(widget, stdout)
local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice =
stdout:match('(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s')
@ -38,9 +38,6 @@ watch([[bash -c "cat /proc/stat | grep '^cpu '"]], 1,
local diff_total = total - total_prev
local diff_usage = (1000 * (diff_total - diff_idle) / diff_total + 5) / 10
widget:set_color(diff_usage > 80 and beautiful.widget_red
or beautiful.widget_main_color)
widget:add_value(diff_usage)
total_prev = total