2017-07-16 03:59:40 -04:00
|
|
|
--[[
|
2017-07-16 13:49:43 -04:00
|
|
|
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)
|
|
|
|
|
|
|
|
RENDERING MODULE STRUCTURE (only used in this module; main.lua):
|
|
|
|
local modname = requires 'modname'
|
|
|
|
-- import all required modules
|
|
|
|
|
|
|
|
local foo = function()
|
|
|
|
-- code
|
|
|
|
end
|
|
|
|
|
|
|
|
local draw = function(args)
|
|
|
|
-- drawing code that uses foo()
|
|
|
|
end
|
|
|
|
|
|
|
|
return draw -- only draw is returned (use as modname(args))
|
2017-07-16 03:59:40 -04:00
|
|
|
|
|
|
|
Var names:
|
2017-07-16 13:49:43 -04:00
|
|
|
- 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:
|
2017-07-16 14:31:18 -04:00
|
|
|
- upval to local: prefix with _
|
|
|
|
- global to local: prefix with __
|
2017-07-16 13:49:43 -04:00
|
|
|
- replace . with _ if callng from table
|
2017-07-16 22:03:35 -04:00
|
|
|
- the only reason to do either of these is for performance, therefore
|
|
|
|
no need to localize variables that are only used during init
|
2017-07-16 13:49:43 -04:00
|
|
|
- global: preceed with g_
|
|
|
|
- Temporal Scope
|
|
|
|
- init: only relevent to startup (nil'ed before first rendering loop)
|
|
|
|
- persistant: always relevent (potentially)
|
2017-07-16 14:50:33 -04:00
|
|
|
- flank init vars with _
|
2017-07-16 13:49:43 -04:00
|
|
|
- Mutability
|
|
|
|
- variable: lowercase
|
|
|
|
- constant: ALL_CAPS
|
|
|
|
- constants can be anything except functions
|
|
|
|
- Module Names:
|
|
|
|
- CapCamalCase
|
|
|
|
- var name is exactly the same as module name
|
2017-07-16 03:59:40 -04:00
|
|
|
--]]
|
2016-08-11 23:25:56 -04:00
|
|
|
local UPDATE_FREQUENCY = 1 --Hz
|
|
|
|
|
2017-07-16 14:50:33 -04:00
|
|
|
_G_INIT_DATA_ = {
|
2017-07-15 20:08:39 -04:00
|
|
|
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,
|
|
|
|
|
2017-12-10 18:15:19 -05:00
|
|
|
-- silly hack, the price of a litewait language
|
|
|
|
ABS_PATH = debug.getinfo(1).source:match("@?(.*/)")
|
2016-08-11 23:25:56 -04:00
|
|
|
}
|
|
|
|
|
2017-07-16 14:50:33 -04:00
|
|
|
_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
|
|
|
|
|
|
|
|
package.path = _G_INIT_DATA_.ABS_PATH..'/?.lua;'..
|
2017-07-19 00:33:56 -04:00
|
|
|
_G_INIT_DATA_.ABS_PATH..'/drawing/?.lua;'..
|
2017-07-16 14:50:33 -04:00
|
|
|
_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;'
|
|
|
|
|
|
|
|
conky_set_update_interval(_G_INIT_DATA_.UPDATE_INTERVAL)
|
2016-08-11 23:25:56 -04:00
|
|
|
|
|
|
|
require 'cairo'
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
_G_Widget_ = require 'Widget'
|
|
|
|
_G_Patterns_ = require 'Patterns'
|
|
|
|
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2016-08-11 23:25:56 -04:00
|
|
|
local Panel = require 'Panel'
|
|
|
|
local System = require 'System'
|
|
|
|
local Network = require 'Network'
|
|
|
|
local Processor = require 'Processor'
|
|
|
|
local FileSystem = require 'FileSystem'
|
|
|
|
local Pacman = require 'Pacman'
|
2017-07-15 20:08:39 -04:00
|
|
|
local Power = require 'Power'
|
2016-08-11 23:25:56 -04:00
|
|
|
local ReadWrite = require 'ReadWrite'
|
2017-07-15 20:08:39 -04:00
|
|
|
local Graphics = require 'Graphics'
|
2016-08-11 23:25:56 -04:00
|
|
|
local Memory = require 'Memory'
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local _unrequire = function(m) package.loaded[m] = nil end
|
2016-08-11 23:25:56 -04:00
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
_G_Widget_ = nil
|
|
|
|
_G_Patterns_ = nil
|
2016-08-11 23:25:56 -04:00
|
|
|
|
2017-07-16 14:13:09 -04:00
|
|
|
_unrequire('Super')
|
|
|
|
_unrequire('Color')
|
|
|
|
_unrequire('Gradient')
|
2017-07-19 02:18:57 -04:00
|
|
|
_unrequire('Widget')
|
|
|
|
_unrequire('Patterns')
|
2016-08-11 23:25:56 -04:00
|
|
|
|
2017-07-16 14:13:09 -04:00
|
|
|
_unrequire = nil
|
2016-08-11 23:25:56 -04:00
|
|
|
|
2017-07-16 14:50:33 -04:00
|
|
|
_G_INIT_DATA_ = nil
|
2016-08-11 23:25:56 -04:00
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local updates = -2
|
|
|
|
|
2017-07-16 14:13:09 -04:00
|
|
|
local __cairo_xlib_surface_create = cairo_xlib_surface_create
|
2018-08-05 11:08:37 -04:00
|
|
|
local __cairo_set_source_surface = cairo_set_source_surface
|
|
|
|
local __cairo_paint = cairo_paint
|
2017-07-16 14:13:09 -04:00
|
|
|
local __cairo_create = cairo_create
|
|
|
|
local __cairo_surface_destroy = cairo_surface_destroy
|
|
|
|
local __cairo_destroy = cairo_destroy
|
|
|
|
local __collectgarbage = collectgarbage
|
2016-08-11 23:25:56 -04:00
|
|
|
|
|
|
|
local using_ac = function()
|
2017-07-19 00:43:44 -04:00
|
|
|
return Util.conky('${acpiacadapter AC}') == 'on-line'
|
2016-08-11 23:25:56 -04:00
|
|
|
end
|
|
|
|
|
2017-07-19 00:43:44 -04:00
|
|
|
local current_last_log_entry = Util.execute_cmd('tail -1 /var/log/pacman.log')
|
2016-08-11 23:25:56 -04:00
|
|
|
|
|
|
|
local check_if_log_changed = function()
|
2017-07-19 00:43:44 -04:00
|
|
|
local new_last_log_entry = Util.execute_cmd('tail -1 /var/log/pacman.log')
|
2016-08-11 23:25:56 -04:00
|
|
|
if new_last_log_entry == current_last_log_entry then return 1 end
|
|
|
|
current_last_log_entry = new_last_log_entry
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2018-08-05 04:05:38 -04:00
|
|
|
local cs_p
|
|
|
|
local uninit = 1
|
|
|
|
|
|
|
|
conky_startup = function()
|
|
|
|
cs_p = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1920, 1080)
|
|
|
|
local cr = __cairo_create(cs_p)
|
2018-08-05 11:22:07 -04:00
|
|
|
|
|
|
|
Panel.draw_static(cr)
|
|
|
|
|
|
|
|
System.draw_static(cr)
|
|
|
|
Graphics.draw_static(cr)
|
|
|
|
Processor.draw_static(cr)
|
|
|
|
|
|
|
|
ReadWrite.draw_static(cr)
|
|
|
|
Network.draw_static(cr)
|
|
|
|
|
|
|
|
Pacman.draw_static(cr)
|
|
|
|
FileSystem.draw_static(cr)
|
|
|
|
Power.draw_static(cr)
|
|
|
|
Memory.draw_static(cr)
|
|
|
|
|
2018-08-05 04:05:38 -04:00
|
|
|
uninit = nil
|
|
|
|
end
|
2017-07-15 20:08:39 -04:00
|
|
|
|
2018-08-05 04:05:38 -04:00
|
|
|
function conky_main()
|
|
|
|
if uninit then return end
|
2018-08-05 11:08:37 -04:00
|
|
|
|
2018-08-05 04:05:38 -04:00
|
|
|
local _cw = conky_window
|
|
|
|
if not _cw then return end
|
2018-08-05 11:08:37 -04:00
|
|
|
|
2018-08-05 04:05:38 -04:00
|
|
|
local cs = __cairo_xlib_surface_create(_cw.display, _cw.drawable, _cw.visual, 1920, 1080)
|
|
|
|
local cr = __cairo_create(cs)
|
2018-08-05 11:22:07 -04:00
|
|
|
|
|
|
|
local pt1 = os.clock()
|
2018-08-05 04:05:38 -04:00
|
|
|
|
|
|
|
cairo_set_source_surface(cr, cs_p, 0, 0)
|
|
|
|
cairo_paint(cr)
|
|
|
|
|
|
|
|
updates = updates + 1
|
|
|
|
|
|
|
|
local t1 = updates % (UPDATE_FREQUENCY * 10)
|
|
|
|
|
|
|
|
local t2
|
|
|
|
local is_using_ac = using_ac()
|
|
|
|
if is_using_ac then
|
|
|
|
t2 = updates % (UPDATE_FREQUENCY * 60)
|
|
|
|
else
|
|
|
|
t2 = updates % (UPDATE_FREQUENCY * 300)
|
|
|
|
end
|
|
|
|
|
|
|
|
local log_is_changed = false
|
|
|
|
if t2 == 0 then log_is_changed = check_if_log_changed() end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
System.draw_dynamic(cr, log_is_changed)
|
|
|
|
Graphics.draw_dynamic(cr)
|
|
|
|
Processor.draw_dynamic(cr)
|
2018-08-05 04:05:38 -04:00
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
ReadWrite.draw_dynamic(cr, UPDATE_FREQUENCY)
|
|
|
|
Network.draw_dynamic(cr, UPDATE_FREQUENCY)
|
2018-08-05 04:05:38 -04:00
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
Pacman.draw_dynamic(cr, log_is_changed)
|
|
|
|
FileSystem.draw_dynamic(cr, t1)
|
|
|
|
Power.draw_dynamic(cr, UPDATE_FREQUENCY, is_using_ac)
|
|
|
|
Memory.draw_dynamic(cr)
|
2018-08-05 04:05:38 -04:00
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
local pt2 = os.clock() - pt1
|
|
|
|
print(pt2)
|
2018-08-05 04:05:38 -04:00
|
|
|
|
|
|
|
__cairo_surface_destroy(cs)
|
|
|
|
__cairo_destroy(cr)
|
|
|
|
__collectgarbage()
|
2016-08-11 23:25:56 -04:00
|
|
|
end
|