REF move config/compile code completely to new module
This commit is contained in:
parent
7ade617e80
commit
d20a9637d1
|
@ -3,7 +3,7 @@ local update_interval = 1 -- in seconds
|
||||||
conky.config = {
|
conky.config = {
|
||||||
background = false,
|
background = false,
|
||||||
|
|
||||||
--adjust cpu dial sensitivity (1-14)
|
-- adjust cpu dial sensitivity (1-14)
|
||||||
cpu_avg_samples = 4,
|
cpu_avg_samples = 4,
|
||||||
net_avg_samples = 1,
|
net_avg_samples = 1,
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ conky.config = {
|
||||||
xinerama_head = 0,
|
xinerama_head = 0,
|
||||||
|
|
||||||
double_buffer = true,
|
double_buffer = true,
|
||||||
|
-- TODO don't hardcode screen size here
|
||||||
minimum_width = 1920,
|
minimum_width = 1920,
|
||||||
minimum_height = 1080,
|
minimum_height = 1080,
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ conky.config = {
|
||||||
|
|
||||||
no_buffers = true,
|
no_buffers = true,
|
||||||
|
|
||||||
--Lua Load
|
-- Lua Load
|
||||||
lua_load = '~/.config/conky/main.lua',
|
lua_load = '~/.config/conky/main.lua',
|
||||||
lua_draw_hook_post = 'main',
|
lua_draw_hook_post = 'main',
|
||||||
lua_startup_hook = string.format('start %f', update_interval)
|
lua_startup_hook = string.format('start %f', update_interval)
|
||||||
|
|
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit ed4fc4ec0304caff96163017ee9a2ae419358a50
|
Subproject commit 87f03c704fe2899d5e780255ac1634d8c260c8fe
|
|
@ -1,18 +1,25 @@
|
||||||
local M = {}
|
|
||||||
|
|
||||||
local pure = require 'pure'
|
local pure = require 'pure'
|
||||||
local geom = require 'geom'
|
local geom = require 'geom'
|
||||||
local fill_rect = require 'fill_rect'
|
local fill_rect = require 'fill_rect'
|
||||||
|
local i_o = require 'i_o'
|
||||||
|
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 yaml = require 'lyaml'
|
||||||
|
local common = require 'common'
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
local reduce_modules_y = function(common_, modlist, init_x, width, acc, new)
|
||||||
-- compile entire layout
|
|
||||||
|
|
||||||
local reduce_modules_y = function(common, modlist, init_x, width, acc, new)
|
|
||||||
if type(new) == "number" then
|
if type(new) == "number" then
|
||||||
acc.next_y = acc.next_y + new
|
acc.next_y = acc.next_y + new
|
||||||
else
|
else
|
||||||
local m = modlist[new](common, width, geom.make_point(init_x, acc.next_y))
|
local m = modlist[new](common_, width, geom.make_point(init_x, acc.next_y))
|
||||||
local r = common.compile_module(
|
local r = common_.compile_module(
|
||||||
m.header,
|
m.header,
|
||||||
m.point,
|
m.point,
|
||||||
m.width,
|
m.width,
|
||||||
|
@ -31,12 +38,12 @@ local reduce_modules_y = function(common, modlist, init_x, width, acc, new)
|
||||||
return acc
|
return acc
|
||||||
end
|
end
|
||||||
|
|
||||||
local reduce_modules_x = function(common, modlist, init_y, acc, x_mods)
|
local reduce_modules_x = function(common_, modlist, init_y, acc, x_mods)
|
||||||
if type(x_mods) == "number" then
|
if type(x_mods) == "number" then
|
||||||
acc.next_x = acc.next_x + x_mods
|
acc.next_x = acc.next_x + x_mods
|
||||||
else
|
else
|
||||||
local r = pure.reduce(
|
local r = pure.reduce(
|
||||||
pure.partial(reduce_modules_y, common, modlist, acc.next_x, x_mods.width),
|
pure.partial(reduce_modules_y, common_, modlist, acc.next_x, x_mods.width),
|
||||||
{next_x = acc.next_x, next_y = init_y, fgroups = acc.fgroups},
|
{next_x = acc.next_x, next_y = init_y, fgroups = acc.fgroups},
|
||||||
x_mods.blocks
|
x_mods.blocks
|
||||||
)
|
)
|
||||||
|
@ -47,9 +54,9 @@ local reduce_modules_x = function(common, modlist, init_y, acc, x_mods)
|
||||||
return acc
|
return acc
|
||||||
end
|
end
|
||||||
|
|
||||||
local arrange_panel_modules = function(common, modlist, point, mods)
|
local arrange_panel_modules = function(common_, modlist, point, mods)
|
||||||
local r = pure.reduce(
|
local r = pure.reduce(
|
||||||
pure.partial(reduce_modules_x, common, modlist, point.y),
|
pure.partial(reduce_modules_x, common_, modlist, point.y),
|
||||||
{next_x = point.x, next_y = point.y, fgroups = {}},
|
{next_x = point.x, next_y = point.y, fgroups = {}},
|
||||||
mods
|
mods
|
||||||
)
|
)
|
||||||
|
@ -63,12 +70,12 @@ local arrange_panel_modules = function(common, modlist, point, mods)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local build_surface = function(common, box, fs)
|
local build_surface = function(common_, box, fs)
|
||||||
local panel_line_thickness = 1
|
local panel_line_thickness = 1
|
||||||
-- move over by half a pixel so the lines don't need to be antialiased
|
-- move over by half a pixel so the lines don't need to be antialiased
|
||||||
local _x = box.corner.x + 0.5
|
local _x = box.corner.x + 0.5
|
||||||
local _y = box.corner.y + 0.5
|
local _y = box.corner.y + 0.5
|
||||||
local panel = common.make_panel(_x, _y, box.width, box.height, panel_line_thickness)
|
local panel = common_.make_panel(_x, _y, box.width, box.height, panel_line_thickness)
|
||||||
local cs_x = _x - panel_line_thickness * 0.5
|
local cs_x = _x - panel_line_thickness * 0.5
|
||||||
local cs_y = _y - panel_line_thickness * 0.5
|
local cs_y = _y - panel_line_thickness * 0.5
|
||||||
local cs_w = box.width + panel_line_thickness
|
local cs_w = box.width + panel_line_thickness
|
||||||
|
@ -87,7 +94,7 @@ local build_surface = function(common, box, fs)
|
||||||
return {x = cs_x, y = cs_y, s = cs}
|
return {x = cs_x, y = cs_y, s = cs}
|
||||||
end
|
end
|
||||||
|
|
||||||
local reduce_static = function(common, mods, y, acc, panel_mods)
|
local reduce_static = function(common_, mods, y, acc, panel_mods)
|
||||||
if type(panel_mods) == "number" then
|
if type(panel_mods) == "number" then
|
||||||
acc.next_x = acc.next_x + panel_mods
|
acc.next_x = acc.next_x + panel_mods
|
||||||
else
|
else
|
||||||
|
@ -95,26 +102,26 @@ local reduce_static = function(common, mods, y, acc, panel_mods)
|
||||||
local margin_x = margins[1]
|
local margin_x = margins[1]
|
||||||
local margin_y = margins[2]
|
local margin_y = margins[2]
|
||||||
local mpoint = geom.make_point(acc.next_x + margin_x, y + margin_y)
|
local mpoint = geom.make_point(acc.next_x + margin_x, y + margin_y)
|
||||||
local r = arrange_panel_modules(common, mods, mpoint, panel_mods.columns)
|
local r = arrange_panel_modules(common_, mods, mpoint, panel_mods.columns)
|
||||||
local w = r.width + margin_x * 2
|
local w = r.width + margin_x * 2
|
||||||
local h = r.height + margin_y * 2
|
local h = r.height + margin_y * 2
|
||||||
local pbox = geom.make_box(acc.next_x, y, w, h)
|
local pbox = geom.make_box(acc.next_x, y, w, h)
|
||||||
acc.next_x = acc.next_x + w
|
acc.next_x = acc.next_x + w
|
||||||
acc.static = pure.flatten({acc.static, {build_surface(common, pbox, r.static)}})
|
acc.static = pure.flatten({acc.static, {build_surface(common_, pbox, r.static)}})
|
||||||
acc.update = pure.flatten({acc.update, r.update})
|
acc.update = pure.flatten({acc.update, r.update})
|
||||||
acc.dynamic = pure.flatten({acc.dynamic, r.dynamic})
|
acc.dynamic = pure.flatten({acc.dynamic, r.dynamic})
|
||||||
end
|
end
|
||||||
return acc
|
return acc
|
||||||
end
|
end
|
||||||
|
|
||||||
M.compile_layout = function(common, point, mods, module_sets)
|
local compile_layout = function(common_, point, mods, module_sets)
|
||||||
local __cairo_set_source_surface = cairo_set_source_surface
|
local __cairo_set_source_surface = cairo_set_source_surface
|
||||||
local __cairo_paint = cairo_paint
|
local __cairo_paint = cairo_paint
|
||||||
|
|
||||||
local r = pure.reduce(
|
local r = pure.reduce(
|
||||||
pure.partial(
|
pure.partial(
|
||||||
reduce_static,
|
reduce_static,
|
||||||
common,
|
common_,
|
||||||
mods,
|
mods,
|
||||||
point.y
|
point.y
|
||||||
),
|
),
|
||||||
|
@ -137,4 +144,40 @@ M.compile_layout = function(common, point, mods, module_sets)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return function(update_interval, config_path)
|
||||||
|
local update_freq = 1 / update_interval
|
||||||
|
local config = yaml.load(i_o.read_file(config_path))
|
||||||
|
local cmods = config.modules
|
||||||
|
|
||||||
|
local main_state = {}
|
||||||
|
|
||||||
|
local mods = {
|
||||||
|
memory = pure.partial(memory, update_freq, cmods.memory),
|
||||||
|
readwrite = pure.partial(readwrite, update_freq, cmods.readwrite),
|
||||||
|
network = pure.partial(network, update_freq),
|
||||||
|
power = pure.partial(power, update_freq, cmods.power),
|
||||||
|
filesystem = pure.partial(filesystem, cmods.filesystem, main_state),
|
||||||
|
system = pure.partial(system, main_state),
|
||||||
|
graphics = pure.partial(graphics, update_freq, cmods.graphics),
|
||||||
|
processor = pure.partial(processor, update_freq, cmods.processor, main_state),
|
||||||
|
pacman = pure.partial(pacman, main_state)
|
||||||
|
}
|
||||||
|
|
||||||
|
local compiled = compile_layout(
|
||||||
|
common(config),
|
||||||
|
geom.make_point(table.unpack(config.layout.anchor)),
|
||||||
|
mods,
|
||||||
|
config.layout.panels
|
||||||
|
)
|
||||||
|
|
||||||
|
local STATS_FILE = '/tmp/.conky_pacman'
|
||||||
|
|
||||||
|
return function(cr, _updates)
|
||||||
|
main_state.trigger10 = _updates % (update_freq * 10)
|
||||||
|
main_state.pacman_stats = i_o.read_file(STATS_FILE)
|
||||||
|
|
||||||
|
compiled.static(cr)
|
||||||
|
compiled.update()
|
||||||
|
compiled.dynamic(cr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
110
main.lua
110
main.lua
|
@ -1,87 +1,49 @@
|
||||||
|
local conky_dir = debug.getinfo(1).source:match("@?(.*/)")
|
||||||
|
local subdirs = {
|
||||||
|
'?.lua',
|
||||||
|
'drawing/?.lua',
|
||||||
|
'schema/?.lua',
|
||||||
|
'core/?.lua',
|
||||||
|
'core/widget/?.lua',
|
||||||
|
'core/widget/arc/?.lua',
|
||||||
|
'core/widget/text/?.lua',
|
||||||
|
'core/widget/timeseries/?.lua',
|
||||||
|
'core/widget/rect/?.lua',
|
||||||
|
'core/widget/line/?.lua',
|
||||||
|
'lib/share/lua/5.4/?.lua',
|
||||||
|
'lib/share/lua/5.4/?/init.lua',
|
||||||
|
}
|
||||||
|
|
||||||
|
for i = 1, #subdirs do
|
||||||
|
package.path = package.path..';'..conky_dir..subdirs[i]
|
||||||
|
end
|
||||||
|
|
||||||
|
package.cpath = package.cpath..';'..conky_dir..'lib/lib/lua/5.4/?.so;'
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- startup - this is where the modules are compiled and arranged
|
||||||
|
|
||||||
require 'cairo'
|
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
|
|
||||||
|
|
||||||
local ABS_PATH = debug.getinfo(1).source:match("@?(.*/)")
|
|
||||||
package.path = ABS_PATH..'?.lua;'..
|
|
||||||
ABS_PATH..'drawing/?.lua;'..
|
|
||||||
ABS_PATH..'schema/?.lua;'..
|
|
||||||
ABS_PATH..'core/?.lua;'..
|
|
||||||
ABS_PATH..'core/widget/?.lua;'..
|
|
||||||
ABS_PATH..'core/widget/arc/?.lua;'..
|
|
||||||
ABS_PATH..'core/widget/text/?.lua;'..
|
|
||||||
ABS_PATH..'core/widget/timeseries/?.lua;'..
|
|
||||||
ABS_PATH..'core/widget/rect/?.lua;'..
|
|
||||||
ABS_PATH..'core/widget/line/?.lua;'..
|
|
||||||
ABS_PATH..'lib/share/lua/5.4/?.lua;'..
|
|
||||||
ABS_PATH..'lib/share/lua/5.4/?/init.lua;'
|
|
||||||
|
|
||||||
package.cpath = ABS_PATH..'lib/lib/lua/5.4/?.so;'
|
|
||||||
|
|
||||||
local i_o = require 'i_o'
|
|
||||||
local geom = require 'geom'
|
|
||||||
local pure = require 'pure'
|
|
||||||
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 compile = require 'compile'
|
local compile = require 'compile'
|
||||||
local common = require 'common'
|
|
||||||
local yaml = require 'lyaml'
|
|
||||||
|
|
||||||
local draw_dynamic
|
local draw_dynamic
|
||||||
|
|
||||||
local build_main = function(update_interval, config_path)
|
|
||||||
local update_freq = 1 / update_interval
|
|
||||||
local config = yaml.load(i_o.read_file(config_path))
|
|
||||||
local cmods = config.modules
|
|
||||||
|
|
||||||
local main_state = {}
|
|
||||||
|
|
||||||
local mods = {
|
|
||||||
memory = pure.partial(memory, update_freq, cmods.memory),
|
|
||||||
readwrite = pure.partial(readwrite, update_freq, cmods.readwrite),
|
|
||||||
network = pure.partial(network, update_freq),
|
|
||||||
power = pure.partial(power, update_freq, cmods.power),
|
|
||||||
filesystem = pure.partial(filesystem, cmods.filesystem, main_state),
|
|
||||||
system = pure.partial(system, main_state),
|
|
||||||
graphics = pure.partial(graphics, update_freq, cmods.graphics),
|
|
||||||
processor = pure.partial(processor, update_freq, cmods.processor, main_state),
|
|
||||||
pacman = pure.partial(pacman, main_state)
|
|
||||||
}
|
|
||||||
|
|
||||||
local compiled = compile.compile_layout(
|
|
||||||
common(config),
|
|
||||||
geom.make_point(table.unpack(config.layout.anchor)),
|
|
||||||
mods,
|
|
||||||
config.layout.panels
|
|
||||||
)
|
|
||||||
|
|
||||||
local STATS_FILE = '/tmp/.conky_pacman'
|
|
||||||
|
|
||||||
return function(cr, _updates)
|
|
||||||
main_state.trigger10 = _updates % (update_freq * 10)
|
|
||||||
main_state.pacman_stats = i_o.read_file(STATS_FILE)
|
|
||||||
|
|
||||||
compiled.static(cr)
|
|
||||||
compiled.update()
|
|
||||||
compiled.dynamic(cr)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function conky_start(update_interval)
|
function conky_start(update_interval)
|
||||||
conky_set_update_interval(update_interval)
|
conky_set_update_interval(update_interval)
|
||||||
|
|
||||||
draw_dynamic = build_main(update_interval, ABS_PATH..'config.yml')
|
draw_dynamic = compile(update_interval, conky_dir..'config.yml')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- main loop - where all the drawing/updating happens
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
local updates = -2 -- this accounts for the first few spazzy iterations
|
local updates = -2 -- this accounts for the first few spazzy iterations
|
||||||
|
|
||||||
function conky_main()
|
function conky_main()
|
||||||
|
@ -89,7 +51,7 @@ function conky_main()
|
||||||
if not _cw then return end
|
if not _cw then return end
|
||||||
|
|
||||||
local cs = __cairo_xlib_surface_create(_cw.display, _cw.drawable,
|
local cs = __cairo_xlib_surface_create(_cw.display, _cw.drawable,
|
||||||
_cw.visual, 1920, 1080)
|
_cw.visual, _cw.width, _cw.height)
|
||||||
local cr = __cairo_create(cs)
|
local cr = __cairo_create(cs)
|
||||||
updates = updates + 1
|
updates = updates + 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue