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
|
|
|
|
2021-07-16 23:25:44 -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;'
|
2017-07-20 00:49:24 -04:00
|
|
|
|
2021-07-29 22:39:38 -04:00
|
|
|
local util = require 'util'
|
2021-07-29 22:18:29 -04:00
|
|
|
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'
|
2019-10-13 21:05:38 -04:00
|
|
|
|
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
|
2021-07-29 22:39:38 -04:00
|
|
|
return util.read_file('/sys/class/power_supply/BAT0/status', nil, '*l') ~= 'Discharging'
|
2018-08-05 16:54:22 -04:00
|
|
|
end
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
local draw_dynamic
|
2019-10-11 21:52:10 -04:00
|
|
|
|
2021-07-16 23:25:44 -04:00
|
|
|
function conky_start(update_interval)
|
|
|
|
conky_set_update_interval(update_interval)
|
2021-07-17 00:17:22 -04:00
|
|
|
|
|
|
|
local update_freq = 1 / update_interval
|
|
|
|
|
2021-07-29 22:18:29 -04:00
|
|
|
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()
|
2021-07-17 00:17:22 -04:00
|
|
|
|
2021-07-29 22:18:29 -04:00
|
|
|
local draw_static = static(
|
2021-07-17 16:59:06 -04:00
|
|
|
{sys.static, gfx.static, proc.static},
|
|
|
|
{rw.static, net.static},
|
2021-07-17 00:17:22 -04:00
|
|
|
{pcm.static, fs.static, pwr.static, mem.static}
|
|
|
|
)
|
|
|
|
|
2021-07-17 16:59:06 -04:00
|
|
|
local STATS_FILE = '/tmp/.conky_pacman'
|
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
draw_dynamic = function(cr, _updates)
|
2021-07-27 23:47:26 -04:00
|
|
|
-- draw static components
|
2021-07-17 16:59:06 -04:00
|
|
|
draw_static(cr)
|
2021-07-17 00:17:22 -04:00
|
|
|
|
2021-07-27 23:47:26 -04:00
|
|
|
-- update dynamic components
|
2021-07-17 00:17:22 -04:00
|
|
|
local t1 = _updates % (update_freq * 10)
|
2021-07-29 22:39:38 -04:00
|
|
|
local pacman_stats = util.read_file(STATS_FILE)
|
2021-07-19 01:23:48 -04:00
|
|
|
local is_using_ac = using_ac()
|
2021-07-17 00:17:22 -04:00
|
|
|
|
2021-07-27 23:47:26 -04:00
|
|
|
sys.update(pacman_stats)
|
|
|
|
gfx.update()
|
|
|
|
proc.update(t1)
|
|
|
|
rw.update()
|
|
|
|
net.update()
|
|
|
|
pcm.update(pacman_stats)
|
|
|
|
fs.update(t1)
|
|
|
|
pwr.update(is_using_ac)
|
|
|
|
mem.update()
|
|
|
|
|
|
|
|
-- draw dynamic components
|
|
|
|
sys.dynamic(cr)
|
2021-07-17 00:17:22 -04:00
|
|
|
gfx.dynamic(cr)
|
2021-07-27 23:47:26 -04:00
|
|
|
proc.dynamic(cr)
|
2021-07-17 00:17:22 -04:00
|
|
|
rw.dynamic(cr)
|
|
|
|
net.dynamic(cr)
|
2021-07-27 23:47:26 -04:00
|
|
|
pcm.dynamic(cr)
|
|
|
|
fs.dynamic(cr)
|
|
|
|
pwr.dynamic(cr)
|
2021-07-17 00:17:22 -04:00
|
|
|
mem.dynamic(cr)
|
|
|
|
end
|
2021-07-16 23:25:44 -04:00
|
|
|
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()
|
2018-08-05 04:05:38 -04:00
|
|
|
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,
|
2019-10-12 18:14:38 -04:00
|
|
|
_cw.visual, 1920, 1080)
|
2018-08-05 04:05:38 -04:00
|
|
|
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
|
|
|
|
2018-08-05 04:05:38 -04:00
|
|
|
__cairo_surface_destroy(cs)
|
|
|
|
__cairo_destroy(cr)
|
2016-08-11 23:25:56 -04:00
|
|
|
end
|