-- Conky, a system monitor https://github.com/brndnmtthws/conky

-- Work out screen width - then position conky 100 pixels off the edge.
xrandr_output = io.popen("xrandr|awk '/^.*primary/ {print(substr($4, 0, 4))}'")
window_width = xrandr_output:read("*n") - 100
xrandr_output:close()

-- We nominally show this bottom right - but it is forced to be
-- Screen size - 100 pixels, offset appropriately from the left so it fills the screen in the middle (ish)
conky.config = {
    alignment = 'bottom_right',
    border_width = 0,
    cpu_avg_samples = 2,
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',
    double_buffer = true,
    draw_borders = false,
    draw_graph_borders = true,
    draw_outline = false,
    draw_shades = false,
    extra_newline = false,
    gap_x = 60,
    gap_y = 0,
    minimum_height = 5,
    minimum_width = window_width,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_ncurses = false,
    out_to_stderr = false,
    out_to_x = true,
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'desktop',
    own_window_transparent = true,
    show_graph_range = false,
    show_graph_scale = false,
    own_window_argb_visual = true,
    stippled_borders = 0,
    update_interval = 1.0,
    uppercase = false,
    use_spacer = 'none',
    use_xft = true,
    xftalpha=1,
    font="Droid Sans:size=10",
    color1 = "#9f6ec2",
    color2 = "#424242",
}

-- Display Time/Date on the right
-- Display Hostname on the left
-- Draw a line
-- Show curently playing media on the left, calling playerctrl
-- Show various system stats on the right

conky.text = [[
${alignr}${color grey}${font :size=100}${time %H:%M}${font Ubuntu Mono:size=32}$color1${time %S}
${alignr}${color grey}${font :size=32}${time %d %B %Y}${font}
${font Great Vibes:size=30}$nodename ${font}$color2$hr
${color grey}${font Droid Sans:size=12}${exec playerctl metadata -a --format '{{status}},{{title}},{{position}},{{mpris:length}},{{playerName}}'|awk -F',' '/^Playing/ { printf("%s%s: %s (%i%)", toupper(substr($5,1,1)), substr($5, 2), $2, $3/$4 * 100) }'}${alignr}${font Ubuntu Mono:size=16}Temp ${execi 5 sensors | awk '/^CPU Temp/ { print(substr($3, 2, length($3) - 2)) }'} | ${if_match $cpu < 10} CPU${else}CPU${endif} $cpu% | RAM $memperc% | FS $fs_used_perc%
]]
