ENH dynamically arrange all panels
This commit is contained in:
parent
088979312d
commit
9bb16d80d3
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit 387195607eb3a481596b6da45ec0b12b5f3c97d1
|
Subproject commit becc24a2c79a582e10db348be435b18f9aba310f
|
|
@ -658,6 +658,7 @@ local _combine_blocks = function(acc, new)
|
||||||
if new.active == true then
|
if new.active == true then
|
||||||
local n = new.f(acc.y + new.offset)
|
local n = new.f(acc.y + new.offset)
|
||||||
table.insert(acc.objs, n.obj)
|
table.insert(acc.objs, n.obj)
|
||||||
|
acc.w = math.max(acc.w, n.w)
|
||||||
acc.y = acc.y + n.h + new.offset
|
acc.y = acc.y + n.h + new.offset
|
||||||
end
|
end
|
||||||
return acc
|
return acc
|
||||||
|
@ -671,18 +672,20 @@ M.reduce_blocks_inner = function(f, header, point, width, blocks)
|
||||||
local mk_header = function(y)
|
local mk_header = function(y)
|
||||||
local obj = M.make_header(point.x, y, width, header)
|
local obj = M.make_header(point.x, y, width, header)
|
||||||
return M.mk_acc_static(
|
return M.mk_acc_static(
|
||||||
|
width,
|
||||||
obj.bottom_y - y,
|
obj.bottom_y - y,
|
||||||
function(cr) M.draw_header(cr, obj) end
|
function(cr) M.draw_header(cr, obj) end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
local r = pure.reduce(
|
local r = pure.reduce(
|
||||||
_combine_blocks,
|
_combine_blocks,
|
||||||
{y = point.y, objs = {}},
|
{w = 0, y = point.y, objs = {}},
|
||||||
{M.mk_block(mk_header, true, 0), table.unpack(blocks)}
|
{M.mk_block(mk_header, true, 0), table.unpack(blocks)}
|
||||||
)
|
)
|
||||||
local us, ss, ds = table.unpack(pure.unzip(r.objs))
|
local us, ss, ds = table.unpack(pure.unzip(r.objs))
|
||||||
return {
|
return {
|
||||||
y = r.y,
|
next_x = point.x + r.w,
|
||||||
|
next_y = r.y,
|
||||||
update = f(table.unpack(non_false(pure.reverse(us)))),
|
update = f(table.unpack(non_false(pure.reverse(us)))),
|
||||||
static = pure.sequence(table.unpack(ss)),
|
static = pure.sequence(table.unpack(ss)),
|
||||||
dynamic = pure.sequence(table.unpack(non_false(ds)))
|
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.reduce_blocks_ = pure.partial(M.reduce_blocks_inner, pure.sequence)
|
||||||
|
|
||||||
M.mk_acc = function(h, u, s, d)
|
M.mk_acc = function(w, h, u, s, d)
|
||||||
return {h = h, obj = {u, s, d}}
|
return {w = w, h = h, obj = {u, s, d}}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.mk_acc_static = function(h, s)
|
M.mk_acc_static = function(w, h, s)
|
||||||
return M.mk_acc(h, false, s, false)
|
return M.mk_acc(w, h, false, s, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.mk_block = function(f, active, offset)
|
M.mk_block = function(f, active, offset)
|
||||||
|
@ -707,7 +710,7 @@ end
|
||||||
|
|
||||||
M.mk_seperator = function(width, x, y)
|
M.mk_seperator = function(width, x, y)
|
||||||
local separator = M.make_separator(x, y, width)
|
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
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -19,13 +19,14 @@ return function(pathspecs, point)
|
||||||
geometry.SECTION_WIDTH,
|
geometry.SECTION_WIDTH,
|
||||||
'SMART Daemon'
|
'SMART Daemon'
|
||||||
)
|
)
|
||||||
local update = function(trigger)
|
local update = function(state)
|
||||||
if trigger == 0 then
|
if state.trigger10 == 0 then
|
||||||
local pid = i_o.execute_cmd('pidof smartd', nil, '*n')
|
local pid = i_o.execute_cmd('pidof smartd', nil, '*n')
|
||||||
common.text_row_set(obj, (pid == '') and 'Error' or 'Running')
|
common.text_row_set(obj, (pid == '') and 'Error' or 'Running')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
0,
|
0,
|
||||||
update,
|
update,
|
||||||
pure.partial(common.text_row_draw_static, obj),
|
pure.partial(common.text_row_draw_static, obj),
|
||||||
|
@ -61,12 +62,13 @@ return function(pathspecs, point)
|
||||||
local read_fs = function(index, cmd)
|
local read_fs = function(index, cmd)
|
||||||
common.compound_bar_set(obj, index, i_o.conky_numeric(cmd))
|
common.compound_bar_set(obj, index, i_o.conky_numeric(cmd))
|
||||||
end
|
end
|
||||||
local update = function(trigger)
|
local update = function(state)
|
||||||
if trigger == 0 then
|
if state.trigger10 == 0 then
|
||||||
impure.ieach(read_fs, CONKY_CMDS)
|
impure.ieach(read_fs, CONKY_CMDS)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
(#pathspecs - 1) * SPACING,
|
(#pathspecs - 1) * SPACING,
|
||||||
update,
|
update,
|
||||||
pure.partial(common.compound_bar_draw_static, obj),
|
pure.partial(common.compound_bar_draw_static, obj),
|
||||||
|
|
|
@ -42,7 +42,13 @@ return function(update_freq, point)
|
||||||
)
|
)
|
||||||
local static = pure.partial(common.tagged_percent_timeseries_draw_static, obj)
|
local static = pure.partial(common.tagged_percent_timeseries_draw_static, obj)
|
||||||
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, 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
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -64,7 +70,7 @@ return function(update_freq, point)
|
||||||
end
|
end
|
||||||
local static = pure.partial(common.text_row_draw_static, obj)
|
local static = pure.partial(common.text_row_draw_static, obj)
|
||||||
local dynamic = pure.partial(common.text_row_draw_dynamic, 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
|
end
|
||||||
|
|
||||||
local mk_sep = pure.partial(
|
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 static = pure.partial(common.threshold_text_row_draw_static, obj)
|
||||||
local dynamic = pure.partial(common.threshold_text_row_draw_dynamic, 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
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -119,7 +125,7 @@ return function(update_freq, point)
|
||||||
end
|
end
|
||||||
local static = pure.partial(common.text_rows_draw_static, obj)
|
local static = pure.partial(common.text_rows_draw_static, obj)
|
||||||
local dynamic = pure.partial(common.text_rows_draw_dynamic, 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
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -227,5 +233,5 @@ return function(update_freq, point)
|
||||||
common.mk_block(mk_vid_util, true, PLOT_SEC_BREAK)
|
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
|
end
|
||||||
|
|
|
@ -79,7 +79,7 @@ return function(update_freq, point)
|
||||||
common.dial_draw_dynamic(swap, cr)
|
common.dial_draw_dynamic(swap, cr)
|
||||||
common.text_rows_draw_dynamic(cache, cr)
|
common.text_rows_draw_dynamic(cache, cr)
|
||||||
end
|
end
|
||||||
return common.mk_acc(DIAL_DIAMETER, update, static, dynamic)
|
return common.mk_acc(geometry.SECTION_WIDTH, DIAL_DIAMETER, update, static, dynamic)
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -94,6 +94,7 @@ return function(update_freq, point)
|
||||||
update_freq
|
update_freq
|
||||||
)
|
)
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
PLOT_HEIGHT,
|
PLOT_HEIGHT,
|
||||||
function(s) timeseries.update(obj, s.mem.used_percent) end,
|
function(s) timeseries.update(obj, s.mem.used_percent) end,
|
||||||
pure.partial(timeseries.draw_static, obj),
|
pure.partial(timeseries.draw_static, obj),
|
||||||
|
@ -131,6 +132,7 @@ return function(update_freq, point)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
TABLE_HEIGHT,
|
TABLE_HEIGHT,
|
||||||
update,
|
update,
|
||||||
pure.partial(text_table.draw_static, obj),
|
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),
|
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
|
end
|
||||||
|
|
|
@ -53,6 +53,7 @@ return function(update_freq, point)
|
||||||
state[key]
|
state[key]
|
||||||
)
|
)
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||||
function(s) common.update_rate_timeseries(obj, s[key]) end,
|
function(s) common.update_rate_timeseries(obj, s[key]) end,
|
||||||
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
|
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
|
end
|
||||||
|
|
|
@ -16,8 +16,11 @@ return function(point)
|
||||||
TEXT_SPACING,
|
TEXT_SPACING,
|
||||||
{'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'}
|
{'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'}
|
||||||
)
|
)
|
||||||
local update = function(pacman_stats)
|
local update = function(state)
|
||||||
local stats = __string_match(pacman_stats, '%d+%s+[^%s]+%s+[^%s]+%s+(.*)$')
|
local stats = __string_match(
|
||||||
|
state.pacman_stats,
|
||||||
|
'%d+%s+[^%s]+%s+[^%s]+%s+(.*)$'
|
||||||
|
)
|
||||||
if stats then
|
if stats then
|
||||||
local i = 1
|
local i = 1
|
||||||
for v in __string_gmatch(stats, '%d+') do
|
for v in __string_gmatch(stats, '%d+') do
|
||||||
|
@ -31,6 +34,7 @@ return function(point)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
TEXT_SPACING * 4,
|
TEXT_SPACING * 4,
|
||||||
update,
|
update,
|
||||||
pure.partial(common.text_rows_draw_static, obj),
|
pure.partial(common.text_rows_draw_static, obj),
|
||||||
|
|
|
@ -53,6 +53,7 @@ return function(update_freq, battery, point)
|
||||||
read()
|
read()
|
||||||
)
|
)
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||||
function(_) common.update_rate_timeseries(obj, read()) end,
|
function(_) common.update_rate_timeseries(obj, read()) end,
|
||||||
mk_static(obj),
|
mk_static(obj),
|
||||||
|
@ -95,9 +96,10 @@ return function(update_freq, battery, point)
|
||||||
update_freq
|
update_freq
|
||||||
)
|
)
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||||
function(ac)
|
function(state)
|
||||||
common.tagged_scaled_timeseries_set(obj, read_battery_power(ac))
|
common.tagged_scaled_timeseries_set(obj, read_battery_power(state.is_using_ac))
|
||||||
end,
|
end,
|
||||||
mk_static(obj),
|
mk_static(obj),
|
||||||
mk_dynamic(obj)
|
mk_dynamic(obj)
|
||||||
|
|
|
@ -102,7 +102,13 @@ return function(update_freq, point)
|
||||||
compound_dial.draw_dynamic(cores[i].loads, cr)
|
compound_dial.draw_dynamic(cores[i].loads, cr)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -129,7 +135,13 @@ return function(update_freq, point)
|
||||||
end
|
end
|
||||||
local static = pure.partial(common.text_rows_draw_static, cpu_status)
|
local static = pure.partial(common.text_rows_draw_static, cpu_status)
|
||||||
local dynamic = pure.partial(common.text_rows_draw_dynamic, 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
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -163,7 +175,13 @@ return function(update_freq, point)
|
||||||
end
|
end
|
||||||
local static = pure.partial(common.tagged_percent_timeseries_draw_static, total_load)
|
local static = pure.partial(common.tagged_percent_timeseries_draw_static, total_load)
|
||||||
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, 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
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -196,7 +214,13 @@ return function(update_freq, point)
|
||||||
end
|
end
|
||||||
local static = pure.partial(text_table.draw_static, tbl)
|
local static = pure.partial(text_table.draw_static, tbl)
|
||||||
local dynamic = pure.partial(text_table.draw_dynamic, 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
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -218,8 +242,8 @@ return function(update_freq, point)
|
||||||
return pure.map_at(
|
return pure.map_at(
|
||||||
"update",
|
"update",
|
||||||
function(f)
|
function(f)
|
||||||
return function(trigger)
|
return function(main_state)
|
||||||
f(update_state(trigger, state.cpu_loads))
|
f(update_state(main_state.trigger10, state.cpu_loads))
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
rbs
|
rbs
|
||||||
|
|
|
@ -36,6 +36,8 @@ return function(update_freq, devices, point)
|
||||||
state[key]
|
state[key]
|
||||||
)
|
)
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
|
-- TODO construct this more sanely without referring to hardcoded vars
|
||||||
|
geometry.SECTION_WIDTH,
|
||||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||||
function() common.update_rate_timeseries(obj, state[key]) end,
|
function() common.update_rate_timeseries(obj, state[key]) end,
|
||||||
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
|
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
|
||||||
|
@ -62,7 +64,7 @@ return function(update_freq, devices, point)
|
||||||
return pure.map_at(
|
return pure.map_at(
|
||||||
"update",
|
"update",
|
||||||
function(f)
|
function(f)
|
||||||
return function()
|
return function(_)
|
||||||
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
|
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
|
||||||
f()
|
f()
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,33 +4,51 @@ 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 _combine_modules = function(acc, new)
|
local reduce_modules_y = function(init_x, acc, new)
|
||||||
local n = new(acc.point)
|
if type(new) == "number" then
|
||||||
table.insert(acc.funs, n.fun)
|
acc.next_y = acc.next_y + new
|
||||||
acc.point = geom.make_point(acc.point.x, acc.point + n.y)
|
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
|
return acc
|
||||||
end
|
end
|
||||||
|
|
||||||
local reduce_modules_inner = function(y, mods)
|
local reduce_modules_x = function(init_y, acc, x_mods)
|
||||||
local r = pure.reduce(_combine_modules, {y = y, mods = {}}, mods)
|
if type(x_mods) == "number" then
|
||||||
-- local us, ss, ds = table.unpack(pure.unzip(r.mods))
|
acc.next_x = acc.next_x + x_mods
|
||||||
return pure.unzip(r.mods)
|
else
|
||||||
-- return {
|
local r = pure.reduce(
|
||||||
-- updater = pure.sequence(table.unpack(us)),
|
pure.partial(reduce_modules_y, acc.next_x),
|
||||||
-- draw_static = pure.sequence(table.unpack(ss)),
|
{next_x = acc.next_x, next_y = init_y, fgroups = acc.fgroups},
|
||||||
-- draw_dynamic = pure.sequence(table.unpack(ds))
|
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
|
end
|
||||||
|
|
||||||
return function(module_sets)
|
local arrange_panel_modules = function(point, mods)
|
||||||
local __cairo_set_source_surface = cairo_set_source_surface
|
local r = pure.reduce(
|
||||||
local __cairo_image_surface_create = cairo_image_surface_create
|
pure.partial(reduce_modules_x, point.y),
|
||||||
local __cairo_translate = cairo_translate
|
{next_x = point.x, next_y = point.y, fgroups = {}},
|
||||||
local __cairo_create = cairo_create
|
mods
|
||||||
local __cairo_destroy = cairo_destroy
|
)
|
||||||
local __cairo_paint = cairo_paint
|
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
|
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
|
||||||
|
@ -41,52 +59,62 @@ return function(module_sets)
|
||||||
local cs_w = box.width + panel_line_thickness
|
local cs_w = box.width + panel_line_thickness
|
||||||
local cs_h = box.height + 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 cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
|
||||||
local cr = __cairo_create(cs)
|
local cr = cairo_create(cs)
|
||||||
|
|
||||||
__cairo_translate(cr, -cs_x, -cs_y)
|
cairo_translate(cr, -cs_x, -cs_y)
|
||||||
|
|
||||||
fill_rect.draw(panel, cr)
|
fill_rect.draw(panel, cr)
|
||||||
for _, f in pairs(modules) do
|
for i = 1, #fs do
|
||||||
f(cr)
|
fs[i](cr)
|
||||||
end
|
end
|
||||||
__cairo_destroy(cr)
|
cairo_destroy(cr)
|
||||||
return {x = cs_x, y = cs_y, s = cs}
|
return {x = cs_x, y = cs_y, s = cs}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO pull this out eventually
|
local reduce_static = function(y, margins, spacing, acc, panel_mods)
|
||||||
local boxes = {
|
if type(panel_mods) == "number" then
|
||||||
geom.make_box(
|
acc.next_x = acc.next_x + panel_mods
|
||||||
geometry.LEFT_X - geometry.PANEL_MARGIN_X,
|
else
|
||||||
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
|
local mpoint = geom.make_point(acc.next_x + margins.x, y + margins.y)
|
||||||
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
|
local r = arrange_panel_modules(mpoint, panel_mods)
|
||||||
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2
|
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(
|
{next_x = point.x, static = {}, update = {}, dynamic = {}},
|
||||||
geometry.CENTER_LEFT_X - geometry.PANEL_MARGIN_X,
|
module_sets
|
||||||
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
|
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
local cs = pure.zip_with(_make_static_surface, boxes, module_sets)
|
local cs = r.static
|
||||||
|
|
||||||
local draw_static_surface = function(cr, cs_obj)
|
return {
|
||||||
__cairo_set_source_surface(cr, cs_obj.s, cs_obj.x, cs_obj.y)
|
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)
|
__cairo_paint(cr)
|
||||||
end
|
end
|
||||||
|
end,
|
||||||
-- return a table with update, static, and dynamic components
|
update = pure.sequence(table.unpack(r.update)),
|
||||||
return function(cr)
|
dynamic = pure.sequence(table.unpack(r.dynamic)),
|
||||||
for i = 1, #cs do
|
}
|
||||||
draw_static_surface(cr, cs[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,10 +16,13 @@ return function(point)
|
||||||
TEXT_SPACING,
|
TEXT_SPACING,
|
||||||
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
|
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
|
||||||
)
|
)
|
||||||
local update = function(pacman_stats)
|
local update = function(state)
|
||||||
local last_update, last_sync
|
local last_update, last_sync
|
||||||
if pacman_stats then
|
if state.pacman_stats then
|
||||||
last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
|
last_update, last_sync = __string_match(
|
||||||
|
state.pacman_stats,
|
||||||
|
"^%d+%s+([^%s]+)%s+([^%s]+).*"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
-- TODO this doesn't need to be update every time
|
-- TODO this doesn't need to be update every time
|
||||||
common.text_rows_set(obj, 1, i_o.conky('$kernel'))
|
common.text_rows_set(obj, 1, i_o.conky('$kernel'))
|
||||||
|
@ -29,7 +32,13 @@ return function(point)
|
||||||
end
|
end
|
||||||
local static = pure.partial(common.text_rows_draw_static, obj)
|
local static = pure.partial(common.text_rows_draw_static, obj)
|
||||||
local dynamic = pure.partial(common.text_rows_draw_dynamic, 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
|
end
|
||||||
|
|
||||||
return common.reduce_blocks_(
|
return common.reduce_blocks_(
|
||||||
|
|
66
main.lua
66
main.lua
|
@ -18,7 +18,7 @@ package.path = ABS_PATH..'?.lua;'..
|
||||||
|
|
||||||
local i_o = require 'i_o'
|
local i_o = require 'i_o'
|
||||||
local geom = require 'geom'
|
local geom = require 'geom'
|
||||||
local geometry = require 'geometry'
|
local pure = require 'pure'
|
||||||
local sys = require 'sys'
|
local sys = require 'sys'
|
||||||
local system = require 'system'
|
local system = require 'system'
|
||||||
local network = require 'network'
|
local network = require 'network'
|
||||||
|
@ -33,6 +33,8 @@ local static = require 'static'
|
||||||
|
|
||||||
local draw_dynamic
|
local draw_dynamic
|
||||||
|
|
||||||
|
local main_state = {}
|
||||||
|
|
||||||
function conky_start(update_interval)
|
function conky_start(update_interval)
|
||||||
conky_set_update_interval(update_interval)
|
conky_set_update_interval(update_interval)
|
||||||
|
|
||||||
|
@ -48,57 +50,39 @@ function conky_start(update_interval)
|
||||||
{'/tmp', 'tmpfs'}
|
{'/tmp', 'tmpfs'}
|
||||||
}
|
}
|
||||||
|
|
||||||
local mem = memory(update_freq, geom.make_point(geometry.RIGHT_X, 712))
|
local mem = pure.partial(memory, update_freq)
|
||||||
local rw = readwrite(update_freq, devices, geom.make_point(geometry.CENTER_LEFT_X, geometry.TOP_Y))
|
local rw = pure.partial(readwrite, update_freq, devices)
|
||||||
local net = network(update_freq, geom.make_point(geometry.CENTER_RIGHT_X, geometry.TOP_Y))
|
local net = pure.partial(network, update_freq)
|
||||||
local pwr = power(update_freq, battery, geom.make_point(geometry.RIGHT_X, 380))
|
local pwr = pure.partial(power, update_freq, battery)
|
||||||
local fs = filesystem(fs_paths, geom.make_point(geometry.RIGHT_X, 170))
|
local fs = pure.partial(filesystem, fs_paths)
|
||||||
local stm = system(geom.make_point(geometry.LEFT_X, geometry.TOP_Y))
|
local stm = system
|
||||||
local gfx = graphics(update_freq, geom.make_point(geometry.LEFT_X, 145))
|
local gfx = pure.partial(graphics, update_freq)
|
||||||
local proc = processor(update_freq, geom.make_point(geometry.LEFT_X, 614))
|
local proc = pure.partial(processor, update_freq)
|
||||||
local pcm = pacman(geom.make_point(geometry.RIGHT_X, geometry.TOP_Y))
|
local pcm = pacman
|
||||||
|
|
||||||
local using_ac = sys.battery_status_reader(battery)
|
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},
|
{{stm, 19, gfx, 16, proc}},
|
||||||
{rw.static, net.static},
|
10,
|
||||||
{pcm.static, fs.static, pwr.static, mem.static}
|
{{rw}, 20, {net}},
|
||||||
|
10,
|
||||||
|
{{pcm, 24, fs, 24, pwr, 19, mem}}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
local STATS_FILE = '/tmp/.conky_pacman'
|
local STATS_FILE = '/tmp/.conky_pacman'
|
||||||
|
|
||||||
draw_dynamic = function(cr, _updates)
|
draw_dynamic = function(cr, _updates)
|
||||||
-- draw static components
|
main_state.trigger10 = _updates % (update_freq * 10)
|
||||||
draw_static(cr)
|
main_state.pacman_stats = i_o.read_file(STATS_FILE)
|
||||||
|
main_state.is_using_ac = using_ac()
|
||||||
|
|
||||||
-- update dynamic components
|
compiled.static(cr)
|
||||||
local t1 = _updates % (update_freq * 10)
|
compiled.update(main_state)
|
||||||
local pacman_stats = i_o.read_file(STATS_FILE)
|
compiled.dynamic(cr)
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue