Advertisement
lswest

draw_bg.lua

Oct 2nd, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. --[[
  2. Background by londonali1010 (2009)
  3. 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.
  4. To call this script in Conky, use (assuming you have saved this script to ~/scripts/):
  5. lua_load ~/scripts/draw_bg.lua
  6. lua_draw_hook_pre draw_bg
  7. Changelog:
  8. + v1.0 -- Original release (07.10.2009)
  9. ]]
  10. -- Change these settings to affect your background.
  11. -- "corner_r" is the radius, in pixels, of the rounded corners. If you don't want rounded corners, use 0.
  12. corner_r=35
  13. -- Set the colour and transparency (alpha) of your background.
  14. bg_colour=0x000000
  15. bg_alpha=0.3
  16. require 'cairo'
  17. 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. function conky_draw_bg()
  21. if conky_window==nil then return end
  22. local w=conky_window.width
  23. local h=conky_window.height
  24. local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
  25. cr=cairo_create(cs)
  26.  
  27. cairo_move_to(cr,corner_r,0)
  28. cairo_line_to(cr,w-corner_r,0)
  29. cairo_curve_to(cr,w,0,w,0,w,corner_r)
  30. cairo_line_to(cr,w,h-corner_r)
  31. cairo_curve_to(cr,w,h,w,h,w-corner_r,h)
  32. cairo_line_to(cr,corner_r,h)
  33. cairo_curve_to(cr,0,h,0,h,0,h-corner_r)
  34. cairo_line_to(cr,0,corner_r)
  35. cairo_curve_to(cr,0,0,0,0,corner_r,0)
  36. cairo_close_path(cr)
  37.  
  38. cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha))
  39. cairo_fill(cr)
  40. end
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement