You are not logged in.

#976 2018-09-28 11:41:29

ragamatrix
Member
Registered: 2015-10-04
Posts: 309

Re: Show us your conky

Hello and thank-you easysid, I've played a little with your colorfill.lua script. I made a test with the font ConkyColors to use "letters" as icons that we can fill... I don't know if you like the idea but it works smile
2018-09-28-131650_1920x1080_scrot.th.png
conkyrc:

conky.config = {
-- work in background (disabled for testing)
background = false,

-- better fonts
use_xft = true,
--xftalpha = 1,

-- update interval
update_interval = 1,
total_run_times = 0,

-- window settings
own_window = true,
own_window_transparent = true,
own_window_type = 'desktop',
own_window_hints = 'undecorated, below, sticky, skip_taskbar, skip_pager',
--own_window_argb_visual = true,
--own_window_argb_value = 0,

-- anti-flickering
double_buffer = true,

-- size
minimum_width = 1350,
minimum_height = 20,
maximum_width = 1350,

 -- shadows
draw_shades = true,
default_shade_color = 'black',

--borders
draw_outline = false,
--default_outline_color = 'D02090',
draw_graph_borders = false,

-- frame
draw_borders = false,

-- color
default_color = '778899',
color1 = 'CD2626', --Firebrick3
color2 = 'FFA500', --orange
color3 = 'FFD700', --gold
color4 = 'ADFF2F', --GreenYellow
color5 = '00CD00', --green3
color6 = '00CED1', --DarkTurquoise
color7 = '87CEEB', --SkyBlue
color8 = '1E90FF', --DodgerBlue1
color9 = 'CA99FF', --VioletRed D02090 -- 9D00FF -- magenta FF44EE

-- position
alignment = 'top_middle',
gap_x = 0,
gap_y = 11,

-- misc
no_buffers = true,
uppercase = false,
cpu_avg_samples = 2,
if_up_strictness = 'address',
use_spacer = 'none',

show_graph_range = false,
show_graph_scale = false,
--default_bar_height = 6,
--default_bar_width = 200,
text_buffer_size = 1000,
override_utf8_locale = true,
--fonts tests:
--LCDMono2
--Lucida Sans
--Neogrey
--PF Tempesta Five Condensed
--PF Tempesta Five Compressed
--Visitor TT1 BRK:Medium:size=9
--Anonymous Pro:Medium:size=8
--Commodore 64 Angled
--Terminus
font = 'Monospace:size=8', --important for shades
template0 = 'Monospace:bold:size=10',
template1 = 'Monospace:bold:size=10',

--•
-- -- Lua load -- #
	lua_load = '~/.conky/script/colorfill2.lua',
	lua_draw_hook_pre = 'conky_main',}

conky.text = [[
${voffset 3}${color1}${exec echo '#!'}${color FF4800} Top: ${color2}${top_mem name 1}\
${goto 180}|${color3} Home: ${color EDFF00}${fs_used_perc /}% (${fs_used /} / ${fs_free /}) \
${goto 370}|${color4} Stock: ${fs_used_perc /media/stock}% \
${goto 450}|${color 32FF00} Share:${color 00FF63} ${fs_used_perc /media/share}%${color 00FF9E} | \
${goto 570} CPU Stress: ${color 00FFD5}${cpu cpu0}% | ${color7}${cpu cpu2}% \
${goto 710}|${color 00AEFF} CPU T°: ${hwmon 0 temp 1}° ${color8}${execi 300 sensors | awk '/Core 0/{gsub("+","");print $3}'} ${color 7D94FF}${execi 300 sensors | awk '/Core 2/{gsub("+","");print $3}'} \
${goto 890}|${color9} Memory: ${memperc}% ${color ED72FF}($mem) \
${color FF4095}${goto 1080}| Net:\
${goto 1140}${color FE361A} ${upspeedf enp0s25} (${totalup enp0s25}) \
${goto 1260}${color FFBB27} ${downspeedf enp0s25} (${totaldown enp0s25}) \

]]

colorfill.lua:

--[[
colorfill.lua
lua script for colors conky
easysid
Monday, 23 January 2017 13:44 IST
Update:
    Tuesday, 24 January 2017
        * Allow conky vars as labels
        * catch nil value errors
]]--

require 'cairo'

-- common
local base = {0xB0B0B0, 0.2} -- {base fill color, alpha}
local font_face = 'White Rabbit'

local settings_t = {
    {
        label = "x",      -- simple label
        arg = "upspeedf enp0s25",
        max = 100,
        x = 1120,
        y = 25,
        color = {0xFF005C, 1},
        font = "ConkyColors",
        size = 20,
    },
    {
        label = "w",      -- simple label
        arg = "downspeedf enp0s25",
        max = 30,
        x = 1240,
        y = 25,
        color = {0xFF9727, 1},
        font = "ConkyColors",
        size = 20,
    },
    {
        label = "f",      -- simple label
        arg = "memperc",
        max = 25,
        x = 1040,
        y = 29,
        color = {0xED72FF, 1},
        font = "ConkyColors",
        size = 25,
    },
    {
        label = "7",        -- no label, use the arg value
        arg = "hwmon 0 temp 1",
        max = 75,
        x = 870,
        y = 29,
        color = {0x7D94FF, 1},
        font = "ConkyColors",
        size = 25
    },
    {
        label = "e",        -- no label, use the arg value
        arg = "cpu cpu0",
        max = 75,
        x = 543,
        y = 29,
        color = {0x00FF9E, 1},
        font = "ConkyColors",
        size = 25
    },
    --[[{
        label = nil,
        arg = "time %S",
        max = 60,
        x = 350,
        y = 100,
        color = {0xCA99FF, 1},
        font = font_face,
        size = 60
    },
    {
        label = "time %B",      -- conky var as a label
        parse_label = true,     -- we need to parse the label value
        arg = "time %m",
        max = 12,
        x = 500,
        y = 90,
        color = {0xd07036, 1},
        font = font_face,
        size = 60
    },
    {
        label = "time %A",
        parse_label = true,
        arg = "time %u",
        max = 7,
        x = 420,
        y = 160,
        color = {0xa9309f, 1},
        font = font_face,
        size = 80
    },--]]
}

-- ###### should not need to edit below this line ###### --

function conky_main()
    if conky_window == nil then return end
    local cs = cairo_xlib_surface_create(conky_window.display,
    conky_window.drawable, conky_window.visual,
    conky_window.width, conky_window.height)
    cr = cairo_create(cs)
    local updates=tonumber(conky_parse('${updates}'))
    if updates > 3 then
        for i in ipairs(settings_t) do
            drawText(settings_t[i])
        end -- for
    end
    cairo_destroy(cr)
    cairo_surface_destroy(cs)
    cr = nil
end --end main()

function drawText(t)
    local text = conky_parse(string.format("${%s}", t.arg))
    local value = tonumber(text)
    -- catch any nil value errors
    if value == nil then
        print(string.format("{%s} returned a nil value", t.arg))
        return
    end
    -- label jugglery
    if t.label then
        text = t.label
        if t.parse_label then
            text = conky_parse(string.format("${%s}", t.label))
        end
    end
    local x = t.x or 100
    local y = t.y or 100
    local font = t.font or "sans"
    local size = t.size or 50
    local col = t.color or {0xFFFFFF, 1}
    local max = t.max or 100
    local perc = 1 - value/max
    local extents=cairo_text_extents_t:create()
    tolua.takeownership(extents)
    cairo_select_font_face(cr, font, 0, 0)
    cairo_set_font_size(cr, size)
    cairo_text_extents(cr, text, extents)
    local w = extents.width
    local h = extents.height
    local pat = cairo_pattern_create_linear(x, y-h, x, y)
    cairo_pattern_add_color_stop_rgba(pat, perc, rgba_to_r_g_b_a(base))
    cairo_pattern_add_color_stop_rgba(pat, perc, rgba_to_r_g_b_a(col))
    cairo_set_source(cr, pat)
    cairo_move_to(cr, x, y)
    cairo_show_text(cr, text)
    cairo_stroke(cr)
end

function rgba_to_r_g_b_a(tcolor)
    local color,alpha=tcolor[1],tcolor[2]
    return ((color / 0x10000) % 0x100) / 255.,
    ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end

Offline

#977 2018-10-08 10:09:46

easysid
Member
Registered: 2016-01-01
Posts: 49

Re: Show us your conky

ragamatrix wrote:

Hello and thank-you easysid, I've played a little with your colorfill.lua script. I made a test with the font ConkyColors to use "letters" as icons that we can fill... I don't know if you like the idea but it works smile

That's a really nice idea smile

Offline

#978 2018-11-03 11:53:28

damo
....moderator....
Registered: 2015-08-20
Posts: 4,378

Re: Show us your conky

Conky for Optimus Nvidia

I haven't found a way to use the output of ${nvidia...} when running a conky on an Optimus laptop - it fails because it can't see the gpu, so the lua script has nothing to draw.

But by using optirun nvidia-smi in a bash script to get the values, and getting the lua script to read them....it is working!
nvidia-post.png

Requirements

  • nvidia-driver (I don't know if things work with nouveau)

  • nvidia-smi: utility to get GPU data

  • nvidia-settings, for the icon

  • bbswitch/optimus setup, to run specific applications with the GPU

__________________________________________________________________________________________

nvidia-optimus.conkyrc

All this does is place the icon and the clock, and provide the window for the lua.
conky.text could be completely empty!

If you have installed nvidia-settings you will find an icon in /usr/share/icons/ or /usr/share/pixmaps/

conky.config = {
--========================  nvidia-optimus.conkyrc  ===========================================
--
-- by damo, November 2018  <damo.linux@gmail.com>
--
--=======================  Based on ideas from...  ===========================================
--  Based on code from sun_rings.lua, which in turn is a modification of 
--  seamod_rings.lua, which is modification of lunatico_rings.lua,
--  which is modification of conky_orange.lua!
--
--  conky_orange.lua:    http://gnome-look.org/content/show.php?content=137503
--  lunatico_rings.lua:  http://gnome-look.org/content/show.php?content=142884
--  seamod_rings.lua:    http://custom-linux.deviantart.com/art/Conky-Seamod-v0-1-283461046
--  sun_rings.lua:       https://forums.bunsenlabs.org/viewtopic.php?pid=49209#p49209
--
-- Ported to Conky v1.10 by damo;
--
--=============================================================================================

    background = true,
    update_interval = 1,
-- uncomment the next line if you are running 2 monitors:
--    xinerama_head = 2,

    cpu_avg_samples = 1,
    net_avg_samples = 2,
    temperature_unit = 'celsius',

    double_buffer = true,
    no_buffers = true,
    text_buffer_size = 2048,

    gap_x = 20,
    gap_y = 20,
    minimum_width = 260, minimum_height = 350,
    maximum_width = 260,

    own_window = true,
    own_window_transparent = true,
    own_window_argb_visual = true,
    own_window_type = 'normal',
    own_window_hints = 'undecorated,skip_taskbar,skip_pager,below,sticky',
    border_inner_margin = 30,
    border_outer_margin = 0,
    alignment = 'top_right',

    draw_shades = false,
    draw_outline = false,
    draw_borders = false,
    draw_graph_borders = false,

    override_utf8_locale = true,
    use_xft = true,
    font = 'Raleway:size=10',
    xftalpha = 1,
    uppercase = false,

-- Defining colors
    default_color = 'FFFFFF',
    color1 = 'FF5B5B',
    color2 = '678b8b',
    color3 = '05C5DA',
    color4 = '8FE03B',

-- Loading lua script for drawing rings
    lua_load = '~/.config/conky/LUA/nvidia-optimus.lua',
    lua_draw_hook_post = 'main',
};

conky.text = [[
${image /usr/share/icons/Paper/48x48/apps/nvidia-settings.png -p 200,10 -s 64x64}
${voffset 57}${alignr}${color4}gpu
${voffset 265}${alignr}${color4}${font Raleway:size=14}${time %H}:${time %M}
]];

__________________________________________________________________________________________

nvidia-optimus.sh

This doesn't have to be made executable, since the lua calls it with "sh" (shell)

#!/bin/bash
##
## ~/.config/conky/scripts/nvidia-optimus.sh
## Script to be called by nvidia-optimus.lua
##
## by damo, November 2018 <damo.linux@gmail.com>
##
########################################################################

OUTPUT=$(optirun nvidia-smi -q)

TEMPERATURE=$(echo "$OUTPUT" | grep 'GPU Current' | awk '{print $(NF-1)}')
TEMP_SLOWDOWN=$(echo "$OUTPUT" | grep 'GPU Slowdown' | awk '{print $(NF-1)}')
TEMP_MAX=$(echo "$OUTPUT" | grep 'GPU Max' | awk '{print $(NF-1)}')
MEM_USED=$(echo "$OUTPUT" | grep 'Used' | awk '{print $(NF-1);exit}')
MEM_TOTAL=$(echo "$OUTPUT" | grep 'Total' | awk '{print $(NF-1);exit}')
UTIL=$(echo "$OUTPUT" | grep 'Gpu' | awk '{print $(NF-1)}')
POWER=$(echo "$OUTPUT" | grep 'Draw' | awk '{print $(NF-1)}')
POWER_MAX=$(echo "$OUTPUT" | grep 'Power Limit'| awk '{print $NF;exit}')

GPU=$(echo "$OUTPUT"| grep 'Product Name' | awk -F ':' '{print $NF}')
DRIVER=$(echo "$OUTPUT" | grep 'Driver Version' | awk '{print $NF}')

# The order of the output is important!! The values are read into an array
# by nvidia-optimus.lua, and the gauges read the values in order.
# Items must correspond exactly with the lua.

## Values for lua gauges{} - FIRST
echo $TEMPERATURE
echo $TEMPERATURE       # used for red high temps sector
echo $MEM_USED
echo $UTIL
echo ${POWER%.*}        # Remove decimals

## Values for text output in lua conky_text{} - SECOND
echo "${GPU#' '}"       # remove leading whitespace
echo "$DRIVER"

## Other values for lua variables - THIRD
echo $TEMP_SLOWDOWN
echo $TEMP_MAX
echo $MEM_TOTAL
echo "$POWER_MAX"

exit

____________________________________________________________________________________________

nvidia-optimus.lua
  • Script path, fonts, colours can be set at the top of the lua script

  • The output values from nvidia-optimus.sh must correspond exactly with the gauge{}, conky_text{} and extra data in the lua script.

  • There will be an initial delay drawing the gauges, while nvidia-smi gathers the data

--==============================================================================
-- nvidia-optimus.lua
-- by damo, November 2018 <damo.linux@gmail.com>
--==============================================================================
--  Based on code from sun_rings.lua by SunForMiles, which in turn is a modification of 
--  seamod_rings.lua, which is a modification of lunatico_rings.lua,
--  which is a modification of conky_orange.lua!
--
--  conky_orange.lua:    http://gnome-look.org/content/show.php?content=137503
--  lunatico_rings.lua:  http://gnome-look.org/content/show.php?content=142884
--  seamod_rings.lua:    http://custom-linux.deviantart.com/art/Conky-Seamod-v0-1-283461046
--  sun_rings.lua:       https://forums.bunsenlabs.org/viewtopic.php?pid=49209#p49209
--==============================================================================

require 'cairo'
--
-- set path to bash script here (script does not have to be executable):
script_path = (os.getenv("HOME")..'/.config/conky/scripts/')
script_name = 'nvidia-optimus.sh'

-- Global settings
-- Add anything you like here, and use it in gauge{} or conky_text{}
-- Values can also be specified in each {} section
font_1 = 'Noto Sans Mono'
font_2 = 'Raleway'
font_size_1 = 10.0
font_size_2 = 12.0
colour_1 = 0x05C5DA
colour_2 = 0x8FE03B

--  GAUGE RINGS DATA
--  NB IMPORTANT!! There must be one section for each gauge value provided by the bash script.
gauge = {
{
    name='nvidia',                 arg='TEMPERATURE',                 max_value=nil, --can be set if known
    x=60,                          y=80,
    graph_radius=30,
    graph_thickness=7,
    graph_start_angle=225,
    graph_unit_angle=2.7,          graph_unit_thickness=2.7,
    graph_bg_colour=0xffffff,      graph_bg_alpha=0.1,
    graph_fg_colour=0x76DFE6,      graph_fg_alpha=0.3,
    hand_fg_colour=0x05C5DA,       hand_fg_alpha=0.5,
    txt_radius=22,                 hand_radius=24,
    hand_width = 2,
    txt_weight=0,                  txt_size=font_size_1,
    txt_fg_colour=colour_1,        txt_fg_alpha=0,
    graduation_radius=23,
    graduation_thickness=0,        graduation_mark_thickness=2,
    graduation_unit_angle=2.7,
    graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
    caption='true',
    caption_weight=0.5,            caption_size=12.0,
    caption_fg_colour=colour_1,    caption_fg_alpha=0.7,
    font = font_2,
},

-- This is a bit of a cheat: layered bg, for red sector, with fg no alpha
   { -- gpu high temps bg section (red)
     -- Set txt_fg_alpha=1 to show slowdown temperature
    name='nvidia',                 arg='TEMPERATURE_BG',                  max_value=11, -- =(max temp)minus(slowdown temp)
    x=60,                          y=80,
    graph_radius=30,
    graph_thickness=7,
    graph_start_angle=108,
    graph_unit_angle=2.7,          graph_unit_thickness=2.7,
    graph_bg_colour=0xff0000,      graph_bg_alpha=0.3,
    graph_fg_colour=0xCE7646,      graph_fg_alpha=0,
    hand_fg_colour=0x477CAF,       hand_fg_alpha=0.0,
    txt_radius=42,                 hand_radius=0,
    hand_width = 0,
    txt_weight=0,                  txt_size=font_size_1,
    txt_fg_colour=0xCE7646,        txt_fg_alpha=1,
    graduation_radius=23,
    graduation_thickness=8,        graduation_mark_thickness=0,
    graduation_unit_angle=2.7,
    graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.5,
    caption='',
    caption_weight=0.5,            caption_size=8.0,
    caption_fg_colour=colour_1,    caption_fg_alpha=0.7,
    font = font_2,
    },
{
    name='nvidia',                 arg='MEM_USED',               max_value=nil, --can be set if known
    x=100,                          y=165,
    graph_radius=30,
    graph_thickness=7,
    graph_start_angle=225,
    graph_unit_angle=0.044,          graph_unit_thickness=2.7,
    graph_bg_colour=0xffffff,      graph_bg_alpha=0.1,
    graph_fg_colour=0x76DFE6,      graph_fg_alpha=0.01,
    hand_fg_colour=0x05C5DA,       hand_fg_alpha=0.5,
    txt_radius=22,                 hand_radius=24,
    hand_width = 2,
    txt_weight=0,                  txt_size=font_size_1,
    txt_fg_colour=0x678b8b,        txt_fg_alpha=0,
    graduation_radius=23,
    graduation_thickness=0,        graduation_mark_thickness=2,
    graduation_unit_angle=2.7,
    graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
    caption='true',
    caption_weight=0.5,            caption_size=12.0,
    caption_fg_colour=colour_1,    caption_fg_alpha=0.7,
    font = font_2,
    },
{
    name='nvidia',                 arg='UTIL',               max_value=100,
    x=160,                          y=250,
    graph_radius=30,
    graph_thickness=7,
    graph_start_angle=225,
    graph_unit_angle=2.7,          graph_unit_thickness=2.7,
    graph_bg_colour=0xffffff,      graph_bg_alpha=0.1,
    graph_fg_colour=0x76DFE6,      graph_fg_alpha=0.3,
    hand_fg_colour=0x05C5DA,       hand_fg_alpha=0.5,
    txt_radius=22,                 hand_radius=24,
    hand_width = 2,
    txt_weight=0,                  txt_size=font_size_1,
    txt_fg_colour=0x678b8b,        txt_fg_alpha=0,
    graduation_radius=23,
    graduation_thickness=0,        graduation_mark_thickness=2,
    graduation_unit_angle=2.7,
    graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
    caption='true',
    caption_weight=0.5,            caption_size=12.0,
    caption_fg_colour=colour_1,    caption_fg_alpha=0.7,
    font = font_2,
    },
{
    name='nvidia',                 arg='POWER',               max_value=nil, --can be set if known
    x=210,                          y=335,
    graph_radius=30,
    graph_thickness=7,
    graph_start_angle=225,
    graph_unit_angle=2.7,          graph_unit_thickness=1.0,
    graph_bg_colour=0xffffff,      graph_bg_alpha=0.1,
    graph_fg_colour=0x76DFE6,      graph_fg_alpha=0.3,
    hand_fg_colour=0x05C5DA,       hand_fg_alpha=0.5,
    hand_width = 2,
    txt_radius=22,                 hand_radius=24,
    txt_weight=0,                  txt_size=font_size_1,
    txt_fg_colour=0x678b8b,        txt_fg_alpha=0,
    graduation_radius=23,
    graduation_thickness=0,        graduation_mark_thickness=2,
    graduation_unit_angle=2.7,
    graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.5,
    caption='true',
    caption_weight=0.5,            caption_size=12.0,
    caption_fg_colour=colour_1,    caption_fg_alpha=0.7,
    font = font_2,
    },
}

-- TEXT
--  NB IMPORTANT!! There must be one {} section for each text value provided by the bash script.

conky_text = {
{   name='GPU',
    x = 110,
    y = 55,
    font = font_2,
    txt_weight=0,                  
    txt_fg_colour=colour_2,
    txt_size=font_size_2,
    txt_fg_alpha=0.7,
    },
{   name='DRIVER',
    x = 110,
    y = 75,
    font = font_2,
    txt_weight=0,                  
    txt_fg_colour=colour_2,
    txt_size=font_size_2,
    txt_fg_alpha=0.7,
    },
}
-------------------------------------------------------------------------------
-- rgb_to_r_g_b
-- converts color in hexa to decimal
--
function rgb_to_r_g_b(colour, alpha)
    return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
-------------------------------------------------------------------------------
-- angle_to_position
-- convert degree to rad and rotate (0 degree is top/north)
--
function angle_to_position(start_angle, current_angle)
    local pos = current_angle + start_angle
    return ( ( pos * (2 * math.pi / 360) ) - (math.pi / 2) )
end

-------------------------------------------------------------------------------
-- draw_gauge_ring
-- displays gauges
--                                                              
function draw_gauge_ring(display, data, value)
    local max_value,graph_unit_angle = set_max_value(data['arg'],data['max_value'],data['graph_unit_angle'])
    local x, y = data['x'], data['y']
    local graph_radius = data['graph_radius']
    local hand_radius = data['hand_radius']
    local hand_width = data['hand_width']
    local graph_thickness, graph_unit_thickness = data['graph_thickness'], data['graph_unit_thickness']
    local graph_start_angle = data['graph_start_angle']
    local graph_bg_colour, graph_bg_alpha = data['graph_bg_colour'], data['graph_bg_alpha']
    local graph_fg_colour, graph_fg_alpha = data['graph_fg_colour'], data['graph_fg_alpha']
    local hand_fg_colour, hand_fg_alpha = data['hand_fg_colour'], data['hand_fg_alpha']
    local graph_end_angle = (max_value * graph_unit_angle) % 360
    local font = data['font']
    local caption = data['caption']

    -- background ring
    cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, 0), angle_to_position(graph_start_angle, graph_end_angle))
    cairo_set_source_rgba(display, rgb_to_r_g_b(graph_bg_colour, graph_bg_alpha))
    cairo_set_line_width(display, graph_thickness)
    cairo_stroke(display)

    -- arc of value
    local val = value % (max_value + 1)
    local start_arc = 0
    local stop_arc = 0
    local i = 1
    while i <= val do
        start_arc = (graph_unit_angle * i) - graph_unit_thickness
        stop_arc = (graph_unit_angle * i)
        cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc))
        cairo_set_source_rgba(display, rgb_to_r_g_b(graph_fg_colour, graph_fg_alpha))
        cairo_stroke(display)
        i = i + 1
    end
    local angle = start_arc

    -- hand
    start_arc = (graph_unit_angle * val) - graph_unit_thickness
    stop_arc = (graph_unit_angle * val)
    cairo_set_line_width(display, hand_width)
    cairo_move_to(display,x,y)
    cairo_arc(display, x, y, hand_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, start_arc))
    cairo_set_source_rgba(display, rgb_to_r_g_b(hand_fg_colour, hand_fg_alpha))
    cairo_stroke(display)

    -- graduations marks
    local graduation_radius = data['graduation_radius']
    local graduation_thickness, graduation_mark_thickness = data['graduation_thickness'], data['graduation_mark_thickness']
    local graduation_unit_angle = data['graduation_unit_angle']
    local graduation_fg_colour, graduation_fg_alpha = data['graduation_fg_colour'], data['graduation_fg_alpha']
    if graduation_radius > 0 and graduation_thickness > 0 and graduation_unit_angle > 0 then
        local nb_graduation = graph_end_angle / graduation_unit_angle
        local i = 0
        while i < nb_graduation do
            cairo_set_line_width(display, graduation_thickness)
            start_arc = (graduation_unit_angle * i) - (graduation_mark_thickness / 2)
            stop_arc = (graduation_unit_angle * i) + (graduation_mark_thickness / 2)
            cairo_arc(display, x, y, graduation_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc))
            cairo_set_source_rgba(display,rgb_to_r_g_b(graduation_fg_colour,graduation_fg_alpha))
            cairo_stroke(display)
            cairo_set_line_width(display, graph_thickness)
            i = i + 1
        end
    end

    -- gauge text - displays value at gauge pointer position.
    -- Except for display of slowdown temperature on temperature gauge:
    if data['arg'] == "TEMPERATURE_BG" then
        if temp_slowdown == nil then
            data['txt_fg_alpha'] = 0
        else
            data['txt_fg_alpha'] = 1
            value = 'Slowdown '..temp_slowdown..' °C'
            graph_start_angle = 108
            angle = 0
        end
    end

    local txt_radius = data['txt_radius']
    local txt_weight, txt_size = data['txt_weight'], data['txt_size']
    local txt_fg_colour, txt_fg_alpha = data['txt_fg_colour'], data['txt_fg_alpha']
    local movex = txt_radius * math.cos(angle_to_position(graph_start_angle, angle))
    local movey = txt_radius * math.sin(angle_to_position(graph_start_angle, angle))
        
    cairo_select_font_face (display, font, CAIRO_FONT_SLANT_NORMAL, txt_weight)
    cairo_set_font_size (display, txt_size)
    cairo_set_source_rgba (display, rgb_to_r_g_b(txt_fg_colour, txt_fg_alpha))
    cairo_move_to (display, x + movex - (txt_size / 2), y + movey + 3)
    
    cairo_show_text (display, value)
    cairo_stroke (display)

    -- caption
    caption = display_caption(caption,value,data['arg'])
    
    local caption_weight, caption_size = data['caption_weight'], data['caption_size']
    local caption_fg_colour, caption_fg_alpha = data['caption_fg_colour'], data['caption_fg_alpha']
    local tox = graph_radius * (math.cos((graph_start_angle * 2 * math.pi / 360)-(math.pi/2)))
    local toy = graph_radius * (math.sin((graph_start_angle * 2 * math.pi / 360)-(math.pi/2)))
    cairo_select_font_face (display, font, CAIRO_FONT_SLANT_NORMAL, caption_weight);
    cairo_set_font_size (display, caption_size)
    cairo_set_source_rgba (display, rgb_to_r_g_b(caption_fg_colour, caption_fg_alpha))
    cairo_move_to (display, x + tox + 2, y + toy + 20)
    cairo_show_text (display, caption)
    cairo_stroke (display)
end
------------------------------------------------------------------------
-- display_text
-- 
function display_text(display,data,value)

    local text_weight, text_size = data['txt_weight'], data['txt_size']
    local text_fg_colour, text_fg_alpha = data['txt_fg_colour'], data['txt_fg_alpha']
    local font = data['font']   
    local x, y = data['x'], data['y']
    
    cairo_select_font_face (display, font, CAIRO_FONT_SLANT_NORMAL, text_weight);
    cairo_set_font_size (display, text_size)
    cairo_set_source_rgba (display, rgb_to_r_g_b(text_fg_colour, text_fg_alpha))
    cairo_move_to (display, x, y)
    if data['name'] == "DRIVER" then
        value = "Driver: "..value
    end
    cairo_show_text (display, value)
    cairo_stroke (display)
end
------------------------------------------------------------------------
-- Format gauge caption
--
function display_caption(caption,val,arg)
    if caption == "true" and arg == "TEMPERATURE" then
        caption = ("Temperature: "..val.."°C")
    elseif caption == "true" and arg == "POWER" then
        caption = ("Power: "..val.." Watts")
    elseif caption == "true" and arg == "MEM_USED" then
        if mem_total == nil then
            caption = ("Memory used: "..val.." MB")
        else
            caption = ("Memory used: "..val.." MB / "..mem_total.." MB")
        end
    elseif caption == "true" and arg == "UTIL" then
        caption = ("GPU Utilization: "..val.."%")
    end

    return caption
end
------------------------------------------------------------------------
-- set maximum values if available, else sane defaults
function set_max_value(arg, maxval, u_angle)
    if arg == 'TEMPERATURE' then
        if temp_max ~= nil then
            maxval = temp_max
        else
            maxval = 100
        end
        u_angle = 270/maxval
        u_angle = tonumber(string.format('%.2f',u_angle))
        
    elseif arg == 'MEM_USED' then
        if mem_total ~= nil then
            maxval = mem_total
        else
            maxval = 2048
        end
        u_angle = 270/maxval
        u_angle = tonumber(string.format('%.3f',u_angle))
        
    elseif arg == 'POWER' then
        if power_max ~= nil then
            maxval = power_max
        else 
            maxval = 300
        end
        if maxval == 'N/A' then
            maxval = 300
        end
        u_angle = 270/maxval
        u_angle = tonumber(string.format('%f',u_angle))
    end
    
    return maxval, u_angle
end
------------------------------------------------------------------------
-- go_gauge_rings
-- loads data and displays gauges
--
function go_gauge_rings(display)
    
    -- get array values from output of bash script
    local val_array = {}
    local val_f = io.popen('sh '..script_path..script_name)
    local n = 1
    for line in val_f:lines() do
        table.insert(val_array,line)
        n = n+1
    end
    val_f:close()
    
    local function load_rings(display, data, value)
        if data['name'] == 'nvidia' then 
            draw_gauge_ring(display, data, value)
        end
    end
        
    local function show_data()
        local j = 1
        for i in pairs(gauge) do
            load_rings(display, gauge[i], val_array[j])
            j = j+1        
        end
    
        for n in pairs(conky_text) do
            display_text(display,conky_text[n],val_array[j])
            j = j+1 
        end
        
        -- add extra data here, if required (THIRD section in bash script output)
        -- NB IMPORTANT!! Variables must correspond to the order in the bash script
        temp_slowdown = val_array[j] -- global var, used by Temperature gauge
        temp_max = val_array[j+1]    -- global var, used by Temperature gauge
        mem_total = val_array[j+2]   -- global var, used by display_caption()
        power_max = val_array[j+3]   -- global var, used by Power gauge
    end

    show_data()      -- use array data for drawing gauges and text

end

-------------------------------------------------------------------------------
--  MAIN
function conky_main()
    if conky_window == nil then
        return
    end

    local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
    local display = cairo_create(cs)

    local updates = conky_parse('${updates}')
    update_num = tonumber(updates)

    if update_num > 5 then
        go_gauge_rings(display)
    end

    cairo_surface_destroy(cs)
    cairo_destroy(display)
end

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#979 2018-11-04 17:30:56

hhh
That's easy!
Registered: 2015-09-17
Posts: 6,101
Website

Offline

Board footer

Powered by FluxBB