ENH dynamically arrange all panels

This commit is contained in:
Nathan Dwarshuis 2022-07-16 00:00:06 -04:00
parent 088979312d
commit 9bb16d80d3
13 changed files with 218 additions and 151 deletions

2
core

@ -1 +1 @@
Subproject commit 387195607eb3a481596b6da45ec0b12b5f3c97d1
Subproject commit becc24a2c79a582e10db348be435b18f9aba310f

View File

@ -658,6 +658,7 @@ local _combine_blocks = function(acc, new)
if new.active == true then
local n = new.f(acc.y + new.offset)
table.insert(acc.objs, n.obj)
acc.w = math.max(acc.w, n.w)
acc.y = acc.y + n.h + new.offset
end
return acc
@ -671,18 +672,20 @@ M.reduce_blocks_inner = function(f, header, point, width, blocks)
local mk_header = function(y)
local obj = M.make_header(point.x, y, width, header)
return M.mk_acc_static(
width,
obj.bottom_y - y,
function(cr) M.draw_header(cr, obj) end
)
end
local r = pure.reduce(
_combine_blocks,
{y = point.y, objs = {}},
{w = 0, y = point.y, objs = {}},
{M.mk_block(mk_header, true, 0), table.unpack(blocks)}
)
local us, ss, ds = table.unpack(pure.unzip(r.objs))
return {
y = r.y,
next_x = point.x + r.w,
next_y = r.y,
update = f(table.unpack(non_false(pure.reverse(us)))),
static = pure.sequence(table.unpack(ss)),
dynamic = pure.sequence(table.unpack(non_false(ds)))
@ -693,12 +696,12 @@ M.reduce_blocks = pure.partial(M.reduce_blocks_inner, pure.compose)
M.reduce_blocks_ = pure.partial(M.reduce_blocks_inner, pure.sequence)
M.mk_acc = function(h, u, s, d)
return {h = h, obj = {u, s, d}}
M.mk_acc = function(w, h, u, s, d)
return {w = w, h = h, obj = {u, s, d}}
end
M.mk_acc_static = function(h, s)
return M.mk_acc(h, false, s, false)
M.mk_acc_static = function(w, h, s)
return M.mk_acc(w, h, false, s, false)
end
M.mk_block = function(f, active, offset)
@ -707,7 +710,7 @@ end
M.mk_seperator = function(width, x, y)
local separator = M.make_separator(x, y, width)
return M.mk_acc_static(0, pure.partial(line.draw, separator))
return M.mk_acc_static(width, 0, pure.partial(line.draw, separator))
end
return M

View File

@ -19,13 +19,14 @@ return function(pathspecs, point)
geometry.SECTION_WIDTH,
'SMART Daemon'
)
local update = function(trigger)
if trigger == 0 then
local update = function(state)
if state.trigger10 == 0 then
local pid = i_o.execute_cmd('pidof smartd', nil, '*n')
common.text_row_set(obj, (pid == '') and 'Error' or 'Running')
end
end
return common.mk_acc(
geometry.SECTION_WIDTH,
0,
update,
pure.partial(common.text_row_draw_static, obj),
@ -61,12 +62,13 @@ return function(pathspecs, point)
local read_fs = function(index, cmd)
common.compound_bar_set(obj, index, i_o.conky_numeric(cmd))
end
local update = function(trigger)
if trigger == 0 then
local update = function(state)
if state.trigger10 == 0 then
impure.ieach(read_fs, CONKY_CMDS)
end
end
return common.mk_acc(
geometry.SECTION_WIDTH,
(#pathspecs - 1) * SPACING,
update,
pure.partial(common.compound_bar_draw_static, obj),

View File

@ -42,7 +42,13 @@ return function(update_freq, point)
)
local static = pure.partial(common.tagged_percent_timeseries_draw_static, obj)
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, obj)
return common.mk_acc(PLOT_HEIGHT + PLOT_SEC_BREAK, update, static, dynamic)
return common.mk_acc(
geometry.SECTION_WIDTH,
PLOT_HEIGHT + PLOT_SEC_BREAK,
update,
static,
dynamic
)
end
-----------------------------------------------------------------------------
@ -64,7 +70,7 @@ return function(update_freq, point)
end
local static = pure.partial(common.text_row_draw_static, obj)
local dynamic = pure.partial(common.text_row_draw_dynamic, obj)
return common.mk_acc(0, update, static, dynamic)
return common.mk_acc(geometry.SECTION_WIDTH, 0, update, static, dynamic)
end
local mk_sep = pure.partial(
@ -94,7 +100,7 @@ return function(update_freq, point)
)
local static = pure.partial(common.threshold_text_row_draw_static, obj)
local dynamic = pure.partial(common.threshold_text_row_draw_dynamic, obj)
return common.mk_acc(0, update, static, dynamic)
return common.mk_acc(geometry.SECTION_WIDTH, 0, update, static, dynamic)
end
-----------------------------------------------------------------------------
@ -119,7 +125,7 @@ return function(update_freq, point)
end
local static = pure.partial(common.text_rows_draw_static, obj)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
return common.mk_acc(TEXT_SPACING, update, static, dynamic)
return common.mk_acc(geometry.SECTION_WIDTH, TEXT_SPACING, update, static, dynamic)
end
-----------------------------------------------------------------------------
@ -227,5 +233,5 @@ return function(update_freq, point)
common.mk_block(mk_vid_util, true, PLOT_SEC_BREAK)
}
)
return pure.map_at("update", function(f) return function() f(update_state()) end end, rbs)
return pure.map_at("update", function(f) return function(_) f(update_state()) end end, rbs)
end

View File

@ -79,7 +79,7 @@ return function(update_freq, point)
common.dial_draw_dynamic(swap, cr)
common.text_rows_draw_dynamic(cache, cr)
end
return common.mk_acc(DIAL_DIAMETER, update, static, dynamic)
return common.mk_acc(geometry.SECTION_WIDTH, DIAL_DIAMETER, update, static, dynamic)
end
-----------------------------------------------------------------------------
@ -94,6 +94,7 @@ return function(update_freq, point)
update_freq
)
return common.mk_acc(
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
function(s) timeseries.update(obj, s.mem.used_percent) end,
pure.partial(timeseries.draw_static, obj),
@ -131,6 +132,7 @@ return function(update_freq, point)
end
end
return common.mk_acc(
geometry.SECTION_WIDTH,
TABLE_HEIGHT,
update,
pure.partial(text_table.draw_static, obj),
@ -188,5 +190,5 @@ return function(update_freq, point)
common.mk_block(mk_tbl, true, TABLE_SECTION_BREAK),
}
)
return pure.map_at("update", function(f) return function() f(read_state()) end end, rbs)
return pure.map_at("update", function(f) return function(_) f(read_state()) end end, rbs)
end

View File

@ -53,6 +53,7 @@ return function(update_freq, point)
state[key]
)
return common.mk_acc(
geometry.SECTION_WIDTH,
PLOT_HEIGHT + PLOT_SEC_BREAK,
function(s) common.update_rate_timeseries(obj, s[key]) end,
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
@ -76,5 +77,5 @@ return function(update_freq, point)
}
)
return pure.map_at("update", function(f) return function() f(read_interfaces()) end end, rbs)
return pure.map_at("update", function(f) return function(_) f(read_interfaces()) end end, rbs)
end

View File

@ -16,8 +16,11 @@ return function(point)
TEXT_SPACING,
{'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'}
)
local update = function(pacman_stats)
local stats = __string_match(pacman_stats, '%d+%s+[^%s]+%s+[^%s]+%s+(.*)$')
local update = function(state)
local stats = __string_match(
state.pacman_stats,
'%d+%s+[^%s]+%s+[^%s]+%s+(.*)$'
)
if stats then
local i = 1
for v in __string_gmatch(stats, '%d+') do
@ -31,6 +34,7 @@ return function(point)
end
end
return common.mk_acc(
geometry.SECTION_WIDTH,
TEXT_SPACING * 4,
update,
pure.partial(common.text_rows_draw_static, obj),

View File

@ -53,6 +53,7 @@ return function(update_freq, battery, point)
read()
)
return common.mk_acc(
geometry.SECTION_WIDTH,
PLOT_HEIGHT + PLOT_SEC_BREAK,
function(_) common.update_rate_timeseries(obj, read()) end,
mk_static(obj),
@ -95,9 +96,10 @@ return function(update_freq, battery, point)
update_freq
)
return common.mk_acc(
geometry.SECTION_WIDTH,
PLOT_HEIGHT + PLOT_SEC_BREAK,
function(ac)
common.tagged_scaled_timeseries_set(obj, read_battery_power(ac))
function(state)
common.tagged_scaled_timeseries_set(obj, read_battery_power(state.is_using_ac))
end,
mk_static(obj),
mk_dynamic(obj)

View File

@ -102,7 +102,13 @@ return function(update_freq, point)
compound_dial.draw_dynamic(cores[i].loads, cr)
end
end
return common.mk_acc(DIAL_OUTER_RADIUS * 2, update, static, dynamic)
return common.mk_acc(
geometry.SECTION_WIDTH,
DIAL_OUTER_RADIUS * 2,
update,
static,
dynamic
)
end
-----------------------------------------------------------------------------
@ -129,7 +135,13 @@ return function(update_freq, point)
end
local static = pure.partial(common.text_rows_draw_static, cpu_status)
local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status)
return common.mk_acc(TEXT_SPACING, update, static, dynamic)
return common.mk_acc(
geometry.SECTION_WIDTH,
TEXT_SPACING,
update,
static,
dynamic
)
end
-----------------------------------------------------------------------------
@ -163,7 +175,13 @@ return function(update_freq, point)
end
local static = pure.partial(common.tagged_percent_timeseries_draw_static, total_load)
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, total_load)
return common.mk_acc(PLOT_HEIGHT + PLOT_SECTION_BREAK, update, static, dynamic)
return common.mk_acc(
geometry.SECTION_WIDTH,
PLOT_HEIGHT + PLOT_SECTION_BREAK,
update,
static,
dynamic
)
end
-----------------------------------------------------------------------------
@ -196,7 +214,13 @@ return function(update_freq, point)
end
local static = pure.partial(text_table.draw_static, tbl)
local dynamic = pure.partial(text_table.draw_dynamic, tbl)
return common.mk_acc(TABLE_HEIGHT, update, static, dynamic)
return common.mk_acc(
geometry.SECTION_WIDTH,
TABLE_HEIGHT,
update,
static,
dynamic
)
end
-----------------------------------------------------------------------------
@ -218,8 +242,8 @@ return function(update_freq, point)
return pure.map_at(
"update",
function(f)
return function(trigger)
f(update_state(trigger, state.cpu_loads))
return function(main_state)
f(update_state(main_state.trigger10, state.cpu_loads))
end
end,
rbs

View File

@ -36,6 +36,8 @@ return function(update_freq, devices, point)
state[key]
)
return common.mk_acc(
-- TODO construct this more sanely without referring to hardcoded vars
geometry.SECTION_WIDTH,
PLOT_HEIGHT + PLOT_SEC_BREAK,
function() common.update_rate_timeseries(obj, state[key]) end,
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
@ -62,7 +64,7 @@ return function(update_freq, devices, point)
return pure.map_at(
"update",
function(f)
return function()
return function(_)
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
f()
end

View File

@ -4,33 +4,51 @@ local geometry = require 'geometry'
local geom = require 'geom'
local fill_rect = require 'fill_rect'
local _combine_modules = function(acc, new)
local n = new(acc.point)
table.insert(acc.funs, n.fun)
acc.point = geom.make_point(acc.point.x, acc.point + n.y)
local reduce_modules_y = function(init_x, acc, new)
if type(new) == "number" then
acc.next_y = acc.next_y + new
else
local r = new(geom.make_point(init_x, acc.next_y))
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_y = r.next_y
end
return acc
end
local reduce_modules_inner = function(y, mods)
local r = pure.reduce(_combine_modules, {y = y, mods = {}}, mods)
-- local us, ss, ds = table.unpack(pure.unzip(r.mods))
return pure.unzip(r.mods)
-- return {
-- updater = pure.sequence(table.unpack(us)),
-- draw_static = pure.sequence(table.unpack(ss)),
-- draw_dynamic = pure.sequence(table.unpack(ds))
-- }
local reduce_modules_x = function(init_y, acc, x_mods)
if type(x_mods) == "number" then
acc.next_x = acc.next_x + x_mods
else
local r = pure.reduce(
pure.partial(reduce_modules_y, acc.next_x),
{next_x = acc.next_x, next_y = init_y, fgroups = acc.fgroups},
x_mods
)
acc.fgroups = r.fgroups
acc.next_x = r.next_x
acc.next_y = math.max(acc.next_y, r.next_y)
end
return acc
end
return function(module_sets)
local __cairo_set_source_surface = cairo_set_source_surface
local __cairo_image_surface_create = cairo_image_surface_create
local __cairo_translate = cairo_translate
local __cairo_create = cairo_create
local __cairo_destroy = cairo_destroy
local __cairo_paint = cairo_paint
local arrange_panel_modules = function(point, mods)
local r = pure.reduce(
pure.partial(reduce_modules_x, point.y),
{next_x = point.x, next_y = point.y, fgroups = {}},
mods
)
return {
point_ul = point,
width = r.next_x - point.x,
height = r.next_y - point.y,
update = pure.map_keys('update', r.fgroups),
static = pure.map_keys('static', r.fgroups),
dynamic = pure.map_keys('dynamic', r.fgroups),
}
end
local _make_static_surface = function(box, modules)
local build_surface = function(box, fs)
local panel_line_thickness = 1
-- move over by half a pixel so the lines don't need to be antialiased
local _x = box.corner.x + 0.5
@ -41,52 +59,62 @@ return function(module_sets)
local cs_w = box.width + panel_line_thickness
local cs_h = box.height + panel_line_thickness
local cs = __cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
local cr = __cairo_create(cs)
local cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
local cr = cairo_create(cs)
__cairo_translate(cr, -cs_x, -cs_y)
cairo_translate(cr, -cs_x, -cs_y)
fill_rect.draw(panel, cr)
for _, f in pairs(modules) do
f(cr)
end
__cairo_destroy(cr)
return { x = cs_x, y = cs_y, s = cs }
for i = 1, #fs do
fs[i](cr)
end
cairo_destroy(cr)
return {x = cs_x, y = cs_y, s = cs}
end
-- TODO pull this out eventually
local boxes = {
geom.make_box(
geometry.LEFT_X - geometry.PANEL_MARGIN_X,
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2
local reduce_static = function(y, margins, spacing, acc, panel_mods)
if type(panel_mods) == "number" then
acc.next_x = acc.next_x + panel_mods
else
local mpoint = geom.make_point(acc.next_x + margins.x, y + margins.y)
local r = arrange_panel_modules(mpoint, panel_mods)
local w = r.width + margins.x * 2
local h = r.height + margins.y * 2
local pbox = geom.make_box(acc.next_x, y, w, h)
acc.next_x = acc.next_x + w
acc.static = pure.flatten({acc.static, {build_surface(pbox, r.static)}})
acc.update = pure.flatten({acc.update, r.update})
acc.dynamic = pure.flatten({acc.dynamic, r.dynamic})
end
return acc
end
return function(point, module_sets)
local __cairo_set_source_surface = cairo_set_source_surface
local __cairo_paint = cairo_paint
local r = pure.reduce(
pure.partial(
reduce_static,
point.y,
{x = geometry.PANEL_MARGIN_X, y = geometry.PANEL_MARGIN_Y},
20
),
geom.make_box(
geometry.CENTER_LEFT_X - geometry.PANEL_MARGIN_X,
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
geometry.CENTER_WIDTH + geometry.PANEL_MARGIN_Y * 2 + geometry.CENTER_PAD,
geometry.CENTER_HEIGHT + geometry.PANEL_MARGIN_Y * 2
),
geom.make_box(
geometry.RIGHT_X - geometry.PANEL_MARGIN_X,
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2
{next_x = point.x, static = {}, update = {}, dynamic = {}},
module_sets
)
}
local cs = pure.zip_with(_make_static_surface, boxes, module_sets)
local cs = r.static
local draw_static_surface = function(cr, cs_obj)
__cairo_set_source_surface(cr, cs_obj.s, cs_obj.x, cs_obj.y)
return {
static = function(cr)
for i = 1, #cs do
local c = cs[i]
__cairo_set_source_surface(cr, c.s, c.x, c.y)
__cairo_paint(cr)
end
-- return a table with update, static, and dynamic components
return function(cr)
for i = 1, #cs do
draw_static_surface(cr, cs[i])
end
end
end,
update = pure.sequence(table.unpack(r.update)),
dynamic = pure.sequence(table.unpack(r.dynamic)),
}
end

View File

@ -16,10 +16,13 @@ return function(point)
TEXT_SPACING,
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
)
local update = function(pacman_stats)
local update = function(state)
local last_update, last_sync
if pacman_stats then
last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
if state.pacman_stats then
last_update, last_sync = __string_match(
state.pacman_stats,
"^%d+%s+([^%s]+)%s+([^%s]+).*"
)
end
-- TODO this doesn't need to be update every time
common.text_rows_set(obj, 1, i_o.conky('$kernel'))
@ -29,7 +32,13 @@ return function(point)
end
local static = pure.partial(common.text_rows_draw_static, obj)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
return common.mk_acc(TEXT_SPACING * 3, update, static, dynamic)
return common.mk_acc(
geometry.SECTION_WIDTH,
TEXT_SPACING * 3,
update,
static,
dynamic
)
end
return common.reduce_blocks_(

View File

@ -18,7 +18,7 @@ package.path = ABS_PATH..'?.lua;'..
local i_o = require 'i_o'
local geom = require 'geom'
local geometry = require 'geometry'
local pure = require 'pure'
local sys = require 'sys'
local system = require 'system'
local network = require 'network'
@ -33,6 +33,8 @@ local static = require 'static'
local draw_dynamic
local main_state = {}
function conky_start(update_interval)
conky_set_update_interval(update_interval)
@ -48,57 +50,39 @@ function conky_start(update_interval)
{'/tmp', 'tmpfs'}
}
local mem = memory(update_freq, geom.make_point(geometry.RIGHT_X, 712))
local rw = readwrite(update_freq, devices, geom.make_point(geometry.CENTER_LEFT_X, geometry.TOP_Y))
local net = network(update_freq, geom.make_point(geometry.CENTER_RIGHT_X, geometry.TOP_Y))
local pwr = power(update_freq, battery, geom.make_point(geometry.RIGHT_X, 380))
local fs = filesystem(fs_paths, geom.make_point(geometry.RIGHT_X, 170))
local stm = system(geom.make_point(geometry.LEFT_X, geometry.TOP_Y))
local gfx = graphics(update_freq, geom.make_point(geometry.LEFT_X, 145))
local proc = processor(update_freq, geom.make_point(geometry.LEFT_X, 614))
local pcm = pacman(geom.make_point(geometry.RIGHT_X, geometry.TOP_Y))
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
local using_ac = sys.battery_status_reader(battery)
local draw_static = static(
local compiled = static(
geom.make_point(12, 11),
{
{stm.static, gfx.static, proc.static},
{rw.static, net.static},
{pcm.static, fs.static, pwr.static, mem.static}
{{stm, 19, gfx, 16, proc}},
10,
{{rw}, 20, {net}},
10,
{{pcm, 24, fs, 24, pwr, 19, mem}}
}
)
local STATS_FILE = '/tmp/.conky_pacman'
draw_dynamic = function(cr, _updates)
-- draw static components
draw_static(cr)
main_state.trigger10 = _updates % (update_freq * 10)
main_state.pacman_stats = i_o.read_file(STATS_FILE)
main_state.is_using_ac = using_ac()
-- update dynamic components
local t1 = _updates % (update_freq * 10)
local pacman_stats = i_o.read_file(STATS_FILE)
local is_using_ac = using_ac()
stm.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
stm.dynamic(cr)
gfx.dynamic(cr)
proc.dynamic(cr)
rw.dynamic(cr)
net.dynamic(cr)
pcm.dynamic(cr)
fs.dynamic(cr)
pwr.dynamic(cr)
mem.dynamic(cr)
compiled.static(cr)
compiled.update(main_state)
compiled.dynamic(cr)
end
end