conky-config/main.lua

111 lines
3.0 KiB
Lua
Raw Normal View History

2018-08-05 16:54:22 -04:00
require 'cairo'
local __cairo_xlib_surface_create = cairo_xlib_surface_create
local __cairo_create = cairo_create
local __cairo_surface_destroy = cairo_surface_destroy
local __cairo_destroy = cairo_destroy
2017-07-16 14:50:33 -04:00
local ABS_PATH = debug.getinfo(1).source:match("@?(.*/)")
package.path = ABS_PATH..'?.lua;'..
ABS_PATH..'drawing/?.lua;'..
ABS_PATH..'schema/?.lua;'..
ABS_PATH..'core/func/?.lua;'..
ABS_PATH..'core/widget/?.lua;'..
ABS_PATH..'core/widget/arc/?.lua;'..
ABS_PATH..'core/widget/text/?.lua;'..
ABS_PATH..'core/widget/plot/?.lua;'..
ABS_PATH..'core/widget/rect/?.lua;'..
2021-07-18 23:54:27 -04:00
ABS_PATH..'core/widget/poly/?.lua;'
local Util = require 'Util'
2016-08-11 23:25:56 -04:00
local System = require 'System'
local Network = require 'Network'
local Processor = require 'Processor'
local FileSystem = require 'FileSystem'
local Pacman = require 'Pacman'
2017-07-15 20:08:39 -04:00
local Power = require 'Power'
2016-08-11 23:25:56 -04:00
local ReadWrite = require 'ReadWrite'
2017-07-15 20:08:39 -04:00
local Graphics = require 'Graphics'
2016-08-11 23:25:56 -04:00
local Memory = require 'Memory'
local Static = require 'Static'
2018-08-05 16:54:22 -04:00
local using_ac = function()
2019-10-12 02:20:45 -04:00
-- for some reason it is much more efficient to test if the battery
-- is off than if the ac is on
return Util.read_file('/sys/class/power_supply/BAT0/status', nil, '*l') ~= 'Discharging'
2018-08-05 16:54:22 -04:00
end
2021-07-17 21:22:17 -04:00
local draw_dynamic
function conky_start(update_interval)
conky_set_update_interval(update_interval)
local update_freq = 1 / update_interval
local mem = Memory(update_freq)
local rw = ReadWrite(update_freq)
local net = Network(update_freq)
local pwr = Power(update_freq)
local fs = FileSystem()
local sys = System()
local gfx = Graphics(update_freq)
local proc = Processor(update_freq)
local pcm = Pacman()
local draw_static = Static(
{sys.static, gfx.static, proc.static},
{rw.static, net.static},
{pcm.static, fs.static, pwr.static, mem.static}
)
local STATS_FILE = '/tmp/.conky_pacman'
2021-07-17 21:22:17 -04:00
draw_dynamic = function(cr, _updates)
2021-07-19 01:23:48 -04:00
-- timings of each line when cpu set to performance
-- 0.7ms
draw_static(cr)
local t1 = _updates % (update_freq * 10)
local pacman_stats = Util.read_file(STATS_FILE)
2021-07-19 01:23:48 -04:00
-- 0.1ms
local is_using_ac = using_ac()
2021-07-19 01:23:48 -04:00
-- <0.1ms
sys.dynamic(cr, pacman_stats)
2021-07-19 01:23:48 -04:00
-- 0.3ms
gfx.dynamic(cr)
2021-07-19 01:23:48 -04:00
-- 0.8-1.1ms
proc.dynamic(cr, t1)
2021-07-19 01:23:48 -04:00
-- 0.1-0.3ms
rw.dynamic(cr)
2021-07-19 01:23:48 -04:00
-- 0.2ms
net.dynamic(cr)
2021-07-19 01:23:48 -04:00
-- <0.1ms
pcm.dynamic(cr, pacman_stats)
2021-07-19 01:23:48 -04:00
-- <0.1ms
fs.dynamic(cr, t1)
2021-07-19 01:23:48 -04:00
-- 0.3ms
pwr.dynamic(cr, is_using_ac)
2021-07-19 01:23:48 -04:00
-- 0.5ms
mem.dynamic(cr)
end
end
2021-07-17 21:22:17 -04:00
local updates = -2 -- this accounts for the first few spazzy iterations
2018-08-05 16:54:22 -04:00
function conky_main()
local _cw = conky_window
if not _cw then return end
2018-08-05 11:08:37 -04:00
2018-08-05 16:54:22 -04:00
local cs = __cairo_xlib_surface_create(_cw.display, _cw.drawable,
_cw.visual, 1920, 1080)
local cr = __cairo_create(cs)
updates = updates + 1
2019-09-01 15:34:10 -04:00
2021-07-17 21:22:17 -04:00
draw_dynamic(cr, updates)
2019-09-01 15:34:10 -04:00
__cairo_surface_destroy(cs)
__cairo_destroy(cr)
2016-08-11 23:25:56 -04:00
end