mirror of
https://github.com/don-philipe/knorke.git
synced 2025-11-08 14:57:02 +01:00
Add CPU widget
This commit is contained in:
63
cpu.lua
Normal file
63
cpu.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
local awful = require("awful")
|
||||
local gears = require("gears")
|
||||
local vicious = require("vicious")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local widget = wibox.widget {
|
||||
{
|
||||
id = "icon",
|
||||
widget = wibox.widget.imagebox,
|
||||
resize = true
|
||||
},
|
||||
{
|
||||
id = "text",
|
||||
widget = wibox.widget.textbox,
|
||||
resize = true,
|
||||
forced_width = 30,
|
||||
align = "right"
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
}
|
||||
local cpus = {}
|
||||
|
||||
vicious.register(widget.text, vicious.widgets.cpu,
|
||||
function (w, args)
|
||||
for i,val in ipairs(args) do
|
||||
cpus[i] = args[i + 1]
|
||||
end
|
||||
return " " .. args[1] .. "%"
|
||||
end, 2)
|
||||
|
||||
-- TODO change cpu govenour
|
||||
widget:buttons(awful.util.table.join(
|
||||
awful.button({}, 1, nil, function()
|
||||
end
|
||||
)
|
||||
))
|
||||
|
||||
-- These icons should come as beautiful.icons
|
||||
function widget.set_icons(cpu)
|
||||
widget.icon:set_image(cpu)
|
||||
end
|
||||
|
||||
-- TODO show cpu bars in tooltip
|
||||
awful.tooltip(
|
||||
{
|
||||
objects = { widget },
|
||||
mode = "outside",
|
||||
align = "right",
|
||||
fg = "white",
|
||||
margin_leftright = 10,
|
||||
margin_topbottom = 10,
|
||||
timer_function = function()
|
||||
local strings = {}
|
||||
for i, val in ipairs(cpus) do
|
||||
strings[i] = "CPU " .. i .. ": " .. val .. "%"
|
||||
end
|
||||
return "CPU count: " .. #(cpus) .. "\n" .. table.concat(strings, "\n")
|
||||
end,
|
||||
preferred_positions = {"right", "left", "top", "bottom"}
|
||||
}
|
||||
)
|
||||
|
||||
return widget
|
||||
Reference in New Issue
Block a user