[awesome] add sensors widget

This commit is contained in:
Simon Bruder 2018-10-28 13:14:27 +00:00
parent 67868a3e46
commit e1de422580
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
4 changed files with 38 additions and 10 deletions

View file

@ -1,13 +1,6 @@
local timer = require("gears.timer")
local wibox = require("wibox")
local function readfile(command)
local file = io.open(command)
if not file then return nil end
local text = file:read('*all')
file:close()
return text:gsub("^%s*(.-)%s*$", "%1")
end
local utils = require("utils")
local battery_widget = wibox.widget{
markup = 'U00',
@ -20,8 +13,8 @@ timer:connect_signal("timeout", function() update() end)
timer:start()
function update()
local percent = readfile("/sys/class/power_supply/BAT1/capacity")
local status = readfile("/sys/class/power_supply/BAT1/status")
local percent = utils.readfile("/sys/class/power_supply/BAT1/capacity")
local status = utils.readfile("/sys/class/power_supply/BAT1/status")
if status == "Charging" then
prefix = "C"

View file

@ -241,6 +241,7 @@ awful.screen.connect_for_each_screen(function(s)
layout = wibox.layout.fixed.horizontal,
wibox.widget.systray(),
require("battery"),
require("sensors"),
mytextclock,
s.mylayoutbox,
},

View file

@ -0,0 +1,23 @@
local timer = require("gears.timer")
local wibox = require("wibox")
local utils = require("utils")
local sensors_widget = wibox.widget{
markup = '00°C',
align = 'center',
widget = wibox.widget.textbox
}
timer = timer({ timeout = 10 })
timer:connect_signal("timeout", function() update() end)
timer:start()
function update()
local temp = utils.readfile("/sys/class/thermal/thermal_zone1/temp") / 1000
sensors_widget:set_markup(string.format("%02d", temp) .. "°C")
end
update()
return wibox.container.margin(sensors_widget, 4)

View file

@ -0,0 +1,11 @@
local utils = {}
function utils.readfile(command)
local file = io.open(command)
if not file then return nil end
local text = file:read('*all')
file:close()
return text:gsub("^%s*(.-)%s*$", "%1")
end
return utils