diff --git a/conky.conf b/conky.conf index bc82389..a89a8f5 100644 --- a/conky.conf +++ b/conky.conf @@ -1,3 +1,5 @@ +local update_interval = 1 -- in seconds + conky.config = { background = false, @@ -28,7 +30,8 @@ conky.config = { --Lua Load lua_load = '~/.config/conky/main.lua', - lua_draw_hook_post = 'main' + lua_draw_hook_post = 'main', + lua_startup_hook = string.format('start %f', update_interval) } --control updates entirely in lua diff --git a/drawing/Common.lua b/drawing/Common.lua index 852cb98..e956a91 100644 --- a/drawing/Common.lua +++ b/drawing/Common.lua @@ -1,6 +1,8 @@ local M = {} local Util = require 'Util' +local Theme = require 'Patterns' +local Startup = require 'Widget' local Arc = require 'Arc' local Text = require 'Text' local CompoundBar = require 'CompoundBar' @@ -58,15 +60,15 @@ M.normal_font_spec = M.make_font_spec(FONT, NORMAL_FONT_SIZE, false) M.label_font_spec = M.make_font_spec(FONT, PLOT_LABEL_FONT_SIZE, false) local _text_row_style = function(x_align, color) - return _G_Widget_.text_style(M.normal_font_spec, color, x_align, 'center') + return Startup.text_style(M.normal_font_spec, color, x_align, 'center') end -M.left_text_style = _text_row_style('left', _G_Patterns_.INACTIVE_TEXT_FG) +M.left_text_style = _text_row_style('left', Theme.INACTIVE_TEXT_FG) -M.right_text_style = _text_row_style('right', _G_Patterns_.PRIMARY_FG) +M.right_text_style = _text_row_style('right', Theme.PRIMARY_FG) local _bare_text = function(pt, text, style) - return _G_Widget_.plainText(pt, text, style) + return Startup.plainText(pt, text, style) end local _left_text = function(pt, text) @@ -84,23 +86,23 @@ M.Header = function(x, y, w, s) local bottom_y = y + HEADER_HEIGHT local underline_y = y + HEADER_UNDERLINE_OFFSET return { - text = _G_Widget_.plainText( - _G_Widget_.make_point(x, y), + text = Startup.plainText( + Startup.make_point(x, y), s, - _G_Widget_.text_style( + Startup.text_style( M.make_font_spec(FONT, HEADER_FONT_SIZE, true), - _G_Patterns_.HEADER_FG, + Theme.HEADER_FG, 'left', 'top' ) ), bottom_y = bottom_y, - underline = _G_Widget_.Line( - _G_Widget_.make_point(x, underline_y), - _G_Widget_.make_point(x + w, underline_y), - _G_Widget_.line_style( + underline = Startup.Line( + Startup.make_point(x, underline_y), + Startup.make_point(x + w, underline_y), + Startup.line_style( HEADER_UNDERLINE_THICKNESS, - _G_Patterns_.HEADER_FG, + Theme.HEADER_FG, HEADER_UNDERLINE_CAP ) ) @@ -115,29 +117,29 @@ end -------------------------------------------------------------------------------- -- label plot -M.default_grid_style = _G_Widget_.grid_style( +M.default_grid_style = Startup.grid_style( PLOT_GRID_X_N, PLOT_GRID_Y_N, - _G_Patterns_.BORDER_FG + Theme.BORDER_FG ) -M.default_plot_style = _G_Widget_.plot_style( +M.default_plot_style = Startup.plot_style( PLOT_NUM_POINTS, - _G_Patterns_.BORDER_FG, - _G_Patterns_.PLOT_FILL_BORDER_PRIMARY, - _G_Patterns_.PLOT_FILL_BG_PRIMARY, + Theme.BORDER_FG, + Theme.PLOT_FILL_BORDER_PRIMARY, + Theme.PLOT_FILL_BG_PRIMARY, M.default_grid_style ) -M.percent_label_style = _G_Widget_.label_style( - _G_Patterns_.INACTIVE_TEXT_FG, +M.percent_label_style = Startup.label_style( + Theme.INACTIVE_TEXT_FG, M.label_font_spec, function(z) return Util.round_to_string(z * 100)..'%' end ) M.initThemedLabelPlot = function(x, y, w, h, label_style) - return _G_Widget_.LabelPlot( - _G_Widget_.make_box(x, y, w, h), + return Startup.LabelPlot( + Startup.make_box(x, y, w, h), 1 / _G_INIT_DATA_.UPDATE_INTERVAL, M.default_plot_style, label_style @@ -149,13 +151,13 @@ end M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, format) return { - label = _left_text(_G_Widget_.make_point(x, y), label), - value = _G_Widget_.formattedThresholdText( - _G_Widget_.make_point(x + w, y), + label = _left_text(Startup.make_point(x, y), label), + value = Startup.formattedThresholdText( + Startup.make_point(x + w, y), nil, M.right_text_style, format, - _G_Widget_.threshold_text_style(_G_Patterns_.CRITICAL_FG, 80) + Startup.threshold_text_style(Theme.CRITICAL_FG, 80) ), plot = M.initThemedLabelPlot( x, @@ -198,16 +200,16 @@ end -- scaled plot M.base_2_scale_data = function(m) - return _G_Widget_.scale_data(2, m, 0.9) + return Startup.scale_data(2, m, 0.9) end M.initThemedScalePlot = function(x, y, w, h, f, min_domain) - return _G_Widget_.ScalePlot( - _G_Widget_.make_box(x, y, w, h), + return Startup.ScalePlot( + Startup.make_box(x, y, w, h), 1 / _G_INIT_DATA_.UPDATE_INTERVAL, M.default_plot_style, - _G_Widget_.label_style( - _G_Patterns_.INACTIVE_TEXT_FG, + Startup.label_style( + Theme.INACTIVE_TEXT_FG, M.label_font_spec, f ), @@ -221,9 +223,9 @@ end M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing, label, min_domain) return { - label = _left_text(_G_Widget_.make_point(x, y), label), - value = _G_Widget_.formatted_text( - _G_Widget_.make_point(x + w, y), + label = _left_text(Startup.make_point(x, y), label), + value = Startup.formatted_text( + Startup.make_point(x + w, y), 0, M.right_text_style, format_fun @@ -253,9 +255,9 @@ end -- I have multiple layers on top of each other M.arc = function(x, y, r, thickness, pattern) - return _G_Widget_.Arc( - _G_Widget_.make_semicircle(x, y, r, 90, 360), - _G_Widget_.arc_style(thickness, pattern) + return Startup.Arc( + Startup.make_semicircle(x, y, r, 90, 360), + Startup.arc_style(thickness, pattern) ) end @@ -263,9 +265,9 @@ end -- ring M.initRing = function(x, y, r) - return _G_Widget_.Arc( - _G_Widget_.make_semicircle(x, y, r, 0, 360), - _G_Widget_.arc_style(ARC_WIDTH, _G_Patterns_.BORDER_FG) + return Startup.Arc( + Startup.make_semicircle(x, y, r, 0, 360), + Startup.arc_style(ARC_WIDTH, Theme.BORDER_FG) ) end @@ -275,17 +277,17 @@ end M.initTextRing = function(x, y, r, fmt, limit) return { ring = M.initRing(x, y, r), - value = _G_Widget_.formattedThresholdText( - _G_Widget_.make_point(x, y), + value = Startup.formattedThresholdText( + Startup.make_point(x, y), nil, - _G_Widget_.text_style( + Startup.text_style( M.normal_font_spec, - _G_Patterns_.PRIMARY_FG, + Theme.PRIMARY_FG, 'center', 'center' ), fmt, - _G_Widget_.threshold_text_style(_G_Patterns_.CRITICAL_FG, limit) + Startup.threshold_text_style(Theme.CRITICAL_FG, limit) ), } end @@ -306,17 +308,17 @@ end -- dial local threshold_indicator = function(threshold) - return _G_Widget_.threshold_style( - _G_Patterns_.INDICATOR_FG_PRIMARY, - _G_Patterns_.INDICATOR_FG_CRITICAL, + return Startup.threshold_style( + Theme.INDICATOR_FG_PRIMARY, + Theme.INDICATOR_FG_CRITICAL, threshold ) end M.dial = function(x, y, radius, thickness, threshold) - return _G_Widget_.Dial( - _G_Widget_.make_semicircle(x, y, radius, DIAL_THETA0, DIAL_THETA1), - _G_Widget_.arc_style(thickness, _G_Patterns_.INDICATOR_BG), + return Startup.Dial( + Startup.make_semicircle(x, y, radius, DIAL_THETA0, DIAL_THETA1), + Startup.arc_style(thickness, Theme.INDICATOR_BG), threshold_indicator(threshold) ) end @@ -326,9 +328,9 @@ end M.compound_dial = function(x, y, outer_radius, inner_radius, thickness, threshold, num_dials) - return _G_Widget_.CompoundDial( - _G_Widget_.make_semicircle(x, y, outer_radius, DIAL_THETA0, DIAL_THETA1), - _G_Widget_.arc_style(thickness, _G_Patterns_.INDICATOR_BG), + return Startup.CompoundDial( + Startup.make_semicircle(x, y, outer_radius, DIAL_THETA0, DIAL_THETA1), + Startup.arc_style(thickness, Theme.INDICATOR_BG), threshold_indicator(threshold), inner_radius, num_dials @@ -340,19 +342,19 @@ end M.compound_bar = function(x, y, w, pad, labels, spacing, thickness, threshold) return { - labels = _G_Widget_.TextColumn( - _G_Widget_.make_point(x, y), + labels = Startup.TextColumn( + Startup.make_point(x, y), labels, M.left_text_style, nil, spacing ), - bars = _G_Widget_.CompoundBar( - _G_Widget_.make_point(x + pad, y), + bars = Startup.CompoundBar( + Startup.make_point(x + pad, y), w - pad, - _G_Widget_.line_style( + Startup.line_style( thickness, - _G_Patterns_.INDICATOR_BG, + Theme.INDICATOR_BG, CAIRO_LINE_JOIN_MITER ), threshold_indicator(threshold), @@ -380,12 +382,12 @@ end -- separator (eg a horizontal line) M.initSeparator = function(x, y, w) - return _G_Widget_.Line( - _G_Widget_.make_point(x, y), - _G_Widget_.make_point(x + w, y), - _G_Widget_.line_style( + return Startup.Line( + Startup.make_point(x, y), + Startup.make_point(x + w, y), + Startup.line_style( SEPARATOR_THICKNESS, - _G_Patterns_.BORDER_FG, + Theme.BORDER_FG, CAIRO_LINE_CAP_BUTT ) ) @@ -396,8 +398,8 @@ end M.initTextRow = function(x, y, w, label) return { - label = _left_text(_G_Widget_.make_point(x, y), label), - value = _right_text(_G_Widget_.make_point(x + w, y), nil), + label = _left_text(Startup.make_point(x, y), label), + value = _right_text(Startup.make_point(x + w, y), nil), } end @@ -418,18 +420,18 @@ end M.initTextRowCrit = function(x, y, w, label, append_end, limit) return{ - label = _left_text(_G_Widget_.make_point(x, y), label), - value = _G_Widget_.formattedThresholdText( - _G_Widget_.make_point(x + w, y), + label = _left_text(Startup.make_point(x, y), label), + value = Startup.formattedThresholdText( + Startup.make_point(x + w, y), nil, - _G_Widget_.text_style( + Startup.text_style( M.normal_font_spec, - _G_Patterns_.PRIMARY_FG, + Theme.PRIMARY_FG, 'right', 'center' ), append_end, - _G_Widget_.threshold_text_style(_G_Patterns_.CRITICAL_FG, limit) + Startup.threshold_text_style(Theme.CRITICAL_FG, limit) ) } end @@ -448,8 +450,8 @@ end -- text column M.text_column = function(x, y, spacing, labels, x_align, color) - return _G_Widget_.TextColumn( - _G_Widget_.make_point(x, y), + return Startup.TextColumn( + Startup.make_point(x, y), labels, _text_row_style(x_align, color), nil, @@ -462,15 +464,15 @@ end M.initTextRows_color = function(x, y, w, spacing, labels, color, format) return { - labels = _G_Widget_.TextColumn( - _G_Widget_.make_point(x, y), + labels = Startup.TextColumn( + Startup.make_point(x, y), labels, M.left_text_style, nil, spacing ), - values = _G_Widget_.initTextColumnN( - _G_Widget_.make_point(x + w, y), + values = Startup.initTextColumnN( + Startup.make_point(x + w, y), #labels, _text_row_style('right', color), format, @@ -486,7 +488,7 @@ M.initTextRows = function(x, y, w, spacing, labels) w, spacing, labels, - _G_Patterns_.PRIMARY_FG, + Theme.PRIMARY_FG, nil ) end @@ -508,27 +510,27 @@ end M.default_table_font_spec = M.make_font_spec(FONT, TABLE_FONT_SIZE, false) -M.default_table_style = _G_Widget_.table_style( - _G_Widget_.rect_style( +M.default_table_style = Startup.table_style( + Startup.rect_style( TABLE_LINE_THICKNESS, - _G_Patterns_.BORDER_FG + Theme.BORDER_FG ), - _G_Widget_.line_style( + Startup.line_style( TABLE_LINE_THICKNESS, - _G_Patterns_.BORDER_FG, + Theme.BORDER_FG, CAIRO_LINE_CAP_BUTT ), - _G_Widget_.table_header_style( + Startup.table_header_style( M.default_table_font_spec, - _G_Patterns_.PRIMARY_FG, + Theme.PRIMARY_FG, TABLE_HEADER_PAD ), - _G_Widget_.table_body_style( + Startup.table_body_style( M.default_table_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG, + Theme.INACTIVE_TEXT_FG, TABLE_BODY_FORMAT ), - _G_Widget_.padding( + Startup.padding( TABLE_HORZ_PAD, TABLE_VERT_PAD, TABLE_HORZ_PAD, @@ -537,8 +539,8 @@ M.default_table_style = _G_Widget_.table_style( ) M.initTable = function(x, y, w, h, n, labels) - return _G_Widget_.Table( - _G_Widget_.make_box(x, y, w, h), + return Startup.Table( + Startup.make_box(x, y, w, h), n, labels, M.default_table_style @@ -549,10 +551,10 @@ end -- panel M.initPanel = function(x, y, w, h, thickness) - return _G_Widget_.FillRect( - _G_Widget_.make_box(x, y, w, h), - _G_Widget_.rect_style(thickness, _G_Patterns_.BORDER_FG), - _G_Patterns_.PANEL_BG + return Startup.FillRect( + Startup.make_box(x, y, w, h), + Startup.rect_style(thickness, Theme.BORDER_FG), + Theme.PANEL_BG ) end diff --git a/drawing/FileSystem.lua b/drawing/FileSystem.lua index df05464..0c191f4 100644 --- a/drawing/FileSystem.lua +++ b/drawing/FileSystem.lua @@ -3,6 +3,7 @@ local M = {} local Line = require 'Line' local Util = require 'Util' local Common = require 'Common' +local Geometry = require 'Geometry' local _FS_PATHS_ = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"} local _MODULE_Y_ = 170 @@ -13,9 +14,9 @@ local _SEPARATOR_SPACING_ = 20 local FS_NUM = #_FS_PATHS_ local header = Common.Header( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _MODULE_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'FILE SYSTEMS' ) @@ -26,26 +27,26 @@ for i, v in pairs(_FS_PATHS_) do end local smart = Common.initTextRow( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, header.bottom_y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'SMART Daemon' ) local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_ local separator = Common.initSeparator( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _SEP_Y_, - _G_INIT_DATA_.SECTION_WIDTH + Geometry.SECTION_WIDTH ) local _BAR_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ local fs = Common.compound_bar( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _BAR_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _BAR_PAD_, {'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'}, _SPACING_, diff --git a/drawing/Graphics.lua b/drawing/Graphics.lua index bf31dec..39d1699 100644 --- a/drawing/Graphics.lua +++ b/drawing/Graphics.lua @@ -2,9 +2,9 @@ local M = {} local Text = require 'Text' local Line = require 'Line' -local LabelPlot = require 'LabelPlot' local Util = require 'Util' local Common = require 'Common' +local Geometry = require 'Geometry' local __string_match = string.match @@ -21,33 +21,33 @@ local na_percent_format = function(x) end local header = Common.Header( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _MODULE_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'NVIDIA GRAPHICS' ) local status = Common.initTextRow( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, header.bottom_y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'Status' ) local _SEP_Y_1_ = header.bottom_y + _SEPARATOR_SPACING_ local separator1 = Common.initSeparator( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _SEP_Y_1_, - _G_INIT_DATA_.SECTION_WIDTH + Geometry.SECTION_WIDTH ) local _INTERNAL_TEMP_Y_ = _SEP_Y_1_ + _SEPARATOR_SPACING_ local internal_temp = Common.initTextRowCrit( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _INTERNAL_TEMP_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'Internal Temperature', function(s) if s == -1 then return NA else return string.format('%s°C', s) end end, 80 @@ -56,17 +56,17 @@ local internal_temp = Common.initTextRowCrit( local _SEP_Y_2_ = _INTERNAL_TEMP_Y_ + _SEPARATOR_SPACING_ local separator2 = Common.initSeparator( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _SEP_Y_2_, - _G_INIT_DATA_.SECTION_WIDTH + Geometry.SECTION_WIDTH ) local _CLOCK_SPEED_Y_ = _SEP_Y_2_ + _SEPARATOR_SPACING_ local clock_speed = Common.initTextRows( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _CLOCK_SPEED_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _TEXT_SPACING_, {'GPU Clock Speed', 'Memory Clock Speed'} ) @@ -74,17 +74,17 @@ local clock_speed = Common.initTextRows( local _SEP_Y_3_ = _CLOCK_SPEED_Y_ + _TEXT_SPACING_ * 2 local separator3 = Common.initSeparator( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _SEP_Y_3_, - _G_INIT_DATA_.SECTION_WIDTH + Geometry.SECTION_WIDTH ) local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_ local gpu_util = Common.initPercentPlot_formatted( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _GPU_UTIL_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, _PLOT_SEC_BREAK_, 'GPU Utilization', @@ -94,9 +94,9 @@ local gpu_util = Common.initPercentPlot_formatted( local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 local mem_util = Common.initPercentPlot_formatted( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _MEM_UTIL_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, _PLOT_SEC_BREAK_, 'Memory Utilization', @@ -106,9 +106,9 @@ local mem_util = Common.initPercentPlot_formatted( local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 local vid_util = Common.initPercentPlot_formatted( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _VID_UTIL_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, _PLOT_SEC_BREAK_, 'Video Utilization', diff --git a/drawing/Memory.lua b/drawing/Memory.lua index ea456df..45221bd 100644 --- a/drawing/Memory.lua +++ b/drawing/Memory.lua @@ -6,6 +6,8 @@ local LabelPlot = require 'LabelPlot' local Table = require 'Table' local Util = require 'Util' local Common = require 'Common' +local Theme = require 'Patterns' +local Geometry = require 'Geometry' local __string_match = string.match local __cairo_path_destroy = cairo_path_destroy @@ -41,16 +43,16 @@ for r = 1, NUM_ROWS do end local header = Common.Header( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _MODULE_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'MEMORY' ) local DIAL_RADIUS = 32 local DIAL_THETA_0 = math.rad(90) local DIAL_THETA_1 = math.rad(360) -local DIAL_X = _G_INIT_DATA_.RIGHT_X + DIAL_RADIUS + _DIAL_THICKNESS_ / 2 +local DIAL_X = Geometry.RIGHT_X + DIAL_RADIUS + _DIAL_THICKNESS_ / 2 local DIAL_Y = header.bottom_y + DIAL_RADIUS + _DIAL_THICKNESS_ / 2 local dial = Common.dial(DIAL_X, DIAL_Y, DIAL_RADIUS, _DIAL_THICKNESS_, 0.8) @@ -59,7 +61,7 @@ local cache_arc = Common.arc( DIAL_Y, DIAL_RADIUS, _DIAL_THICKNESS_, - _G_Patterns_.INDICATOR_FG_SECONDARY + Theme.INDICATOR_FG_SECONDARY ) local text_ring = Common.initTextRing( @@ -71,8 +73,8 @@ local text_ring = Common.initTextRing( ) 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 _TEXT_LEFT_X_ = Geometry.RIGHT_X + DIAL_RADIUS * 2 + _TEXT_LEFT_X_OFFSET_ +local _RIGHT_X_ = Geometry.RIGHT_X + Geometry.SECTION_WIDTH local swap = Common.initTextRowCrit( _TEXT_LEFT_X_, @@ -87,27 +89,27 @@ local swap = Common.initTextRowCrit( local cache = Common.initTextRows_color( _TEXT_LEFT_X_, _LINE_1_Y_ + _TEXT_SPACING_, - _G_INIT_DATA_.SECTION_WIDTH - _TEXT_LEFT_X_OFFSET_ - DIAL_RADIUS * 2, + Geometry.SECTION_WIDTH - _TEXT_LEFT_X_OFFSET_ - DIAL_RADIUS * 2, _TEXT_SPACING_, {'Page Cache', 'Buffers', 'Kernel Slab'}, - _G_Patterns_.SECONDARY_FG, + Theme.SECONDARY_FG, '%s%%' ) local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2 local plot = Common.initThemedLabelPlot( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _PLOT_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, Common.percent_label_style ) local tbl = Common.initTable( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _TABLE_HEIGHT_, NUM_ROWS, {'Name', 'PID', 'Mem (%)'} diff --git a/drawing/Network.lua b/drawing/Network.lua index e813947..0ab4a1f 100644 --- a/drawing/Network.lua +++ b/drawing/Network.lua @@ -2,6 +2,7 @@ local M = {} local Util = require 'Util' local Common = require 'Common' +local Geometry = require 'Geometry' local __string_gmatch = string.gmatch local __math_floor = math.floor @@ -20,16 +21,16 @@ local value_format_function = function(bits) end local header = Common.Header( - _G_INIT_DATA_.CENTER_RIGHT_X, - _G_INIT_DATA_.TOP_Y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.CENTER_RIGHT_X, + Geometry.TOP_Y, + Geometry.SECTION_WIDTH, 'NETWORK' ) local dnload = Common.initLabeledScalePlot( - _G_INIT_DATA_.CENTER_RIGHT_X, + Geometry.CENTER_RIGHT_X, header.bottom_y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, value_format_function, network_label_function, @@ -39,9 +40,9 @@ local dnload = Common.initLabeledScalePlot( ) local upload = Common.initLabeledScalePlot( - _G_INIT_DATA_.CENTER_RIGHT_X, + Geometry.CENTER_RIGHT_X, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, value_format_function, network_label_function, @@ -95,21 +96,8 @@ local update = function(cr, update_frequency) if tx_delta > 0 then uspeed = uspeed + tx_delta * update_frequency end end - -- local dspeed_unit, dspeed_value = Util.convert_data_val(dspeed) - -- local uspeed_unit, uspeed_value = Util.convert_data_val(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 - ) + Common.annotated_scale_plot_set(dnload, cr, dspeed) + Common.annotated_scale_plot_set(upload, cr, uspeed) end _PLOT_SEC_BREAK_ = nil diff --git a/drawing/Pacman.lua b/drawing/Pacman.lua index c24e081..ce74301 100644 --- a/drawing/Pacman.lua +++ b/drawing/Pacman.lua @@ -1,6 +1,7 @@ local M = {} local Common = require 'Common' +local Geometry = require 'Geometry' local __string_match = string.match local __string_gmatch = string.gmatch @@ -8,16 +9,16 @@ local __string_gmatch = string.gmatch local _TEXT_SPACING_ = 20 local header = Common.Header( - _G_INIT_DATA_.RIGHT_X, - _G_INIT_DATA_.TOP_Y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.RIGHT_X, + Geometry.TOP_Y, + Geometry.SECTION_WIDTH, 'PACMAN' ) local rows = Common.initTextRows( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, header.bottom_y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _TEXT_SPACING_, {'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'} ) diff --git a/drawing/Power.lua b/drawing/Power.lua index 3528536..dffc320 100644 --- a/drawing/Power.lua +++ b/drawing/Power.lua @@ -2,6 +2,7 @@ local M = {} local Util = require 'Util' local Common = require 'Common' +local Geometry = require 'Geometry' local _MODULE_Y_ = 380 local _TEXT_SPACING_ = 20 @@ -31,16 +32,16 @@ local ac_format_function = function(watts) end local header = Common.Header( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _MODULE_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'POWER' ) local pkg0 = Common.initLabeledScalePlot( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, header.bottom_y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, power_format_function, power_label_function, @@ -52,9 +53,9 @@ local pkg0 = Common.initLabeledScalePlot( local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_ local dram = Common.initLabeledScalePlot( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _CORE_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, power_format_function, power_label_function, @@ -65,9 +66,9 @@ local dram = Common.initLabeledScalePlot( dram.value.append_end = ' W' local battery_draw = Common.initLabeledScalePlot( - _G_INIT_DATA_.RIGHT_X, + Geometry.RIGHT_X, _CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, ac_format_function, power_label_function, diff --git a/drawing/Processor.lua b/drawing/Processor.lua index 50b2ad3..d9ce038 100644 --- a/drawing/Processor.lua +++ b/drawing/Processor.lua @@ -5,6 +5,7 @@ local Line = require 'Line' local Table = require 'Table' local Util = require 'Util' local Common = require 'Common' +local Geometry = require 'Geometry' local __string_match = string.match local __string_gmatch = string.gmatch @@ -74,9 +75,9 @@ local _create_core_ = function(cores, id, x, y) end local header = Common.Header( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _MODULE_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, 'PROCESSOR' ) @@ -84,8 +85,8 @@ local header = Common.Header( local cores = {} for c = 0, NUM_PHYSICAL_CORES - 1 do - local dial_x = _G_INIT_DATA_.LEFT_X + _DIAL_OUTER_RADIUS_ + - (_G_INIT_DATA_.SECTION_WIDTH - 2 * _DIAL_OUTER_RADIUS_) * c / 3 + local dial_x = Geometry.LEFT_X + _DIAL_OUTER_RADIUS_ + + (Geometry.SECTION_WIDTH - 2 * _DIAL_OUTER_RADIUS_) * c / 3 local dial_y = header.bottom_y + _DIAL_OUTER_RADIUS_ _create_core_(cores, c, dial_x, dial_y) end @@ -95,9 +96,9 @@ local _HWP_Y_ = header.bottom_y + _DIAL_OUTER_RADIUS_ * 2 + _PLOT_SECTION_BREAK_ local _FREQ_Y_ = _HWP_Y_ + _TEXT_SPACING_ local cpu_status = Common.initTextRows( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _HWP_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _TEXT_SPACING_, {'HWP Preference', 'Ave Freq'} ) @@ -105,9 +106,9 @@ local cpu_status = Common.initTextRows( local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_ local separator = Common.initSeparator( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _SEP_Y_, - _G_INIT_DATA_.SECTION_WIDTH + Geometry.SECTION_WIDTH ) local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ @@ -115,18 +116,18 @@ local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_ local total_load = Common.initPercentPlot( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _LOAD_Y_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, _PLOT_SECTION_BREAK_, "Total Load" ) local tbl = Common.initTable( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _TABLE_HEIGHT_, NUM_ROWS, {'Name', 'PID', 'CPU (%)'} diff --git a/drawing/ReadWrite.lua b/drawing/ReadWrite.lua index a3fed89..2a5e8b8 100644 --- a/drawing/ReadWrite.lua +++ b/drawing/ReadWrite.lua @@ -2,6 +2,7 @@ local M = {} local Util = require 'Util' local Common = require 'Common' +local Geometry = require 'Geometry' local __tonumber = tonumber local __string_match = string.match @@ -44,16 +45,16 @@ local format_value_function = function(bps) end local header = Common.Header( - _G_INIT_DATA_.CENTER_LEFT_X, - _G_INIT_DATA_.TOP_Y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.CENTER_LEFT_X, + Geometry.TOP_Y, + Geometry.SECTION_WIDTH, 'INPUT / OUTPUT' ) local reads = Common.initLabeledScalePlot( - _G_INIT_DATA_.CENTER_LEFT_X, + Geometry.CENTER_LEFT_X, header.bottom_y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, format_value_function, io_label_function, @@ -64,9 +65,9 @@ local reads = Common.initLabeledScalePlot( ) local writes = Common.initLabeledScalePlot( - _G_INIT_DATA_.CENTER_LEFT_X, + Geometry.CENTER_LEFT_X, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _PLOT_HEIGHT_, format_value_function, io_label_function, diff --git a/drawing/System.lua b/drawing/System.lua index 587c79e..bd8310a 100644 --- a/drawing/System.lua +++ b/drawing/System.lua @@ -2,22 +2,23 @@ local M = {} local Util = require 'Util' local Common = require 'Common' +local Geometry = require 'Geometry' local __string_match = string.match local _TEXT_SPACING_ = 20 local header = Common.Header( - _G_INIT_DATA_.LEFT_X, - _G_INIT_DATA_.TOP_Y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.LEFT_X, + Geometry.TOP_Y, + Geometry.SECTION_WIDTH, 'SYSTEM' ) local rows = Common.initTextRows( - _G_INIT_DATA_.LEFT_X, + Geometry.LEFT_X, header.bottom_y, - _G_INIT_DATA_.SECTION_WIDTH, + Geometry.SECTION_WIDTH, _TEXT_SPACING_, {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'} ) diff --git a/main.lua b/main.lua index 63dde45..f765b1b 100644 --- a/main.lua +++ b/main.lua @@ -1,88 +1,12 @@ ---[[ -Boolean conventions: - 0 is true, 1 is false - -Module format: - LIBRARY STRUCTURE (a collection of functions/values in a table): - local M = {} -- define module-level table to return - - local modname = requires 'modname' - -- import all required modules - - local foo = function() - -- code - end - - -- define more functions - - M.foo = foo -- dump all functions into table - - return M -- return entire table (use functions as modname.foo) - -Var names: - - delimiters: all words separated by _ (unless camalCase) - - booleans: preceed by is_ (as in is_awesome) - - Spacial scope: - - Everything declared local by default - - reassigning to local: - - upval to local: prefix with _ - - global to local: prefix with __ - - replace . with _ if callng from table - - the only reason to do either of these is for performance, therefore - no need to localize variables that are only used during init - - global: preceed with g_ - - Temporal Scope - - init: only relevent to startup (nil'ed before first rendering loop) - - persistant: always relevent (potentially) - - flank init vars with _ - - Mutability - - variable: lowercase - - constant: ALL_CAPS - - constants can be anything except functions - - Module Names: - - CapCamalCase - - var name is exactly the same as module name ---]] - -- -- initialialize global geometric data -- local UPDATE_FREQUENCY = 1 --Hz _G_INIT_DATA_ = { - UPDATE_INTERVAL = 1 / UPDATE_FREQUENCY, - - LEFT_X = 32, - SECTION_WIDTH = 436, - CENTER_PAD = 20, - PANEL_HORZ_SPACING = 10, - PANEL_MARGIN_X = 20, - PANEL_MARGIN_Y = 10, - - TOP_Y = 21, - SIDE_HEIGHT = 1020, - CENTER_HEIGHT = 220, - - -- silly hack, the price of a litewait language - ABS_PATH = debug.getinfo(1).source:match("@?(.*/)") + UPDATE_INTERVAL = 1 / UPDATE_FREQUENCY, } -_G_INIT_DATA_.CENTER_LEFT_X = _G_INIT_DATA_.LEFT_X + - _G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2 + - _G_INIT_DATA_.PANEL_HORZ_SPACING - -_G_INIT_DATA_.CENTER_RIGHT_X = _G_INIT_DATA_.CENTER_LEFT_X + - _G_INIT_DATA_.SECTION_WIDTH + _G_INIT_DATA_.CENTER_PAD - -_G_INIT_DATA_.CENTER_WIDTH = _G_INIT_DATA_.SECTION_WIDTH * 2 + - _G_INIT_DATA_.CENTER_PAD - -_G_INIT_DATA_.RIGHT_X = _G_INIT_DATA_.CENTER_LEFT_X + - _G_INIT_DATA_.CENTER_WIDTH + _G_INIT_DATA_.PANEL_MARGIN_X * 2 + - _G_INIT_DATA_.PANEL_HORZ_SPACING - -conky_set_update_interval(_G_INIT_DATA_.UPDATE_INTERVAL) - -- -- init cairo -- @@ -96,24 +20,19 @@ local __cairo_surface_destroy = cairo_surface_destroy local __cairo_destroy = cairo_destroy local __cairo_translate = cairo_translate --- --- import all packages and init with global geometric data --- -package.path = _G_INIT_DATA_.ABS_PATH..'?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'drawing/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'schema/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/func/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/super/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/widget/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/widget/arc/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/widget/text/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/widget/plot/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/widget/rect/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/widget/poly/?.lua;'.. - _G_INIT_DATA_.ABS_PATH..'core/widget/image/?.lua;' - -_G_Widget_ = require 'Widget' -_G_Patterns_ = require 'Patterns' +local ABS_PATH = debug.getinfo(1).source:match("@?(.*/)") +package.path = ABS_PATH..'?.lua;'.. + ABS_PATH..'drawing/?.lua;'.. + ABS_PATH..'schema/?.lua;'.. + ABS_PATH..'core/func/?.lua;'.. + ABS_PATH..'core/super/?.lua;'.. + ABS_PATH..'core/widget/?.lua;'.. + ABS_PATH..'core/widget/arc/?.lua;'.. + ABS_PATH..'core/widget/text/?.lua;'.. + ABS_PATH..'core/widget/plot/?.lua;'.. + ABS_PATH..'core/widget/rect/?.lua;'.. + ABS_PATH..'core/widget/poly/?.lua;'.. + ABS_PATH..'core/widget/image/?.lua;' local Util = require 'Util' local FillRect = require 'FillRect' @@ -127,6 +46,7 @@ local ReadWrite = require 'ReadWrite' local Graphics = require 'Graphics' local Memory = require 'Memory' local Common = require 'Common' +local Geometry = require 'Geometry' -- -- initialize static surfaces @@ -162,26 +82,26 @@ local draw_static_surface = function(cr, cs_obj) end local cs_left = _make_static_surface( - _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, + Geometry.LEFT_X - Geometry.PANEL_MARGIN_X, + Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y, + Geometry.SECTION_WIDTH + Geometry.PANEL_MARGIN_X * 2, + Geometry.SIDE_HEIGHT + Geometry.PANEL_MARGIN_Y * 2, {System.draw_static, Graphics.draw_static, Processor.draw_static} ) local cs_center = _make_static_surface( - _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, + Geometry.CENTER_LEFT_X - Geometry.PANEL_MARGIN_X, + Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y, + Geometry.CENTER_WIDTH + Geometry.PANEL_MARGIN_Y * 2 + Geometry.CENTER_PAD, + Geometry.CENTER_HEIGHT + Geometry.PANEL_MARGIN_Y * 2, {ReadWrite.draw_static, Network.draw_static} ) local cs_right = _make_static_surface( - _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, + Geometry.RIGHT_X - Geometry.PANEL_MARGIN_X, + Geometry.TOP_Y - Geometry.PANEL_MARGIN_Y, + Geometry.SECTION_WIDTH + Geometry.PANEL_MARGIN_X * 2, + Geometry.SIDE_HEIGHT + Geometry.PANEL_MARGIN_Y * 2, {Pacman.draw_static, FileSystem.draw_static, Power.draw_static, Memory.draw_static} ) @@ -190,9 +110,6 @@ local cs_right = _make_static_surface( -- local _unrequire = function(m) package.loaded[m] = nil end -_G_Widget_ = nil -_G_Patterns_ = nil - _unrequire('Super') _unrequire('Color') _unrequire('Widget') @@ -216,6 +133,10 @@ end local updates = -2 -- this accounts for the first few spazzy iterations local STATS_FILE = '/tmp/.conky_pacman' +function conky_start(update_interval) + conky_set_update_interval(update_interval) +end + function conky_main() local _cw = conky_window if not _cw then return end diff --git a/schema/Geometry.lua b/schema/Geometry.lua new file mode 100644 index 0000000..ee90afb --- /dev/null +++ b/schema/Geometry.lua @@ -0,0 +1,20 @@ +local M = {} + +M.LEFT_X = 32 +M.SECTION_WIDTH = 436 +M.CENTER_PAD = 20 +M.PANEL_HORZ_SPACING = 10 +M.PANEL_MARGIN_X = 20 +M.PANEL_MARGIN_Y = 10 +M.TOP_Y = 21 +M.SIDE_HEIGHT = 1020 +M.CENTER_HEIGHT = 220 + +local margin_width = M.PANEL_MARGIN_X * 2 + M.PANEL_HORZ_SPACING + +M.CENTER_LEFT_X = M.LEFT_X + M.SECTION_WIDTH + margin_width +M.CENTER_RIGHT_X = M.CENTER_LEFT_X + M.SECTION_WIDTH + M.CENTER_PAD +M.CENTER_WIDTH = M.SECTION_WIDTH * 2 + M.CENTER_PAD +M.RIGHT_X = M.CENTER_LEFT_X + M.CENTER_WIDTH + margin_width + +return M