REF move patterns into common theming/widget composition module

This commit is contained in:
Nathan Dwarshuis 2021-07-05 23:27:43 -04:00
parent d4ac91ac35
commit b33cf3933f
12 changed files with 800 additions and 877 deletions

2
core

@ -1 +1 @@
Subproject commit a5f1912f6bf2a1fa54d9385971400fcb2de80e90 Subproject commit b1034354e38299cf997ddface80aaf43a4de8523

358
drawing/Common.lua Normal file
View File

@ -0,0 +1,358 @@
local M = {}
local Arc = require 'Arc'
local Text = require 'Text'
local CriticalText = require 'CriticalText'
local TextColumn = require 'TextColumn'
local Line = require 'Line'
local LabelPlot = require 'LabelPlot'
local ScalePlot = require 'ScalePlot'
local HEADER_HEIGHT = 45
local HEADER_FONT_SIZE = 15
-- TODO move all this font stuff to the theme file
local HEADER_FONT_SLANT = CAIRO_FONT_SLANT_NORMAL
local HEADER_FONT_WEIGHT = CAIRO_FONT_WEIGHT_BOLD
local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND
local HEADER_UNDERLINE_OFFSET = -20
local HEADER_UNDERLINE_THICKNESS = 3
--------------------------------------------------------------------------------
-- header
M.Header = function(x, y, w, s)
-- TODO what's the point of bottom_y?
local bottom_y = y + HEADER_HEIGHT
local underline_y = bottom_y + HEADER_UNDERLINE_OFFSET
local obj = {
text = _G_Widget_.Text{
x = x,
y = y,
text = s,
font_size = HEADER_FONT_SIZE,
x_align = 'left',
y_align = 'top',
text_color = _G_Patterns_.HEADER_FG,
slant = HEADER_FONT_SLANT,
weight = HEADER_FONT_WEIGHT
},
bottom_y = bottom_y,
underline = _G_Widget_.Line{
p1 = {x = x, y = underline_y},
p2 = {x = x + w, y = underline_y},
thickness = HEADER_UNDERLINE_THICKNESS,
line_pattern = _G_Patterns_.HEADER_FG,
cap = HEADER_UNDERLINE_CAP
}
}
return obj
end
M.drawHeader = function(cr, header)
Text.draw(header.text, cr)
Line.draw(header.underline, cr)
end
--------------------------------------------------------------------------------
-- label plot
M.initThemedLabelPlot = function(x, y, w, h)
return _G_Widget_.LabelPlot{
x = x,
y = y,
width = w,
height = h,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
label_color = _G_Patterns_.INACTIVE_TEXT_FG,
}
end
--------------------------------------------------------------------------------
-- percent plot (label plot with percent signs and some indicator data above it)
M.initPercentPlot = function(x, y, w, h, spacing, label)
return {
label = _G_Widget_.Text{
x = x,
y = y,
text = label,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
},
value = _G_Widget_.CriticalText{
x = x + w,
y = y,
x_align = 'right',
append_end = '%',
critical_limit = '>80',
text_color = _G_Patterns_.PRIMARY_FG,
critical_color = _G_Patterns_.PRIMARY_FG,
},
plot = M.initThemedLabelPlot(x, y + spacing, w, h),
}
end
M.percent_plot_draw_static = function(pp, cr)
Text.draw(pp.label, cr)
LabelPlot.draw_static(pp.plot, cr)
end
M.percent_plot_draw_dynamic = function(pp, cr)
CriticalText.draw(pp.value, cr)
LabelPlot.draw_dynamic(pp.plot, cr)
end
M.percent_plot_set = function(pp, cr, value)
Text.set(pp.value, cr, math.floor(value))
LabelPlot.update(pp.plot, value * 0.01)
end
--------------------------------------------------------------------------------
-- scaled plot
M.initThemedScalePlot = function(x, y, w, h, f)
return _G_Widget_.ScalePlot{
x = x,
y = y,
width = w,
height = h,
y_label_func = f,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
label_color = _G_Patterns_.INACTIVE_TEXT_FG,
}
end
--------------------------------------------------------------------------------
-- scaled plot (with textual data above it)
M.initLabeledScalePlot = function(x, y, w, h, f, spacing, label)
return {
label = _G_Widget_.Text{
x = x,
y = y,
text = label,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
},
value = _G_Widget_.Text{
x = x + w,
y = y,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG
},
plot = M.initThemedScalePlot(x, y + spacing, w, h, f),
}
end
M.annotated_scale_plot_draw_static = function(asp, cr)
Text.draw(asp.label, cr)
end
M.annotated_scale_plot_draw_dynamic = function(asp, cr)
Text.draw(asp.value, cr)
ScalePlot.draw_dynamic(asp.plot, cr)
end
M.annotated_scale_plot_set = function(asp, cr, text_value, plot_value)
-- TODO this could be made more intelligent
Text.set(asp.value, cr, text_value)
ScalePlot.update(asp.plot, cr, plot_value)
end
--------------------------------------------------------------------------------
-- ring
M.initRing = function(x, y, r)
return _G_Widget_.Arc{
x = x,
y = y,
radius = r,
theta0 = 0,
theta1 = 360,
arc_pattern = _G_Patterns_.BORDER_FG
}
end
--------------------------------------------------------------------------------
-- ring with text data in the center
M.initTextRing = function(x, y, r, append_end, limit)
return {
ring = M.initRing(x, y, r),
value = _G_Widget_.CriticalText{
x = x,
y = y,
x_align = 'center',
y_align = 'center',
append_end = append_end,
critical_limit = limit,
text_color = _G_Patterns_.PRIMARY_FG,
critical_color = _G_Patterns_.CRITICAL_FG,
},
}
end
M.text_ring_draw_static = function(tr, cr)
Arc.draw(tr.ring, cr)
end
M.text_ring_draw_dynamic = function(tr, cr)
CriticalText.draw(tr.value, cr)
end
M.text_ring_set = function(tr, cr, value)
CriticalText.set(tr.value, cr, value)
end
--------------------------------------------------------------------------------
-- separator (eg a horizontal line)
M.initSeparator = function(x, y, w)
return _G_Widget_.Line{
p1 = {x = x, y = y},
p2 = {x = x + w, y = y},
line_pattern = _G_Patterns_.BORDER_FG,
}
end
--------------------------------------------------------------------------------
-- text row (label with a value, aligned as far apart as possible)
M.initTextRow = function(x, y, w, label)
return {
label = _G_Widget_.Text{
x = x,
y = y,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
text = label,
},
value = _G_Widget_.Text{
x = x + w,
y = y,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = "<NA>",
}
}
end
M.text_row_draw_static = function(row, cr)
Text.draw(row.label, cr)
end
M.text_row_draw_dynamic = function(row, cr)
Text.draw(row.value, cr)
end
M.text_row_set = function(row, cr, value)
Text.set(row.value, cr, value)
end
--------------------------------------------------------------------------------
-- text row with critical indicator
-- TODO add limit to this
M.initTextRowCrit = function(x, y, w, label, append_end)
return{
label = _G_Widget_.Text{
x = x,
y = y,
text = label,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
},
value = _G_Widget_.CriticalText{
x = x + w,
y = y,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
critical_color = _G_Patterns_.CRITICAL_FG,
append_end = append_end,
text = '<NA>',
}
}
end
M.text_row_crit_draw_static = M.text_row_draw_static
M.text_row_crit_draw_dynamic = function(row, cr)
CriticalText.draw(row.value, cr)
end
M.text_row_crit_set = function(row, cr, value)
CriticalText.set(row.value, cr, value)
end
--------------------------------------------------------------------------------
-- multiple text row separated by spacing
M.initTextRows = function(x, y, w, spacing, labels)
return {
labels = _G_Widget_.TextColumn{
x = x,
y = y,
spacing = spacing,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
table.unpack(labels),
},
values = _G_Widget_.TextColumn{
x = x + w,
y = y,
spacing = spacing,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
num_rows = #labels,
}
}
end
M.text_rows_draw_static = function(rows, cr)
TextColumn.draw(rows.labels, cr)
end
M.text_rows_draw_dynamic = function(rows, cr)
TextColumn.draw(rows.values, cr)
end
M.text_rows_set = function(rows, cr, i, value)
TextColumn.set(rows.values, cr, i, value)
end
--------------------------------------------------------------------------------
-- table
M.initTable = function(x, y, w, h, n, labels)
return _G_Widget_.Table{
x = x,
y = y,
width = w,
height = h,
num_rows = n,
body_color = _G_Patterns_.INACTIVE_TEXT_FG,
header_color = _G_Patterns_.PRIMARY_FG,
line_pattern = _G_Patterns_.BORDER_FG,
separator_pattern = _G_Patterns_.BORDER_FG,
table.unpack(labels),
}
end
--------------------------------------------------------------------------------
-- panel
M.initPanel = function(x, y, w, h)
return _G_Widget_.FillRect{
x = x + 0.5,
y = y + 0.5,
width = w,
height = h,
line_pattern = _G_Patterns_.BORDER_FG,
fill_pattern = _G_Patterns_.PANEL_BG,
}
end
return M

View File

@ -1,13 +1,11 @@
local M = {} local M = {}
local Patterns = require 'Patterns' local Patterns = require 'Patterns'
local Text = require 'Text'
local Line = require 'Line' local Line = require 'Line'
local TextColumn = require 'TextColumn' local TextColumn = require 'TextColumn'
local CompoundBar = require 'CompoundBar' local CompoundBar = require 'CompoundBar'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local __string_match = string.match
local _FS_PATHS_ = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"} local _FS_PATHS_ = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"}
local _MODULE_Y_ = 170 local _MODULE_Y_ = 170
@ -17,12 +15,12 @@ local _SEPARATOR_SPACING_ = 20
local FS_NUM = #_FS_PATHS_ local FS_NUM = #_FS_PATHS_
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
y = _MODULE_Y_, _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'FILE SYSTEMS' 'FILE SYSTEMS'
} )
local conky_used_perc = {} local conky_used_perc = {}
@ -30,34 +28,20 @@ for i, v in pairs(_FS_PATHS_) do
conky_used_perc[i] = '${fs_used_perc '..v..'}' conky_used_perc[i] = '${fs_used_perc '..v..'}'
end end
local smart = { local smart = Common.initTextRow(
label = _G_Widget_.Text{ _G_INIT_DATA_.RIGHT_X,
x = _G_INIT_DATA_.RIGHT_X, header.bottom_y,
y = header.bottom_y, _G_INIT_DATA_.SECTION_WIDTH,
text = 'SMART Daemon' 'SMART Daemon'
}, )
value = _G_Widget_.Text{
x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = header.bottom_y,
x_align = 'right',
text_color = Patterns.PRIMARY_FG,
text = '<smartd>',
}
}
local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_ local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_
local separator = _G_Widget_.Line{ local separator = Common.initSeparator(
p1 = { _G_INIT_DATA_.RIGHT_X,
x = _G_INIT_DATA_.RIGHT_X, _SEP_Y_,
y = _SEP_Y_, _G_INIT_DATA_.SECTION_WIDTH
}, )
p2 = {
x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = _SEP_Y_,
},
line_pattern = _G_Patterns_.BORDER_FG,
}
local _BAR_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ local _BAR_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
@ -77,6 +61,7 @@ local labels = _G_Widget_.TextColumn{
x = _G_INIT_DATA_.RIGHT_X, x = _G_INIT_DATA_.RIGHT_X,
y = _BAR_Y_, y = _BAR_Y_,
spacing = _SPACING_, spacing = _SPACING_,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
'root', 'root',
'boot', 'boot',
'home', 'home',
@ -95,7 +80,7 @@ _SEP_Y_ = nil
local update = function(cr) local update = function(cr)
local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n') local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n')
Text.set(smart.value, cr, (smart_pid == '') and 'Error' or 'Running') Common.text_row_set(smart, cr, (smart_pid == '') and 'Error' or 'Running')
for i = 1, FS_NUM do for i = 1, FS_NUM do
local percent = Util.conky_numeric(conky_used_perc[i]) local percent = Util.conky_numeric(conky_used_perc[i])
@ -104,10 +89,9 @@ local update = function(cr)
end end
local draw_static = function(cr) local draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr)
Text.draw(smart.label, cr) Common.text_row_draw_static(smart, cr)
Line.draw(separator, cr) Line.draw(separator, cr)
TextColumn.draw(labels, cr) TextColumn.draw(labels, cr)
@ -117,7 +101,7 @@ end
local draw_dynamic = function(cr, trigger) local draw_dynamic = function(cr, trigger)
if trigger == 0 then update(cr) end if trigger == 0 then update(cr) end
Text.draw(smart.value, cr) Common.text_row_draw_dynamic(smart, cr)
CompoundBar.draw_dynamic(bars, cr) CompoundBar.draw_dynamic(bars, cr)
end end

View File

@ -1,13 +1,11 @@
local M = {} local M = {}
local CriticalText = require 'CriticalText'
local Text = require 'Text' local Text = require 'Text'
local TextColumn = require 'TextColumn'
local Line = require 'Line' local Line = require 'Line'
local LabelPlot = require 'LabelPlot' local LabelPlot = require 'LabelPlot'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local __tonumber = tonumber
local __string_match = string.match local __string_match = string.match
local _MODULE_Y_ = 145 local _MODULE_Y_ = 145
@ -16,171 +14,96 @@ local _TEXT_SPACING_ = 20
local _PLOT_SEC_BREAK_ = 20 local _PLOT_SEC_BREAK_ = 20
local _PLOT_HEIGHT_ = 56 local _PLOT_HEIGHT_ = 56
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.LEFT_X, _G_INIT_DATA_.LEFT_X,
y = _MODULE_Y_, _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'NVIDIA GRAPHICS' 'NVIDIA GRAPHICS'
} )
local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH local status = Common.initTextRow(
_G_INIT_DATA_.LEFT_X,
local status = { header.bottom_y,
label = _G_Widget_.Text{ _G_INIT_DATA_.SECTION_WIDTH,
x = _G_INIT_DATA_.LEFT_X, 'Status'
y = header.bottom_y, )
text = 'Status'
},
value = _G_Widget_.Text{
x = _RIGHT_X_,
y = header.bottom_y,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = '<status>'
}
}
local _SEP_Y_1_ = header.bottom_y + _SEPARATOR_SPACING_ local _SEP_Y_1_ = header.bottom_y + _SEPARATOR_SPACING_
local separator1 = _G_Widget_.Line{ local separator1 = Common.initSeparator(
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_1_}, _G_INIT_DATA_.LEFT_X,
p2 = {x = _RIGHT_X_, y = _SEP_Y_1_}, _SEP_Y_1_,
line_pattern = _G_Patterns_.BORDER_FG, _G_INIT_DATA_.SECTION_WIDTH
} )
local _INTERNAL_TEMP_Y_ = _SEP_Y_1_ + _SEPARATOR_SPACING_ local _INTERNAL_TEMP_Y_ = _SEP_Y_1_ + _SEPARATOR_SPACING_
local internal_temp = { local internal_temp = Common.initTextRowCrit(
label = _G_Widget_.Text{ _G_INIT_DATA_.LEFT_X,
x = _G_INIT_DATA_.LEFT_X, _INTERNAL_TEMP_Y_,
y = _INTERNAL_TEMP_Y_, _G_INIT_DATA_.SECTION_WIDTH,
text = 'Internal Temperature' 'Internal Temperature',
}, '°C'
value = _G_Widget_.CriticalText{ )
x = _RIGHT_X_,
y = _INTERNAL_TEMP_Y_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = '<gpu_temp>'
}
}
local _SEP_Y_2_ = _INTERNAL_TEMP_Y_ + _SEPARATOR_SPACING_ local _SEP_Y_2_ = _INTERNAL_TEMP_Y_ + _SEPARATOR_SPACING_
local separator2 = _G_Widget_.Line{ local separator2 = Common.initSeparator(
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_2_}, _G_INIT_DATA_.LEFT_X,
p2 = {x = _RIGHT_X_, y = _SEP_Y_2_}, _SEP_Y_2_,
line_pattern = _G_Patterns_.BORDER_FG, _G_INIT_DATA_.SECTION_WIDTH
} )
local _CLOCK_SPEED_Y_ = _SEP_Y_2_ + _SEPARATOR_SPACING_ local _CLOCK_SPEED_Y_ = _SEP_Y_2_ + _SEPARATOR_SPACING_
local clock_speed = { local clock_speed = Common.initTextRows(
labels = _G_Widget_.TextColumn{ _G_INIT_DATA_.LEFT_X,
x = _G_INIT_DATA_.LEFT_X, _CLOCK_SPEED_Y_,
y = _CLOCK_SPEED_Y_, _G_INIT_DATA_.SECTION_WIDTH,
spacing = _TEXT_SPACING_, _TEXT_SPACING_,
'GPU Clock Speed', {'GPU Clock Speed', 'Memory Clock Speed'}
'Memory Clock Speed' )
},
values = _G_Widget_.TextColumn{
x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = _CLOCK_SPEED_Y_,
spacing = _TEXT_SPACING_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
num_rows = 2
}
}
local _SEP_Y_3_ = _CLOCK_SPEED_Y_ + _TEXT_SPACING_ * 2 local _SEP_Y_3_ = _CLOCK_SPEED_Y_ + _TEXT_SPACING_ * 2
local separator3 = _G_Widget_.Line{ local separator3 = Common.initSeparator(
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_3_}, _G_INIT_DATA_.LEFT_X,
p2 = {x = _RIGHT_X_, y = _SEP_Y_3_}, _SEP_Y_3_,
line_pattern = _G_Patterns_.BORDER_FG, _G_INIT_DATA_.SECTION_WIDTH
} )
local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_ local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_
local gpu_util = { local gpu_util = Common.initPercentPlot(
label = _G_Widget_.Text{ _G_INIT_DATA_.LEFT_X,
x = _G_INIT_DATA_.LEFT_X, _GPU_UTIL_Y_,
y = _GPU_UTIL_Y_, _G_INIT_DATA_.SECTION_WIDTH,
text = 'GPU Utilization' _PLOT_HEIGHT_,
}, _PLOT_SEC_BREAK_,
value = _G_Widget_.Text{ 'GPU Utilization'
x = _RIGHT_X_, )
y = _GPU_UTIL_Y_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = '<gpu_util>'
},
plot = _G_Widget_.LabelPlot{
x = _G_INIT_DATA_.LEFT_X,
y = _GPU_UTIL_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local mem_util = { local mem_util = Common.initPercentPlot(
label = _G_Widget_.Text{ _G_INIT_DATA_.LEFT_X,
x = _G_INIT_DATA_.LEFT_X, _MEM_UTIL_Y_,
y = _MEM_UTIL_Y_, _G_INIT_DATA_.SECTION_WIDTH,
text = 'Memory Utilization' _PLOT_HEIGHT_,
}, _PLOT_SEC_BREAK_,
value = _G_Widget_.Text{ 'Memory Utilization'
x = _RIGHT_X_, )
y = _MEM_UTIL_Y_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = '<mem_util>'
},
plot = _G_Widget_.LabelPlot{
x = _G_INIT_DATA_.LEFT_X,
y = _MEM_UTIL_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local vid_util = { local vid_util = Common.initPercentPlot(
label = _G_Widget_.Text{ _G_INIT_DATA_.LEFT_X,
x = _G_INIT_DATA_.LEFT_X, _VID_UTIL_Y_,
y = _VID_UTIL_Y_, _G_INIT_DATA_.SECTION_WIDTH,
text = 'Video Utilization' _PLOT_HEIGHT_,
}, _PLOT_SEC_BREAK_,
value = _G_Widget_.Text{ 'Video Utilization'
x = _RIGHT_X_, )
y = _VID_UTIL_Y_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = '<vid_util>'
},
plot = _G_Widget_.LabelPlot{
x = _G_INIT_DATA_.LEFT_X,
y = _VID_UTIL_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
--[[ --[[
vars to process the nv settings glob vars to process the nv settings glob
@ -208,10 +131,9 @@ local NV_REGEX = '(%d+)\n'..
local NA = 'N/A' local NA = 'N/A'
local nvidia_off = function(cr) local nvidia_off = function(cr)
CriticalText.set(internal_temp.value, cr, NA, false) Common.text_rows_crit_set(internal_temp, cr, NA)
Common.text_rows_set.set(clock_speed, cr, 1, NA)
TextColumn.set(clock_speed.values, cr, 1, NA) Common.text_rows_set.set(clock_speed, cr, 2, NA)
TextColumn.set(clock_speed.values, cr, 2, NA)
Text.set(gpu_util.value, cr, NA) Text.set(gpu_util.value, cr, NA)
Text.set(mem_util.value, cr, NA) Text.set(mem_util.value, cr, NA)
@ -231,29 +153,19 @@ local update = function(cr)
Text.set(status.value, cr, 'Error') Text.set(status.value, cr, 'Error')
nvidia_off(cr) nvidia_off(cr)
else else
Text.set(status.value, cr, 'On') Common.text_row_set(status, cr, 'On')
local used_memory, total_memory, temp_reading, gpu_frequency, local used_memory, total_memory, temp_reading, gpu_frequency,
memory_frequency, gpu_utilization, vid_utilization memory_frequency, gpu_utilization, vid_utilization
= __string_match(nvidia_settings_glob, NV_REGEX) = __string_match(nvidia_settings_glob, NV_REGEX)
local is_critical = false Common.text_row_crit_set(internal_temp, cr, temp_reading)
if __tonumber(temp_reading) > 80 then is_critical = true end Common.text_rows_set(clock_speed, cr, 1, gpu_frequency..' Mhz')
Common.text_rows_set(clock_speed, cr, 2, memory_frequency..' Mhz')
CriticalText.set(internal_temp.value, cr, temp_reading..'°C', is_critical) Common.percent_plot_set(gpu_util, cr, gpu_utilization)
Common.percent_plot_set(mem_util, cr, used_memory / total_memory * 100)
TextColumn.set(clock_speed.values, cr, 1, gpu_frequency..' Mhz') Common.percent_plot_set(vid_util, cr, vid_utilization)
TextColumn.set(clock_speed.values, cr, 2, memory_frequency..' Mhz')
local percent_used_memory = used_memory / total_memory
Text.set(gpu_util.value, cr, gpu_utilization..'%')
Text.set(mem_util.value, cr, Util.round_to_string(percent_used_memory * 100)..'%')
Text.set(vid_util.value, cr, vid_utilization..'%')
LabelPlot.update(gpu_util.plot, gpu_utilization * 0.01)
LabelPlot.update(mem_util.plot, percent_used_memory)
LabelPlot.update(vid_util.plot, vid_utilization * 0.01)
end end
else else
Text.set(status.value, cr, 'Off') Text.set(status.value, cr, 'Off')
@ -266,7 +178,6 @@ _SEPARATOR_SPACING_ = nil
_TEXT_SPACING_ = nil _TEXT_SPACING_ = nil
_PLOT_SEC_BREAK_ = nil _PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil _PLOT_HEIGHT_ = nil
_RIGHT_X_ = nil
_SEP_Y_1_ = nil _SEP_Y_1_ = nil
_SEP_Y_2_ = nil _SEP_Y_2_ = nil
_SEP_Y_3_ = nil _SEP_Y_3_ = nil
@ -276,47 +187,32 @@ _GPU_UTIL_Y_ = nil
_MEM_UTIL_Y_ = nil _MEM_UTIL_Y_ = nil
_VID_UTIL_Y_ = nil _VID_UTIL_Y_ = nil
local draw_static = function(cr) M.draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr)
Text.draw(status.label, cr) Common.text_row_draw_static(status, cr)
Line.draw(separator1, cr) Line.draw(separator1, cr)
Text.draw(internal_temp.label, cr) Common.text_row_crit_draw_static(internal_temp, cr)
Line.draw(separator2, cr) Line.draw(separator2, cr)
TextColumn.draw(clock_speed.labels, cr) Common.text_rows_draw_static(clock_speed, cr)
Line.draw(separator3, cr) Line.draw(separator3, cr)
Text.draw(gpu_util.label, cr) Common.percent_plot_draw_static(gpu_util, cr)
LabelPlot.draw_static(gpu_util.plot, cr) Common.percent_plot_draw_static(mem_util, cr)
Common.percent_plot_draw_static(vid_util, cr)
Text.draw(mem_util.label, cr)
LabelPlot.draw_static(mem_util.plot, cr)
Text.draw(vid_util.label, cr)
LabelPlot.draw_static(vid_util.plot, cr)
end end
local draw_dynamic = function(cr) M.draw_dynamic = function(cr)
update(cr) update(cr)
Text.draw(status.value, cr) Common.text_row_draw_dynamic(status, cr)
Text.draw(internal_temp.value, cr) Common.text_row_crit_draw_dynamic(internal_temp, cr)
TextColumn.draw(clock_speed.values, cr) Common.text_rows_draw_dynamic(clock_speed, cr)
Common.percent_plot_draw_dynamic(gpu_util, cr)
Text.draw(gpu_util.value, cr) Common.percent_plot_draw_dynamic(mem_util, cr)
LabelPlot.draw_dynamic(gpu_util.plot, cr) Common.percent_plot_draw_dynamic(vid_util, cr)
Text.draw(mem_util.value, cr)
LabelPlot.draw_dynamic(mem_util.plot, cr)
Text.draw(vid_util.value, cr)
LabelPlot.draw_dynamic(vid_util.plot, cr)
end end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M return M

View File

@ -2,21 +2,17 @@ local M = {}
local Arc = require 'Arc' local Arc = require 'Arc'
local Dial = require 'Dial' local Dial = require 'Dial'
local CriticalText = require 'CriticalText'
local Text = require 'Text'
local TextColumn = require 'TextColumn' local TextColumn = require 'TextColumn'
local Line = require 'Line'
local LabelPlot = require 'LabelPlot' local LabelPlot = require 'LabelPlot'
local Table = require 'Table' local Table = require 'Table'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local __string_match = string.match local __string_match = string.match
local __cairo_path_destroy = cairo_path_destroy local __cairo_path_destroy = cairo_path_destroy
local __io_popen = io.popen
local _MODULE_Y_ = 712 local _MODULE_Y_ = 712
local _DIAL_THICKNESS_ = 8 local _DIAL_THICKNESS_ = 8
local _DIAL_SPACING_ = 1
local _TEXT_Y_OFFSET_ = 7 local _TEXT_Y_OFFSET_ = 7
local _TEXT_LEFT_X_OFFSET_ = 30 local _TEXT_LEFT_X_OFFSET_ = 30
local _TEXT_SPACING_ = 20 local _TEXT_SPACING_ = 20
@ -45,12 +41,12 @@ for r = 1, NUM_ROWS do
TABLE_CONKY[r].mem = '${top_mem mem '..r..'}' TABLE_CONKY[r].mem = '${top_mem mem '..r..'}'
end end
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
y = _MODULE_Y_, _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'MEMORY' 'MEMORY'
} )
local DIAL_RADIUS = 32 local DIAL_RADIUS = 32
local DIAL_THETA_0 = math.rad(90) local DIAL_THETA_0 = math.rad(90)
@ -75,47 +71,33 @@ local cache_arc = _G_Widget_.Arc{
arc_pattern = _G_Patterns_.INDICATOR_FG_SECONDARY arc_pattern = _G_Patterns_.INDICATOR_FG_SECONDARY
} }
local total_used = _G_Widget_.CriticalText{ local text_ring = Common.initTextRing(
x = DIAL_X, DIAL_X,
y = DIAL_Y, DIAL_Y,
x_align = 'center', DIAL_RADIUS - _DIAL_THICKNESS_ / 2 - 2,
y_align = 'center', '%',
append_end = '%' '>80'
} )
local inner_ring = _G_Widget_.Arc{
x = DIAL_X,
y = DIAL_Y,
radius = DIAL_RADIUS - _DIAL_THICKNESS_ / 2 - 2,
theta0 = 0,
theta1 = 360,
arc_pattern = _G_Patterns_.BORDER_FG
}
local _LINE_1_Y_ = header.bottom_y + _TEXT_Y_OFFSET_ local _LINE_1_Y_ = header.bottom_y + _TEXT_Y_OFFSET_
local _TEXT_LEFT_X_ = _G_INIT_DATA_.RIGHT_X + DIAL_RADIUS * 2 + _TEXT_LEFT_X_OFFSET_ local _TEXT_LEFT_X_ = _G_INIT_DATA_.RIGHT_X + DIAL_RADIUS * 2 + _TEXT_LEFT_X_OFFSET_
local _RIGHT_X_ = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH local _RIGHT_X_ = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH
local swap= { local swap = Common.initTextRowCrit(
label = _G_Widget_.Text{ _TEXT_LEFT_X_,
x = _TEXT_LEFT_X_, _LINE_1_Y_,
y = _LINE_1_Y_, -- TODO this is silly
spacing = _TEXT_SPACING_, _RIGHT_X_ - _TEXT_LEFT_X_,
text = 'Swap Usage' 'Swap Usage',
}, ' %'
percent = _G_Widget_.CriticalText{ )
x = _RIGHT_X_,
y = _LINE_1_Y_,
x_align = 'right',
append_end = ' %',
},
}
local cache = { local cache = {
labels = _G_Widget_.TextColumn{ labels = _G_Widget_.TextColumn{
x = _TEXT_LEFT_X_, x = _TEXT_LEFT_X_,
y = _LINE_1_Y_ + _TEXT_SPACING_, y = _LINE_1_Y_ + _TEXT_SPACING_,
spacing = _TEXT_SPACING_, spacing = _TEXT_SPACING_,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
'Page Cache', 'Page Cache',
'Buffers', 'Buffers',
'Kernel Slab' 'Kernel Slab'
@ -134,30 +116,21 @@ local cache = {
local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2 local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2
local plot = _G_Widget_.LabelPlot{ local plot = Common.initThemedLabelPlot(
x = _G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
y = _PLOT_Y_, _PLOT_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_, _PLOT_HEIGHT_
outline_pattern = _G_Patterns_.BORDER_FG, )
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
local tbl = _G_Widget_.Table{ local tbl = Common.initTable(
x = _G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
y = _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_, _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
height = _TABLE_HEIGHT_, _TABLE_HEIGHT_,
body_color = _G_Patterns_.INACTIVE_TEXT_FG, NUM_ROWS,
header_color = _G_Patterns_.PRIMARY_FG, {'Name', 'PID', 'Mem (%)'}
line_pattern = _G_Patterns_.BORDER_FG, )
separator_pattern = _G_Patterns_.BORDER_FG,
'Name',
'PID',
'Mem (%)'
}
local update = function(cr) local update = function(cr)
local conky = Util.conky local conky = Util.conky
@ -169,14 +142,16 @@ local update = function(cr)
local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB
Dial.set(dial, used_percent) Dial.set(dial, used_percent)
CriticalText.set(total_used, cr, Util.round_to_string(used_percent * 100)) Common.text_ring_set(text_ring, cr, Util.round_to_string(used_percent * 100))
local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / MEM_TOTAL_KB * memfree_kb + DIAL_THETA_1 local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / MEM_TOTAL_KB * memfree_kb + DIAL_THETA_1
__cairo_path_destroy(cache_arc.path) __cairo_path_destroy(cache_arc.path)
cache_arc.path = Arc.create_path(cr, DIAL_X, DIAL_Y, DIAL_RADIUS, dial.dial_angle, cache_theta) cache_arc.path = Arc.create_path(cr, DIAL_X, DIAL_Y, DIAL_RADIUS, dial.dial_angle, cache_theta)
CriticalText.set(swap.percent, cr, Util.precision_round_to_string( Common.text_row_crit_set(swap, cr,
(swap_total_kb - swap_free_kb) / swap_total_kb * 100)) Util.precision_round_to_string(
(swap_total_kb - swap_free_kb)
/ swap_total_kb * 100))
local _percents = cache.percents local _percents = cache.percents
@ -216,28 +191,27 @@ _TEXT_LEFT_X_ = nil
_RIGHT_X_ = nil _RIGHT_X_ = nil
_PLOT_Y_ = nil _PLOT_Y_ = nil
local draw_static = function(cr) M.draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr)
Arc.draw(inner_ring, cr) Common.text_ring_draw_static(text_ring, cr)
Dial.draw_static(dial, cr) Dial.draw_static(dial, cr)
Text.draw(swap.label, cr) Common.text_row_crit_draw_static(swap, cr)
TextColumn.draw(cache.labels, cr) TextColumn.draw(cache.labels, cr)
LabelPlot.draw_static(plot, cr) LabelPlot.draw_static(plot, cr)
Table.draw_static(tbl, cr) Table.draw_static(tbl, cr)
end end
local draw_dynamic = function(cr) M.draw_dynamic = function(cr)
update(cr) update(cr)
Dial.draw_dynamic(dial, cr) Dial.draw_dynamic(dial, cr)
Arc.draw(cache_arc, cr) Arc.draw(cache_arc, cr)
CriticalText.draw(total_used, cr) Common.text_ring_draw_dynamic(text_ring, cr)
CriticalText.draw(swap.percent, cr) Common.text_row_crit_draw_dynamic(swap, cr)
TextColumn.draw(cache.percents, cr) TextColumn.draw(cache.percents, cr)
LabelPlot.draw_dynamic(plot, cr) LabelPlot.draw_dynamic(plot, cr)
@ -245,7 +219,4 @@ local draw_dynamic = function(cr)
Table.draw_dynamic(tbl, cr) Table.draw_dynamic(tbl, cr)
end end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M return M

View File

@ -1,9 +1,7 @@
local M = {} local M = {}
local Text = require 'Text'
local Line = require 'Line'
local ScalePlot = require 'ScalePlot'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local __string_gmatch = string.gmatch local __string_gmatch = string.gmatch
@ -16,66 +14,32 @@ local network_label_function = function(bits)
return Util.round_to_string(new_value, precision)..' '..new_unit..'b/s' return Util.round_to_string(new_value, precision)..' '..new_unit..'b/s'
end end
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.CENTER_RIGHT_X, _G_INIT_DATA_.CENTER_RIGHT_X,
y = _G_INIT_DATA_.TOP_Y, _G_INIT_DATA_.TOP_Y,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'NETWORK' 'NETWORK'
} )
local _RIGHT_X_ = _G_INIT_DATA_.CENTER_RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH local dnload = Common.initLabeledScalePlot(
_G_INIT_DATA_.CENTER_RIGHT_X,
header.bottom_y,
_G_INIT_DATA_.SECTION_WIDTH,
_PLOT_HEIGHT_,
network_label_function,
_PLOT_SEC_BREAK_,
'Download'
)
local dnload = { local upload = Common.initLabeledScalePlot(
label = _G_Widget_.Text{ _G_INIT_DATA_.CENTER_RIGHT_X,
x = _G_INIT_DATA_.CENTER_RIGHT_X, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
y = header.bottom_y, _G_INIT_DATA_.SECTION_WIDTH,
text = 'Download', _PLOT_HEIGHT_,
}, network_label_function,
speed = _G_Widget_.Text{ _PLOT_SEC_BREAK_,
x = _RIGHT_X_, 'Upload'
y = header.bottom_y, )
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG
},
plot = _G_Widget_.ScalePlot{
x = _G_INIT_DATA_.CENTER_RIGHT_X,
y = header.bottom_y + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
y_label_func = network_label_function,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
local _UPLOAD_Y_ = header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local upload = {
label = _G_Widget_.Text{
x = _G_INIT_DATA_.CENTER_RIGHT_X,
y = _UPLOAD_Y_,
text = 'Upload',
},
speed = _G_Widget_.Text{
x = _RIGHT_X_,
y = _UPLOAD_Y_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG
},
plot = _G_Widget_.ScalePlot{
x = _G_INIT_DATA_.CENTER_RIGHT_X,
y = _UPLOAD_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
y_label_func = network_label_function,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
local interface_counters_tbl = {} local interface_counters_tbl = {}
@ -125,37 +89,33 @@ local update = function(cr, update_frequency)
local dspeed_unit, dspeed_value = Util.convert_data_val(dspeed) local dspeed_unit, dspeed_value = Util.convert_data_val(dspeed)
local uspeed_unit, uspeed_value = Util.convert_data_val(uspeed) local uspeed_unit, uspeed_value = Util.convert_data_val(uspeed)
dnload.speed.append_end = ' '..dspeed_unit..'b/s' Common.annotated_scale_plot_set(
upload.speed.append_end = ' '..uspeed_unit..'b/s' dnload,
cr,
Text.set(dnload.speed, cr, Util.precision_round_to_string(dspeed_value, 3)) Util.precision_round_to_string(dspeed_value, 3)..' '..dspeed_unit..'b/s',
Text.set(upload.speed, cr, Util.precision_round_to_string(uspeed_value, 3)) dspeed
)
ScalePlot.update(dnload.plot, cr, dspeed) Common.annotated_scale_plot_set(
ScalePlot.update(upload.plot, cr, uspeed) upload,
cr,
Util.precision_round_to_string(uspeed_value, 3)..' '..uspeed_unit..'b/s',
uspeed
)
end end
_PLOT_SEC_BREAK_ = nil _PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil _PLOT_HEIGHT_ = nil
_RIGHT_X_ = nil
_UPLOAD_Y_ = nil
local draw_static = function(cr) local draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr) Common.annotated_scale_plot_draw_static(dnload, cr)
Common.annotated_scale_plot_draw_static(upload, cr)
Text.draw(dnload.label, cr)
Text.draw(upload.label, cr)
end end
local draw_dynamic = function(cr, update_frequency) local draw_dynamic = function(cr, update_frequency)
update(cr, update_frequency) update(cr, update_frequency)
Common.annotated_scale_plot_draw_dynamic(dnload, cr)
Text.draw(dnload.speed, cr) Common.annotated_scale_plot_draw_dynamic(upload, cr)
ScalePlot.draw_dynamic(dnload.plot, cr)
Text.draw(upload.speed, cr)
ScalePlot.draw_dynamic(upload.plot, cr)
end end
M.draw_static = draw_static M.draw_static = draw_static

View File

@ -1,40 +1,26 @@
local M = {} local M = {}
local Text = require 'Text' local Common = require 'Common'
local Line = require 'Line'
local TextColumn = require 'TextColumn'
local Util = require 'Util'
local __string_match = string.match local __string_match = string.match
local __string_gmatch = string.gmatch local __string_gmatch = string.gmatch
local _TEXT_SPACING_ = 20 local _TEXT_SPACING_ = 20
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
y = _G_INIT_DATA_.TOP_Y, _G_INIT_DATA_.TOP_Y,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'PACMAN' 'PACMAN'
} )
local labels = _G_Widget_.TextColumn{ local rows = Common.initTextRows(
x = _G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
y = header.bottom_y, header.bottom_y,
spacing = _TEXT_SPACING_, _G_INIT_DATA_.SECTION_WIDTH,
'Total', _TEXT_SPACING_,
'Explicit', {'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'}
'Outdated', )
'Orphaned',
'Local'
}
local info = _G_Widget_.TextColumn{
x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = header.bottom_y,
spacing = _TEXT_SPACING_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
num_rows = 5
}
_TEXT_SPACING_ = nil _TEXT_SPACING_ = nil
@ -43,28 +29,24 @@ local update = function(cr, pacman_stats)
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
TextColumn.set(info, cr, i, v) Common.text_rows_set(rows, cr, i, v)
i = i + 1 i = i + 1
end end
else else
for i=1,5 do for i=1, 5 do
TextColumn.set(info, cr, i, 'N/A') Common.text_rows_set(rows, cr, i, 'N/A')
end end
end end
end end
local draw_static = function(cr) M.draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr) Common.text_rows_draw_static(rows, cr)
TextColumn.draw(labels, cr)
end end
local draw_dynamic = function(cr, pacman_stats) M.draw_dynamic = function(cr, pacman_stats)
update(cr, pacman_stats) update(cr, pacman_stats)
TextColumn.draw(info, cr) Common.text_rows_draw_dynamic(rows, cr)
end end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M return M

View File

@ -1,11 +1,7 @@
local M = {} local M = {}
local Patterns = require 'Patterns'
local Text = require 'Text'
local TextColumn = require 'TextColumn'
local Line = require 'Line'
local ScalePlot = require 'ScalePlot'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local _MODULE_Y_ = 380 local _MODULE_Y_ = 380
local _TEXT_SPACING_ = 20 local _TEXT_SPACING_ = 20
@ -14,7 +10,7 @@ local _PLOT_HEIGHT_ = 56
local power_label_function = function(watts) return watts..' W' end local power_label_function = function(watts) return watts..' W' end
local calculate_power = function(cr, prev_cnt, cnt, update_frequency) local calculate_power = function(prev_cnt, cnt, update_frequency)
if cnt > prev_cnt then if cnt > prev_cnt then
return (cnt - prev_cnt) * update_frequency * 0.000001 return (cnt - prev_cnt) * update_frequency * 0.000001
else else
@ -22,97 +18,46 @@ local calculate_power = function(cr, prev_cnt, cnt, update_frequency)
end end
end end
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
y = _MODULE_Y_, _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'POWER' 'POWER'
} )
local _RIGHT_X_ = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH local pkg0 = Common.initLabeledScalePlot(
_G_INIT_DATA_.RIGHT_X,
local pkg0 = { header.bottom_y,
label = _G_Widget_.Text{ _G_INIT_DATA_.SECTION_WIDTH,
x = _G_INIT_DATA_.RIGHT_X, _PLOT_HEIGHT_,
y = header.bottom_y, power_label_function,
text = 'PKG0', _PLOT_SEC_BREAK_,
}, 'PKG0'
value = _G_Widget_.Text{ )
x = _RIGHT_X_, pkg0.value.append_end = ' W'
y = header.bottom_y,
x_align = 'right',
text_color = Patterns.PRIMARY_FG,
text = '<core>',
append_end = ' W',
},
plot = _G_Widget_.ScalePlot{
x = _G_INIT_DATA_.RIGHT_X,
y = header.bottom_y + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
y_label_func = power_label_function,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
},
}
local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_ local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_
local dram = { local dram = Common.initLabeledScalePlot(
label = _G_Widget_.Text{ _G_INIT_DATA_.RIGHT_X,
x = _G_INIT_DATA_.RIGHT_X, _CORE_Y_,
y = _CORE_Y_, _G_INIT_DATA_.SECTION_WIDTH,
text = 'DRAM' _PLOT_HEIGHT_,
}, power_label_function,
value = _G_Widget_.Text{ _PLOT_SEC_BREAK_,
x = _RIGHT_X_, 'DRAM'
y = _CORE_Y_, )
x_align = 'right', dram.value.append_end = ' W'
text_color = _G_Patterns_.PRIMARY_FG,
text = '<dram>',
append_end = ' W'
},
plot = _G_Widget_.ScalePlot{
x = _G_INIT_DATA_.RIGHT_X,
y = _CORE_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
y_label_func = power_label_function,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
local _BATTERY_DRAW_Y_ = _CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_ local battery_draw = Common.initLabeledScalePlot(
_G_INIT_DATA_.RIGHT_X,
local battery_draw = { _CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_,
label = _G_Widget_.Text{ _G_INIT_DATA_.SECTION_WIDTH,
x = _G_INIT_DATA_.RIGHT_X, _PLOT_HEIGHT_,
y = _BATTERY_DRAW_Y_, power_label_function,
spacing = _TEXT_SPACING_, _PLOT_SEC_BREAK_,
text = 'Battery Draw' 'Battery Draw'
}, )
value = _G_Widget_.CriticalText{
x = _RIGHT_X_,
y = _BATTERY_DRAW_Y_,
x_align = 'right',
},
plot = _G_Widget_.ScalePlot{
x = _G_INIT_DATA_.RIGHT_X,
y = _BATTERY_DRAW_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
y_label_func = power_label_function,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj' local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj' local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
@ -124,66 +69,46 @@ local update = function(cr, update_frequency, is_using_ac)
local pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n') local pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
local dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n') local dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n')
local pkg0_power = calculate_power(cr, prev_pkg0_uj_cnt, pkg0_uj_cnt, update_frequency) local pkg0_power = calculate_power(prev_pkg0_uj_cnt, pkg0_uj_cnt, update_frequency)
Text.set(pkg0.value, cr, Util.precision_round_to_string(pkg0_power, 3)) Common.annotated_scale_plot_set(pkg0, cr, Util.precision_round_to_string(pkg0_power, 3), pkg0_power)
ScalePlot.update(pkg0.plot, cr, pkg0_power) local dram_power = calculate_power(prev_dram_uj_cnt, dram_uj_cnt, update_frequency)
local dram_power = calculate_power(cr, prev_dram_uj_cnt, dram_uj_cnt, update_frequency) Common.annotated_scale_plot_set(dram, cr, Util.precision_round_to_string(dram_power, 3), dram_power)
Text.set(dram.value, cr, Util.precision_round_to_string(dram_power, 3))
ScalePlot.update(dram.plot, cr, dram_power)
prev_pkg0_uj_cnt = pkg0_uj_cnt prev_pkg0_uj_cnt = pkg0_uj_cnt
prev_dram_uj_cnt = dram_uj_cnt prev_dram_uj_cnt = dram_uj_cnt
if is_using_ac then if is_using_ac then
Text.set(battery_draw.value, cr, 'A/C') Common.annotated_scale_plot_set(battery_draw, cr, 'A/C', 0)
ScalePlot.update(battery_draw.plot, cr, 0)
else else
local current = Util.read_file('/sys/class/power_supply/BAT0/current_now', nil, '*n') local current = Util.read_file('/sys/class/power_supply/BAT0/current_now', nil, '*n')
local voltage = Util.read_file('/sys/class/power_supply/BAT0/voltage_now', nil, '*n') local voltage = Util.read_file('/sys/class/power_supply/BAT0/voltage_now', nil, '*n')
local power = current * voltage * 0.000000000001 local power = current * voltage * 0.000000000001
local t = Util.precision_round_to_string(power, 3)..' W'
Text.set(battery_draw.value, cr, Util.precision_round_to_string(power, 3)..' W') Common.annotated_scale_plot_set(battery_draw, cr, t, power)
ScalePlot.update(battery_draw.plot, cr, power)
end end
end end
Patterns = nil
_MODULE_Y_ = nil _MODULE_Y_ = nil
_TEXT_SPACING_ = nil _TEXT_SPACING_ = nil
_PLOT_SEC_BREAK_ = nil _PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil _PLOT_HEIGHT_ = nil
_RIGHT_X_ = nil
_CORE_Y_ = nil _CORE_Y_ = nil
_BATTERY_DRAW_Y_ = nil
local draw_static = function(cr) M.draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr) Common.annotated_scale_plot_draw_static(pkg0, cr)
Common.annotated_scale_plot_draw_static(dram, cr)
Text.draw(pkg0.label, cr) Common.annotated_scale_plot_draw_static(battery_draw, cr)
Text.draw(dram.label, cr)
Text.draw(battery_draw.label, cr)
end end
local draw_dynamic = function(cr, update_frequency, is_using_ac) M.draw_dynamic = function(cr, update_frequency, is_using_ac)
update(cr, update_frequency, is_using_ac) update(cr, update_frequency, is_using_ac)
Common.annotated_scale_plot_draw_dynamic(pkg0, cr)
Text.draw(pkg0.value, cr) Common.annotated_scale_plot_draw_dynamic(dram, cr)
ScalePlot.draw_dynamic(pkg0.plot, cr) Common.annotated_scale_plot_draw_dynamic(battery_draw, cr)
Text.draw(dram.value, cr)
ScalePlot.draw_dynamic(dram.plot, cr)
Text.draw(battery_draw.value, cr)
ScalePlot.draw_dynamic(battery_draw.plot, cr)
end end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M return M

View File

@ -1,15 +1,10 @@
local M = {} local M = {}
local Arc = require 'Arc'
local CompoundDial = require 'CompoundDial' local CompoundDial = require 'CompoundDial'
local CriticalText = require 'CriticalText'
local Text = require 'Text'
local Line = require 'Line' local Line = require 'Line'
local LabelPlot = require 'LabelPlot'
local Table = require 'Table' local Table = require 'Table'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local __string_format = string.format
local CORETEMP_PATH = '/sys/devices/platform/coretemp.0/hwmon/hwmon%i/%s' local CORETEMP_PATH = '/sys/devices/platform/coretemp.0/hwmon/hwmon%i/%s'
@ -72,34 +67,25 @@ local _create_core_ = function(cores, id, x, y)
dial_pattern = _G_Patterns_.INDICATOR_FG_PRIMARY, dial_pattern = _G_Patterns_.INDICATOR_FG_PRIMARY,
arc_pattern = _G_Patterns_.INDICATOR_BG arc_pattern = _G_Patterns_.INDICATOR_BG
}, },
inner_ring = _G_Widget_.Arc{ text_ring = Common.initTextRing(
x = x, x,
y = y, y,
radius = _DIAL_INNER_RADIUS_ - 2, _DIAL_INNER_RADIUS_ - 2,
theta0 = 0, '°C',
theta1 = 360, '>90'
arc_pattern = _G_Patterns_.BORDER_FG ),
},
coretemp_text = _G_Widget_.CriticalText{
x = x,
y = y,
x_align = 'center',
y_align = 'center',
append_end = '°C',
critical_limit = '>90'
},
coretemp_path = string.format(CORETEMP_PATH, hwmon_index, 'temp'..(id + 2)..'_input'), coretemp_path = string.format(CORETEMP_PATH, hwmon_index, 'temp'..(id + 2)..'_input'),
conky_loads = conky_loads, conky_loads = conky_loads,
conky_freqs = conky_freqs conky_freqs = conky_freqs
} }
end end
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.LEFT_X, _G_INIT_DATA_.LEFT_X,
y = _MODULE_Y_, _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'PROCESSOR' 'PROCESSOR'
} )
--we assume that this cpu has 4 physical cores with 2 logical each --we assume that this cpu has 4 physical cores with 2 logical each
local cores = {} local cores = {}
@ -111,98 +97,50 @@ for c = 0, NUM_PHYSICAL_CORES - 1 do
_create_core_(cores, c, dial_x, dial_y) _create_core_(cores, c, dial_x, dial_y)
end end
local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH
local _HWP_Y_ = header.bottom_y + _DIAL_OUTER_RADIUS_ * 2 + _PLOT_SECTION_BREAK_ local _HWP_Y_ = header.bottom_y + _DIAL_OUTER_RADIUS_ * 2 + _PLOT_SECTION_BREAK_
local hwp = {
label = _G_Widget_.Text{
x = _G_INIT_DATA_.LEFT_X,
y = _HWP_Y_,
text = 'HWP Preference'
},
value = _G_Widget_.Text{
x = _RIGHT_X_,
y = _HWP_Y_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = '<hwp_pref>'
}
}
local _FREQ_Y_ = _HWP_Y_ + _TEXT_SPACING_ local _FREQ_Y_ = _HWP_Y_ + _TEXT_SPACING_
local ave_freq = { local cpu_status = Common.initTextRows(
label = _G_Widget_.Text{ _G_INIT_DATA_.LEFT_X,
x = _G_INIT_DATA_.LEFT_X, _HWP_Y_,
y = _FREQ_Y_, _G_INIT_DATA_.SECTION_WIDTH,
text = 'Ave Freq' _TEXT_SPACING_,
}, {'HWP Preference', 'Ave Freq'}
value = _G_Widget_.Text{ )
x = _RIGHT_X_,
y = _FREQ_Y_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
text = '<freq>'
}
}
local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_ local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_
local separator = _G_Widget_.Line{ local separator = Common.initSeparator(
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_}, _G_INIT_DATA_.LEFT_X,
p2 = {x = _RIGHT_X_, y = _SEP_Y_}, _SEP_Y_,
line_pattern = _G_Patterns_.BORDER_FG, _G_INIT_DATA_.SECTION_WIDTH
} )
local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
local total_load = {
label = _G_Widget_.Text{
x = _G_INIT_DATA_.LEFT_X,
y = _LOAD_Y_,
text = 'Total Load'
},
value = _G_Widget_.CriticalText{
x = _RIGHT_X_,
y = _LOAD_Y_,
x_align = 'right',
append_end = '%',
critical_limit = '>80'
}
}
local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_ local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_
local plot = _G_Widget_.LabelPlot{ local total_load = Common.initPercentPlot(
x = _G_INIT_DATA_.LEFT_X, _G_INIT_DATA_.LEFT_X,
y = _PLOT_Y_, _LOAD_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_, _PLOT_HEIGHT_,
outline_pattern = _G_Patterns_.BORDER_FG, _PLOT_SECTION_BREAK_,
intrvl_pattern = _G_Patterns_.BORDER_FG, "Total Load"
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY, )
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
local tbl = _G_Widget_.Table{ local tbl = Common.initTable(
x = _G_INIT_DATA_.LEFT_X, _G_INIT_DATA_.LEFT_X,
y = _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_, _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
height = _TABLE_HEIGHT_, _TABLE_HEIGHT_,
num_rows = NUM_ROWS, NUM_ROWS,
body_color = _G_Patterns_.INACTIVE_TEXT_FG, {'Name', 'PID', 'CPU (%)'}
header_color = _G_Patterns_.ACTIVE_FG, )
line_pattern = _G_Patterns_.BORDER_FG,
separator_pattern = _G_Patterns_.BORDER_FG,
'Name',
'PID',
'CPU (%)'
}
local update = function(cr) local update = function(cr)
local conky = Util.conky local conky = Util.conky
local char_count = Util.char_count
local load_sum = 0 local load_sum = 0
local freq_sum = 0 local freq_sum = 0
@ -221,8 +159,7 @@ local update = function(cr)
freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t]) freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t])
end end
CriticalText.set( Common.text_ring_set(core.text_ring, cr,
core.coretemp_text, cr,
Util.round_to_string( Util.round_to_string(
0.001 * Util.read_file(core.coretemp_path, nil, '*n'))) 0.001 * Util.read_file(core.coretemp_path, nil, '*n')))
end end
@ -239,29 +176,25 @@ local update = function(cr)
i = i + 1 i = i + 1
end end
local hwp_val = "Unknown"
if mixed then if mixed then
Text.set(hwp.value, cr, "Mixed") hwp_val = "Mixed"
elseif hwp_pref == "power" then elseif hwp_pref == "power" then
Text.set(hwp.value, cr, "Power") hwp_val = "Power"
elseif hwp_pref == "balance_power" then elseif hwp_pref == "balance_power" then
Text.set(hwp.value, cr, "Bal. Power") hwp_val = "Bal. Power"
elseif hwp_pref == "balance_performance" then elseif hwp_pref == "balance_performance" then
Text.set(hwp.value, cr, "Bal. Performance") hwp_val = "Bal. Performance"
elseif hwp_pref == "performance" then elseif hwp_pref == "performance" then
Text.set(hwp.value, cr, "Performance") hwp_val = "Performance"
elseif hwp_pref == "default" then elseif hwp_pref == "default" then
Text.set(hwp.value, cr, "Default") hwp_val = "Default"
else
Text.set(hwp.value, cr, "Unknown")
end end
Common.text_rows_set(cpu_status, cr, 1, hwp_val)
Common.text_rows_set(cpu_status, cr, 2,
Util.round_to_string(freq_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE) .. ' MHz')
Text.set(ave_freq.value, cr, Util.round_to_string(freq_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE) .. ' MHz') Common.percent_plot_set(total_load, cr, load_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE * 100)
local load_percent = Util.round(load_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE, 2)
CriticalText.set(total_load.value, cr,
Util.round_to_string(load_percent * 100))
LabelPlot.update(plot, load_percent)
for r = 1, NUM_ROWS do for r = 1, NUM_ROWS do
local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces
@ -289,50 +222,40 @@ _TABLE_HEIGHT_ = nil
_create_core_ = nil _create_core_ = nil
_FREQ_Y_ = nil _FREQ_Y_ = nil
_LOAD_Y_ = nil _LOAD_Y_ = nil
_RIGHT_X_ = nil
_SEP_Y_ = nil _SEP_Y_ = nil
_HWP_Y_ = nil _HWP_Y_ = nil
_PLOT_Y_ = nil _PLOT_Y_ = nil
local draw_static = function(cr) M.draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr)
for c = 1, NUM_PHYSICAL_CORES do for c = 1, NUM_PHYSICAL_CORES do
local this_core = cores[c] local this_core = cores[c]
Arc.draw(this_core.inner_ring, cr) Common.text_ring_draw_static(this_core.text_ring, cr)
CompoundDial.draw_static(this_core.dials, cr) CompoundDial.draw_static(this_core.dials, cr)
end end
Text.draw(hwp.label, cr) Common.text_rows_draw_static(cpu_status, cr)
Text.draw(ave_freq.label, cr)
Line.draw(separator, cr) Line.draw(separator, cr)
Text.draw(total_load.label, cr) Common.percent_plot_draw_static(total_load, cr)
LabelPlot.draw_static(plot, cr)
Table.draw_static(tbl, cr) Table.draw_static(tbl, cr)
end end
local draw_dynamic = function(cr) M.draw_dynamic = function(cr)
update(cr) update(cr)
for c = 1, NUM_PHYSICAL_CORES do for c = 1, NUM_PHYSICAL_CORES do
local this_core = cores[c] local this_core = cores[c]
CompoundDial.draw_dynamic(this_core.dials, cr) CompoundDial.draw_dynamic(this_core.dials, cr)
CriticalText.draw(this_core.coretemp_text, cr) Common.text_ring_draw_dynamic(this_core.text_ring, cr)
end end
Text.draw(hwp.value, cr) Common.text_rows_draw_dynamic(cpu_status, cr)
Text.draw(ave_freq.value, cr) Common.percent_plot_draw_dynamic(total_load, cr)
CriticalText.draw(total_load.value, cr)
LabelPlot.draw_dynamic(plot, cr)
Table.draw_dynamic(tbl, cr) Table.draw_dynamic(tbl, cr)
end end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M return M

View File

@ -1,9 +1,7 @@
local M = {} local M = {}
local Text = require 'Text'
local Line = require 'Line'
local ScalePlot = require 'ScalePlot'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local __tonumber = tonumber local __tonumber = tonumber
local __string_match = string.match local __string_match = string.match
@ -26,17 +24,15 @@ local update_stat = function(cr, stat, byte_cnt, update_frequency)
local delta_bytes = byte_cnt - stat.prev_byte_cnt local delta_bytes = byte_cnt - stat.prev_byte_cnt
stat.prev_byte_cnt = byte_cnt stat.prev_byte_cnt = byte_cnt
local text_value = '0.00 B/s'
local plot_value = 0
if delta_bytes > 0 then if delta_bytes > 0 then
local bps = delta_bytes * update_frequency local bps = delta_bytes * update_frequency
local unit, value = Util.convert_data_val(bps) local unit, value = Util.convert_data_val(bps)
stat.rate.append_end = ' '..unit..'B/s' text_value = Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
Text.set(stat.rate, cr, Util.precision_round_to_string(value, 3)) plot_value = bps
ScalePlot.update(stat.plot, cr, bps)
else
stat.rate.append_end = ' B/s'
Text.set(stat.rate, cr, '0.00')
ScalePlot.update(stat.plot, cr, 0)
end end
Common.annotated_scale_plot_set(stat, cr, text_value, plot_value)
end end
local io_label_function = function(bytes) local io_label_function = function(bytes)
@ -48,73 +44,35 @@ local io_label_function = function(bytes)
return Util.round_to_string(new_value, precision)..' '..new_unit..'B/s' return Util.round_to_string(new_value, precision)..' '..new_unit..'B/s'
end end
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.CENTER_LEFT_X, _G_INIT_DATA_.CENTER_LEFT_X,
y = _G_INIT_DATA_.TOP_Y, _G_INIT_DATA_.TOP_Y,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'INPUT / OUTPUT' 'INPUT / OUTPUT'
} )
local _RIGHT_X_ = _G_INIT_DATA_.CENTER_LEFT_X + _G_INIT_DATA_.SECTION_WIDTH local reads = Common.initLabeledScalePlot(
_G_INIT_DATA_.CENTER_LEFT_X,
header.bottom_y,
_G_INIT_DATA_.SECTION_WIDTH,
_PLOT_HEIGHT_,
io_label_function,
_PLOT_SEC_BREAK_,
'Reads'
)
local reads = { local writes = Common.initLabeledScalePlot(
label = _G_Widget_.Text{ _G_INIT_DATA_.CENTER_LEFT_X,
x = _G_INIT_DATA_.CENTER_LEFT_X, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
y = header.bottom_y, _G_INIT_DATA_.SECTION_WIDTH,
text = 'Reads', _PLOT_HEIGHT_,
}, io_label_function,
rate = _G_Widget_.Text{ _PLOT_SEC_BREAK_,
x = _RIGHT_X_, 'Writes'
y = header.bottom_y, )
x_align = 'right',
append_end=' B/s',
text_color = _G_Patterns_.PRIMARY_FG
},
plot = _G_Widget_.ScalePlot{
x = _G_INIT_DATA_.CENTER_LEFT_X,
y = header.bottom_y + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
y_label_func = io_label_function,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
local _WRITE_Y_ = header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local writes = {
label = _G_Widget_.Text{
x = _G_INIT_DATA_.CENTER_LEFT_X,
y = _WRITE_Y_,
text = 'Writes',
},
rate = _G_Widget_.Text{
x = _RIGHT_X_,
y = _WRITE_Y_,
x_align = 'right',
append_end =' B/s',
text_color = _G_Patterns_.PRIMARY_FG
},
plot = _G_Widget_.ScalePlot{
x = _G_INIT_DATA_.CENTER_LEFT_X,
y = _WRITE_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_,
y_label_func = io_label_function,
outline_pattern = _G_Patterns_.BORDER_FG,
intrvl_pattern = _G_Patterns_.BORDER_FG,
data_line_pattern = _G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
data_fill_pattern = _G_Patterns_.PLOT_FILL_BG_PRIMARY,
}
}
_PLOT_SEC_BREAK_ = nil _PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil _PLOT_HEIGHT_ = nil
_RIGHT_X_ = nil
_WRITE_Y_ = nil
reads.byte_cnt = 0 reads.byte_cnt = 0
writes.byte_cnt = 0 writes.byte_cnt = 0
@ -127,21 +85,15 @@ local update = function(cr, update_frequency)
end end
local draw_static = function(cr) local draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Line.draw(header.underline, cr) Common.annotated_scale_plot_draw_static(reads, cr)
Common.annotated_scale_plot_draw_static(writes, cr)
Text.draw(reads.label, cr)
Text.draw(writes.label, cr)
end end
local draw_dynamic = function(cr, update_frequency) local draw_dynamic = function(cr, update_frequency)
update(cr, update_frequency) update(cr, update_frequency)
Common.annotated_scale_plot_draw_dynamic(reads, cr)
Text.draw(reads.rate, cr) Common.annotated_scale_plot_draw_dynamic(writes, cr)
ScalePlot.draw_dynamic(reads.plot, cr)
Text.draw(writes.rate, cr)
ScalePlot.draw_dynamic(writes.plot, cr)
end end
M.draw_static = draw_static M.draw_static = draw_static

View File

@ -1,73 +1,44 @@
local M = {} local M = {}
local Text = require 'Text'
local Line = require 'Line'
local TextColumn = require 'TextColumn'
local Util = require 'Util' local Util = require 'Util'
local Common = require 'Common'
local __string_match = string.match local __string_match = string.match
local _TEXT_SPACING_ = 20 local _TEXT_SPACING_ = 20
local header = _G_Widget_.Header{ local header = Common.Header(
x = _G_INIT_DATA_.LEFT_X, _G_INIT_DATA_.LEFT_X,
y = _G_INIT_DATA_.TOP_Y, _G_INIT_DATA_.TOP_Y,
width = _G_INIT_DATA_.SECTION_WIDTH, _G_INIT_DATA_.SECTION_WIDTH,
header = 'SYSTEM' 'SYSTEM'
} )
local labels = _G_Widget_.TextColumn{ local rows = Common.initTextRows(
x = _G_INIT_DATA_.LEFT_X, _G_INIT_DATA_.LEFT_X,
y = header.bottom_y, header.bottom_y,
spacing = _TEXT_SPACING_, _G_INIT_DATA_.SECTION_WIDTH,
'Kernel', _TEXT_SPACING_,
'Uptime', {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
'Last Upgrade', )
'Last Sync'
}
local kernel = _G_Widget_.Text{
x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = header.bottom_y,
x_align = 'right',
text = Util.conky('$kernel'),
text_color = _G_Patterns_.PRIMARY_FG
}
local info = _G_Widget_.TextColumn{
x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = header.bottom_y + _TEXT_SPACING_,
spacing = _TEXT_SPACING_,
x_align = 'right',
text_color = _G_Patterns_.PRIMARY_FG,
'<row1>',
'<row2>',
'<row3>'
}
_TEXT_SPACING_ = nil _TEXT_SPACING_ = nil
local draw_static = function(cr) M.draw_static = function(cr)
Text.draw(header.text, cr) Common.drawHeader(cr, header)
Text.draw(kernel, cr) Common.text_rows_draw_static(rows, cr)
Line.draw(header.underline, cr)
TextColumn.draw(labels, cr)
end end
local draw_dynamic = function(cr, pacman_stats) M.draw_dynamic = function(cr, pacman_stats)
TextColumn.set(info, cr, 1, Util.conky('$uptime')) local last_update, last_sync = "N/A", "N/A"
if pacman_stats then if pacman_stats then
local last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*") last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
TextColumn.set(info, cr, 2, last_update)
TextColumn.set(info, cr, 3, last_sync)
else
TextColumn.set(info, cr, 2, "N/A")
TextColumn.set(info, cr, 3, "N/A")
end end
Common.text_rows_set(rows, cr, 1, Util.conky('$kernel'))
TextColumn.draw(info, cr) Common.text_rows_set(rows, cr, 2, Util.conky('$uptime'))
Common.text_rows_set(rows, cr, 3, last_update)
Common.text_rows_set(rows, cr, 4, last_sync)
Common.text_rows_draw_dynamic(rows, cr)
end end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M return M

View File

@ -126,28 +126,29 @@ local Power = require 'Power'
local ReadWrite = require 'ReadWrite' local ReadWrite = require 'ReadWrite'
local Graphics = require 'Graphics' local Graphics = require 'Graphics'
local Memory = require 'Memory' local Memory = require 'Memory'
local Common = require 'Common'
-- --
-- initialize static surfaces -- initialize static surfaces
-- --
local left = _G_Widget_.Panel{ local left = Common.initPanel(
x = _G_INIT_DATA_.LEFT_X - _G_INIT_DATA_.PANEL_MARGIN_X, _G_INIT_DATA_.LEFT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
y = _G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y, _G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y,
width = _G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2, _G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2,
height = _G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2, _G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2
} )
local center = _G_Widget_.Panel{ local center = Common.initPanel(
x = _G_INIT_DATA_.CENTER_LEFT_X - _G_INIT_DATA_.PANEL_MARGIN_X, _G_INIT_DATA_.CENTER_LEFT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
y = _G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y, _G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y,
width = _G_INIT_DATA_.CENTER_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_Y * 2 + _G_INIT_DATA_.CENTER_PAD, _G_INIT_DATA_.CENTER_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_Y * 2 + _G_INIT_DATA_.CENTER_PAD,
height = _G_INIT_DATA_.CENTER_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2, _G_INIT_DATA_.CENTER_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2
} )
local right = _G_Widget_.Panel{ local right = Common.initPanel(
x = _G_INIT_DATA_.RIGHT_X - _G_INIT_DATA_.PANEL_MARGIN_X, _G_INIT_DATA_.RIGHT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
y = _G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y, _G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y,
width = _G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2, _G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2,
height = _G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2, _G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2
} )
local _make_static_surface = function(panel, ...) local _make_static_surface = function(panel, ...)
local x = panel.x - panel.thickness * 0.5 local x = panel.x - panel.thickness * 0.5