Advertisement
PackRat-2017

transbg.lua

Oct 2nd, 2022
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. --[[Background originally by londonali1010 (2009)
  2. ability to set any size for background mrpeachy 2011
  3. ability to set variables for bg in conkyrc dk75
  4.  
  5. the change is that if you set width and/or height to 0
  6. then it assumes the width and/or height of the conky window
  7.  
  8. so:
  9.  
  10. Above and After TEXT (requires a composite manager or it blinks!)
  11.  
  12. lua_load ~/wea_conky/draw_bg.lua
  13. TEXT
  14. ${lua conky_draw_bg 10 0 0 0 0 0x000000 0.4}
  15.  
  16. OR Both above TEXT (no composite manager required - no blinking!)
  17.  
  18. lua_load ~/wea_conky/draw_bg.lua
  19. lua_draw_hook_pre draw_bg 10 0 0 0 0 0x000000 0.5
  20. TEXT
  21.  
  22. Note
  23. ${lua conky_draw_bg 20 0 0 0 0 0x000000 0.4}
  24. See below: 1 2 3 4 5 6 7
  25.  
  26. ${lua conky_draw_bg corner_radius x_position y_position width height color alpha}
  27.  
  28. covers the whole window and will change if you change the minimum_size setting
  29.  
  30. 1 = 20 corner_radius
  31. 2 = 0 x_position
  32. 3 = 0 y_position
  33. 3 = 0 width
  34. 5 = 0 height
  35. 6 = 0x000000 color
  36. 7 = 0.4 alpha
  37.  
  38. ]]
  39.  
  40. require 'cairo'
  41. local cs, cr = nil
  42. function rgb_to_r_g_b(colour,alpha)
  43. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  44. end
  45. function conky_draw_bg(r,x,y,w,h,color,alpha)
  46. if conky_window == nil then return end
  47. if cs == nil then cairo_surface_destroy(cs) end
  48. if cr == nil then cairo_destroy(cr) end
  49. local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  50. local cr = cairo_create(cs)
  51. w=w
  52. h=h
  53. if w=="0" then w=tonumber(conky_window.width) end
  54. if h=="0" then h=tonumber(conky_window.height) end
  55. cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
  56. --top left mid circle
  57. local xtl=x+r
  58. local ytl=y+r
  59. --top right mid circle
  60. local xtr=(x+r)+((w)-(2*r))
  61. local ytr=y+r
  62. --bottom right mid circle
  63. local xbr=(x+r)+((w)-(2*r))
  64. local ybr=(y+r)+((h)-(2*r))
  65. --bottom right mid circle
  66. local xbl=(x+r)
  67. local ybl=(y+r)+((h)-(2*r))
  68. -----------------------------
  69. cairo_move_to (cr,xtl,ytl-r)
  70. cairo_line_to (cr,xtr,ytr-r)
  71. cairo_arc(cr,xtr,ytr,r,((2*math.pi/4)*3),((2*math.pi/4)*4))
  72. cairo_line_to (cr,xbr+r,ybr)
  73. cairo_arc(cr,xbr,ybr,r,((2*math.pi/4)*4),((2*math.pi/4)*1))
  74. cairo_line_to (cr,xbl,ybl+r)
  75. cairo_arc(cr,xbl,ybl,r,((2*math.pi/4)*1),((2*math.pi/4)*2))
  76. cairo_line_to (cr,xtl-r,ytl)
  77. cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
  78. cairo_close_path(cr)
  79. cairo_fill (cr)
  80. ------------------------------------------------------------
  81. cairo_surface_destroy(cs)
  82. cairo_destroy(cr)
  83. return ""
  84. end
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement