Advertisement
Brutico

draw_bg.lua

Jan 27th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. --[[
  2. Background by londonali1010 (2009)
  3.  
  4.  
  5.  
  6. 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.
  7.  
  8.  
  9.  
  10. To call this script in Conky, use (assuming you have saved this script to ~/scripts/):
  11.  
  12. lua_load ~/scripts/draw_bg.lua
  13.  
  14. lua_draw_hook_pre draw_bg
  15.  
  16.  
  17.  
  18. Changelog:
  19.  
  20. + v1.0 -- Original release (07.10.2009)
  21.  
  22. ]]
  23.  
  24.  
  25.  
  26. -- Change these settings to affect your background.
  27.  
  28. -- "corner_r" is the radius, in pixels, of the rounded corners. If you don't want rounded corners, use 0.
  29.  
  30.  
  31.  
  32. corner_r=15
  33.  
  34.  
  35.  
  36. -- Set the colour and transparency (alpha) of your background.
  37.  
  38.  
  39.  
  40. bg_colour=0x000000
  41.  
  42. bg_alpha=0.5
  43.  
  44.  
  45.  
  46. require 'cairo'
  47.  
  48. function rgb_to_r_g_b(colour,alpha)
  49.  
  50. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  51.  
  52. end
  53.  
  54.  
  55.  
  56. function conky_draw_bg()
  57.  
  58. if conky_window==nil then return end
  59.  
  60. local w=conky_window.width
  61.  
  62. local h=conky_window.height
  63.  
  64. local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
  65.  
  66. cr=cairo_create(cs)
  67.  
  68.  
  69.  
  70. cairo_move_to(cr,corner_r,0)
  71.  
  72. cairo_line_to(cr,w-corner_r,0)
  73.  
  74. cairo_curve_to(cr,w,0,w,0,w,corner_r)
  75.  
  76. cairo_line_to(cr,w,h-corner_r)
  77.  
  78. cairo_curve_to(cr,w,h,w,h,w-corner_r,h)
  79.  
  80. cairo_line_to(cr,corner_r,h)
  81.  
  82. cairo_curve_to(cr,0,h,0,h,0,h-corner_r)
  83.  
  84. cairo_line_to(cr,0,corner_r)
  85.  
  86. cairo_curve_to(cr,0,0,0,0,corner_r,0)
  87.  
  88. cairo_close_path(cr)
  89.  
  90.  
  91.  
  92. cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha))
  93.  
  94. cairo_fill(cr)
  95.  
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement