JeSuisNerd

conky_widgets.lua

Apr 20th, 2012
673
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.  
  3. All credit to londonali1010 for the hollow widgets script and for the clockwise rings function.  http://londonali1010.deviantart.com/art/Conky-Widgets-Script-141963883
  4.  
  5. The Counter-clockwise ring function is my own edit of the clockwise rings function for ease of use (as opposed to the counter-clockwise rings script, also by londonali).
  6.  
  7. Graph widget code is by wlourf, and I've configured it myself to work inside londonali's widget script and play nicely with everything else.  http://wlourf.deviantart.com/art/Graph-Widget-for-Conky-1-1-184541530
  8.  
  9. --JeSuisNerd
  10.  
  11. --]]
  12.  
  13. require 'cairo'
  14.  
  15. -- CLOCKWISE RINGS
  16. function ring(cr, name, arg, max, bgc, bga, fgc, fga, xc, yc, r, t, sa, ea)
  17.     local function rgb_to_r_g_b(colour,alpha)
  18.         return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  19.     end
  20.    
  21.     local function draw_ring(pct)
  22.         local angle_0=sa*(2*math.pi/360)-math.pi/2
  23.         local angle_f=ea*(2*math.pi/360)-math.pi/2
  24.         local pct_arc=pct*(angle_f-angle_0)
  25.  
  26.         -- Draw background ring
  27.  
  28.         cairo_arc(cr,xc,yc,r,angle_0,angle_f)
  29.         cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
  30.         cairo_set_line_width(cr,t)
  31.         cairo_stroke(cr)
  32.    
  33.         -- Draw indicator ring
  34.  
  35.         cairo_arc(cr,xc,yc,r,angle_0,angle_0+pct_arc)
  36.         cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
  37.         cairo_stroke(cr)
  38.     end
  39.    
  40.     local function setup_ring()
  41.         local str = ''
  42.         local value = 0
  43.        
  44.         str = string.format('${%s %s}', name, arg)
  45.         str = conky_parse(str)
  46.        
  47.         value = tonumber(str)
  48.         if value == nil then value = 0 end
  49.         pct = value/max
  50.        
  51.         draw_ring(pct)
  52.     end
  53.    
  54.     local updates=conky_parse('${updates}')
  55.     update_num=tonumber(updates)
  56.    
  57.     if update_num>5 then setup_ring() end
  58. end
  59.  
  60.  
  61.  
  62. -- CCW RINGS
  63. function ring_ccw(cr, name, arg, max, bgc, bga, fgc, fga, xc, yc, r, t, sa, ea)
  64.     local function rgb_to_r_g_b(colour,alpha)
  65.         return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  66.     end
  67.    
  68.     local function draw_ring(pct)
  69.         local angle_0=sa*(2*math.pi/360)-math.pi/2
  70.         local angle_f=ea*(2*math.pi/360)-math.pi/2
  71.         local pct_arc=pct*(angle_f-angle_0)
  72.  
  73.         -- Draw background ring
  74.  
  75.         cairo_arc(cr,xc,yc,r,angle_0,angle_f)
  76.         cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
  77.         cairo_set_line_width(cr,t)
  78.         cairo_stroke(cr)
  79.    
  80.         -- Draw indicator ring
  81.  
  82.         cairo_arc(cr,xc,yc,r,angle_f-pct_arc,angle_f)
  83.         cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
  84.         cairo_stroke(cr)
  85.     end
  86.    
  87.     local function setup_ring()
  88.         local str = ''
  89.         local value = 0
  90.        
  91.         str = string.format('${%s %s}', name, arg)
  92.         str = conky_parse(str)
  93.        
  94.         value = tonumber(str)
  95.         if value == nil then value = 0 end
  96.         pct = value/max
  97.        
  98.         draw_ring(pct)
  99.     end
  100.    
  101.     local updates=conky_parse('${updates}')
  102.     update_num=tonumber(updates)
  103.    
  104.     if update_num>5 then setup_ring() end
  105. end
  106.  
  107.  
  108.  
  109. --------------------------------------------------------------------------------------------------------------------------------------
  110. --[[
  111. 3 parameters are mandatory
  112. name        - the name of the conky variable to display,
  113.               for example for {$cpu cpu0}, just write name="cpu"
  114. arg         - the argument of the above variable,
  115.               for example for {$cpu cpu1}, just write arg="cpu1"
  116.               arg can be a numerical value if name=""
  117. max         - the maximum value the above variable can reach,
  118.               for example for {$cpu cpu1}, just write max=100 or less or more
  119.    
  120. Optional parameters:
  121. x,y         - coordinates of the bottom-left corner of the graph,
  122.               relative to the top-left corner of the conky window
  123.               default =  bottom-left corner of the conky window
  124. width       - width of the graph, default = 100 pixels
  125. height      - height of the graph, default = 20 pixels
  126. nb_values   - number of values to display in the graph, default=width
  127.               i.e. 1 pixel for 1 value
  128. autoscale   - if set to true, calculate the max valeu of the y axis and
  129.               doesn't use the max parameter above, default=false
  130. skew_x      - skew graph around x axis, défaut = 0
  131. skew_y      - skew graph around y axis, défaut = 0
  132. angle       - angle of rotation of the graph in degress, default = 0
  133.               i.e. a horizontal graph)
  134. inverse     - if set to true, graph are draw from right to left, default=false
  135. background  - if set to false, background is not drawn, default=true
  136. foreground  - if set to false, foreground is not drawn, default=true
  137.               foreground = plain graph
  138. bg_bd_size  - size of the border of the background, default=0=no border
  139. fg_bd_size  - size of the border of the foreground, default=0=no border
  140.  
  141.  
  142. Colours tables below are defined into braces :
  143. {position in the gradient (0 to 1), colour in hexadecimal, alpha (0 to 1)}
  144. example for a single colour table :
  145. {{0,0xFFAA00,1}} position parameter doesn't matter
  146. example for a two-colours table :
  147. {{0,0xFFAA00,1},{1,0x00AA00,1}} or {{0.5,0xFFAA00,1},{1,0x00AA00,1}}
  148. example for a three-colours table :
  149. {{0,0xFFAA00,1},{0.5,0xFF0000,1},{1,0x00AA00,1}}
  150.  
  151. bg_colour   - colour table for background,
  152.               default = {{0,0x000000,.5},{1,0xFFFFFF,.5}}
  153. fg_colour   - colour table for foreground,
  154.               default = {{0,0x00FFFF,1},{1,0x0000FF,1}}
  155. bg_bd_colour- colour table for background border,
  156.               default = {{1,0xFFFFFF,1}}             
  157. fg_bd_colour- colour table for foreground border,
  158.               default = {{1,0xFFFF00,1}}             
  159.  
  160. bg_orientation, bg_bd_orientation, fg_orientation, fg_bd_orientation,
  161.             - "orientation" defines the starting point of the gradient,
  162.               default="nn"
  163.               there are 8 available starting points :
  164.               "nw","nn","ne","ee","se","ss","sw","ww"
  165.               (n for north, w for west ...)
  166.               theses 8 points are the 4 corners + the 4 middles of graph
  167.               so a gradient "nn" will go from "nn" to "ss"
  168.               a gradient "nw" will go from "nw" to "se"
  169.  
  170. draw_me     - if set to false, graph is not drawn (default = true)
  171.               it can be used with a conky string, if the string returns 1, the graph is drawn :
  172.               example : "${if_empty ${wireless_essid wlan0}}${else}1$endif"
  173. ]]
  174. function set_settings()
  175.     graph_settings={
  176.         --eth0
  177.         {
  178.         name="upspeedf",
  179.             arg="eth0",
  180.             max=1000,
  181.             autoscale=true,
  182.             x=85,
  183.             y=835,
  184.             width=160,
  185.             height=42,
  186.             nb_values=100,
  187.             background=true,
  188.             foreground=true,
  189.             inverse=true,
  190.             bg_bd_size=1,
  191.         fg_bd_size=3,
  192.         angle=-90,
  193.         fg_orientation="ss",
  194.         bg_orientation="nn",
  195.         bg_colour = {{0,0xa49a30,0},{1,0xa49a30,.1}},
  196.         fg_colour = {{0,0xa49a30,0.7},{1,0x348a8f,0.7}},
  197.         fg_bd_colour={{0,0xa49a30,0}},
  198.         bg_bd_colour={{0,0xa49a30,0.7}},
  199.         draw_me=true,
  200.         },
  201.         {
  202.         name="downspeedf",
  203.         arg="eth0",
  204.         max=1000,
  205.         autoscale=true,
  206.         x=87,
  207.         y=675,
  208.         width=160,
  209.         height=42,
  210.         nb_values=100,
  211.         background=true,
  212.         foreground=true,
  213.         inverse=true,
  214.         bg_bd_size=1,
  215.         fg_bd_size=3,
  216.         angle=90,
  217.         fg_orientation="ss",
  218.         bg_orientation="nn",
  219.         bg_colour = {{0,0xa49a30,0},{1,0xa49a30,.1}},
  220.         fg_colour = {{0,0xa49a30,0.7},{1,0x348a8f,0.7}},
  221.         fg_bd_colour={{0,0xa49a30,0}},
  222.         bg_bd_colour={{0,0xa49a30,0.7}},
  223.         draw_me=true,
  224.         },
  225.         --wlan0
  226.         {
  227.         name="upspeedf",
  228.         arg="wlan0",
  229.         max=1000,
  230.         autoscale=true,
  231.         x=200,
  232.         y=835,
  233.         width=160,
  234.         height=42,
  235.         nb_values=100,
  236.         background=true,
  237.         foreground=true,
  238.         inverse=true,
  239.         bg_bd_size=1,
  240.         fg_bd_size=3,
  241.         angle=-90,
  242.         fg_orientation="ss",
  243.         bg_orientation="nn",
  244.         bg_colour = {{0,0x348a8f,0},{1,0x348a8f,.1}},
  245.         fg_colour = {{.3,0x348a8f,0.7},{1,0xa49a30,0.7}},
  246.         fg_bd_colour={{0,0x348a8f,0}},
  247.         bg_bd_colour={{0,0x348a8f,0.7}},
  248.         draw_me=true,
  249.         },
  250.         {
  251.         name="downspeedf",
  252.         arg="wlan0",
  253.         max=1000,
  254.         autoscale=true,
  255.         x=202,
  256.         y=675,
  257.         width=160,
  258.         height=42,
  259.         nb_values=100,
  260.         background=true,
  261.         foreground=true,
  262.         inverse=true,
  263.         bg_bd_size=1,
  264.         fg_bd_size=3,
  265.         angle=90,
  266.         fg_orientation="ss",
  267.         bg_orientation="nn",
  268.         bg_colour = {{0,0x348a8f,0},{1,0x348a8f,.1}},
  269.         fg_colour = {{.3,0x348a8f,0.7},{1,0x348a8f,0.7}},
  270.         fg_bd_colour={{0,0x348a8f,0}},
  271.         bg_bd_colour={{0,0x348a8f,0.7}},
  272.         draw_me=true,
  273.         }
  274.     }
  275. end
  276.  
  277. function check_settings(t)
  278.     --tables are check only when conky start
  279.     if t.name==nil and t.arg==nil then
  280.         print ("No input values ... use parameters 'name'" ..
  281.             " with 'arg' or only parameter 'arg' ")
  282.         return 1
  283.     end
  284.  
  285.     if t.max==nil then
  286.         print ("No maximum value defined, use 'max'")
  287.         print ("for name=" .. t.name .. " with arg=" .. t.arg)
  288.         return 1
  289.     end
  290.     if t.name==nil then t.name="" end
  291.     if t.arg==nil then t.arg="" end
  292.     return 0
  293. end
  294.  
  295. function draw_graph(t)
  296.     --drawing function
  297.  
  298.     local function rgb_to_r_g_b(colour)
  299.         return ((colour[2] / 0x10000) % 0x100) / 255., ((colour[2] / 0x100) % 0x100) / 255., (colour[2] % 0x100) / 255., colour[3]
  300.     end
  301.  
  302.     local function linear_orientation(o,w,h)
  303.         --set gradient for bg and bg border
  304.         local p
  305.         if o=="nn" then
  306.             p={w/2,h,w/2,0}
  307.         elseif o=="ne" then
  308.             p={w,h,0,0}
  309.         elseif o=="ww" then
  310.             p={0,h/2,w,h/2}
  311.         elseif o=="se" then
  312.             p={w,0,0,h}
  313.         elseif o=="ss" then
  314.             p={w/2,0,w/2,h}
  315.         elseif o=="ee" then
  316.             p={w,h/2,0,h/2}    
  317.         elseif o=="sw" then
  318.             p={0,0,w,h}
  319.         elseif o=="nw" then
  320.             p={0,h,w,0}
  321.         end
  322.         return p
  323.     end
  324.  
  325.     local function linear_orientation_inv(o,w,h)
  326.         --set gradient for fg and fg border
  327.         local p
  328.         if o=="ss" then
  329.             p={w/2,h,w/2,0}
  330.         elseif o=="sw" then
  331.             p={w,h,0,0}
  332.         elseif o=="ee" then
  333.             p={0,h/2,w,h/2}
  334.         elseif o=="nw" then
  335.             p={w,0,0,h}
  336.         elseif o=="nn" then
  337.             p={w/2,0,w/2,h}
  338.         elseif o=="ww" then
  339.             p={w,h/2,0,h/2}    
  340.         elseif o=="ne" then
  341.             p={0,0,w,h}
  342.         elseif o=="se" then
  343.             p={0,h,w,0}
  344.         end
  345.         return p
  346.     end
  347.  
  348.  
  349.     --set default values
  350.    
  351.     --cancel drawing if not needed
  352.     if t.draw_me~=nil and conky_parse(tostring(t.draw_me)) ~= "1" then
  353.         return
  354.     end
  355.    
  356.  
  357.    
  358.     if t.height==nil    then t.height=20 end
  359.     --checked in previous part : width and nb_values
  360.        
  361.     if t.background==nil    then t.background=true end
  362.     if t.bg_bd_size==nil    then t.bg_bd_size=0 end
  363.     if t.x==nil             then t.x=t.bg_bd_size end
  364.     if t.y==nil             then t.y=conky_window.height -t.bg_bd_size end
  365.     if t.bg_colour==nil     then t.bg_colour={{0,0x000000,.5},{1,0xFFFFFF,.5}} end
  366.     if t.bg_bd_colour==nil  then t.bg_bd_colour={{1,0xFFFFFF,1}} end
  367.    
  368.     if t.foreground==nil    then t.foreground=true end
  369.     if t.fg_colour==nil     then t.fg_colour={{0,0x00FFFF,1},{1,0x0000FF,1}} end
  370.    
  371.     if t.fg_bd_size==nil    then t.fg_bd_size=0 end
  372.     if t.fg_bd_colour==nil  then t.fg_bd_colour={{1,0xFFFF00,1}} end
  373.    
  374.     if t.autoscale==nil     then t.autoscale=false end
  375.     if t.inverse==nil       then t.inverse=false end
  376.     if t.angle==nil         then t.angle=0 end
  377.    
  378.     if t.bg_bd_orientation==nil then t.bg_bd_orientation="nn" end
  379.     if t.bg_orientation==nil then t.bg_orientation="nn" end
  380.     if t.fg_bd_orientation==nil then t.fg_bd_orientation="nn" end
  381.     if t.fg_orientation==nil then t.fg_orientation="nn" end
  382.  
  383.     --check colours tables
  384.     for i=1, #t.fg_colour do    
  385.         if #t.fg_colour[i]~=3 then
  386.             print ("error in fg_colour table")
  387.             t.fg_colour[i]={1,0x0000FF,1}
  388.         end
  389.     end
  390.    
  391.     for i=1, #t.fg_bd_colour do    
  392.         if #t.fg_bd_colour[i]~=3 then
  393.             print ("error in fg_bd_colour table")
  394.             t.fg_bd_colour[i]={1,0x00FF00,1}
  395.         end
  396.     end
  397.    
  398.     for i=1, #t.bg_colour do    
  399.         if #t.bg_colour[i]~=3 then
  400.             print ("error in background color table")
  401.             t.bg_colour[i]={1,0xFFFFFF,0.5}
  402.         end
  403.     end    
  404.  
  405.     for i=1, #t.bg_bd_colour do    
  406.         if #t.bg_bd_colour[i]~=3 then
  407.             print ("error in background border color table")
  408.             t.bg_bd_colour[i]={1,0xFFFFFF,1}
  409.         end
  410.     end    
  411.  
  412.     --calculate skew parameters if needed
  413.     if t.flag_init then
  414.         if t.skew_x == nil then
  415.             t.skew_x=0
  416.         else
  417.             t.skew_x = math.pi*t.skew_x/180
  418.         end
  419.         if t.skew_y == nil then
  420.             t.skew_y=0
  421.         else
  422.             t.skew_y = math.pi*t.skew_y/180
  423.         end
  424.         t.flag_init=false
  425.     end
  426.  
  427.     cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
  428.     cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND)
  429.  
  430.     local matrix0 = cairo_matrix_t:create()
  431.     tolua.takeownership(matrix0)
  432.     cairo_save(cr)
  433.     cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
  434.     cairo_transform(cr,matrix0)
  435.    
  436.     local ratio=t.width/t.nb_values
  437.  
  438.     cairo_translate(cr,t.x,t.y)
  439.     cairo_rotate(cr,t.angle*math.pi/180)
  440.     cairo_scale(cr,1,-1)
  441.  
  442.     --background
  443.     if t.background then
  444.         local pts=linear_orientation(t.bg_orientation,t.width,t.height)
  445.         local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
  446.         for i=1, #t.bg_colour do
  447.             --print ("i",i,t.colour[i][1], rgb_to_r_g_b(t.colour[i]))
  448.             cairo_pattern_add_color_stop_rgba (pat, t.bg_colour[i][1], rgb_to_r_g_b(t.bg_colour[i]))
  449.         end
  450.         cairo_set_source (cr, pat)
  451.         cairo_rectangle(cr,0,0,t.width,t.height)   
  452.         cairo_fill(cr) 
  453.         cairo_pattern_destroy(pat)
  454.     end
  455.    
  456.     --autoscale
  457.     cairo_save(cr)
  458.     if t.autoscale then
  459.         t.max= t.automax*1.1
  460.     end
  461.    
  462.     local scale_x = t.width/(t.nb_values-1)
  463.     local scale_y = t.height/t.max
  464.    
  465.     --define first point of the graph
  466.     if updates-updates_gap <t.nb_values then
  467.         t.beg = t.beg - 1
  468.         --next line prevent segmentation error when conky window is redraw
  469.         --quicly when another window "fly" over it
  470.         if t.beg<0 then t.beg=0 end
  471.     else
  472.         t.beg=0
  473.     end
  474.     if t.inverse then cairo_scale(cr,-1,1)
  475.     cairo_translate(cr,-t.width,0) end
  476.  
  477.     --graph foreground
  478.     if t.foreground then
  479.         local pts_fg=linear_orientation_inv(t.fg_orientation,t.width,t.height)
  480.         local pat = cairo_pattern_create_linear (pts_fg[1],pts_fg[2],pts_fg[3],pts_fg[4])
  481.         for i=1,#t.fg_colour,1 do
  482.             cairo_pattern_add_color_stop_rgba (pat, 1-t.fg_colour[i][1], rgb_to_r_g_b(t.fg_colour[i]))
  483.         end
  484.         cairo_set_source (cr, pat)
  485.  
  486.         cairo_move_to(cr,t.beg*scale_x,0)
  487.         cairo_line_to(cr,t.beg*scale_x,t.values[t.beg+1]*scale_y)
  488.         for i=t.beg, t.nb_values-1 do
  489.             cairo_line_to(cr,i*scale_x,t.values[i+1]*scale_y)      
  490.         end
  491.         cairo_line_to(cr,(t.nb_values-1)*scale_x,0)
  492.         cairo_close_path(cr)
  493.         cairo_fill(cr)
  494.         cairo_pattern_destroy(pat)
  495.     end
  496.  
  497.     --graph_border
  498.     if t.fg_bd_size>0 then
  499.         local pts=linear_orientation_inv(t.fg_bd_orientation,t.width,t.height)
  500.         local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
  501.         for i=1,#t.fg_bd_colour,1 do
  502.             cairo_pattern_add_color_stop_rgba (pat, 1-t.fg_bd_colour[i][1], rgb_to_r_g_b(t.fg_bd_colour[i]))
  503.         end
  504.         cairo_set_source (cr, pat)
  505.         cairo_move_to(cr,t.beg*scale_x,t.values[t.beg+1]*scale_y)
  506.         for i=t.beg, t.nb_values-1 do
  507.             cairo_line_to(cr,i*scale_x,t.values[i+1]*scale_y)      
  508.         end
  509.         cairo_set_line_width(cr,t.fg_bd_size)
  510.         cairo_stroke(cr)
  511.         cairo_pattern_destroy(pat)
  512.     end
  513.     cairo_restore(cr)
  514.  
  515.     --background border
  516.     if t.bg_bd_size>0 then
  517.         local pts=linear_orientation(t.bg_bd_orientation,t.width,t.height)
  518.         local pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
  519.         for i=1, #t.bg_bd_colour do
  520.             --print ("i",i,t.colour[i][1], rgb_to_r_g_b(t.colour[i]))
  521.             cairo_pattern_add_color_stop_rgba (pat, t.bg_bd_colour[i][1], rgb_to_r_g_b(t.bg_bd_colour[i]))
  522.         end
  523.         cairo_set_source (cr, pat)
  524.         cairo_rectangle(cr,0,0,t.width,t.height)   
  525.         cairo_set_line_width(cr,t.bg_bd_size)
  526.         cairo_stroke(cr)
  527.         cairo_pattern_destroy(pat) 
  528.     end
  529.  
  530.     cairo_restore(cr)
  531.  
  532. end
  533.  
  534. function conky_widgets()
  535.     if conky_window == nil then return end
  536.     local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  537.     local w=conky_window.width
  538.     local h=conky_window.height
  539.     cr = cairo_create(cs)
  540.  
  541.     --Rings--
  542.    
  543.     --ring (cr, type, argument, maxvalue, backcolor, backalpha, forecolor, forealpha, x, y, radius, thickness, start, end)
  544.     ring(cr, 'cpu', 'cpu0', 100, 0x020202, .1, 0x7365BC, 1, 95, 178, 62, 4, 90, 360)
  545.     ring(cr, 'cpu', 'cpu1', 100, 0x020202, .1, 0x34678F, 1, 95, 178, 55, 4, 90, 360)
  546.     ring(cr, 'cpu', 'cpu2', 100, 0x020202, .1, 0x348a8f, 1, 95, 178, 48, 4, 90, 360)
  547.     ring(cr, 'cpu', 'cpu3', 100, 0x020202, .1, 0x348f43, 1, 95, 178, 41, 4, 90, 360)
  548.     ring(cr, 'cpu', 'cpu4', 100, 0x020202, .1, 0x8f8834, 1, 95, 178, 34, 4, 90, 360)
  549.     ring(cr, 'cpu', 'cpu5', 100, 0x020202, .1, 0xb55511, 1, 95, 178, 27, 4, 90, 360)
  550.     ring(cr, 'cpu', 'cpu6', 100, 0x020202, .1, 0x942a36, 1, 95, 178, 20, 4, 90, 360)
  551.     ring(cr, 'cpu', 'cpu7', 100, 0x020202, .1, 0x7365BC, 1, 95, 178, 13, 4, 90, 360)
  552.     ring_ccw(cr, 'memperc', '', 100, 0x020202, .1, 0xa49a30, 1, 190, 293, 62, 4, 0, 270)
  553.     ring(cr, 'fs_used_perc', '/', 100, 0x020202, .1, 0x348f43, 1, 95, 413, 62, 4, 90, 360)
  554.     ring(cr, 'fs_used_perc', '/media/Speedy/', 100, 0x020202, .1, 0x8f8834, 1, 95, 413, 55, 4, 90, 360)
  555.     ring(cr, 'fs_used_perc', '/home/', 100, 0x020202, .1, 0x7365BC, 1, 95, 413, 48, 4, 90, 360)
  556.     ring_ccw(cr, 'battery_percent', 'BAT0', 100, 0x020202, .1, 0xa49a30, 1, 190, 526, 62, 4, 0, 270)
  557.  
  558.  
  559.  
  560.     --Graphs--
  561.     updates=tonumber(conky_parse('${updates}'))
  562.     --start drawing after "updates_gap" updates
  563.     --prevent segmentation error for cpu
  564.     updates_gap=5
  565.     flagOK=0
  566.     if updates<=1 then    
  567.         set_settings()
  568.        
  569.         for i in pairs(graph_settings) do
  570.             if graph_settings[i].width==nil then graph_settings[i].width=100 end
  571.             if graph_settings[i].nb_values==nil then  
  572.                 graph_settings[i].nb_values= graph_settings[i].width
  573.             end
  574.             --create an empty table to store values
  575.             graph_settings[i]["values"]={}
  576.             --beginning point
  577.             graph_settings[i].beg = graph_settings[i].nb_values
  578.             --graph_settings[i].beg = 0
  579.             for j =1, graph_settings[i].nb_values do
  580.                 graph_settings[i].values[j]=0
  581.             end
  582.             graph_settings[i].flag_init=true
  583.             flagOK=flagOK + check_settings(graph_settings[i])
  584.  
  585.         end
  586.     end
  587.  
  588.     if flagOK>0 then
  589.         --abort script if error in one of the tables
  590.         print ("ERROR : Check the graph_setting table")
  591.         return
  592.     end
  593.  
  594.     --drawing process
  595.     if updates > updates_gap then
  596.         for i in pairs(graph_settings) do
  597.             if graph_settings[i].draw_me==true then graph_settings[i].draw_me = nil end
  598.             if (graph_settings[i].draw_me==nil or conky_parse(tostring(graph_settings[i].draw_me)) == "1") then
  599.                 local nb_values=graph_settings[i].nb_values
  600.                 graph_settings[i].automax=0
  601.                 for j =1, nb_values do
  602.                     if graph_settings[i].values[j+1]==nil then
  603.                         graph_settings[i].values[j+1]=0
  604.                     end
  605.                
  606.                     graph_settings[i].values[j]=graph_settings[i].values[j+1]
  607.                     if j==nb_values then
  608.                         --store value
  609.                         if graph_settings[i].name=="" then
  610.                             value=graph_settings[i].arg
  611.                         else
  612.                             value=tonumber(conky_parse('${' ..
  613.                                 graph_settings[i].name .. " " ..
  614.                                 graph_settings[i].arg ..'}'))
  615.                         end
  616.                         graph_settings[i].values[nb_values]=value
  617.                     end
  618.                     graph_settings[i].automax=math.max(graph_settings[i].automax,
  619.                                                        graph_settings[i].values[j])
  620.                     --should stop weird glitches at beginning when no values reported yet for upspeed or diskio
  621.                     if graph_settings[i].automax == 0 then graph_settings[i].automax = 1 end
  622.                 end
  623.                 draw_graph(graph_settings[i])
  624.             end
  625.         end
  626.     end
  627.  
  628.     cairo_destroy(cr)
  629.  
  630. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×