ENH use layout from config

This commit is contained in:
Nathan Dwarshuis 2022-07-17 12:07:38 -04:00
parent fef8f9c80e
commit 9986969ed1
4 changed files with 40 additions and 51 deletions

View File

@ -2,18 +2,12 @@ modules:
filesystem: filesystem:
show_smart: true show_smart: true
fs_paths: fs_paths:
- path: / - {path: /, name: root}
name: root - {path: /boot, name: boot}
- path: /boot - {path: /home, name: home}
name: boot - {path: /mnt/data, name: data}
- path: /home - {path: /mnt/dcache, name: dcache}
name: home - {path: /tmp, name: tmpfs}
- path: /mnt/data
name: data
- path: /mnt/dcache
name: dcache
- path: /tmp
name: tmpfs
graphics: graphics:
show_temp: true show_temp: true
show_clock: true show_clock: true
@ -27,10 +21,8 @@ modules:
power: power:
battery: BAT0 battery: BAT0
rapl_specs: rapl_specs:
- name: PKG0 - {name: PKG0, address: intel-rapl:0}
address: intel-rapl:0 - {name: DRAM, address: intel-rapl:0:2}
- name: DRAM
address: intel-rapl:0:2
processor: processor:
show_cores: true show_cores: true
show_stats: true show_stats: true
@ -41,8 +33,8 @@ modules:
layout: layout:
anchor: [12, 11] anchor: [12, 11]
panels: panels:
- !!seq [[system, 19, graphics, 16, processor]] - [[system, 19, graphics, 16, processor]]
- 10 - 10
- !!seq [[readwrite], 20, [network]] - [[readwrite], 20, [network]]
- 10 - 10
- !!seq [[pacman, 24, filesystem, 24, power, 19, memory]] - [[pacman, 24, filesystem, 24, power, 19, memory]]

View File

@ -4,11 +4,11 @@ local geometry = require 'geometry'
local geom = require 'geom' local geom = require 'geom'
local fill_rect = require 'fill_rect' local fill_rect = require 'fill_rect'
local reduce_modules_y = function(init_x, acc, new) local reduce_modules_y = function(modlist, init_x, 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 r = new(geom.make_point(init_x, acc.next_y)) local r = modlist[new](geom.make_point(init_x, acc.next_y))
table.insert(acc.fgroups, {update = r.update, static = r.static, dynamic = r.dynamic}) table.insert(acc.fgroups, {update = r.update, static = r.static, dynamic = r.dynamic})
acc.next_x = math.max(acc.next_x, r.next_x) acc.next_x = math.max(acc.next_x, r.next_x)
acc.next_y = r.next_y acc.next_y = r.next_y
@ -16,12 +16,12 @@ local reduce_modules_y = function(init_x, acc, new)
return acc return acc
end end
local reduce_modules_x = function(init_y, acc, x_mods) local reduce_modules_x = function(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, acc.next_x), pure.partial(reduce_modules_y, modlist, acc.next_x),
{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 x_mods
) )
@ -32,9 +32,9 @@ local reduce_modules_x = function(init_y, acc, x_mods)
return acc return acc
end end
local arrange_panel_modules = function(point, mods) local arrange_panel_modules = function(modlist, point, mods)
local r = pure.reduce( local r = pure.reduce(
pure.partial(reduce_modules_x, point.y), pure.partial(reduce_modules_x, modlist, point.y),
{next_x = point.x, next_y = point.y, fgroups = {}}, {next_x = point.x, next_y = point.y, fgroups = {}},
mods mods
) )
@ -72,12 +72,12 @@ local build_surface = function(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(y, margins, acc, panel_mods) local reduce_static = function(mods, y, margins, 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
local mpoint = geom.make_point(acc.next_x + margins.x, y + margins.y) local mpoint = geom.make_point(acc.next_x + margins.x, y + margins.y)
local r = arrange_panel_modules(mpoint, panel_mods) local r = arrange_panel_modules(mods, mpoint, panel_mods)
local w = r.width + margins.x * 2 local w = r.width + margins.x * 2
local h = r.height + margins.y * 2 local h = r.height + margins.y * 2
local pbox = geom.make_box(acc.next_x, y, w, h) local pbox = geom.make_box(acc.next_x, y, w, h)
@ -89,13 +89,14 @@ local reduce_static = function(y, margins, acc, panel_mods)
return acc return acc
end end
return function(point, module_sets) return function(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,
mods,
point.y, point.y,
{x = geometry.PANEL_MARGIN_X, y = geometry.PANEL_MARGIN_Y} {x = geometry.PANEL_MARGIN_X, y = geometry.PANEL_MARGIN_Y}
), ),

View File

@ -15,7 +15,10 @@ package.path = ABS_PATH..'?.lua;'..
ABS_PATH..'core/widget/timeseries/?.lua;'.. ABS_PATH..'core/widget/timeseries/?.lua;'..
ABS_PATH..'core/widget/rect/?.lua;'.. ABS_PATH..'core/widget/rect/?.lua;'..
ABS_PATH..'core/widget/line/?.lua;'.. ABS_PATH..'core/widget/line/?.lua;'..
ABS_PATH..'lib/share/lua/5.4/?.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 i_o = require 'i_o'
local geom = require 'geom' local geom = require 'geom'
@ -30,7 +33,7 @@ local readwrite = require 'readwrite'
local graphics = require 'graphics' local graphics = require 'graphics'
local memory = require 'memory' local memory = require 'memory'
local static = require 'static' local static = require 'static'
local yaml = require 'tinyyaml' local yaml = require 'lyaml'
local draw_dynamic local draw_dynamic
@ -41,28 +44,25 @@ function conky_start(update_interval)
local main_state = {} local main_state = {}
local config = yaml.parse(i_o.read_file(ABS_PATH..'config.yml')) local config = yaml.load(i_o.read_file(ABS_PATH..'config.yml'))
local cmods = config.modules local cmods = config.modules
local mem = pure.partial(memory, update_freq, cmods.memory) local mods = {
local rw = pure.partial(readwrite, update_freq, cmods.readwrite) memory = pure.partial(memory, update_freq, cmods.memory),
local net = pure.partial(network, update_freq) readwrite = pure.partial(readwrite, update_freq, cmods.readwrite),
local pwr = pure.partial(power, update_freq, cmods.power) network = pure.partial(network, update_freq),
local fs = pure.partial(filesystem, cmods.filesystem, main_state) power = pure.partial(power, update_freq, cmods.power),
local stm = pure.partial(system, main_state) filesystem = pure.partial(filesystem, cmods.filesystem, main_state),
local gfx = pure.partial(graphics, update_freq, cmods.graphics) system = pure.partial(system, main_state),
local proc = pure.partial(processor, update_freq, cmods.processor, main_state) graphics = pure.partial(graphics, update_freq, cmods.graphics),
local pcm = pure.partial(pacman, main_state) processor = pure.partial(processor, update_freq, cmods.processor, main_state),
pacman = pure.partial(pacman, main_state)
}
local compiled = static( local compiled = static(
geom.make_point(table.unpack(config.layout.anchor)), geom.make_point(table.unpack(config.layout.anchor)),
{ mods,
{{stm, 19, gfx, 16, proc}}, config.layout.panels
10,
{{rw}, 20, {net}},
10,
{{pcm, 24, fs, 24, pwr, 19, mem}}
}
) )
local STATS_FILE = '/tmp/.conky_pacman' local STATS_FILE = '/tmp/.conky_pacman'

View File

@ -152,7 +152,3 @@ properties:
pattern: pattern:
"^system|graphics|processor|readwrite|\ "^system|graphics|processor|readwrite|\
network|pacman|filesystem|power|memory$" network|pacman|filesystem|power|memory$"