Guest User

draw_bg.lua

a guest
Feb 19th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. --[[ Background by londonali1010 (2009)
  2. VinDSL Background Hack (2010-2011)
  3.  
  4. This script draws a background to the Conky window. It covers the whole of the Conky window, but you can specify rounded corners, if you wish.
  5.  
  6. To call this script in Conky, use (assuming you have saved this script to ~/scripts/):
  7. lua_load ~/scripts/draw_bg.lua
  8. lua_draw_hook_pre draw_bg
  9.  
  10. Changelog:
  11. + v3.0 VinDSL Hack (01.28.2011) Killed memory leak.
  12. + v2.4 VinDSL Hack (01.25.2011) Declared all variables in local.
  13. + v2.3 VinDSL Hack (12.31.2010) Added shading example(s).
  14. + v2.2 VinDSL Hack (12.30.2010) Cleaned up the code a bit.
  15. + v2.1 VinDSL Hack (12.24.2010) Added cairo destroy function(s).
  16. + v2.0 VinDSL Hack (12.21.2010) Added height adjustment variable.
  17. + v1.0 Original release (07.10.2009)
  18.  
  19. ]]
  20.  
  21. --------------START OF PARAMETERS ------------
  22. -- Change these settings to affect your background:
  23.  
  24. -- "corner_r" is the radius, in pixels, of the rounded corners. If you don't want rounded corners, use 0.
  25.  
  26. local corner_r = 0
  27.  
  28. -- Set the colour and transparency (alpha) of your background (0.00 - 0.99).
  29.  
  30. -- (Light Shading Example)
  31. -- local bg_colour = 0x4d4d4d
  32. -- local bg_alpha = 0.50
  33.  
  34. -- (Medium Shading Example)
  35. -- local bg_colour = 0x222222
  36. -- local bg_alpha = 0.50
  37.  
  38. -- (Dark Shading Example)
  39. -- local bg_colour = 0x000000
  40. -- local bg_alpha = 0.50
  41.  
  42. local bg_colour = 0x000000
  43. local bg_alpha = 0.4
  44.  
  45. -- Tweaks the height of your background, in pixels. If you don't need to adjust the height, use 0.
  46.  
  47. -- (Default Setting)
  48. -- local vindsl_hack_height = 0
  49.  
  50. local vindsl_hack_height = 0
  51. ---------------END OF PARAMETERS -------------
  52.  
  53. require 'cairo'
  54. local cs, cr = nil
  55.  
  56. local function rgb_to_r_g_b(colour,alpha)
  57. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  58. end
  59.  
  60. function conky_draw_bg()
  61. if conky_window == nil then return end
  62. if cs == nil then cairo_surface_destroy(cs) end
  63. if cr == nil then cairo_destroy(cr) end
  64. local w = conky_window.width
  65. local h = conky_window.height
  66. local v = vindsl_hack_height
  67. local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  68. local cr = cairo_create(cs)
  69.  
  70. cairo_move_to(cr,corner_r,0)
  71. cairo_line_to(cr,w-corner_r,0)
  72. cairo_curve_to(cr,w,0,w,0,w,corner_r)
  73. cairo_line_to(cr,w,h+v-corner_r)
  74. cairo_curve_to(cr,w,h+v,w,h+v,w-corner_r,h+v)
  75. cairo_line_to(cr,corner_r,h+v)
  76. cairo_curve_to(cr,0,h+v,0,h+v,0,h+v-corner_r)
  77. cairo_line_to(cr,0,corner_r)
  78. cairo_curve_to(cr,0,0,0,0,corner_r,0)
  79. cairo_close_path(cr)
  80.  
  81. cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha))
  82. cairo_fill(cr)
  83.  
  84. cairo_surface_destroy(cs)
  85. cairo_destroy(cr)
  86. end
Advertisement
Add Comment
Please, Sign In to add comment