vorron

lua conky

Sep 25th, 2013
2,057
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -------------------------------------------------------------------------------
  2. --                                                                
  3. --                            conky shi lua script
  4. --
  5. -------------------------------------------------------------------------------
  6.  
  7. require 'cairo'
  8.  
  9. -------------------------------------------------------------------------------
  10. ---------------------------------shared vars-----------------------------------
  11. -------------------------------------------------------------------------------
  12.  
  13. -- placement vars
  14. ----------------------------   
  15. local pcmt = {
  16.     border_gap = 50,
  17.     vertical_gap = {103.5,105},
  18.     wall_image_width = 844
  19. }
  20. local colomn_width = (1920 - pcmt.wall_image_width)/2 - pcmt.border_gap
  21.  
  22. -- color setup
  23. ----------------------------
  24. local white_color = 0xa0a0a0
  25. local back_color = 0x161616
  26. local gray_color = 0x404040
  27. --local main_color = 0x146056
  28. --local main_color = 0x0f6537
  29. local main_color = 0x169281
  30.  
  31. -- cairo settings
  32. ----------------------------
  33. local extents = cairo_text_extents_t:create()
  34.  
  35. local font = "Play"
  36. local main_font_size = 24
  37. local font_face=CAIRO_FONT_WEIGHT_BOLD
  38. local font_slant=CAIRO_FONT_SLANT_NORMAL
  39.  
  40. local line_width=1
  41. local line_cap=CAIRO_LINE_CAP_BUTT
  42. local fill_rule=CAIRO_FILL_RULE_EVEN_ODD
  43.  
  44. local main_text_height = 0
  45.  
  46. --shared elements size
  47. ----------------------------
  48. local main_bar = { 
  49.     width = 6,
  50.     height = 17,
  51.     ang = 0,
  52.     gap = 12
  53. }
  54.  
  55. local main_up_bar = {
  56.     width = 17,
  57.     height = 6,
  58.     ang = 0,
  59.     gap = 21
  60. }
  61.  
  62. local main_chart_bar = {
  63.     width = 6,
  64.     height = 35,
  65.     gap = 9
  66. }
  67.  
  68. local main_corner = {
  69.     width = 40,
  70.     height = 20,
  71.     line = 5,
  72.     gap = 10,
  73.     num = 10
  74. }
  75.  
  76.  
  77. -------------------------------------------------------------------------------
  78. -----------------------cairo image drawing functions---------------------------
  79. -------------------------------------------------------------------------------
  80.  
  81. -------------------------------------------------------------------------------
  82. --                             feather image
  83. -------------------------------------------------------------------------------
  84.  
  85. function draw_feather(coord,scale_factor)
  86.  
  87.     --orinal image size 512x512
  88.     ----------------------------
  89.     scale_factor = scale_factor or {1,1}
  90.  
  91.     cairo_save(cr)
  92.     cairo_translate (cr, coord.x, coord.y) 
  93.     cairo_scale (cr, scale_factor[1], scale_factor[2])
  94.    
  95.     local m1 = cairo_matrix_t:create()
  96.     cairo_matrix_init (m1,18.69,0,0,18.69,-2742,-7251)
  97.     cairo_transform(cr, m1)
  98.    
  99.     cairo_set_line_width (cr, 1)
  100.    
  101.     ----------------------------
  102.     cairo_move_to (cr,152,409.6)
  103.     cairo_rel_curve_to (cr,-4.7,-5.5,4.2,-14.6,10.1,-17.4)
  104.     cairo_rel_curve_to (cr,15.3,-7.3,11.2,1.8,5.9,4.5)
  105.     cairo_rel_curve_to (cr,-4.6,2.3,-6.6,5.3,-8.5,8.2)
  106.     cairo_rel_curve_to (cr,-1.1,1.7,-3.9,2.9,-6.9,2.8)
  107.     cairo_fill (cr)
  108.    
  109.     cairo_move_to (cr,151,408.7)
  110.     cairo_rel_curve_to (cr,-1.3,-0.7,-2,-1.8,-2.7,-2.9)
  111.     cairo_rel_line_to (cr,2,0.6)
  112.     cairo_rel_curve_to (cr,-0.7,-1.1,-1.1,-2.3,-1.4,-3.4)
  113.     cairo_rel_line_to (cr,3.4,2.2)
  114.     cairo_fill (cr)
  115.    
  116.     cairo_move_to (cr,152.8,404.9)
  117.     cairo_rel_curve_to (cr,-1.5,3,-2.5,6.1,-3,9.2)
  118.     cairo_stroke (cr)
  119.  
  120.     ----------------------------   
  121.     cairo_set_source_rgba (cr,rgb_to_r_g_b(back_color,1))
  122.  
  123.     cairo_move_to (cr,170.7,397.4)
  124.     cairo_rel_line_to (cr,-6.5,-0.2)
  125.     cairo_rel_line_to (cr,4.6,1.6)
  126.    
  127.     cairo_move_to (cr,173.4,394.5)
  128.     cairo_rel_line_to (cr,-6.4,1.5)
  129.     cairo_rel_line_to (cr,4.9,0.4)
  130.    
  131.     cairo_move_to (cr,161.6,409.3)
  132.     cairo_rel_line_to (cr,-4.5,-4.8)
  133.     cairo_rel_line_to (cr,2.1,4.4)
  134.  
  135.     cairo_move_to (cr,157.4,411)
  136.     cairo_rel_line_to (cr,-1.5,-6.4)
  137.     cairo_rel_line_to (cr,-0.4,4.9)
  138.    
  139.     cairo_move_to (cr,164.2,390.1)
  140.     cairo_rel_line_to (cr,-4.6,4.8)
  141.     cairo_rel_line_to (cr,2.1,-4.4)
  142.  
  143.     cairo_move_to (cr,157.8,391.9)
  144.     cairo_rel_line_to (cr,-1.6,6.4)
  145.     cairo_rel_line_to (cr,-0.3,-4.8)
  146.    
  147.     cairo_move_to (cr,173.1,389.2)
  148.     cairo_rel_line_to (cr,-6.3,1.9)
  149.     cairo_rel_line_to (cr,4.1,-2.8)
  150.     cairo_fill (cr)
  151.    
  152.     cairo_move_to (cr,150.9,414.1)
  153.     cairo_rel_curve_to (cr,1.7,-10.5,7.2,-17.8,16,-21.3)
  154.     cairo_stroke (cr)
  155.    
  156.     ----------------------------
  157.     cairo_restore(cr)          
  158. end
  159.  
  160. -------------------------------------------------------------------------------
  161. --                              stamp image
  162. -------------------------------------------------------------------------------
  163.  
  164. function draw_stamp(coord, color)
  165.  
  166.     -- stamp size settings
  167.     ----------------------------   
  168.     local base_length = 12
  169.     local w = 8
  170.     local h = 6
  171.        
  172.     -- base length = 12
  173.     ----------------------------   
  174.     local function draw_border(num)
  175.         for i=1,num do
  176.             cairo_rel_line_to (cr,3,0)
  177.             cairo_rel_curve_to (cr,1,3,5,3,6,0)
  178.             cairo_rel_line_to (cr,3,0)
  179.         end
  180.         cairo_rotate (cr, math.pi/2)
  181.     end
  182.  
  183.     cairo_save(cr)
  184.     cairo_set_source_rgba (cr,rgb_to_r_g_b(color,1))
  185.     cairo_translate (cr, coord.x, coord.y)
  186.    
  187.     -- border
  188.     ----------------------------   
  189.     cairo_move_to (cr,0,0) 
  190.     local size = {w,h,w,h}
  191.  
  192.     for i=1,4 do
  193.         draw_border(size[i])
  194.     end        
  195.     cairo_close_path (cr)
  196.    
  197.     local border_width = 8
  198.     cairo_rectangle (cr,border_width,border_width, w*base_length-2*border_width, h*base_length-2*border_width)
  199.  
  200.     -- draw シ
  201.     ----------------------------   
  202.     cairo_move_to (cr,34.74,49.02)
  203.     cairo_rel_curve_to (cr,12.09,-5.76,26.48,-17.17,40.38,-28.91)
  204.     cairo_rel_curve_to (cr,-8.24,16.39,-20.22,25.17,-34.22,32.95)
  205.     cairo_rel_curve_to (cr,-0.96,1.05,-0.76,4.36,-5.2,2.67)
  206.     cairo_rel_curve_to (cr,-4.02,-1.82,-7.25,-9.33,-0.96,-6.71)
  207.     cairo_close_path (cr)
  208.            
  209.     cairo_move_to (cr,25.31,28.86)
  210.     cairo_rel_curve_to (cr,5.24,0.97,12.07,0.57,13.96,4.46)
  211.     cairo_rel_curve_to (cr,0.61,2.82,0.12,4.88,-3.49,4.77)
  212.     cairo_rel_curve_to (cr,-3.18,-4.07,-6.83,-6.65,-10.47,-9.23)
  213.     cairo_close_path (cr)
  214.        
  215.     cairo_move_to (cr,32.62,17.13)
  216.     cairo_rel_curve_to (cr,0.85,-0.56,11.07,5.72,11.5,7.38)
  217.     cairo_rel_curve_to (cr,2.78,-0.29,4.56,-1.44,3.69,-4.88)
  218.     cairo_rel_curve_to (cr,-2.77,-3.76,-8.82,-3.34,-15.19,-2.5)
  219.     cairo_close_path (cr)
  220.                
  221.     cairo_fill (cr)    
  222.                
  223.     ----------------------------   
  224.     cairo_restore(cr)
  225.    
  226.     return {w = w*base_length, h = h*base_length}
  227. end
  228.  
  229. -------------------------------------------------------------------------------
  230. --                            envelope image
  231. -------------------------------------------------------------------------------
  232.  
  233. function draw_envelope(coord, scale_factor, letter)
  234.  
  235.     --orinal image size 100x100
  236.     ----------------------------
  237.     scale_factor = scale_factor or {1,1}
  238.    
  239.     cairo_save(cr)
  240.     cairo_translate (cr, coord.x, coord.y)
  241.     cairo_scale (cr, scale_factor[1], scale_factor[2])
  242.    
  243.     -- envelope
  244.     ----------------------------
  245.     cairo_move_to (cr,30.13,54.64)
  246.     cairo_rel_line_to (cr,23.01,-31.71)
  247.     cairo_rel_line_to (cr,30.42,21.8)
  248.     cairo_rel_line_to (cr,9.78,-7.29)
  249.     cairo_rel_curve_to (cr,1.33,-1.3,1.21,-2.61,0,-3.96)
  250.     cairo_rel_line_to (cr,-42.07,-31.228)
  251.     cairo_rel_curve_to (cr,-0.8,-0.525,-1.48,-0.41,-2.1,-0.016)
  252.     cairo_rel_line_to (cr,-42.951,32.234)
  253.     cairo_rel_curve_to (cr,-0.437,0.75,-0.539,1.48,0,2.14)
  254.     cairo_close_path (cr)
  255.  
  256.     cairo_move_to (cr,71.68,60.2)
  257.     cairo_rel_curve_to (cr,-1.4,1.2,-0.8,2.36,0,3.47)
  258.     cairo_rel_line_to (cr,23.59,28.38)
  259.     cairo_rel_curve_to (cr,2.01,2.3,3.11,1.2,4.11,0)
  260.     cairo_rel_line_to (cr,0,-48.14)
  261.     cairo_rel_curve_to (cr,-1.3,-2.18,-2.4,-1.69,-3.52,-1.09)
  262.     cairo_close_path (cr)
  263.  
  264.     cairo_move_to (cr,28.87,60.2)
  265.     cairo_rel_curve_to (cr,1.42,1.2,0.75,2.36,0,3.47)
  266.     cairo_rel_line_to (cr,-23.604,28.39)
  267.     cairo_rel_curve_to (cr,-2.009,2.28,-3.081,1.21,-4.11,0)
  268.     cairo_rel_line_to (cr,-0.039,-48.15)
  269.     cairo_rel_curve_to (cr,1.334,-2.18,2.453,-1.69,3.563,-1.09)
  270.     cairo_close_path (cr)
  271.  
  272.     cairo_move_to (cr,50.22,77.56)
  273.     cairo_rel_line_to (cr,14.44,-11.03)
  274.     cairo_rel_curve_to (cr,0.86,-0.62,1.71,-0.87,2.81,0)
  275.     cairo_rel_line_to (cr,23.35,28.01)
  276.     cairo_rel_curve_to (cr,0.55,2.75,-0.54,3.2,-2.05,3.55)
  277.     cairo_rel_line_to (cr,-77.63,-0.06)
  278.     cairo_rel_curve_to (cr,-1.451,-0.34,-2.48,-0.9,-1.671,-3.33)
  279.     cairo_rel_line_to (cr,23.271,-28)
  280.     cairo_rel_curve_to (cr,1.06,-0.84,2.12,-0.72,3.18,0)
  281.     cairo_close_path (cr)
  282.    
  283.     cairo_fill (cr)
  284.  
  285.     -- letters
  286.     ----------------------------   
  287.     cairo_rotate (cr, -math.pi/3.25)       
  288.     cairo_set_font_size (cr, 20)
  289.     draw_text_by_right({x = 2, y = 80}, letter)
  290.    
  291.     ----------------------------
  292.     cairo_restore(cr)
  293.    
  294.     return {w = 100*scale_factor[1], h = 100*scale_factor[2]}
  295. end
  296.  
  297.  
  298. -------------------------------------------------------------------------------
  299. ----------------------------support functions----------------------------------
  300. -------------------------------------------------------------------------------
  301.  
  302. -------------------------------------------------------------------------------
  303. --                 converts color in hexa to decimal
  304. -------------------------------------------------------------------------------
  305.  
  306. function rgb_to_r_g_b(colour, alpha)
  307.     return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  308. end
  309.  
  310. -------------------------------------------------------------------------------
  311. --                          make copy of table
  312. -------------------------------------------------------------------------------
  313.  
  314. function table_copy(t)
  315.   local new_t = {}
  316.   for k,v in pairs(t) do new_t[k] = v end
  317.   return new_t
  318. end
  319.  
  320. -------------------------------------------------------------------------------
  321. --              converts conky disk i/o measure to kilobytes
  322. -------------------------------------------------------------------------------
  323.  
  324. function convert_to_k(value)
  325.  
  326.     local res = string.gsub(value, '%a', '')
  327.  
  328.     if string.match(value, "KiB") then
  329.         return res*1000
  330.     elseif string.match(value, "MiB") then
  331.         return res*1000000
  332.     else
  333.         return 0
  334.     end
  335.        
  336. end
  337.  
  338. -------------------------------------------------------------------------------
  339. --                split text and digits in conky measure
  340. -------------------------------------------------------------------------------
  341.  
  342. function split_text(value)
  343.     return string.match(value, "[%d%.]+"), string.match(value, "%a+")
  344. end
  345.  
  346. -------------------------------------------------------------------------------
  347. --                        get CLI command output
  348. -------------------------------------------------------------------------------
  349.  
  350. function read_CLI(command)
  351.     local file = io.popen(command)
  352.     local output = file:read("*a")
  353.     file:close()
  354.     return output
  355. end
  356.  
  357. -------------------------------------------------------------------------------
  358. --                          cut text length
  359. -------------------------------------------------------------------------------
  360.  
  361. function cut_text(text, width)
  362.  
  363.         cairo_text_extents(cr, "...", extents)
  364.         local dot_length = extents.width
  365.        
  366.         cairo_text_extents(cr, text, extents)
  367.  
  368.         if extents.width > width then
  369.             while extents.width + dot_length > width do
  370.                 text = string.sub(text, 1, #text-1)
  371.                 cairo_text_extents(cr, text, extents)
  372.             end
  373.             return text.."..."
  374.         else
  375.             return text
  376.         end
  377. end
  378.  
  379. -------------------------------------------------------------------------------
  380. --                         draw text aligned by center
  381. -------------------------------------------------------------------------------
  382.  
  383. function draw_text_by_center(coord, text)
  384.  
  385.     cairo_text_extents(cr, text, extents)
  386.     cairo_move_to (cr, coord.x - (extents.width/2 + extents.x_bearing), coord.y - (extents.height/2 + extents.y_bearing))
  387.     cairo_show_text (cr, text)     
  388. end
  389.  
  390. -------------------------------------------------------------------------------
  391. --                         draw text aligned by right
  392. -------------------------------------------------------------------------------
  393.  
  394. function draw_text_by_right(coord, text)
  395.  
  396.     cairo_text_extents(cr, text, extents)
  397.     cairo_move_to (cr, coord.x-(extents.width + extents.x_bearing),coord.y)
  398.     cairo_show_text (cr, text)     
  399. end
  400.  
  401. -------------------------------------------------------------------------------
  402. --                       draw text aligned by width
  403. -------------------------------------------------------------------------------
  404.  
  405. function draw_text_by_wide(coord, width, text)
  406.  
  407.     cairo_text_extents(cr, text, extents)  
  408.     local text_gap = (width - extents.width-extents.x_bearing)/(#text - 1)
  409.     local gap = 0
  410.  
  411.     for i=1,#text do
  412.         c = string.sub(text, i, i)
  413.         cairo_move_to (cr,coord.x + gap, coord.y)
  414.         cairo_show_text (cr, c)
  415.        
  416.         cairo_text_extents(cr, c, extents)
  417.         gap = gap + text_gap + extents.width + extents.x_bearing
  418.         -- !!! WALKAROUND for space character width only for font size=24 !!!
  419.         if c == " " then
  420.             gap = gap + 6
  421.         end
  422.     end
  423. end
  424.  
  425. -------------------------------------------------------------------------------
  426. --                     draw two labels aligned by wide
  427. -------------------------------------------------------------------------------
  428.  
  429. function draw_double_text(coord, width, text1, text2, second_color)
  430.  
  431.     cairo_text_extents(cr, text2, extents)
  432.     cairo_move_to (cr, coord.x, coord.y)
  433.     cairo_show_text (cr, text1)
  434.     if second_color ~=nil then
  435.         cairo_set_source_rgba (cr, rgb_to_r_g_b(second_color,1))
  436.     end
  437.     cairo_move_to (cr, coord.x + width-extents.width - extents.x_bearing, coord.y)
  438.     cairo_show_text (cr, text2)
  439. end
  440.  
  441. -------------------------------------------------------------------------------
  442. --                  draw progress bar with dash style
  443. -------------------------------------------------------------------------------
  444.  
  445. function draw_dash_bar(coord, bar, progress, width)
  446.  
  447.     local add_w = bar.height*math.atan(bar.ang)
  448.     local num = math.floor((width - bar.width - add_w)/(bar.gap)) + 1
  449.     local gap = (width - bar.width - add_w)/(num - 1)
  450.     local color_point = math.ceil(progress*num)
  451.    
  452.     local strt = {0, color_point}
  453.     local fin = {color_point-1, num - 1}
  454.     local color = {main_color, gray_color}
  455.    
  456.     for k=1,2 do
  457.         cairo_set_source_rgba (cr,rgb_to_r_g_b(color[k],1))
  458.    
  459.         for i=strt[k], fin[k] do
  460.             cairo_move_to (cr,coord.x+i*gap,coord.y+bar.height)
  461.             cairo_rel_line_to(cr, add_w, -bar.height)
  462.             cairo_rel_line_to(cr, bar.width, 0)
  463.             cairo_rel_line_to(cr, -add_w, bar.height)
  464.             cairo_close_path (cr)
  465.         end
  466.         cairo_fill (cr)
  467.     end
  468. end
  469.  
  470. -------------------------------------------------------------------------------
  471. --                   vertical corners style indicator
  472. -------------------------------------------------------------------------------
  473.  
  474. local function draw_corner_graph(coord, corner, progress)
  475.    
  476.     local color_point = math.ceil(progress*corner.num)
  477.     local start = {0, color_point}
  478.     local fin = {color_point - 1,corner.num - 1}
  479.     local color = {main_color, gray_color}
  480.  
  481.     for k=1,2 do
  482.  
  483.         cairo_set_source_rgba (cr,rgb_to_r_g_b(color[k],1))
  484.         for i=start[k], fin[k] do
  485.             cairo_move_to (cr,coord.x,coord.y - i*corner.gap)
  486.             cairo_rel_line_to (cr, corner.width/2, -corner.height)
  487.             cairo_rel_line_to (cr, corner.width/2, corner.height)
  488.             cairo_rel_line_to (cr, -corner.line, 0)
  489.             cairo_rel_line_to (cr, -corner.width/2+corner.line, -corner.height + corner.line)
  490.             cairo_rel_line_to (cr, -corner.width/2+corner.line, corner.height - corner.line)
  491.             cairo_close_path (cr)
  492.         end
  493.         cairo_fill (cr)
  494.     end
  495. end
  496.  
  497. -------------------------------------------------------------------------------
  498. --                       initializate new graph chart
  499. -------------------------------------------------------------------------------
  500.  
  501. function new_graph(history_size)
  502.  
  503.     -- initializate new table for chart
  504.     ----------------------------
  505.     local history_table = {}
  506.     for i=0, history_size-1 do history_table[i] = 0 end
  507.    
  508.     -- calculate chart table and draw full chart info
  509.     ----------------------------
  510.     return function (coord, chart, value, maxm, text)
  511.    
  512.         local history_size = #history_table + 1
  513.         local zero_height = 4
  514.         local chart_maxm = maxm
  515.  
  516.         -- insert current value in table
  517.         ----------------------------
  518.         local cc = updates % history_size
  519.         history_table[cc] = value
  520.  
  521.         --find maximum in table if it's need
  522.         ----------------------------
  523.         if chart.scale then
  524.             --minimum value to scale
  525.             chart_maxm = 40
  526.             for i,v in ipairs(history_table) do
  527.                 if v > chart_maxm then chart_maxm = v end
  528.             end
  529.         end
  530.        
  531.         -- draw chart
  532.         ----------------------------
  533.         for i=1, history_size do
  534.             local c_bar_h = (chart.bar.height-zero_height) * history_table[(cc+i) % history_size] / chart_maxm
  535.             cairo_move_to (cr,coord.x + chart.bar.width/2 + (i-1)*chart.bar.gap, coord.y)
  536.             cairo_rel_line_to(cr, 0, -zero_height)
  537.             cairo_rel_line_to(cr, 0, -c_bar_h)
  538.         end
  539.        
  540.         cairo_set_line_width (cr, chart.bar.width)
  541.         cairo_stroke (cr)
  542.        
  543.         --draw bar
  544.         ----------------------------
  545.         local prog_bar_coord = {
  546.             x = coord.x,
  547.             y = coord.y - chart.bar.height - chart.sign_gap - chart.up_bar.height
  548.         }
  549.         local prog_bar_width = (history_size-1)*chart.bar.gap + chart.bar.width
  550.         local prog = value/maxm
  551.        
  552.         draw_dash_bar(prog_bar_coord, chart.up_bar, prog, prog_bar_width)
  553.        
  554.         --draw sign    
  555.         ----------------------------
  556.         cairo_set_source_rgba (cr,rgb_to_r_g_b(gray_color,1))
  557.        
  558.         local sign_coord = {
  559.             x = coord.x-chart.bar.width/2,
  560.             y = prog_bar_coord.y-chart.sign_gap
  561.         }
  562.         draw_double_text(sign_coord, prog_bar_width, text.left, text.right)
  563.     end
  564. end
  565.  
  566.  
  567. -------------------------------------------------------------------------------
  568. ----------------------------main elements functions----------------------------
  569. -------------------------------------------------------------------------------
  570.  
  571. -------------------------------------------------------------------------------
  572. --               draw date and system updates available
  573. -------------------------------------------------------------------------------
  574.  
  575. function draw_date(coord)
  576.  
  577.     -- get date
  578.     ----------------------------
  579.     local day = os.date("%d")
  580.     local month = string.upper(os.date("%B"))
  581.     local weekday = tonumber(os.date("%u"))
  582.     local year = os.date("%Y")
  583.  
  584.     -- element settings
  585.     ----------------------------
  586.     local total_width = colomn_width - 10
  587.     local graph_gap = 30
  588.     local line_gap = 10
  589.     local day_gap_table = {8,15,6,8}
  590.     local day_gap = day_gap_table[math.floor(day/10) + 1]
  591.    
  592.     -- image settings
  593.     ----------------------------
  594.     local image_size = {512,512}
  595.     local scale_factor = {0.08,0.11}
  596.  
  597.     -- day
  598.     ----------------------------
  599.     cairo_set_source_rgba (cr,rgb_to_r_g_b(gray_color,1))
  600.  
  601.     cairo_set_font_size (cr, 126)  
  602.     cairo_text_extents(cr, day, extents)
  603.     local day_height = extents.height
  604.     local day_width = extents.width + 2
  605.  
  606.     cairo_move_to (cr, coord.x - day_gap, coord.y + day_height)
  607.     cairo_show_text (cr, day)
  608.    
  609.     -- month and year sign
  610.     ----------------------------
  611.     local graph_width = total_width - day_width - graph_gap
  612.     cairo_set_font_size (cr, main_font_size)
  613.    
  614.     local month_coord = {
  615.         x = coord.x + total_width - graph_width,
  616.         y = coord.y + main_text_height
  617.     }
  618.     draw_double_text(month_coord, graph_width, month,year)
  619.    
  620.     -- system updates  
  621.     ----------------------------
  622.     local sign_coord = {
  623.         x = coord.x,
  624.         y = month_coord.y + day_height + line_gap+main_text_height
  625.     }
  626.    
  627.     -- check updates with interval
  628.     ----------------------------
  629.     if updates % 150 == 0 or updates == 1 then
  630.         -- global var
  631.         sys_upd = string.match(string.match(read_CLI("apt-get --just-print upgrade"), "%d+%supgraded"), "%d+")
  632.     end
  633.     draw_double_text(sign_coord, day_width, sys_upd, "UPDATES")
  634.    
  635.     sign_coord.x = month_coord.x
  636.     draw_double_text(sign_coord, graph_width, "RARING","RINGTAIL") 
  637.    
  638.     -- weekday indikator
  639.     ----------------------------
  640.     local image_width = image_size[1]*scale_factor[1]
  641.     local image_gap = (graph_width - image_width)/6
  642.     local graph_gap_v = day_height - image_size[2]*scale_factor[2] + 3
  643.    
  644.     for i=0, 6 do
  645.         local color = i+1 == weekday and main_color or gray_color
  646.         cairo_set_source_rgba (cr,rgb_to_r_g_b(color, 1))
  647.        
  648.         local image_coord = {
  649.             x = month_coord.x + i*image_gap - 3,
  650.             y = coord.y + graph_gap_v
  651.         }
  652.         draw_feather (image_coord, scale_factor)
  653.     end
  654.    
  655.     -- full height
  656.     ----------------------------
  657.     return line_gap + day_height + 2*main_text_height
  658.    
  659. end
  660.  
  661. -------------------------------------------------------------------------------
  662. --                     draw cpu ram swap indicators
  663. -------------------------------------------------------------------------------
  664.  
  665. function draw_cpu(coord)
  666.  
  667.     -- element settings
  668.     ----------------------------
  669.     local total_width = colomn_width - 10
  670.     local first_line_gap = 25
  671.     local line_gap = 40
  672.     ----------------------------
  673.     local bar = table_copy(main_bar)
  674.  
  675.     -- monitor settings
  676.     ----------------------------
  677.     local perc_command = {"${memperc}","${swapperc}"}  
  678.     local command = {"${mem}","${swap}"}   
  679.    
  680.     -- cpu graph settings
  681.     ----------------------------
  682.     local corner = table_copy(main_corner)
  683.     local graph_height = (corner.num-1)*corner.gap+corner.height
  684.     local graph_place_gap = (total_width-corner.width)/7
  685.    
  686.     -- sign and full bar size
  687.     ----------------------------
  688.     local sign_width = corner.width + graph_place_gap
  689.     local bar_graph_width = total_width - 2*graph_place_gap
  690.  
  691.     -- start level will show while several first conky updates
  692.     ----------------------------
  693.     local prog = 0
  694.  
  695.     --cpu indicators
  696.     ----------------------------
  697.     for i=1,8 do
  698.         local cpu_us = tonumber(conky_parse("${cpu cpu"..i.."}"))
  699.         if cpu_us ~= nil then prog = cpu_us/100 end
  700.        
  701.         graph_coord = {
  702.             x = coord.x + (i-1)*graph_place_gap,
  703.             y = coord.y + graph_height
  704.         }
  705.         draw_corner_graph(graph_coord, corner, prog)   
  706.     end
  707.    
  708.     -- ram and swap indicator
  709.     ----------------------------   
  710.     for i=1,2 do
  711.         local mem_perc = tonumber(conky_parse(perc_command[i]))
  712.         local mem = string.gsub(conky_parse(command[i]), " ", "")
  713.        
  714.         if mem == "0B" or mem == nil then
  715.             mem = "0.00MiB"
  716.             prog = 0
  717.         else
  718.             prog = mem_perc/100
  719.         end
  720.        
  721.         local bar_coord = {
  722.             x = coord.x,
  723.             y = coord.y + graph_height + first_line_gap + (i-1)*line_gap
  724.         }
  725.         draw_dash_bar(bar_coord, bar, prog, bar_graph_width)
  726.        
  727.         local sign_coord = {
  728.             x = coord.x + total_width-sign_width,
  729.             y = bar_coord.y + bar.height
  730.         }
  731.         draw_double_text(sign_coord, sign_width, split_text(mem))
  732.     end
  733.  
  734.     -- full height
  735.     ----------------------------
  736.     return graph_height+first_line_gap+line_gap+main_text_height
  737.  
  738. end
  739.  
  740. -------------------------------------------------------------------------------
  741. --                                draw disk usage
  742. -------------------------------------------------------------------------------
  743.  
  744. function draw_disk(coord)
  745.  
  746.     -- element settings
  747.     local total_width = colomn_width - 10
  748.     local sign_width = 75
  749.     local bar_graph_width = colomn_width - sign_width - 30
  750.     local line_gap = 40
  751.     ----------------------------
  752.     local bar = table_copy(main_bar)
  753.        
  754.     --disks settings
  755.     ----------------------------
  756.     local disks = {"/", "/home", "/opt", "/mnt/media"}
  757.     local labels = {"ROOT", "HOME", "OPT", "MEDIA"}
  758.    
  759.     --disks indicators
  760.     ----------------------------
  761.     local bar_coord = {
  762.         x = coord.x + total_width - bar_graph_width,
  763.         y = coord.y
  764.     }
  765.    
  766.     for i=1,4 do
  767.    
  768.         -- get disks usage
  769.         ----------------------------
  770.         local disk_us_perc = tonumber(conky_parse("${fs_used_perc "..disks[i].."}"))
  771.         local prog = disk_us_perc/100
  772.        
  773.         -- draw disk usage chart
  774.         ----------------------------
  775.         draw_dash_bar(bar_coord, bar, prog, bar_graph_width)
  776.        
  777.         cairo_move_to (cr, coord.x, bar_coord.y+bar.height)
  778.         cairo_show_text (cr, labels[i])
  779.         --draw_text_by_wide({x=coord.x,y=bar_coord.y+bar.height}, sign_width, labels[i])
  780.        
  781.         bar_coord.y = bar_coord.y + line_gap
  782.     end
  783.  
  784.     -- full height
  785.     ----------------------------
  786.     return 3*line_gap + main_text_height
  787.  
  788. end
  789.  
  790. -------------------------------------------------------------------------------
  791. --                 draw history chart for disk activity
  792. -------------------------------------------------------------------------------
  793.  
  794. function draw_disk_charts(coord)
  795.  
  796.     -- element settings
  797.     ----------------------------
  798.     local total_width = colomn_width - 10
  799.     local chart = {
  800.         bar = table_copy(main_chart_bar),
  801.         up_bar = table_copy(main_up_bar),
  802.         scale = true,
  803.         sign_gap = 8
  804.     }
  805.     ----------------------------
  806.     local between_charts_gap = 15
  807.     local between_charts_gap_vert = 20
  808.     local chart_height = chart.bar.height+chart.sign_gap*2+chart.up_bar.height+main_text_height
  809.     local val = 0
  810.  
  811.     -- width tettings
  812.     ----------------------------
  813.     chart.width = (total_width - between_charts_gap_vert)/2
  814.     local chart_size = math.floor((chart.width - 2*chart.bar.width)/(chart.bar.gap))+1
  815.     chart.bar.gap = (chart.width-2*chart.bar.width)/(chart_size-1)
  816.  
  817.     ----------------------------   
  818.     local command = {}
  819.     local label = {}
  820.     local maxm = {}
  821.  
  822.     --ssd chart settings
  823.     ----------------------------
  824.     command[1] = {"${diskio_read /dev/sdb}","${diskio_write /dev/sdb}"}
  825.     label[1] = "SSD"
  826.     maxm[1] = {400000000,400000000}
  827.    
  828.     --hdd chart settings
  829.     ----------------------------
  830.     command[2] = {"${diskio_read /dev/sdc}","${diskio_write /dev/sdc}"}
  831.     label[2] = "HDD"
  832.     maxm[2] = {125000000,125000000}
  833.  
  834.     --initializate standalone function for each chart
  835.     ----------------------------   
  836.     if updates == 1 then
  837.         disk_graph = {}
  838.         for i=1, 4 do disk_graph[i] = new_graph(chart_size) end
  839.     end
  840.  
  841.     -- draw charts and signs
  842.     ----------------------------   
  843.     for i=1, 2 do
  844.         for j=1, 2 do
  845.  
  846.             --get current value
  847.             ----------------------------
  848.             local value = conky_parse(command[i][j])
  849.             local val = tonumber(convert_to_k(value))
  850.             if val > maxm[i][j] then val = maxm[i][j] end
  851.            
  852.             -- draw chart
  853.             ----------------------------
  854.             cairo_set_source_rgba (cr,rgb_to_r_g_b(gray_color,1))
  855.            
  856.             local chart_coord = {
  857.                 x = coord.x + (i-1)*(chart.width + between_charts_gap_vert),
  858.                 y = coord.y + j*chart_height + between_charts_gap*(j-1)
  859.             }
  860.             local chart_text = {
  861.                 left = label[i],
  862.                 right = string.gsub(value, " ", "")
  863.             }
  864.            
  865.             disk_graph[j+2*(i-1)](chart_coord, chart, val, maxm[i][j], chart_text)
  866.         end
  867.     end
  868.    
  869.     -- full height
  870.     ----------------------------
  871.     return 2*chart_height + between_charts_gap
  872.    
  873. end
  874.  
  875. -------------------------------------------------------------------------------
  876. --              draw history chart for network activity
  877. -------------------------------------------------------------------------------
  878.  
  879. function draw_net_charts(coord)
  880.  
  881.     -- element settings
  882.     ----------------------------
  883.     local total_width = colomn_width - 10
  884.     local chart = {
  885.         bar = table_copy(main_chart_bar),
  886.         up_bar = table_copy(main_up_bar),
  887.         scale = false,
  888.         sign_gap = 8
  889.     }
  890.     ----------------------------
  891.     local between_charts_gap = 15
  892.     local chart_height = chart.bar.height+chart.sign_gap*2+chart.up_bar.height+main_text_height
  893.     local val = 0
  894.  
  895.     --net chart settings
  896.     ----------------------------
  897.     local command = {"${upspeedf wlan0}","${upspeed wlan0}","${downspeedf wlan0}","${downspeed wlan0}"}
  898.     local label = "NET"
  899.     local maxm = {80,650}
  900.    
  901.     -- image settings
  902.     ----------------------------
  903.     local scale_factor = {0.85,0.75}
  904.     local letter = {"UP","DN"}
  905.  
  906.     --draw image
  907.     ----------------------------
  908.     cairo_set_source_rgba (cr,rgb_to_r_g_b(gray_color,1))
  909.     local total_height = chart_height*2+between_charts_gap
  910.     local image_coord = {
  911.         x = coord.x - 5,
  912.         y = coord.y
  913.     }
  914.     local image_size = draw_envelope(image_coord, scale_factor, letter[1])
  915.     image_coord.y = coord.y + total_height - image_size.h + 2
  916.     draw_envelope(image_coord, scale_factor, letter[2])
  917.  
  918.     -- width tettings
  919.     ----------------------------
  920.     chart.width = total_width - image_size.w - 20
  921.     local chart_size = math.floor((chart.width - 2*chart.bar.width)/(chart.bar.gap)) + 1
  922.     chart.bar.gap = (chart.width - 2*chart.bar.width)/(chart_size - 1)
  923.  
  924.     --initializate standalone function for each chart
  925.     ----------------------------   
  926.     if updates == 1 then
  927.         net_graph = {}
  928.         for i=1, 2 do net_graph[i] = new_graph(chart_size) end
  929.     end
  930.  
  931.     -- draw charts and signs
  932.     ----------------------------   
  933.     for j=1, 2 do
  934.    
  935.         --get current value
  936.         ----------------------------
  937.         val = tonumber(conky_parse(command[2*j-1]))    
  938.         if val > maxm[j] then val = maxm[j] end
  939.        
  940.         -- draw chart
  941.         ----------------------------
  942.         local chart_coord = {
  943.             x = coord.x + total_width - chart.width,
  944.             y = coord.y + chart_height*j + between_charts_gap*(j-1)
  945.         }
  946.         local chart_text = {
  947.             left = label,
  948.             right = string.gsub(conky_parse(command[j*2]), " ","")
  949.         }
  950.        
  951.         net_graph[j](chart_coord, chart, val, maxm[j], chart_text)
  952.     end
  953.  
  954.     -- full height
  955.     ----------------------------
  956.     return total_height
  957.    
  958. end
  959.  
  960. -------------------------------------------------------------------------------
  961. --                            draw torrents graph
  962. -------------------------------------------------------------------------------
  963.  
  964. function draw_torrent(coord)
  965.  
  966.     -- !!! Transmission should have at least one torrent !!!
  967.     -- I'm too lazy to make proper exception for blank torrent list
  968.  
  969.     -- element settings
  970.     ----------------------------
  971.     local line_gap = 40
  972.     local first_line_gap = 25
  973.     local total_width = colomn_width - 10
  974.     local label_width = 70
  975.     ----------------------------
  976.     local bar = table_copy(main_bar)
  977.    
  978.     -- progress indicator settings
  979.     ----------------------------
  980.     local corner = table_copy(main_corner)
  981.     local graph_num = 8
  982.     local graph_place_gap = (total_width-corner.width)/(graph_num-1)
  983.     local graph_height = (corner.num-1)*corner.gap+corner.height
  984.  
  985.     -- sign and full bar size
  986.     ----------------------------
  987.     local sign_width = corner.width + graph_place_gap
  988.     local bar_graph_width = total_width - 2*graph_place_gap
  989.    
  990.     -- speed limits in kilobyte
  991.     ----------------------------
  992.     local download_max = 600
  993.     local upload_max = 55
  994.  
  995.     -- check if transmission started
  996.     ----------------------------
  997.     if read_CLI("pidof -x transmission-gtk") ~= "" then
  998.    
  999.         -- get torrents list
  1000.         ----------------------------
  1001.         local output = read_CLI("transmission-remote -l")
  1002.         local status_pos = string.find(output, "Status")
  1003.         output = string.gsub(output,"Up & Down","Downloading")
  1004.  
  1005.         local torrent_list = {}
  1006.         local last_line = ""
  1007.         local seed_num = 0
  1008.         local dnld_num = 0
  1009.        
  1010.         for line in string.gmatch(output, "[^\n]+") do
  1011.            
  1012.             last_line = line
  1013.             torrent_list[#torrent_list + 1] =  {
  1014.                 prog = string.match(line, "%d+%%"),
  1015.                 status = string.match(string.sub(line, status_pos), "%a+")
  1016.             }
  1017.            
  1018.             if torrent_list[#torrent_list].status == "Seeding" then
  1019.                 seed_num = seed_num + 1
  1020.             elseif torrent_list[#torrent_list].status == "Downloading" then
  1021.                 dnld_num = dnld_num + 1
  1022.             end
  1023.         end
  1024.  
  1025.         --get total speed value from last line
  1026.         ----------------------------
  1027.         local sum = {}
  1028.         for pat in string.gmatch(last_line,"[%d+%.]+") do
  1029.             sum[#sum + 1] = pat
  1030.         end
  1031.        
  1032.         --sort torrent
  1033.         ----------------------------
  1034.         local function sort_torrent(a,b)
  1035.             return a.status == "Downloading" and b.status ~= "Downloading" or a.status =="Stopped" and b.status ~= "Stopped" and b.status ~= "Downloading"
  1036.         end
  1037.        
  1038.         table.remove(torrent_list, 1)
  1039.         table.remove(torrent_list, #torrent_list)
  1040.         table.sort(torrent_list, sort_torrent)
  1041.  
  1042.         --check torrent num
  1043.         ----------------------------
  1044.         if graph_num > #torrent_list then graph_num = #torrent_list end
  1045.        
  1046.         --draw torrents progress indicators
  1047.         ----------------------------
  1048.         cairo_set_source_rgba (cr,rgb_to_r_g_b(gray_color,1))
  1049.        
  1050.         for i=1, graph_num do
  1051.             local val = string.match(torrent_list[i].prog,"%d+")
  1052.             local prog = val/100
  1053.             local graph_coord = {
  1054.                 x = coord.x + (i-1)*graph_place_gap,
  1055.                 y = coord.y + graph_height
  1056.             }
  1057.             draw_corner_graph(graph_coord, corner, prog)
  1058.         end
  1059.            
  1060.         --draw active torrents num and speed   
  1061.         ----------------------------
  1062.         local bar_prog = {
  1063.             sum[2]/upload_max,
  1064.             sum[3]/download_max
  1065.         }
  1066.         local label = {"SEED", "DNLD"}
  1067.         local nums = {seed_num, dnld_num}
  1068.        
  1069.         for i=1, 2 do
  1070.        
  1071.             --torrent speed bar
  1072.             ----------------------------
  1073.             if bar_prog[i] > 1 then bar_prog[i] = 1 end
  1074.                
  1075.             local bar_coord = {
  1076.                 x = coord.x,
  1077.                 y = coord.y+graph_height+first_line_gap+(i-1)*line_gap
  1078.             }
  1079.             draw_dash_bar(bar_coord, bar, bar_prog[i], bar_graph_width)
  1080.        
  1081.             --labels
  1082.             ----------------------------
  1083.             local sign_coord = {
  1084.                 x = coord.x + total_width - sign_width,
  1085.                 y = bar_coord.y+bar.height
  1086.             }
  1087.             draw_text_by_wide(sign_coord, label_width, label[i])
  1088.  
  1089.             -- active torrent num
  1090.             ----------------------------
  1091.             sign_coord = {
  1092.                 x = coord.x+total_width,
  1093.                 y = bar_coord.y+bar.height
  1094.             }
  1095.             draw_text_by_right(sign_coord, nums[i])
  1096.         end
  1097.        
  1098.     else
  1099.         --draw message if transmission not running 
  1100.         ----------------------------
  1101.         cairo_set_source_rgba (cr, rgb_to_r_g_b(main_color,1)) 
  1102.         cairo_set_font_size (cr, 32)
  1103.        
  1104.         local label_coord = {
  1105.             x = coord.x + (total_width)/2,
  1106.             y = coord.y + graph_height/2
  1107.         }
  1108.         draw_text_by_center(label_coord, "TRANSMISSION")
  1109.         label_coord.y = label_coord.y + (first_line_gap + line_gap + main_text_height + graph_height)/2
  1110.         draw_text_by_center(label_coord, "IS NOT RUNNING")
  1111.        
  1112.         cairo_set_font_size (cr, main_font_size)
  1113.     end
  1114.  
  1115.     -- full height
  1116.     ----------------------------
  1117.     return graph_height+first_line_gap+line_gap+main_text_height
  1118.  
  1119. end
  1120.  
  1121. -------------------------------------------------------------------------------
  1122. --                          draw temperature graph
  1123. -------------------------------------------------------------------------------
  1124.  
  1125. function draw_temp(coord)
  1126.    
  1127.     -- element settings
  1128.     ----------------------------
  1129.     local total_width = colomn_width - 10
  1130.     local label_width = 55
  1131.     local bar = table_copy(main_bar)
  1132.     local line_gap = 40
  1133.     local bar_gap = 75
  1134.     local bar_graph_width = total_width - bar_gap - 60
  1135.        
  1136.     --temperature settings 
  1137.     ----------------------------
  1138.     local labels = {"CPU","HDD","GPU"}
  1139.     local temp_text = {"","","-- - "}
  1140.     local temp = {0,0,0}
  1141.     local k = {100,60,100}
  1142.     local alert_temp = {75,42,80}
  1143.  
  1144.     -- get cpu temperature
  1145.     ----------------------------
  1146.     temp[1] = tonumber(conky_parse("${acpitemp}"))
  1147.  
  1148.     --get hdd temperature
  1149.     ----------------------------
  1150.     temp[2] = tonumber(read_CLI("user-hddtemp /dev/sdc | cut -c35-36"))
  1151.  
  1152.     -- get nvidia card temperature if it's acrive
  1153.     ----------------------------
  1154.     local nvidia_on = string.find(read_CLI("cat /proc/acpi/bbswitch"), "ON")
  1155.     if nvidia_on ~= nil then
  1156.         temp[3] = tonumber(read_CLI("optirun nvidia-settings -c :8 -q gpucoretemp -t"))
  1157.     end
  1158.  
  1159.     -- draw temperature graph
  1160.     ----------------------------
  1161.     local bar_coord = {
  1162.         x = coord.x + bar_gap,
  1163.         y = coord.y
  1164.     }
  1165.  
  1166.     for i=1,3 do
  1167.         -- temperature bar
  1168.         ----------------------------
  1169.         local prog = temp[i]/k[i]  
  1170.         draw_dash_bar(bar_coord, bar, prog, bar_graph_width)
  1171.        
  1172.         -- temperature labels
  1173.         ----------------------------
  1174.         local label_coord = {
  1175.             x = coord.x,
  1176.             y = bar_coord.y+bar.height
  1177.         }
  1178.         draw_text_by_wide(label_coord, label_width, labels[i])
  1179.        
  1180.         -- temperature value
  1181.         ----------------------------
  1182.         if temp[i] ~= 0 then temp_text[i] = temp[i].."°" end
  1183.         local temp_color = temp[i] > alert_temp[i] and main_color or gray_color
  1184.         local value_coord = {
  1185.             x = coord.x + total_width,
  1186.             y = bar_coord.y + bar.height
  1187.         }
  1188.        
  1189.         cairo_set_source_rgba (cr,rgb_to_r_g_b(temp_color,1))      
  1190.         draw_text_by_right(value_coord, temp_text[i])
  1191.  
  1192.         ----------------------------
  1193.         bar_coord.y = bar_coord.y+line_gap
  1194.     end
  1195.  
  1196.     -- full height
  1197.     ----------------------------
  1198.     return 2*line_gap+main_text_height
  1199. end
  1200.  
  1201. -------------------------------------------------------------------------------
  1202. --                          draw top process
  1203. -------------------------------------------------------------------------------
  1204.  
  1205. function draw_top(coord)
  1206.    
  1207.     -- element settings
  1208.     ----------------------------
  1209.     local line_gap = 35
  1210.     local line_num = 5
  1211.     local upd_per_top = 4
  1212.  
  1213.     -- top settings
  1214.     ----------------------------
  1215.     local command = {
  1216.         {"${top name ", "${top cpu "};
  1217.         {"${top_mem name ", "${top_mem mem "}
  1218.     }
  1219.     local alert_perc = {15,20}
  1220.  
  1221.     -- image settings
  1222.     ----------------------------
  1223.     local image_colors = {gray_color, main_color}  
  1224.  
  1225.     -- switch between cpu and ram top
  1226.     ----------------------------
  1227.     local k = math.floor((updates % (2*upd_per_top)) / upd_per_top) + 1
  1228.  
  1229.     -- image
  1230.     ----------------------------
  1231.     local total_height = (line_num - 1)*line_gap + main_text_height
  1232.    
  1233.     local image_coord = {
  1234.         x = coord.x,
  1235.         y = coord.y
  1236.     }
  1237.     local image_size = draw_stamp(image_coord, image_colors[k % 2 + 1])
  1238.    
  1239.     image_coord.y = image_coord.y+total_height-image_size.h
  1240.     draw_stamp(image_coord, image_colors[(k+1) % 2 + 1])   
  1241.  
  1242.     -- width settings
  1243.     ----------------------------
  1244.     local total_width = colomn_width - 10
  1245.     local image_gap = image_size.w + 25
  1246.     local line_width = total_width - image_gap
  1247.     local name_width = line_width - 80 
  1248.  
  1249.     -- top process 
  1250.     ----------------------------
  1251.     for i = 1, line_num do
  1252.    
  1253.         -- get top info
  1254.         ----------------------------
  1255.         local proc_name = string.upper(conky_parse(command[k][1]..i.."}"))
  1256.         local proc_perc = conky_parse(command[k][2]..i.."}")
  1257.        
  1258.         -- print info
  1259.         ----------------------------
  1260.         proc_name = cut_text(proc_name,name_width)
  1261.        
  1262.         if updates > 5 then
  1263.             local text_color = tonumber(proc_perc) >= alert_perc[k] and main_color or gray_color         
  1264.             cairo_set_source_rgba (cr,rgb_to_r_g_b(text_color,1))
  1265.            
  1266.             local line_coord = {
  1267.                 x = coord.x + image_gap,
  1268.                 y = coord.y + (i-1)*line_gap+main_text_height
  1269.             }
  1270.             draw_double_text(line_coord, line_width, proc_name, proc_perc)
  1271.         end
  1272.     end
  1273.  
  1274.     -- full height
  1275.     ----------------------------
  1276.     return total_height
  1277.  
  1278. end
  1279.  
  1280. -------------------------------------------------------------------------------
  1281. ---------------------------------main script-----------------------------------
  1282. -------------------------------------------------------------------------------
  1283.  
  1284. function conky_main()
  1285.    
  1286.     ----------------------------
  1287.     -- initialization cairo
  1288.     ----------------------------
  1289.     if conky_window == nil then return end
  1290.     local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  1291.     cr = cairo_create(cs)
  1292.    
  1293.     -- some cairo settings
  1294.     ----------------------------   
  1295.     cairo_set_font_size (cr, main_font_size)
  1296.     cairo_select_font_face (cr, font, font_slant, font_face)
  1297.    
  1298.     cairo_text_extents(cr, "TEXT", extents)
  1299.     main_text_height = extents.height
  1300.     main_bar.height = extents.height
  1301.    
  1302.     cairo_set_line_width (cr, line_width)
  1303.     cairo_set_line_cap (cr, line_cap)
  1304.     cairo_set_fill_rule (cr, fill_rule)
  1305.  
  1306.     ----------------------------
  1307.     --main elements
  1308.     ----------------------------
  1309.    
  1310.     --update counter
  1311.     ----------------------------
  1312.     updates = tonumber(conky_parse('${updates}'))
  1313.  
  1314.     -- element settings
  1315.     ----------------------------
  1316.     local el_height = 0
  1317.     --local el_height_sum = {0,0}
  1318.     local draw_element = {}
  1319.     local el_coord = {
  1320.         x = pcmt.border_gap+5,
  1321.         y = pcmt.border_gap
  1322.     }
  1323.    
  1324.     -- element placement in two colomns
  1325.     ----------------------------
  1326.     local strt = {1, 5}
  1327.     local fin = {4, 8}
  1328.    
  1329.     draw_element[1] = draw_date
  1330.     draw_element[2] = draw_cpu
  1331.     draw_element[3] = draw_top
  1332.     draw_element[4] = draw_disk
  1333.     draw_element[5] = draw_torrent
  1334.     draw_element[6] = draw_net_charts
  1335.     draw_element[7] = draw_temp
  1336.     draw_element[8] = draw_disk_charts
  1337.  
  1338.     -- draw elements
  1339.     ----------------------------
  1340.     for k = 1,2 do
  1341.         for i = strt[k], fin[k] do
  1342.             el_height = draw_element[i](el_coord)
  1343.             el_coord.y = el_coord.y + el_height + pcmt.vertical_gap[k]
  1344.             --el_height_sum[k] = el_height_sum[k] + el_height
  1345.         end
  1346.         el_coord.x = 1920 - colomn_width - pcmt.border_gap + 5
  1347.         el_coord.y = pcmt.border_gap
  1348.     end
  1349.  
  1350.     ----------------------------
  1351.     --temporary debag elements
  1352.     ----------------------------
  1353.    
  1354.     -- calculate vertical gaps between elements
  1355.     ----------------------------
  1356.     --print((1030 - el_height_sum[1] - 2*pcmt.border_gap)/3, (1030 - el_height_sum[2] - 2*pcmt.border_gap)/3)
  1357.     --print(conky_window.width)
  1358.    
  1359.     -- placemend grid
  1360.     ----------------------------   
  1361. --[[
  1362.     cairo_set_source_rgba (cr,rgb_to_r_g_b(white_color,1))
  1363.     cairo_set_line_width (cr, 1)
  1364.  
  1365.     cairo_move_to (cr, pcmt.border_gap, 0)
  1366.     cairo_rel_line_to(cr, 0, conky_window.height)
  1367.     cairo_move_to (cr, pcmt.border_gap + colomn_width, 0)
  1368.     cairo_rel_line_to(cr, 0, conky_window.height)
  1369.     cairo_move_to (cr, conky_window.width - pcmt.border_gap, 0)
  1370.     cairo_rel_line_to(cr, 0, conky_window.height)
  1371.     cairo_move_to (cr, conky_window.width - pcmt.border_gap - colomn_width, 0)
  1372.     cairo_rel_line_to(cr, 0, conky_window.height)
  1373.     ----------------------------
  1374.     cairo_move_to (cr, 0, pcmt.border_gap)
  1375.     cairo_rel_line_to(cr, conky_window.width, 0)
  1376.     cairo_move_to (cr, 0, conky_window.height)
  1377.     cairo_rel_line_to(cr, conky_window.width, 0)
  1378.     cairo_move_to (cr, 0, conky_window.height - pcmt.border_gap)
  1379.     cairo_rel_line_to(cr, conky_window.width, 0)
  1380.  
  1381.     cairo_stroke (cr)
  1382. -- ]]
  1383.     ----------------------------
  1384.     -- destroy cairo
  1385.     ----------------------------
  1386.     cairo_destroy(cr)
  1387.     cairo_surface_destroy(cs)
  1388.     cr=nil
  1389. end
RAW Paste Data