clean up graphics

This commit is contained in:
petrucci4prez 2017-07-16 15:17:09 -04:00
parent 30f53ce37e
commit 0cb38ea880
1 changed files with 85 additions and 88 deletions

View File

@ -7,23 +7,24 @@ local LabelPlot = require 'LabelPlot'
local util = require 'util' local util = require 'util'
local schema = require 'default_patterns' local schema = require 'default_patterns'
local _TONUMBER = tonumber local __tonumber = tonumber
local __string_find = string.find
local __string_match = string.match
--construction params local _MODULE_Y_ = 145
local MODULE_Y = 145 local _SEPARATOR_SPACING_ = 20
local SEPARATOR_SPACING = 20 local _TEXT_SPACING_ = 20
local TEXT_SPACING = 20 local _PLOT_SEC_BREAK_ = 20
local PLOT_SEC_BREAK = 20 local _PLOT_HEIGHT_ = 56
local PLOT_HEIGHT = 56
local header = Widget.Header{ local header = Widget.Header{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = MODULE_Y, y = _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
header = 'NVIDIA GRAPHICS' header = 'NVIDIA GRAPHICS'
} }
local RIGHT_X = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH
local status = { local status = {
label = Widget.Text{ label = Widget.Text{
@ -32,7 +33,7 @@ local status = {
text = 'Status' text = 'Status'
}, },
value = Widget.Text{ value = Widget.Text{
x = RIGHT_X, x = _RIGHT_X_,
y = header.bottom_y, y = header.bottom_y,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
@ -40,150 +41,147 @@ local status = {
} }
} }
local SEP_Y_1 = header.bottom_y + SEPARATOR_SPACING local _SEP_Y_1_ = header.bottom_y + _SEPARATOR_SPACING_
local separator1 = Widget.Line{ local separator1 = Widget.Line{
p1 = {x = _G_INIT_DATA_.LEFT_X, y = SEP_Y_1}, p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_1_},
p2 = {x = RIGHT_X, y = SEP_Y_1} p2 = {x = _RIGHT_X_, y = _SEP_Y_1_}
} }
local INTERNAL_TEMP_Y = SEP_Y_1 + SEPARATOR_SPACING local _INTERNAL_TEMP_Y_ = _SEP_Y_1_ + _SEPARATOR_SPACING_
local internal_temp = { local internal_temp = {
label = Widget.Text{ label = Widget.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = INTERNAL_TEMP_Y, y = _INTERNAL_TEMP_Y_,
text = 'Internal Temperature' text = 'Internal Temperature'
}, },
value = Widget.CriticalText{ value = Widget.CriticalText{
x = RIGHT_X, x = _RIGHT_X_,
y = INTERNAL_TEMP_Y, y = _INTERNAL_TEMP_Y_,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
text = '<gpu_temp>' text = '<gpu_temp>'
} }
} }
local PCI_UTIL_Y = INTERNAL_TEMP_Y + TEXT_SPACING local _PCI_UTIL_Y_ = _INTERNAL_TEMP_Y_ + _TEXT_SPACING_
local pci_util = { local pci_util = {
label = Widget.Text{ label = Widget.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = PCI_UTIL_Y, y = _PCI_UTIL_Y_,
text = 'PCI Utilization' text = 'PCI Utilization'
}, },
value = Widget.Text{ value = Widget.Text{
x = RIGHT_X, x = _RIGHT_X_,
y = PCI_UTIL_Y, y = _PCI_UTIL_Y_,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
text = '<pci_util>' text = '<pci_util>'
} }
} }
local SEP_Y_2 = PCI_UTIL_Y + SEPARATOR_SPACING local _SEP_Y_2_ = _PCI_UTIL_Y_ + _SEPARATOR_SPACING_
local separator2 = Widget.Line{ local separator2 = Widget.Line{
p1 = {x = _G_INIT_DATA_.LEFT_X, y = SEP_Y_2}, p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_2_},
p2 = {x = RIGHT_X, y = SEP_Y_2} p2 = {x = _RIGHT_X_, y = _SEP_Y_2_}
} }
local CLOCK_SPEED_Y = SEP_Y_2 + SEPARATOR_SPACING local _CLOCK_SPEED_Y_ = _SEP_Y_2_ + _SEPARATOR_SPACING_
local clock_speed = { local clock_speed = {
labels = Widget.TextColumn{ labels = Widget.TextColumn{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = CLOCK_SPEED_Y, y = _CLOCK_SPEED_Y_,
spacing = TEXT_SPACING, spacing = _TEXT_SPACING_,
'GPU Clock Speed', 'GPU Clock Speed',
'Memory Clock Speed' 'Memory Clock Speed'
}, },
values = Widget.TextColumn{ values = Widget.TextColumn{
x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH, x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = CLOCK_SPEED_Y, y = _CLOCK_SPEED_Y_,
spacing = TEXT_SPACING, spacing = _TEXT_SPACING_,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
num_rows = 2 num_rows = 2
} }
} }
local SEP_Y_3 = CLOCK_SPEED_Y + TEXT_SPACING * 2 local _SEP_Y_3_ = _CLOCK_SPEED_Y_ + _TEXT_SPACING_ * 2
local separator3 = Widget.Line{ local separator3 = Widget.Line{
p1 = {x = _G_INIT_DATA_.LEFT_X, y = SEP_Y_3}, p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_3_},
p2 = {x = RIGHT_X, y = SEP_Y_3} p2 = {x = _RIGHT_X_, y = _SEP_Y_3_}
} }
local GPU_UTIL_Y = SEP_Y_3 + SEPARATOR_SPACING local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_
local GPU_UTIL_PLOT_Y = GPU_UTIL_Y + PLOT_SEC_BREAK
local gpu_util = { local gpu_util = {
label = Widget.Text{ label = Widget.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = GPU_UTIL_Y, y = _GPU_UTIL_Y_,
text = 'GPU Utilization' text = 'GPU Utilization'
}, },
value = Widget.Text{ value = Widget.Text{
x = RIGHT_X, x = _RIGHT_X_,
y = GPU_UTIL_Y, y = _GPU_UTIL_Y_,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
text = '<gpu_util>' text = '<gpu_util>'
}, },
plot = Widget.LabelPlot{ plot = Widget.LabelPlot{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = GPU_UTIL_PLOT_Y, y = _GPU_UTIL_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
height = PLOT_HEIGHT height = _PLOT_HEIGHT_
} }
} }
local MEM_UTIL_Y = GPU_UTIL_PLOT_Y + PLOT_HEIGHT + PLOT_SEC_BREAK local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local MEM_UTIL_PLOT_Y = MEM_UTIL_Y + PLOT_SEC_BREAK
local mem_util = { local mem_util = {
label = Widget.Text{ label = Widget.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = MEM_UTIL_Y, y = _MEM_UTIL_Y_,
text = 'Memory Utilization' text = 'Memory Utilization'
}, },
value = Widget.Text{ value = Widget.Text{
x = RIGHT_X, x = _RIGHT_X_,
y = MEM_UTIL_Y, y = _MEM_UTIL_Y_,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
text = '<mem_util>' text = '<mem_util>'
}, },
plot = Widget.LabelPlot{ plot = Widget.LabelPlot{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = MEM_UTIL_PLOT_Y, y = _MEM_UTIL_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
height = PLOT_HEIGHT height = _PLOT_HEIGHT_
} }
} }
local VID_UTIL_Y = MEM_UTIL_PLOT_Y + PLOT_HEIGHT + PLOT_SEC_BREAK local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local VID_UTIL_PLOT_Y = VID_UTIL_Y + PLOT_SEC_BREAK
local vid_util = { local vid_util = {
label = Widget.Text{ label = Widget.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = VID_UTIL_Y, y = _VID_UTIL_Y_,
text = 'Video Utilization' text = 'Video Utilization'
}, },
value = Widget.Text{ value = Widget.Text{
x = RIGHT_X, x = _RIGHT_X_,
y = VID_UTIL_Y, y = _VID_UTIL_Y_,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
text = '<vid_util>' text = '<vid_util>'
}, },
plot = Widget.LabelPlot{ plot = Widget.LabelPlot{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = VID_UTIL_PLOT_Y, y = _VID_UTIL_Y_ + _PLOT_SEC_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
height = PLOT_HEIGHT height = _PLOT_HEIGHT_
} }
} }
@ -210,39 +208,41 @@ local NV_REGEX = '(%d+)\n'..
'(%d+),(%d+)\n'.. '(%d+),(%d+)\n'..
'graphics=(%d+), memory=%d+, video=(%d+), PCIe=(%d+)\n' 'graphics=(%d+), memory=%d+, video=(%d+), PCIe=(%d+)\n'
local __nvidia_off = function(cr) local NA = 'N / A'
CriticalText.set(internal_temp.value, cr, 'N/A', 1)
Text.set(pci_util.value, cr, 'N/A')
TextColumn.set(clock_speed.values, cr, 1, 'N/A') local nvidia_off = function(cr)
TextColumn.set(clock_speed.values, cr, 2, 'N/A') CriticalText.set(internal_temp.value, cr, NA, 1)
Text.set(pci_util.value, cr, NA)
Text.set(gpu_util.value, cr, 'N/A') TextColumn.set(clock_speed.values, cr, 1, NA)
Text.set(mem_util.value, cr, 'N/A') TextColumn.set(clock_speed.values, cr, 2, NA)
Text.set(vid_util.value, cr, 'N/A')
Text.set(gpu_util.value, cr, NA)
Text.set(mem_util.value, cr, NA)
Text.set(vid_util.value, cr, NA)
LabelPlot.update(gpu_util.plot, 0) LabelPlot.update(gpu_util.plot, 0)
LabelPlot.update(mem_util.plot, 0) LabelPlot.update(mem_util.plot, 0)
LabelPlot.update(vid_util.plot, 0) LabelPlot.update(vid_util.plot, 0)
end end
local __update = function(cr) local update = function(cr)
if util.read_file('/proc/acpi/bbswitch', '.+%s+(%u+)') == 'ON' then if util.read_file('/proc/acpi/bbswitch', '.+%s+(%u+)') == 'ON' then
if string.find(util.execute_cmd('ps -A -o comm'), 'optirun') == nil then if __string_find(util.execute_cmd('ps -A -o comm'), 'optirun') == nil then
Text.set(status.value, cr, 'Mixed') Text.set(status.value, cr, 'Mixed')
__nvidia_off(cr) nvidia_off(cr)
else else
Text.set(status.value, cr, 'On') Text.set(status.value, cr, 'On')
local nvidia_settings_glob = util.execute_cmd(NV_QUERY) local nvidia_settings_glob = util.execute_cmd(NV_QUERY)
local used_memory, total_memory, temp_reading, gpu_frequency, local used_memory, total_memory, temp_reading, gpu_frequency,
memory_frequency, gpu_utilization, vid_utilization, memory_frequency, gpu_utilization, vid_utilization,
pci_utilization = string.match(nvidia_settings_glob, NV_REGEX) pci_utilization = __string_match(nvidia_settings_glob, NV_REGEX)
local force = 1 local is_critical = 1
if _TONUMBER(temp_reading) > 80 then force = 0 end if __tonumber(temp_reading) > 80 then is_critical = 0 end
CriticalText.set(internal_temp.value, cr, temp_reading..'°C', force) CriticalText.set(internal_temp.value, cr, temp_reading..'°C', is_critical)
Text.set(pci_util.value, cr, pci_utilization..'%') Text.set(pci_util.value, cr, pci_utilization..'%')
TextColumn.set(clock_speed.values, cr, 1, gpu_frequency..' Mhz') TextColumn.set(clock_speed.values, cr, 1, gpu_frequency..' Mhz')
@ -260,33 +260,30 @@ local __update = function(cr)
end end
else else
Text.set(status.value, cr, 'Off') Text.set(status.value, cr, 'Off')
__nvidia_off(cr) nvidia_off(cr)
end end
end end
Widget = nil Widget = nil
schema = nil schema = nil
MODULE_Y = nil _MODULE_Y_ = nil
SEPARATOR_SPACING = nil _SEPARATOR_SPACING_ = nil
TEXT_SPACING = nil _TEXT_SPACING_ = nil
PLOT_SECTION_BREAK = nil _PLOT_SEC_BREAK_ = nil
PLOT_HEIGHT = nil _PLOT_HEIGHT_ = nil
RIGHT_X = nil _RIGHT_X_ = nil
SEP_Y_1 = nil _SEP_Y_1_ = nil
SEP_Y_2 = nil _SEP_Y_2_ = nil
SEP_Y_3 = nil _SEP_Y_3_ = nil
INTERNAL_TEMP_Y = nil _INTERNAL_TEMP_Y_ = nil
PCI_UTIL_Y = nil _PCI_UTIL_Y_ = nil
CLOCK_SPEED_Y = nil _CLOCK_SPEED_Y_ = nil
GPU_UTIL_Y = nil _GPU_UTIL_Y_ = nil
GPU_UTIL_PLOT_Y = nil _MEM_UTIL_Y_ = nil
MEM_UTIL_Y = nil _VID_UTIL_Y_ = nil
MEM_UTIL_PLOT_Y = nil
VID_UTIL_Y = nil
VID_UTIL_PLOT_Y = nil
local draw = function(cr, current_interface) local draw = function(cr, current_interface)
__update(cr) update(cr)
if current_interface == 0 then if current_interface == 0 then
Text.draw(header.text, cr) Text.draw(header.text, cr)