Skip to content

Commit

Permalink
use gradient over cpu-widget, from main color to red
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Mar 19, 2019
1 parent f65a120 commit 94252c4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cpu-widget/cpu-widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
-- 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,
background_color = "#00000000",
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
Expand All @@ -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')

Expand All @@ -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
Expand Down

0 comments on commit 94252c4

Please sign in to comment.