--- /dev/null
+--[[\r
+Ring Meters by londonali1010 (2009)\r
+\r
+This script draws percentage meters as rings. It is fully customisable; all options are described in the script.\r
+\r
+IMPORTANT: if you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away. The if statement on line 145 uses a delay to make sure that this doesn't happen. It calculates the length of the delay by the number of updates since Conky started. Generally, a value of 5s is long enough, so if you update Conky every 1s, use update_num > 5 in that if statement (the default). If you only update Conky every 2s, you should change it to update_num > 3; conversely if you update Conky every 0.5s, you should use update_num > 10. ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it, otherwise the update_num will not be reset and you will get an error.\r
+\r
+To call this script in Conky, use the following (assuming that you save this script to ~/scripts/rings.lua):\r
+ lua_load ~/scripts/rings-v1.2.1.lua\r
+ lua_draw_hook_pre ring_stats\r
+\r
+Changelog:\r
++ v1.2.1 -- Fixed minor bug that caused script to crash if conky_parse() returns a nil value (20.10.2009)\r
++ v1.2 -- Added option for the ending angle of the rings (07.10.2009)\r
++ v1.1 -- Added options for the starting angle of the rings, and added the "max" variable, to allow for variables that output a numerical value rather than a percentage (29.09.2009)\r
++ v1.0 -- Original release (28.09.2009)\r
+]]\r
+\r
+settings_table = {\r
+ {\r
+ -- Edit this table to customise your rings.\r
+ -- You can create more rings simply by adding more elements to settings_table.\r
+ -- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.\r
+ name='time',\r
+ -- "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 ''.\r
+ arg='%I.%M',\r
+ -- "max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.\r
+ max=12,\r
+ -- "bg_colour" is the colour of the base ring.\r
+ bg_colour=0xffffff,\r
+ -- "bg_alpha" is the alpha value of the base ring.\r
+ bg_alpha=0.1,\r
+ -- "fg_colour" is the colour of the indicator part of the ring.\r
+ fg_colour=0xffffff,\r
+ -- "fg_alpha" is the alpha value of the indicator part of the ring.\r
+ fg_alpha=0.2,\r
+ -- "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.\r
+ x=165, y=170,\r
+ -- "radius" is the radius of the ring.\r
+ radius=50,\r
+ -- "thickness" is the thickness of the ring, centred around the radius.\r
+ thickness=5,\r
+ -- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.\r
+ start_angle=0,\r
+ -- "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.\r
+ end_angle=360\r
+ },\r
+ {\r
+ name='time',\r
+ arg='%M.%S',\r
+ max=60,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.1,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.4,\r
+ x=165, y=170,\r
+ radius=56,\r
+ thickness=5,\r
+ start_angle=0,\r
+ end_angle=360\r
+ },\r
+ {\r
+ name='time',\r
+ arg='%S',\r
+ max=60,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.1,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.6,\r
+ x=165, y=170,\r
+ radius=62,\r
+ thickness=5,\r
+ start_angle=0,\r
+ end_angle=360\r
+ },\r
+ {\r
+ name='cpu',\r
+ arg='cpu0',\r
+ max=100,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.1,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.4,\r
+ x=165, y=170,\r
+ radius=84.5,\r
+ thickness=8,\r
+ start_angle=60,\r
+ end_angle=120\r
+ },\r
+ {\r
+ name='battery_percent',\r
+ arg='BAT1',\r
+ max=100,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.1,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.6,\r
+ x=165, y=170,\r
+ radius=72,\r
+ thickness=11,\r
+ start_angle=122,\r
+ end_angle=210\r
+ },\r
+ {\r
+ name='memperc',\r
+ arg='',\r
+ max=100,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.1,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.8,\r
+ x=165, y=170,\r
+ radius=83.5,\r
+ thickness=8,\r
+ start_angle=122,\r
+ end_angle=210\r
+ },\r
+ {\r
+ name='time',\r
+ arg='%d',\r
+ max=31,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.1,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.8,\r
+ x=165, y=170,\r
+ radius=70,\r
+ thickness=5,\r
+ start_angle=212,\r
+ end_angle=360\r
+ },\r
+ {\r
+ name='time',\r
+ arg='%m',\r
+ max=12,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.1,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.8,\r
+ x=165, y=170,\r
+ radius=76,\r
+ thickness=5,\r
+ start_angle=212,\r
+ end_angle=360\r
+ },\r
+ {\r
+ name='fs_used_perc',\r
+ arg='/',\r
+ max=150,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.2,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.3,\r
+ x=165, y=170,\r
+ radius=108.5,\r
+ thickness=3,\r
+ start_angle=-120,\r
+ end_angle=240\r
+ },\r
+ {\r
+ name='fs_used_perc',\r
+ arg='/',\r
+ max=100,\r
+ bg_colour=0xffffff,\r
+ bg_alpha=0.2,\r
+ fg_colour=0xffffff,\r
+ fg_alpha=0.3,\r
+ x=165, y=170,\r
+ radius=135,\r
+ thickness=50,\r
+ start_angle=-120,\r
+ end_angle=120\r
+ },\r
+}\r
+\r
+require 'cairo'\r
+\r
+function rgb_to_r_g_b(colour,alpha)\r
+ return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha\r
+end\r
+\r
+function draw_ring(cr,t,pt)\r
+ local w,h=conky_window.width,conky_window.height\r
+\r
+ local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']\r
+ local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']\r
+\r
+ local angle_0=sa*(2*math.pi/360)-math.pi/2\r
+ local angle_f=ea*(2*math.pi/360)-math.pi/2\r
+ local t_arc=t*(angle_f-angle_0)\r
+\r
+ -- Draw background ring\r
+\r
+ cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)\r
+ cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))\r
+ cairo_set_line_width(cr,ring_w)\r
+ cairo_stroke(cr)\r
+\r
+ -- Draw indicator ring\r
+\r
+ cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)\r
+ cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))\r
+ cairo_stroke(cr) \r
+end\r
+\r
+function conky_ring_stats()\r
+ local function setup_rings(cr,pt)\r
+ local str=''\r
+ local value=0\r
+\r
+ str=string.format('${%s %s}',pt['name'],pt['arg'])\r
+ str=conky_parse(str)\r
+\r
+ value=tonumber(str)\r
+ if value == nil then value = 0 end\r
+ pct=value/pt['max']\r
+\r
+ draw_ring(cr,pct,pt)\r
+ end\r
+\r
+ if conky_window==nil then return end\r
+ local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)\r
+\r
+ local cr=cairo_create(cs) \r
+\r
+ local updates=conky_parse('${updates}')\r
+ update_num=tonumber(updates)\r
+\r
+ if update_num>5 then\r
+ for i in pairs(settings_table) do\r
+ setup_rings(cr,settings_table[i])\r
+ end\r
+ end\r
+ cairo_surface_destroy(cs)\r
+ cairo_destroy(cr)\r
+end\r