REF move patterns into common theming/widget composition module
This commit is contained in:
parent
d4ac91ac35
commit
b33cf3933f
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit a5f1912f6bf2a1fa54d9385971400fcb2de80e90
|
||||
Subproject commit b1034354e38299cf997ddface80aaf43a4de8523
|
|
@ -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
|
|
@ -1,13 +1,11 @@
|
|||
local M = {}
|
||||
|
||||
local Patterns = require 'Patterns'
|
||||
local Text = require 'Text'
|
||||
local Line = require 'Line'
|
||||
local TextColumn = require 'TextColumn'
|
||||
local CompoundBar = require 'CompoundBar'
|
||||
local Util = require 'Util'
|
||||
|
||||
local __string_match = string.match
|
||||
local Common = require 'Common'
|
||||
|
||||
local _FS_PATHS_ = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"}
|
||||
local _MODULE_Y_ = 170
|
||||
|
@ -17,12 +15,12 @@ local _SEPARATOR_SPACING_ = 20
|
|||
|
||||
local FS_NUM = #_FS_PATHS_
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _MODULE_Y_,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'FILE SYSTEMS'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_MODULE_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'FILE SYSTEMS'
|
||||
)
|
||||
|
||||
local conky_used_perc = {}
|
||||
|
||||
|
@ -30,34 +28,20 @@ for i, v in pairs(_FS_PATHS_) do
|
|||
conky_used_perc[i] = '${fs_used_perc '..v..'}'
|
||||
end
|
||||
|
||||
local smart = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = header.bottom_y,
|
||||
text = '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 smart = Common.initTextRow(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
header.bottom_y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'SMART Daemon'
|
||||
)
|
||||
|
||||
local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_
|
||||
|
||||
local separator = _G_Widget_.Line{
|
||||
p1 = {
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _SEP_Y_,
|
||||
},
|
||||
p2 = {
|
||||
x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH,
|
||||
y = _SEP_Y_,
|
||||
},
|
||||
line_pattern = _G_Patterns_.BORDER_FG,
|
||||
}
|
||||
local separator = Common.initSeparator(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_SEP_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH
|
||||
)
|
||||
|
||||
local _BAR_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
|
||||
|
||||
|
@ -77,6 +61,7 @@ local labels = _G_Widget_.TextColumn{
|
|||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _BAR_Y_,
|
||||
spacing = _SPACING_,
|
||||
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
|
||||
'root',
|
||||
'boot',
|
||||
'home',
|
||||
|
@ -95,8 +80,8 @@ _SEP_Y_ = nil
|
|||
|
||||
local update = function(cr)
|
||||
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
|
||||
local percent = Util.conky_numeric(conky_used_perc[i])
|
||||
CompoundBar.set(bars, i, percent * 0.01)
|
||||
|
@ -104,10 +89,9 @@ local update = function(cr)
|
|||
end
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
Common.drawHeader(cr, header)
|
||||
|
||||
Text.draw(smart.label, cr)
|
||||
Common.text_row_draw_static(smart, cr)
|
||||
Line.draw(separator, cr)
|
||||
|
||||
TextColumn.draw(labels, cr)
|
||||
|
@ -117,7 +101,7 @@ end
|
|||
local draw_dynamic = function(cr, trigger)
|
||||
if trigger == 0 then update(cr) end
|
||||
|
||||
Text.draw(smart.value, cr)
|
||||
Common.text_row_draw_dynamic(smart, cr)
|
||||
|
||||
CompoundBar.draw_dynamic(bars, cr)
|
||||
end
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
local M = {}
|
||||
|
||||
local CriticalText = require 'CriticalText'
|
||||
local Text = require 'Text'
|
||||
local TextColumn = require 'TextColumn'
|
||||
local Line = require 'Line'
|
||||
local LabelPlot = require 'LabelPlot'
|
||||
local Util = require 'Util'
|
||||
local Common = require 'Common'
|
||||
|
||||
local __tonumber = tonumber
|
||||
local __string_match = string.match
|
||||
|
||||
local _MODULE_Y_ = 145
|
||||
|
@ -16,171 +14,96 @@ local _TEXT_SPACING_ = 20
|
|||
local _PLOT_SEC_BREAK_ = 20
|
||||
local _PLOT_HEIGHT_ = 56
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _MODULE_Y_,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'NVIDIA GRAPHICS'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_MODULE_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'NVIDIA GRAPHICS'
|
||||
)
|
||||
|
||||
local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH
|
||||
|
||||
local status = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
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 status = Common.initTextRow(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
header.bottom_y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'Status'
|
||||
)
|
||||
|
||||
local _SEP_Y_1_ = header.bottom_y + _SEPARATOR_SPACING_
|
||||
|
||||
local separator1 = _G_Widget_.Line{
|
||||
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_1_},
|
||||
p2 = {x = _RIGHT_X_, y = _SEP_Y_1_},
|
||||
line_pattern = _G_Patterns_.BORDER_FG,
|
||||
}
|
||||
local separator1 = Common.initSeparator(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_SEP_Y_1_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH
|
||||
)
|
||||
|
||||
local _INTERNAL_TEMP_Y_ = _SEP_Y_1_ + _SEPARATOR_SPACING_
|
||||
|
||||
local internal_temp = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _INTERNAL_TEMP_Y_,
|
||||
text = 'Internal Temperature'
|
||||
},
|
||||
value = _G_Widget_.CriticalText{
|
||||
x = _RIGHT_X_,
|
||||
y = _INTERNAL_TEMP_Y_,
|
||||
x_align = 'right',
|
||||
text_color = _G_Patterns_.PRIMARY_FG,
|
||||
text = '<gpu_temp>'
|
||||
}
|
||||
}
|
||||
local internal_temp = Common.initTextRowCrit(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_INTERNAL_TEMP_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'Internal Temperature',
|
||||
'°C'
|
||||
)
|
||||
|
||||
local _SEP_Y_2_ = _INTERNAL_TEMP_Y_ + _SEPARATOR_SPACING_
|
||||
|
||||
local separator2 = _G_Widget_.Line{
|
||||
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_2_},
|
||||
p2 = {x = _RIGHT_X_, y = _SEP_Y_2_},
|
||||
line_pattern = _G_Patterns_.BORDER_FG,
|
||||
}
|
||||
local separator2 = Common.initSeparator(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_SEP_Y_2_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH
|
||||
)
|
||||
|
||||
local _CLOCK_SPEED_Y_ = _SEP_Y_2_ + _SEPARATOR_SPACING_
|
||||
|
||||
local clock_speed = {
|
||||
labels = _G_Widget_.TextColumn{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _CLOCK_SPEED_Y_,
|
||||
spacing = _TEXT_SPACING_,
|
||||
'GPU 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 clock_speed = Common.initTextRows(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_CLOCK_SPEED_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_TEXT_SPACING_,
|
||||
{'GPU Clock Speed', 'Memory Clock Speed'}
|
||||
)
|
||||
|
||||
local _SEP_Y_3_ = _CLOCK_SPEED_Y_ + _TEXT_SPACING_ * 2
|
||||
|
||||
local separator3 = _G_Widget_.Line{
|
||||
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_3_},
|
||||
p2 = {x = _RIGHT_X_, y = _SEP_Y_3_},
|
||||
line_pattern = _G_Patterns_.BORDER_FG,
|
||||
}
|
||||
local separator3 = Common.initSeparator(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_SEP_Y_3_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH
|
||||
)
|
||||
|
||||
local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_
|
||||
|
||||
local gpu_util = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _GPU_UTIL_Y_,
|
||||
text = 'GPU Utilization'
|
||||
},
|
||||
value = _G_Widget_.Text{
|
||||
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 gpu_util = Common.initPercentPlot(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_GPU_UTIL_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'GPU Utilization'
|
||||
)
|
||||
|
||||
local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
|
||||
|
||||
local mem_util = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _MEM_UTIL_Y_,
|
||||
text = 'Memory Utilization'
|
||||
},
|
||||
value = _G_Widget_.Text{
|
||||
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 mem_util = Common.initPercentPlot(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_MEM_UTIL_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'Memory Utilization'
|
||||
)
|
||||
|
||||
local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
|
||||
|
||||
local vid_util = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _VID_UTIL_Y_,
|
||||
text = 'Video Utilization'
|
||||
},
|
||||
value = _G_Widget_.Text{
|
||||
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,
|
||||
}
|
||||
}
|
||||
local vid_util = Common.initPercentPlot(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_VID_UTIL_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'Video Utilization'
|
||||
)
|
||||
|
||||
--[[
|
||||
vars to process the nv settings glob
|
||||
|
@ -208,10 +131,9 @@ local NV_REGEX = '(%d+)\n'..
|
|||
local NA = 'N/A'
|
||||
|
||||
local nvidia_off = function(cr)
|
||||
CriticalText.set(internal_temp.value, cr, NA, false)
|
||||
|
||||
TextColumn.set(clock_speed.values, cr, 1, NA)
|
||||
TextColumn.set(clock_speed.values, cr, 2, NA)
|
||||
Common.text_rows_crit_set(internal_temp, cr, NA)
|
||||
Common.text_rows_set.set(clock_speed, cr, 1, NA)
|
||||
Common.text_rows_set.set(clock_speed, cr, 2, NA)
|
||||
|
||||
Text.set(gpu_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')
|
||||
nvidia_off(cr)
|
||||
else
|
||||
Text.set(status.value, cr, 'On')
|
||||
Common.text_row_set(status, cr, 'On')
|
||||
|
||||
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)
|
||||
|
||||
local is_critical = false
|
||||
if __tonumber(temp_reading) > 80 then is_critical = true end
|
||||
Common.text_row_crit_set(internal_temp, cr, temp_reading)
|
||||
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)
|
||||
|
||||
TextColumn.set(clock_speed.values, cr, 1, gpu_frequency..' Mhz')
|
||||
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)
|
||||
Common.percent_plot_set(gpu_util, cr, gpu_utilization)
|
||||
Common.percent_plot_set(mem_util, cr, used_memory / total_memory * 100)
|
||||
Common.percent_plot_set(vid_util, cr, vid_utilization)
|
||||
end
|
||||
else
|
||||
Text.set(status.value, cr, 'Off')
|
||||
|
@ -266,7 +178,6 @@ _SEPARATOR_SPACING_ = nil
|
|||
_TEXT_SPACING_ = nil
|
||||
_PLOT_SEC_BREAK_ = nil
|
||||
_PLOT_HEIGHT_ = nil
|
||||
_RIGHT_X_ = nil
|
||||
_SEP_Y_1_ = nil
|
||||
_SEP_Y_2_ = nil
|
||||
_SEP_Y_3_ = nil
|
||||
|
@ -276,47 +187,32 @@ _GPU_UTIL_Y_ = nil
|
|||
_MEM_UTIL_Y_ = nil
|
||||
_VID_UTIL_Y_ = nil
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
M.draw_static = function(cr)
|
||||
Common.drawHeader(cr, header)
|
||||
|
||||
Text.draw(status.label, cr)
|
||||
Common.text_row_draw_static(status, cr)
|
||||
Line.draw(separator1, cr)
|
||||
|
||||
Text.draw(internal_temp.label, cr)
|
||||
Common.text_row_crit_draw_static(internal_temp, cr)
|
||||
Line.draw(separator2, cr)
|
||||
|
||||
TextColumn.draw(clock_speed.labels, cr)
|
||||
Common.text_rows_draw_static(clock_speed, cr)
|
||||
Line.draw(separator3, cr)
|
||||
|
||||
Text.draw(gpu_util.label, cr)
|
||||
LabelPlot.draw_static(gpu_util.plot, 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)
|
||||
Common.percent_plot_draw_static(gpu_util, cr)
|
||||
Common.percent_plot_draw_static(mem_util, cr)
|
||||
Common.percent_plot_draw_static(vid_util, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr)
|
||||
M.draw_dynamic = function(cr)
|
||||
update(cr)
|
||||
|
||||
Text.draw(status.value, cr)
|
||||
Text.draw(internal_temp.value, cr)
|
||||
TextColumn.draw(clock_speed.values, cr)
|
||||
|
||||
Text.draw(gpu_util.value, cr)
|
||||
LabelPlot.draw_dynamic(gpu_util.plot, 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)
|
||||
Common.text_row_draw_dynamic(status, cr)
|
||||
Common.text_row_crit_draw_dynamic(internal_temp, cr)
|
||||
Common.text_rows_draw_dynamic(clock_speed, cr)
|
||||
Common.percent_plot_draw_dynamic(gpu_util, cr)
|
||||
Common.percent_plot_draw_dynamic(mem_util, cr)
|
||||
Common.percent_plot_draw_dynamic(vid_util, cr)
|
||||
end
|
||||
|
||||
M.draw_static = draw_static
|
||||
M.draw_dynamic = draw_dynamic
|
||||
|
||||
return M
|
||||
|
|
|
@ -2,21 +2,17 @@ local M = {}
|
|||
|
||||
local Arc = require 'Arc'
|
||||
local Dial = require 'Dial'
|
||||
local CriticalText = require 'CriticalText'
|
||||
local Text = require 'Text'
|
||||
local TextColumn = require 'TextColumn'
|
||||
local Line = require 'Line'
|
||||
local LabelPlot = require 'LabelPlot'
|
||||
local Table = require 'Table'
|
||||
local Util = require 'Util'
|
||||
local Common = require 'Common'
|
||||
|
||||
local __string_match = string.match
|
||||
local __cairo_path_destroy = cairo_path_destroy
|
||||
local __io_popen = io.popen
|
||||
|
||||
local _MODULE_Y_ = 712
|
||||
local _DIAL_THICKNESS_ = 8
|
||||
local _DIAL_SPACING_ = 1
|
||||
local _TEXT_Y_OFFSET_ = 7
|
||||
local _TEXT_LEFT_X_OFFSET_ = 30
|
||||
local _TEXT_SPACING_ = 20
|
||||
|
@ -45,12 +41,12 @@ for r = 1, NUM_ROWS do
|
|||
TABLE_CONKY[r].mem = '${top_mem mem '..r..'}'
|
||||
end
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _MODULE_Y_,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'MEMORY'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_MODULE_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'MEMORY'
|
||||
)
|
||||
|
||||
local DIAL_RADIUS = 32
|
||||
local DIAL_THETA_0 = math.rad(90)
|
||||
|
@ -60,7 +56,7 @@ local DIAL_Y = header.bottom_y + DIAL_RADIUS + _DIAL_THICKNESS_ / 2
|
|||
|
||||
local dial = _G_Widget_.Dial{
|
||||
x = DIAL_X,
|
||||
y = DIAL_Y,
|
||||
y = DIAL_Y,
|
||||
radius = DIAL_RADIUS,
|
||||
thickness = _DIAL_THICKNESS_,
|
||||
critical_limit = '>0.8',
|
||||
|
@ -69,53 +65,39 @@ local dial = _G_Widget_.Dial{
|
|||
}
|
||||
local cache_arc = _G_Widget_.Arc{
|
||||
x = DIAL_X,
|
||||
y = DIAL_Y,
|
||||
y = DIAL_Y,
|
||||
radius = DIAL_RADIUS,
|
||||
thickness = _DIAL_THICKNESS_,
|
||||
arc_pattern = _G_Patterns_.INDICATOR_FG_SECONDARY
|
||||
}
|
||||
|
||||
local total_used = _G_Widget_.CriticalText{
|
||||
x = DIAL_X,
|
||||
y = DIAL_Y,
|
||||
x_align = 'center',
|
||||
y_align = 'center',
|
||||
append_end = '%'
|
||||
}
|
||||
|
||||
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 text_ring = Common.initTextRing(
|
||||
DIAL_X,
|
||||
DIAL_Y,
|
||||
DIAL_RADIUS - _DIAL_THICKNESS_ / 2 - 2,
|
||||
'%',
|
||||
'>80'
|
||||
)
|
||||
|
||||
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 _RIGHT_X_ = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH
|
||||
|
||||
local swap= {
|
||||
label = _G_Widget_.Text{
|
||||
x = _TEXT_LEFT_X_,
|
||||
y = _LINE_1_Y_,
|
||||
spacing = _TEXT_SPACING_,
|
||||
text = 'Swap Usage'
|
||||
},
|
||||
percent = _G_Widget_.CriticalText{
|
||||
x = _RIGHT_X_,
|
||||
y = _LINE_1_Y_,
|
||||
x_align = 'right',
|
||||
append_end = ' %',
|
||||
},
|
||||
}
|
||||
local swap = Common.initTextRowCrit(
|
||||
_TEXT_LEFT_X_,
|
||||
_LINE_1_Y_,
|
||||
-- TODO this is silly
|
||||
_RIGHT_X_ - _TEXT_LEFT_X_,
|
||||
'Swap Usage',
|
||||
' %'
|
||||
)
|
||||
|
||||
local cache = {
|
||||
labels = _G_Widget_.TextColumn{
|
||||
x = _TEXT_LEFT_X_,
|
||||
y = _LINE_1_Y_ + _TEXT_SPACING_,
|
||||
spacing = _TEXT_SPACING_,
|
||||
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
|
||||
'Page Cache',
|
||||
'Buffers',
|
||||
'Kernel Slab'
|
||||
|
@ -134,30 +116,21 @@ local cache = {
|
|||
|
||||
local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2
|
||||
|
||||
local plot = _G_Widget_.LabelPlot{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _PLOT_Y_,
|
||||
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 plot = Common.initThemedLabelPlot(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_PLOT_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_
|
||||
)
|
||||
|
||||
local tbl = _G_Widget_.Table{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
height = _TABLE_HEIGHT_,
|
||||
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,
|
||||
'Name',
|
||||
'PID',
|
||||
'Mem (%)'
|
||||
}
|
||||
local tbl = Common.initTable(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_TABLE_HEIGHT_,
|
||||
NUM_ROWS,
|
||||
{'Name', 'PID', 'Mem (%)'}
|
||||
)
|
||||
|
||||
local update = function(cr)
|
||||
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
|
||||
|
||||
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
|
||||
__cairo_path_destroy(cache_arc.path)
|
||||
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(
|
||||
(swap_total_kb - swap_free_kb) / swap_total_kb * 100))
|
||||
Common.text_row_crit_set(swap, cr,
|
||||
Util.precision_round_to_string(
|
||||
(swap_total_kb - swap_free_kb)
|
||||
/ swap_total_kb * 100))
|
||||
|
||||
local _percents = cache.percents
|
||||
|
||||
|
@ -216,36 +191,32 @@ _TEXT_LEFT_X_ = nil
|
|||
_RIGHT_X_ = nil
|
||||
_PLOT_Y_ = nil
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
M.draw_static = function(cr)
|
||||
Common.drawHeader(cr, header)
|
||||
|
||||
Arc.draw(inner_ring, cr)
|
||||
Common.text_ring_draw_static(text_ring, cr)
|
||||
Dial.draw_static(dial, cr)
|
||||
|
||||
Text.draw(swap.label, cr)
|
||||
Common.text_row_crit_draw_static(swap, cr)
|
||||
TextColumn.draw(cache.labels, cr)
|
||||
LabelPlot.draw_static(plot, cr)
|
||||
|
||||
Table.draw_static(tbl, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr)
|
||||
M.draw_dynamic = function(cr)
|
||||
update(cr)
|
||||
|
||||
Dial.draw_dynamic(dial, 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)
|
||||
|
||||
|
||||
LabelPlot.draw_dynamic(plot, cr)
|
||||
|
||||
|
||||
Table.draw_dynamic(tbl, cr)
|
||||
end
|
||||
|
||||
M.draw_static = draw_static
|
||||
M.draw_dynamic = draw_dynamic
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
local M = {}
|
||||
|
||||
local Text = require 'Text'
|
||||
local Line = require 'Line'
|
||||
local ScalePlot = require 'ScalePlot'
|
||||
local Util = require 'Util'
|
||||
local Common = require 'Common'
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.CENTER_RIGHT_X,
|
||||
y = _G_INIT_DATA_.TOP_Y,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'NETWORK'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.CENTER_RIGHT_X,
|
||||
_G_INIT_DATA_.TOP_Y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'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 = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.CENTER_RIGHT_X,
|
||||
y = header.bottom_y,
|
||||
text = 'Download',
|
||||
},
|
||||
speed = _G_Widget_.Text{
|
||||
x = _RIGHT_X_,
|
||||
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 upload = Common.initLabeledScalePlot(
|
||||
_G_INIT_DATA_.CENTER_RIGHT_X,
|
||||
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
network_label_function,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'Upload'
|
||||
)
|
||||
|
||||
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 uspeed_unit, uspeed_value = Util.convert_data_val(uspeed)
|
||||
|
||||
dnload.speed.append_end = ' '..dspeed_unit..'b/s'
|
||||
upload.speed.append_end = ' '..uspeed_unit..'b/s'
|
||||
|
||||
Text.set(dnload.speed, cr, Util.precision_round_to_string(dspeed_value, 3))
|
||||
Text.set(upload.speed, cr, Util.precision_round_to_string(uspeed_value, 3))
|
||||
|
||||
ScalePlot.update(dnload.plot, cr, dspeed)
|
||||
ScalePlot.update(upload.plot, cr, uspeed)
|
||||
Common.annotated_scale_plot_set(
|
||||
dnload,
|
||||
cr,
|
||||
Util.precision_round_to_string(dspeed_value, 3)..' '..dspeed_unit..'b/s',
|
||||
dspeed
|
||||
)
|
||||
Common.annotated_scale_plot_set(
|
||||
upload,
|
||||
cr,
|
||||
Util.precision_round_to_string(uspeed_value, 3)..' '..uspeed_unit..'b/s',
|
||||
uspeed
|
||||
)
|
||||
end
|
||||
|
||||
_PLOT_SEC_BREAK_ = nil
|
||||
_PLOT_HEIGHT_ = nil
|
||||
_RIGHT_X_ = nil
|
||||
_UPLOAD_Y_ = nil
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
|
||||
Text.draw(dnload.label, cr)
|
||||
Text.draw(upload.label, cr)
|
||||
Common.drawHeader(cr, header)
|
||||
Common.annotated_scale_plot_draw_static(dnload, cr)
|
||||
Common.annotated_scale_plot_draw_static(upload, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr, update_frequency)
|
||||
update(cr, update_frequency)
|
||||
|
||||
Text.draw(dnload.speed, cr)
|
||||
ScalePlot.draw_dynamic(dnload.plot, cr)
|
||||
|
||||
Text.draw(upload.speed, cr)
|
||||
ScalePlot.draw_dynamic(upload.plot, cr)
|
||||
Common.annotated_scale_plot_draw_dynamic(dnload, cr)
|
||||
Common.annotated_scale_plot_draw_dynamic(upload, cr)
|
||||
end
|
||||
|
||||
M.draw_static = draw_static
|
||||
|
|
|
@ -1,40 +1,26 @@
|
|||
local M = {}
|
||||
|
||||
local Text = require 'Text'
|
||||
local Line = require 'Line'
|
||||
local TextColumn = require 'TextColumn'
|
||||
local Util = require 'Util'
|
||||
local Common = require 'Common'
|
||||
|
||||
local __string_match = string.match
|
||||
local __string_gmatch = string.gmatch
|
||||
|
||||
local _TEXT_SPACING_ = 20
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _G_INIT_DATA_.TOP_Y,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'PACMAN'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_G_INIT_DATA_.TOP_Y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'PACMAN'
|
||||
)
|
||||
|
||||
local labels = _G_Widget_.TextColumn{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = header.bottom_y,
|
||||
spacing = _TEXT_SPACING_,
|
||||
'Total',
|
||||
'Explicit',
|
||||
'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
|
||||
}
|
||||
local rows = Common.initTextRows(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
header.bottom_y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_TEXT_SPACING_,
|
||||
{'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'}
|
||||
)
|
||||
|
||||
_TEXT_SPACING_ = nil
|
||||
|
||||
|
@ -43,28 +29,24 @@ local update = function(cr, pacman_stats)
|
|||
if stats then
|
||||
local i = 1
|
||||
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
|
||||
end
|
||||
else
|
||||
for i=1,5 do
|
||||
TextColumn.set(info, cr, i, 'N/A')
|
||||
for i=1, 5 do
|
||||
Common.text_rows_set(rows, cr, i, 'N/A')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
TextColumn.draw(labels, cr)
|
||||
M.draw_static = function(cr)
|
||||
Common.drawHeader(cr, header)
|
||||
Common.text_rows_draw_static(rows, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr, pacman_stats)
|
||||
M.draw_dynamic = function(cr, pacman_stats)
|
||||
update(cr, pacman_stats)
|
||||
TextColumn.draw(info, cr)
|
||||
Common.text_rows_draw_dynamic(rows, cr)
|
||||
end
|
||||
|
||||
M.draw_static = draw_static
|
||||
M.draw_dynamic = draw_dynamic
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
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 Common = require 'Common'
|
||||
|
||||
local _MODULE_Y_ = 380
|
||||
local _TEXT_SPACING_ = 20
|
||||
|
@ -14,7 +10,7 @@ local _PLOT_HEIGHT_ = 56
|
|||
|
||||
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
|
||||
return (cnt - prev_cnt) * update_frequency * 0.000001
|
||||
else
|
||||
|
@ -22,97 +18,46 @@ local calculate_power = function(cr, prev_cnt, cnt, update_frequency)
|
|||
end
|
||||
end
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _MODULE_Y_,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'POWER'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_MODULE_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'POWER'
|
||||
)
|
||||
|
||||
local _RIGHT_X_ = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH
|
||||
|
||||
local pkg0 = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = header.bottom_y,
|
||||
text = 'PKG0',
|
||||
},
|
||||
value = _G_Widget_.Text{
|
||||
x = _RIGHT_X_,
|
||||
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 pkg0 = Common.initLabeledScalePlot(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
header.bottom_y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
power_label_function,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'PKG0'
|
||||
)
|
||||
pkg0.value.append_end = ' W'
|
||||
|
||||
local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_
|
||||
|
||||
local dram = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _CORE_Y_,
|
||||
text = 'DRAM'
|
||||
},
|
||||
value = _G_Widget_.Text{
|
||||
x = _RIGHT_X_,
|
||||
y = _CORE_Y_,
|
||||
x_align = 'right',
|
||||
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 dram = Common.initLabeledScalePlot(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_CORE_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
power_label_function,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'DRAM'
|
||||
)
|
||||
dram.value.append_end = ' W'
|
||||
|
||||
local _BATTERY_DRAW_Y_ = _CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_
|
||||
|
||||
local battery_draw = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.RIGHT_X,
|
||||
y = _BATTERY_DRAW_Y_,
|
||||
spacing = _TEXT_SPACING_,
|
||||
text = '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 battery_draw = Common.initLabeledScalePlot(
|
||||
_G_INIT_DATA_.RIGHT_X,
|
||||
_CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
power_label_function,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'Battery Draw'
|
||||
)
|
||||
|
||||
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
|
||||
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
|
||||
|
@ -121,69 +66,49 @@ local prev_pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
|
|||
local prev_dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n')
|
||||
|
||||
local update = function(cr, update_frequency, is_using_ac)
|
||||
local pkg0_uj_cnt = Util.read_file(PKG0_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_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
|
||||
local dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n')
|
||||
|
||||
Text.set(pkg0.value, cr, Util.precision_round_to_string(pkg0_power, 3))
|
||||
|
||||
ScalePlot.update(pkg0.plot, cr, pkg0_power)
|
||||
local pkg0_power = calculate_power(prev_pkg0_uj_cnt, pkg0_uj_cnt, update_frequency)
|
||||
|
||||
local dram_power = calculate_power(cr, prev_dram_uj_cnt, dram_uj_cnt, update_frequency)
|
||||
|
||||
Text.set(dram.value, cr, Util.precision_round_to_string(dram_power, 3))
|
||||
ScalePlot.update(dram.plot, cr, dram_power)
|
||||
Common.annotated_scale_plot_set(pkg0, cr, Util.precision_round_to_string(pkg0_power, 3), pkg0_power)
|
||||
|
||||
prev_pkg0_uj_cnt = pkg0_uj_cnt
|
||||
prev_dram_uj_cnt = dram_uj_cnt
|
||||
local dram_power = calculate_power(prev_dram_uj_cnt, dram_uj_cnt, update_frequency)
|
||||
|
||||
if is_using_ac then
|
||||
Text.set(battery_draw.value, cr, 'A/C')
|
||||
ScalePlot.update(battery_draw.plot, cr, 0)
|
||||
else
|
||||
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 power = current * voltage * 0.000000000001
|
||||
Common.annotated_scale_plot_set(dram, cr, Util.precision_round_to_string(dram_power, 3), dram_power)
|
||||
|
||||
Text.set(battery_draw.value, cr, Util.precision_round_to_string(power, 3)..' W')
|
||||
ScalePlot.update(battery_draw.plot, cr, power)
|
||||
end
|
||||
prev_pkg0_uj_cnt = pkg0_uj_cnt
|
||||
prev_dram_uj_cnt = dram_uj_cnt
|
||||
|
||||
if is_using_ac then
|
||||
Common.annotated_scale_plot_set(battery_draw, cr, 'A/C', 0)
|
||||
else
|
||||
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 power = current * voltage * 0.000000000001
|
||||
local t = Util.precision_round_to_string(power, 3)..' W'
|
||||
Common.annotated_scale_plot_set(battery_draw, cr, t, power)
|
||||
end
|
||||
end
|
||||
|
||||
Patterns = nil
|
||||
_MODULE_Y_ = nil
|
||||
_TEXT_SPACING_ = nil
|
||||
_PLOT_SEC_BREAK_ = nil
|
||||
_PLOT_HEIGHT_ = nil
|
||||
_RIGHT_X_ = nil
|
||||
_CORE_Y_ = nil
|
||||
_BATTERY_DRAW_Y_ = nil
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
|
||||
Text.draw(pkg0.label, cr)
|
||||
|
||||
Text.draw(dram.label, cr)
|
||||
Text.draw(battery_draw.label, cr)
|
||||
M.draw_static = function(cr)
|
||||
Common.drawHeader(cr, header)
|
||||
Common.annotated_scale_plot_draw_static(pkg0, cr)
|
||||
Common.annotated_scale_plot_draw_static(dram, cr)
|
||||
Common.annotated_scale_plot_draw_static(battery_draw, cr)
|
||||
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)
|
||||
|
||||
Text.draw(pkg0.value, cr)
|
||||
ScalePlot.draw_dynamic(pkg0.plot, 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)
|
||||
Common.annotated_scale_plot_draw_dynamic(pkg0, cr)
|
||||
Common.annotated_scale_plot_draw_dynamic(dram, cr)
|
||||
Common.annotated_scale_plot_draw_dynamic(battery_draw, cr)
|
||||
end
|
||||
|
||||
M.draw_static = draw_static
|
||||
M.draw_dynamic = draw_dynamic
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
local M = {}
|
||||
|
||||
local Arc = require 'Arc'
|
||||
local CompoundDial = require 'CompoundDial'
|
||||
local CriticalText = require 'CriticalText'
|
||||
local Text = require 'Text'
|
||||
local Line = require 'Line'
|
||||
local LabelPlot = require 'LabelPlot'
|
||||
local Table = require 'Table'
|
||||
local Util = require 'Util'
|
||||
|
||||
local __string_format = string.format
|
||||
local Common = require 'Common'
|
||||
|
||||
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,
|
||||
arc_pattern = _G_Patterns_.INDICATOR_BG
|
||||
},
|
||||
inner_ring = _G_Widget_.Arc{
|
||||
x = x,
|
||||
y = y,
|
||||
radius = _DIAL_INNER_RADIUS_ - 2,
|
||||
theta0 = 0,
|
||||
theta1 = 360,
|
||||
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'
|
||||
},
|
||||
text_ring = Common.initTextRing(
|
||||
x,
|
||||
y,
|
||||
_DIAL_INNER_RADIUS_ - 2,
|
||||
'°C',
|
||||
'>90'
|
||||
),
|
||||
coretemp_path = string.format(CORETEMP_PATH, hwmon_index, 'temp'..(id + 2)..'_input'),
|
||||
conky_loads = conky_loads,
|
||||
conky_freqs = conky_freqs
|
||||
}
|
||||
end
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _MODULE_Y_,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'PROCESSOR'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_MODULE_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'PROCESSOR'
|
||||
)
|
||||
|
||||
--we assume that this cpu has 4 physical cores with 2 logical each
|
||||
local cores = {}
|
||||
|
@ -111,98 +97,50 @@ for c = 0, NUM_PHYSICAL_CORES - 1 do
|
|||
_create_core_(cores, c, dial_x, dial_y)
|
||||
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 = {
|
||||
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 ave_freq = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _FREQ_Y_,
|
||||
text = 'Ave Freq'
|
||||
},
|
||||
value = _G_Widget_.Text{
|
||||
x = _RIGHT_X_,
|
||||
y = _FREQ_Y_,
|
||||
x_align = 'right',
|
||||
text_color = _G_Patterns_.PRIMARY_FG,
|
||||
text = '<freq>'
|
||||
}
|
||||
}
|
||||
local cpu_status = Common.initTextRows(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_HWP_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_TEXT_SPACING_,
|
||||
{'HWP Preference', 'Ave Freq'}
|
||||
)
|
||||
|
||||
local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_
|
||||
|
||||
local separator = _G_Widget_.Line{
|
||||
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_},
|
||||
p2 = {x = _RIGHT_X_, y = _SEP_Y_},
|
||||
line_pattern = _G_Patterns_.BORDER_FG,
|
||||
}
|
||||
local separator = Common.initSeparator(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_SEP_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH
|
||||
)
|
||||
|
||||
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 = _G_Widget_.LabelPlot{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _PLOT_Y_,
|
||||
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 total_load = Common.initPercentPlot(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_LOAD_Y_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
_PLOT_SECTION_BREAK_,
|
||||
"Total Load"
|
||||
)
|
||||
|
||||
local tbl = _G_Widget_.Table{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
height = _TABLE_HEIGHT_,
|
||||
num_rows = NUM_ROWS,
|
||||
body_color = _G_Patterns_.INACTIVE_TEXT_FG,
|
||||
header_color = _G_Patterns_.ACTIVE_FG,
|
||||
line_pattern = _G_Patterns_.BORDER_FG,
|
||||
separator_pattern = _G_Patterns_.BORDER_FG,
|
||||
'Name',
|
||||
'PID',
|
||||
'CPU (%)'
|
||||
}
|
||||
local tbl = Common.initTable(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_TABLE_HEIGHT_,
|
||||
NUM_ROWS,
|
||||
{'Name', 'PID', 'CPU (%)'}
|
||||
)
|
||||
|
||||
local update = function(cr)
|
||||
local conky = Util.conky
|
||||
local char_count = Util.char_count
|
||||
|
||||
local load_sum = 0
|
||||
local freq_sum = 0
|
||||
|
@ -221,10 +159,9 @@ local update = function(cr)
|
|||
freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t])
|
||||
end
|
||||
|
||||
CriticalText.set(
|
||||
core.coretemp_text, cr,
|
||||
Util.round_to_string(
|
||||
0.001 * Util.read_file(core.coretemp_path, nil, '*n')))
|
||||
Common.text_ring_set(core.text_ring, cr,
|
||||
Util.round_to_string(
|
||||
0.001 * Util.read_file(core.coretemp_path, nil, '*n')))
|
||||
end
|
||||
|
||||
-- read HWP of first cpu, then test all others to see if they match
|
||||
|
@ -239,29 +176,25 @@ local update = function(cr)
|
|||
i = i + 1
|
||||
end
|
||||
|
||||
local hwp_val = "Unknown"
|
||||
if mixed then
|
||||
Text.set(hwp.value, cr, "Mixed")
|
||||
hwp_val = "Mixed"
|
||||
elseif hwp_pref == "power" then
|
||||
Text.set(hwp.value, cr, "Power")
|
||||
hwp_val = "Power"
|
||||
elseif hwp_pref == "balance_power" then
|
||||
Text.set(hwp.value, cr, "Bal. Power")
|
||||
hwp_val = "Bal. Power"
|
||||
elseif hwp_pref == "balance_performance" then
|
||||
Text.set(hwp.value, cr, "Bal. Performance")
|
||||
hwp_val = "Bal. Performance"
|
||||
elseif hwp_pref == "performance" then
|
||||
Text.set(hwp.value, cr, "Performance")
|
||||
hwp_val = "Performance"
|
||||
elseif hwp_pref == "default" then
|
||||
Text.set(hwp.value, cr, "Default")
|
||||
else
|
||||
Text.set(hwp.value, cr, "Unknown")
|
||||
hwp_val = "Default"
|
||||
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')
|
||||
|
||||
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)
|
||||
Common.percent_plot_set(total_load, cr, load_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE * 100)
|
||||
|
||||
for r = 1, NUM_ROWS do
|
||||
local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces
|
||||
|
@ -289,50 +222,40 @@ _TABLE_HEIGHT_ = nil
|
|||
_create_core_ = nil
|
||||
_FREQ_Y_ = nil
|
||||
_LOAD_Y_ = nil
|
||||
_RIGHT_X_ = nil
|
||||
_SEP_Y_ = nil
|
||||
_HWP_Y_ = nil
|
||||
_PLOT_Y_ = nil
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
M.draw_static = function(cr)
|
||||
Common.drawHeader(cr, header)
|
||||
|
||||
for c = 1, NUM_PHYSICAL_CORES do
|
||||
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)
|
||||
end
|
||||
|
||||
Text.draw(hwp.label, cr)
|
||||
Text.draw(ave_freq.label, cr)
|
||||
Common.text_rows_draw_static(cpu_status, cr)
|
||||
Line.draw(separator, cr)
|
||||
|
||||
Text.draw(total_load.label, cr)
|
||||
LabelPlot.draw_static(plot, cr)
|
||||
Common.percent_plot_draw_static(total_load, cr)
|
||||
|
||||
Table.draw_static(tbl, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr)
|
||||
M.draw_dynamic = function(cr)
|
||||
update(cr)
|
||||
|
||||
for c = 1, NUM_PHYSICAL_CORES do
|
||||
local this_core = cores[c]
|
||||
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
|
||||
|
||||
Text.draw(hwp.value, cr)
|
||||
Text.draw(ave_freq.value, cr)
|
||||
|
||||
CriticalText.draw(total_load.value, cr)
|
||||
LabelPlot.draw_dynamic(plot, cr)
|
||||
Common.text_rows_draw_dynamic(cpu_status, cr)
|
||||
Common.percent_plot_draw_dynamic(total_load, cr)
|
||||
|
||||
Table.draw_dynamic(tbl, cr)
|
||||
end
|
||||
|
||||
M.draw_static = draw_static
|
||||
M.draw_dynamic = draw_dynamic
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
local M = {}
|
||||
|
||||
local Text = require 'Text'
|
||||
local Line = require 'Line'
|
||||
local ScalePlot = require 'ScalePlot'
|
||||
local Util = require 'Util'
|
||||
local Common = require 'Common'
|
||||
|
||||
local __tonumber = tonumber
|
||||
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
|
||||
stat.prev_byte_cnt = byte_cnt
|
||||
|
||||
local text_value = '0.00 B/s'
|
||||
local plot_value = 0
|
||||
if delta_bytes > 0 then
|
||||
local bps = delta_bytes * update_frequency
|
||||
local unit, value = Util.convert_data_val(bps)
|
||||
stat.rate.append_end = ' '..unit..'B/s'
|
||||
Text.set(stat.rate, cr, Util.precision_round_to_string(value, 3))
|
||||
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)
|
||||
text_value = Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
|
||||
plot_value = bps
|
||||
end
|
||||
Common.annotated_scale_plot_set(stat, cr, text_value, plot_value)
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.CENTER_LEFT_X,
|
||||
y = _G_INIT_DATA_.TOP_Y,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'INPUT / OUTPUT'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.CENTER_LEFT_X,
|
||||
_G_INIT_DATA_.TOP_Y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'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 = {
|
||||
label = _G_Widget_.Text{
|
||||
x = _G_INIT_DATA_.CENTER_LEFT_X,
|
||||
y = header.bottom_y,
|
||||
text = 'Reads',
|
||||
},
|
||||
rate = _G_Widget_.Text{
|
||||
x = _RIGHT_X_,
|
||||
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,
|
||||
}
|
||||
}
|
||||
local writes = Common.initLabeledScalePlot(
|
||||
_G_INIT_DATA_.CENTER_LEFT_X,
|
||||
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_PLOT_HEIGHT_,
|
||||
io_label_function,
|
||||
_PLOT_SEC_BREAK_,
|
||||
'Writes'
|
||||
)
|
||||
|
||||
_PLOT_SEC_BREAK_ = nil
|
||||
_PLOT_HEIGHT_ = nil
|
||||
_RIGHT_X_ = nil
|
||||
_WRITE_Y_ = nil
|
||||
|
||||
reads.byte_cnt = 0
|
||||
writes.byte_cnt = 0
|
||||
|
@ -127,21 +85,15 @@ local update = function(cr, update_frequency)
|
|||
end
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
|
||||
Text.draw(reads.label, cr)
|
||||
Text.draw(writes.label, cr)
|
||||
Common.drawHeader(cr, header)
|
||||
Common.annotated_scale_plot_draw_static(reads, cr)
|
||||
Common.annotated_scale_plot_draw_static(writes, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr, update_frequency)
|
||||
update(cr, update_frequency)
|
||||
|
||||
Text.draw(reads.rate, cr)
|
||||
ScalePlot.draw_dynamic(reads.plot, cr)
|
||||
|
||||
Text.draw(writes.rate, cr)
|
||||
ScalePlot.draw_dynamic(writes.plot, cr)
|
||||
Common.annotated_scale_plot_draw_dynamic(reads, cr)
|
||||
Common.annotated_scale_plot_draw_dynamic(writes, cr)
|
||||
end
|
||||
|
||||
M.draw_static = draw_static
|
||||
|
|
|
@ -1,73 +1,44 @@
|
|||
local M = {}
|
||||
|
||||
local Text = require 'Text'
|
||||
local Line = require 'Line'
|
||||
local TextColumn = require 'TextColumn'
|
||||
local Util = require 'Util'
|
||||
local Common = require 'Common'
|
||||
|
||||
local __string_match = string.match
|
||||
|
||||
local _TEXT_SPACING_ = 20
|
||||
|
||||
local header = _G_Widget_.Header{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = _G_INIT_DATA_.TOP_Y,
|
||||
width = _G_INIT_DATA_.SECTION_WIDTH,
|
||||
header = 'SYSTEM'
|
||||
}
|
||||
local header = Common.Header(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
_G_INIT_DATA_.TOP_Y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
'SYSTEM'
|
||||
)
|
||||
|
||||
local labels = _G_Widget_.TextColumn{
|
||||
x = _G_INIT_DATA_.LEFT_X,
|
||||
y = header.bottom_y,
|
||||
spacing = _TEXT_SPACING_,
|
||||
'Kernel',
|
||||
'Uptime',
|
||||
'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>'
|
||||
}
|
||||
local rows = Common.initTextRows(
|
||||
_G_INIT_DATA_.LEFT_X,
|
||||
header.bottom_y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH,
|
||||
_TEXT_SPACING_,
|
||||
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
|
||||
)
|
||||
|
||||
_TEXT_SPACING_ = nil
|
||||
|
||||
local draw_static = function(cr)
|
||||
Text.draw(header.text, cr)
|
||||
Text.draw(kernel, cr)
|
||||
Line.draw(header.underline, cr)
|
||||
TextColumn.draw(labels, cr)
|
||||
M.draw_static = function(cr)
|
||||
Common.drawHeader(cr, header)
|
||||
Common.text_rows_draw_static(rows, cr)
|
||||
end
|
||||
|
||||
local draw_dynamic = function(cr, pacman_stats)
|
||||
TextColumn.set(info, cr, 1, Util.conky('$uptime'))
|
||||
|
||||
M.draw_dynamic = function(cr, pacman_stats)
|
||||
local last_update, last_sync = "N/A", "N/A"
|
||||
if pacman_stats then
|
||||
local 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")
|
||||
last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
|
||||
end
|
||||
|
||||
TextColumn.draw(info, cr)
|
||||
Common.text_rows_set(rows, cr, 1, Util.conky('$kernel'))
|
||||
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
|
||||
|
||||
M.draw_static = draw_static
|
||||
M.draw_dynamic = draw_dynamic
|
||||
|
||||
return M
|
||||
|
|
37
main.lua
37
main.lua
|
@ -126,28 +126,29 @@ local Power = require 'Power'
|
|||
local ReadWrite = require 'ReadWrite'
|
||||
local Graphics = require 'Graphics'
|
||||
local Memory = require 'Memory'
|
||||
local Common = require 'Common'
|
||||
|
||||
--
|
||||
-- initialize static surfaces
|
||||
--
|
||||
local left = _G_Widget_.Panel{
|
||||
x = _G_INIT_DATA_.LEFT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
|
||||
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,
|
||||
height = _G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2,
|
||||
}
|
||||
local center = _G_Widget_.Panel{
|
||||
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,
|
||||
width = _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,
|
||||
}
|
||||
local right = _G_Widget_.Panel{
|
||||
x = _G_INIT_DATA_.RIGHT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
|
||||
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,
|
||||
height = _G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2,
|
||||
}
|
||||
local left = Common.initPanel(
|
||||
_G_INIT_DATA_.LEFT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
|
||||
_G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2,
|
||||
_G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2
|
||||
)
|
||||
local center = Common.initPanel(
|
||||
_G_INIT_DATA_.CENTER_LEFT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
|
||||
_G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y,
|
||||
_G_INIT_DATA_.CENTER_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_Y * 2 + _G_INIT_DATA_.CENTER_PAD,
|
||||
_G_INIT_DATA_.CENTER_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2
|
||||
)
|
||||
local right = Common.initPanel(
|
||||
_G_INIT_DATA_.RIGHT_X - _G_INIT_DATA_.PANEL_MARGIN_X,
|
||||
_G_INIT_DATA_.TOP_Y - _G_INIT_DATA_.PANEL_MARGIN_Y,
|
||||
_G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2,
|
||||
_G_INIT_DATA_.SIDE_HEIGHT + _G_INIT_DATA_.PANEL_MARGIN_Y * 2
|
||||
)
|
||||
|
||||
local _make_static_surface = function(panel, ...)
|
||||
local x = panel.x - panel.thickness * 0.5
|
||||
|
|
Loading…
Reference in New Issue