Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'cairo'
- require 'imlib2'
- --[[ RING WIDGET ]]
- --[[ v1.1 by londonali1010 (2009) ]]
- --[[ Options (name, arg, max, bg_colour, bg_alpha, xc, yc, radius, thickness, start_angle, end_angle):
- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.
- "arg" is the argument to the stat type, e.g. if in Conky you would write ${cpu cpu0}, 'cpu0' would be the argument. If you would not use an argument in the Conky variable, use ''.
- "max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.
- "bg_colour" is the colour of the base ring.
- "bg_alpha" is the alpha value of the base ring.
- "fg_colour" is the colour of the indicator part of the ring.
- "fg_alpha" is the alpha value of the indicator part of the ring.
- "x" and "y" are the x and y coordinates of the centre of the ring, relative to the top left corner of the Conky window.
- "radius" is the radius of the ring.
- "thickness" is the thickness of the ring, centred around the radius.
- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.
- "end_angle" is the ending angle of the ring, in degrees, clockwise from top. Value can be either positive or negative, but must be larger (e.g. more clockwise) than start_angle. ]]
- function rgb_to_r_g_b(colour, alpha)
- return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
- end
- function ring(name, arg, max, bgc, bga, fgc, fga, xc, yc, r, t, sa, ea)
- local function draw_ring(pct)
- local angle_0 = sa * (2 * math.pi/360) - math.pi/2
- local angle_f = ea * (2 * math.pi/360) - math.pi/2
- local pct_arc = pct * (angle_f - angle_0)
- -- Draw background ring
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT) -- square line ends
- cairo_arc(cr, xc, yc, r, angle_0, angle_f)
- cairo_set_source_rgba(cr, rgb_to_r_g_b(bgc, bga))
- cairo_set_line_width(cr, t)
- cairo_stroke(cr)
- -- Draw indicator ring
- cairo_arc(cr, xc, yc, r, angle_0, angle_0 + pct_arc)
- cairo_set_source_rgba(cr, rgb_to_r_g_b(fgc, fga))
- cairo_stroke(cr)
- end;
- local function setup_ring()
- local str = ''
- local value = 0
- str = string.format('${%s %s}', name, arg)
- str = conky_parse(str)
- value = tonumber(str)
- if value == nil then value = 0 end
- pct = value/max
- draw_ring(pct)
- end
- local updates = conky_parse('${updates}')
- update_num = tonumber(updates)
- if update_num > 5 then setup_ring() end
- cairo_stroke (cr);
- end
- function draw_atext(arg, x, y, ff, fs, r, cl, ca, sl, wg)
- local rad=(math.pi*r)/180
- if sl == 'italic' then
- slant = CAIRO_FONT_SLANT_ITALIC
- else--if sl == 'normal' then
- slant = CAIRO_FONT_SLANT_NORMAL
- end
- if wg == 'bold' then
- weight = CAIRO_FONT_WEIGHT_BOLD
- else--if wg == 'normal' then
- weight = CAIRO_FONT_WEIGHT_NORMAL
- end
- cairo_select_font_face (cr, ff, slant, weight)
- cairo_set_font_size (cr, fs)
- cairo_set_source_rgba(cr, rgb_to_r_g_b(cl, ca))
- cairo_move_to (cr, x, y)
- cairo_rotate(cr, rad)
- cairo_show_text (cr, conky_parse(arg))
- cairo_rotate(cr, -rad)
- cairo_stroke (cr)
- end
- function draw_aline(x1, y1, x2, y2, width, cl, ca)
- cairo_set_source_rgba(cr, rgb_to_r_g_b(cl, ca))
- cairo_set_line_width (cr, width)
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND)
- cairo_move_to (cr, x1, y1)
- cairo_rel_line_to (cr, -x1+x2, -y1+y2)
- cairo_stroke (cr)
- end
- function draw_arectangle(x1, y1, width, height, radius, rct_fill_cl, rct_fill_al, outl_width, outl_cl, outl_al)
- --aspect=1.0
- --corner_radius = 30.0
- --radius = corner_radius / aspect
- degrees = math.pi / 180.0
- cairo_new_sub_path (cr)
- cairo_arc (cr, x1 + width - radius, y1 + radius, radius, -90 * degrees, 0 * degrees)
- cairo_arc (cr, x1 + width - radius, y1 + height - radius, radius, 0 * degrees, 90 * degrees)
- cairo_arc (cr, x1 + radius, y1 + height - radius, radius, 90 * degrees, 180 * degrees)
- cairo_arc (cr, x1 + radius, y1 + radius, radius, 180 * degrees, 270 * degrees)
- cairo_close_path (cr)
- cairo_set_source_rgba(cr, rgb_to_r_g_b(rct_fill_cl, rct_fill_al))
- cairo_fill_preserve (cr)
- cairo_set_source_rgba(cr, rgb_to_r_g_b(outl_cl, outl_al))
- --cairo_set_source_rgba (cr, 0.5, 0, 0, 0.5)
- cairo_set_line_width (cr, outl_width)
- cairo_stroke (cr)
- end
- -- RUNTIME
- function conky_draw_widgets()
- 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)
- draw_arectangle(0, 0, 200, 660, 20, 0x000000, 0.4, 0, 0x92CC00, 0.4)
- draw_arectangle(1, 1, 198, 658, 18, 0x000000, 0.0, 2, 0x92CC00, 0.4)
- ring('time','%I.%M',12,0x92CC00,0.1,0x92CC00,0.4,95, 35,20,4,0,360)
- ring('time','%M.%S',60,0xA4E600,0.1,0xA4E600,0.6,95, 35,25,4,0,360)
- ring('time','%S',60,0xB7FF00,0.1,0xB7FF00,0.8,95, 35,29,2,0,360)
- ring('memperc','',100,0x1E90FF,0.2,0x1E90FF,0.8,127, 150.5,25,12,180,360)
- ring('swapperc','',100,0x1E90FF,0.2,0x1E90FF,0.8,127, 220,25,12,180,360)
- ring('cpu','cpu1',100,0x1E90FF,0.2,0x1E90FF,0.8,50, 280,25,4,90,180)
- ring('cpu','cpu2',100,0xB7FF00,0.2,0xB7FF00,0.8,50, 335,25,4,0,90)
- ring('cpu','cpu1',100,0xB7FF00,0.2,0xB7FF00,0.8,105, 280,25,4,180,270)
- ring('cpu','cpu2',100,0x1E90FF,0.2,0x1E90FF,0.8,105, 335,25,4,270,360)
- ring('fs_free_perc','/',100,0xFF6E00,0.1,0xFF6E00,0.6,127, 400,25,12,180,360)
- ring('fs_used_perc','/home',100,0xFF6E00,0.1,0xFF6E00,0.6,127, 470,25,12,180,360)
- draw_aline(10, 25, 60, 25, 2, 0x92CC00, 0.4)
- --draw_aline(60, 210, 130, 210, 5, 0xffffff, 0.1)
- draw_atext('${time %H:%M}', 16.0, 20.0, 'Ubuntu', 14.0, 0.0, 0xB7FF00, 1.0, 'normal', 'bold')
- draw_atext('Memory', 25.0, 226.0, 'Ubuntu', 22.0, -90, 0xffffff, 0.2, 'normal', 'bold')
- draw_atext('RAM', 50.0, 128.0, 'Ubuntu', 14.0, 0.0, 0x1E90FF, 1.0, 'normal', 'normal')
- draw_atext('Swap', 50.0, 198.0, 'Ubuntu', 14.0, 0.0, 0x1E90FF, 1.0, 'normal', 'normal')
- draw_atext('CPU', 25.0, 330.0, 'Ubuntu', 22.0, -90, 0xffffff, 0.2, 'normal', 'bold')
- draw_atext('1', 54.0, 295.0, 'Ubuntu', 16.0, 0, 0xffffff, 0.2, 'normal', 'bold')
- draw_atext('2', 90.0, 295.0, 'Ubuntu', 16.0, 0, 0xffffff, 0.2, 'normal', 'bold')
- draw_atext('3', 54.0, 330.0, 'Ubuntu', 16.0, 0, 0xffffff, 0.2, 'normal', 'bold')
- draw_atext('4', 90.0, 330.0, 'Ubuntu', 16.0, 0, 0xffffff, 0.2, 'normal', 'bold')
- draw_atext('Disk Usage', 25.0, 495.0, 'Ubuntu', 22.0, -90, 0xffffff, 0.2, 'normal', 'bold')
- draw_atext('Root', 50.0, 378.0, 'Ubuntu', 14.0, 0.0, 0xFF6E00, 1.0, 'normal', 'normal')
- draw_atext('Home', 50.0, 448.0, 'Ubuntu', 14.0, 0.0, 0xFF6E00, 1.0, 'normal', 'normal')
- draw_atext('NET', 25.0, 600, 'Ubuntu', 22.0, -90, 0xffffff, 0.2, 'normal', 'bold')
- cairo_destroy(cr)
- end
Advertisement
Add Comment
Please, Sign In to add comment