[awesome] add sensors widget
This commit is contained in:
parent
67868a3e46
commit
e1de422580
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
23
home/.config/awesome/sensors.lua
Normal file
23
home/.config/awesome/sensors.lua
Normal 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)
|
11
home/.config/awesome/utils.lua
Normal file
11
home/.config/awesome/utils.lua
Normal 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
|
Reference in a new issue