conky-config/main.lua

105 lines
2.9 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;'..
2021-08-08 15:10:09 -04:00
ABS_PATH..'core/?.lua;'..
ABS_PATH..'core/widget/?.lua;'..
ABS_PATH..'core/widget/arc/?.lua;'..
ABS_PATH..'core/widget/text/?.lua;'..
2021-08-08 15:10:09 -04:00
ABS_PATH..'core/widget/timeseries/?.lua;'..
ABS_PATH..'core/widget/rect/?.lua;'..
2021-08-08 18:19:37 -04:00
ABS_PATH..'core/widget/line/?.lua;'
2021-08-08 15:58:53 -04:00
local i_o = require 'i_o'
local geom = require 'geom'
2022-07-16 00:00:06 -04:00
local pure = require 'pure'
2021-08-08 19:12:31 -04:00
local sys = require 'sys'
local system = require 'system'
local network = require 'network'
local processor = require 'processor'
local filesystem = require 'filesystem'
local pacman = require 'pacman'
local power = require 'power'
local readwrite = require 'readwrite'
local graphics = require 'graphics'
local memory = require 'memory'
local static = require 'static'
2021-07-17 21:22:17 -04:00
local draw_dynamic
2022-07-16 00:00:06 -04:00
local main_state = {}
function conky_start(update_interval)
conky_set_update_interval(update_interval)
local update_freq = 1 / update_interval
2021-08-08 19:12:31 -04:00
local devices = {'sda', 'nvme0n1'}
local battery = 'BAT0'
local fs_paths = {
{'/', 'root'},
{'/boot', 'boot'},
{'/home', 'home'},
{'/mnt/data', 'data'},
{'/mnt/dcache', 'dcache'},
{'/tmp', 'tmpfs'}
}
2022-07-16 00:00:06 -04:00
local mem = pure.partial(memory, update_freq)
local rw = pure.partial(readwrite, update_freq, devices)
local net = pure.partial(network, update_freq)
local pwr = pure.partial(power, update_freq, battery)
local fs = pure.partial(filesystem, fs_paths)
local stm = system
local gfx = pure.partial(graphics, update_freq)
local proc = pure.partial(processor, update_freq)
local pcm = pacman
2021-08-08 19:12:31 -04:00
local using_ac = sys.battery_status_reader(battery)
2022-07-16 00:00:06 -04:00
local compiled = static(
geom.make_point(12, 11),
2022-07-10 16:25:12 -04:00
{
2022-07-16 00:00:06 -04:00
{{stm, 19, gfx, 16, proc}},
10,
{{rw}, 20, {net}},
10,
{{pcm, 24, fs, 24, pwr, 19, mem}}
2022-07-10 16:25:12 -04:00
}
)
local STATS_FILE = '/tmp/.conky_pacman'
2021-07-17 21:22:17 -04:00
draw_dynamic = function(cr, _updates)
2022-07-16 00:00:06 -04:00
main_state.trigger10 = _updates % (update_freq * 10)
main_state.pacman_stats = i_o.read_file(STATS_FILE)
main_state.is_using_ac = using_ac()
compiled.static(cr)
compiled.update(main_state)
compiled.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