SHARE
TWEET

draw_bg.lua

freieschaf Nov 16th, 2011 696 Never
  1. --[[
  2. Background by londonali1010 (2009)
  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
  9.  
  10. Changelog:
  11. + v1.0 -- Original release (07.10.2009)
  12. ]]
  13.  
  14. -- Change these settings to affect your background.
  15. -- "corner_r" is the radius, in pixels, of the rounded corners. If you don't want rounded corners, use 0.
  16.  
  17. corner_r=95
  18.  
  19. -- Set the colour and transparency (alpha) of your background.
  20.  
  21. bg_colour=0x000000
  22. bg_alpha=0.2
  23.  
  24. require 'cairo'
  25. function rgb_to_r_g_b(colour,alpha)
  26.         return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  27. end
  28.  
  29. function conky_draw_bg()
  30.         if conky_window==nil then return end
  31.         local w=conky_window.width
  32.         local h=conky_window.height
  33.         local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
  34.         cr=cairo_create(cs)
  35.  
  36.         cairo_move_to(cr,corner_r,0)
  37.         cairo_line_to(cr,w-corner_r,0)
  38.         cairo_curve_to(cr,w,0,w,0,w,corner_r)
  39.         cairo_line_to(cr,w,h-corner_r)
  40.         cairo_curve_to(cr,w,h,w,h,w-corner_r,h)
  41.         cairo_line_to(cr,corner_r,h)
  42.         cairo_curve_to(cr,0,h,0,h,0,h-corner_r)
  43.         cairo_line_to(cr,0,corner_r)
  44.         cairo_curve_to(cr,0,0,0,0,corner_r,0)
  45.         cairo_close_path(cr)
  46.  
  47.         cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha))
  48.         cairo_fill(cr)
  49. end
  50.  
RAW Paste Data
Top