Advertisement
maxpro4u

red lua rings

Mar 20th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.93 KB | None | 0 0
  1. settings_table = {
  2. {
  3. -- Edit this table to customise your rings.
  4. -- You can create more rings simply by adding more elements to settings_table.
  5. -- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.
  6. name='time',
  7. -- "arg" is the argument to the stat type, e.g. if in Conky you would write ${cpu cpu0}, 'cpu0' would be the argument. If you would not use an argument in the Conky variable, use ''.
  8. arg='%I.%M',
  9. -- "max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.
  10. max=12,
  11. -- "bg_colour" is the colour of the base ring.
  12. bg_colour=0xC26666,
  13. -- "bg_alpha" is the alpha value of the base ring.
  14. bg_alpha=0.1,
  15. -- "fg_colour" is the colour of the indicator part of the ring.
  16. fg_colour=0x990000,
  17. -- "fg_alpha" is the alpha value of the indicator part of the ring.
  18. fg_alpha=0.2,
  19. -- "x" and "y" are the x and y coordinates of the centre of the ring, relative to the top left corner of the Conky window.
  20. x=100, y=150,
  21. -- "radius" is the radius of the ring.
  22. radius=50,
  23. -- "thickness" is the thickness of the ring, centred around the radius.
  24. thickness=5,
  25. -- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.
  26. start_angle=0,
  27. -- "end_angle" is the ending angle of the ring, in degrees, clockwise from top. Value can be either positive or negative, but must be larger than start_angle.
  28. end_angle=360
  29. },
  30. {
  31. name='time',
  32. arg='%M.%S',
  33. max=60,
  34. bg_colour=0xC26666,
  35. bg_alpha=0.1,
  36. fg_colour=0x990000,
  37. fg_alpha=0.4,
  38. x=100, y=150,
  39. radius=56,
  40. thickness=5,
  41. start_angle=0,
  42. end_angle=360
  43. },
  44. {
  45. name='time',
  46. arg='%S',
  47. max=60,
  48. bg_colour=0xC26666,
  49. bg_alpha=0.1,
  50. fg_colour=0x990000,
  51. fg_alpha=0.6,
  52. x=100, y=150,
  53. radius=62,
  54. thickness=5,
  55. start_angle=0,
  56. end_angle=360
  57. },
  58. {
  59. name='time',
  60. arg='%d',
  61. max=31,
  62. bg_colour=0xC26666,
  63. bg_alpha=0.1,
  64. fg_colour=0x990000,
  65. fg_alpha=0.8,
  66. x=100, y=150,
  67. radius=70,
  68. thickness=5,
  69. start_angle=-90,
  70. end_angle=90
  71. },
  72. {
  73. name='time',
  74. arg='%m',
  75. max=12,
  76. bg_colour=0xC26666,
  77. bg_alpha=0.1,
  78. fg_colour=0x990000,
  79. fg_alpha=1,
  80. x=100, y=150,
  81. radius=76,
  82. thickness=5,
  83. start_angle=-90,
  84. end_angle=90
  85. },
  86. {
  87. name='cpu',
  88. arg='cpu0',
  89. max=100,
  90. bg_colour=0xC26666,
  91. bg_alpha=0.2,
  92. fg_colour=0x990000,
  93. fg_alpha=0.8,
  94. x=120, y=270,
  95. radius=30,
  96. thickness=5,
  97. start_angle=-80,
  98. end_angle=160
  99. },
  100. {
  101. name='cpu',
  102. arg='cpu1',
  103. max=100,
  104. bg_colour=0xC26666,
  105. bg_alpha=0.2,
  106. fg_colour=0x990000,
  107. fg_alpha=0.8,
  108. x=120, y=270,
  109. radius=45,
  110. thickness=5,
  111. start_angle=-100,
  112. end_angle=200
  113. },
  114. {
  115. name='memperc',
  116. arg='',
  117. max=100,
  118. bg_colour=0xC26666,
  119. bg_alpha=0.2,
  120. fg_colour=0x990000,
  121. fg_alpha=0.8,
  122. x=40, y=330,
  123. radius=35,
  124. thickness=5,
  125. start_angle=-120,
  126. end_angle=180
  127. },
  128. {
  129. name='acpitemp',
  130. arg='',
  131. max=212,
  132. bg_colour=0xC26666,
  133. bg_alpha=0.2,
  134. fg_colour=0x990000,
  135. fg_alpha=0.8,
  136. x=100, y=390,
  137. radius=30,
  138. thickness=5,
  139. start_angle=-100,
  140. end_angle=180
  141. },
  142. {
  143. name='fs_used_perc',
  144. arg='/',
  145. max=100,
  146. bg_colour=0xC26666,
  147. bg_alpha=0.2,
  148. fg_colour=0x990000,
  149. fg_alpha=0.8,
  150. x=30, y=455,
  151. radius=25,
  152. thickness=5,
  153. start_angle=-90,
  154. end_angle=180
  155. },
  156. {
  157. name='fs_used_perc',
  158. arg='/home',
  159. max=100,
  160. bg_colour=0xC26666,
  161. bg_alpha=0.2,
  162. fg_colour=0x990000,
  163. fg_alpha=0.8,
  164. x=90, y=455,
  165. radius=25,
  166. thickness=5,
  167. start_angle=-90,
  168. end_angle=180
  169. },
  170. {
  171. name='battery_percent',
  172. arg='C23B',
  173. max=100,
  174. bg_colour=0xC26666,
  175. bg_alpha=0.2,
  176. fg_colour=0x990000,
  177. fg_alpha=0.8,
  178. x=150, y=455,
  179. radius=25,
  180. thickness=5,
  181. start_angle=-90,
  182. end_angle=180
  183. },
  184. {
  185. name='downspeedf',
  186. arg='eth0',
  187. max=100,
  188. bg_colour=0xC26666,
  189. bg_alpha=0.2,
  190. fg_colour=0x990000,
  191. fg_alpha=0.8,
  192. x=130, y=510,
  193. radius=25,
  194. thickness=4,
  195. start_angle=-90,
  196. end_angle=180
  197. },
  198. {
  199. name='upspeedf',
  200. arg='eth0',
  201. max=100,
  202. bg_colour=0xC26666,
  203. bg_alpha=0.2,
  204. fg_colour=0x990000,
  205. fg_alpha=0.8,
  206. x=130, y=510,
  207. radius=20,
  208. thickness=4,
  209. start_angle=-90,
  210. end_angle=180
  211. },
  212. {
  213. name='downspeedf',
  214. arg='wlp16s0',
  215. max=100,
  216. bg_colour=0xC26666,
  217. bg_alpha=0.2,
  218. fg_colour=0x990000,
  219. fg_alpha=0.8,
  220. x=50, y=510,
  221. radius=25,
  222. thickness=4,
  223. start_angle=-90,
  224. end_angle=180
  225. },
  226. {
  227. name='upspeedf',
  228. arg='wlp16s0',
  229. max=100,
  230. bg_colour=0xC26666,
  231. bg_alpha=0.2,
  232. fg_colour=0x990000,
  233. fg_alpha=0.8,
  234. x=50, y=510,
  235. radius=20,
  236. thickness=4,
  237. start_angle=-90,
  238. end_angle=180
  239. },
  240. {
  241. name='wireless_link_qual',
  242. arg='wlp16s0',
  243. max=100,
  244. bg_colour=0xC26666,
  245. bg_alpha=0.2,
  246. fg_colour=0x990000,
  247. fg_alpha=0.8,
  248. x=90, y=560,
  249. radius=25,
  250. thickness=4,
  251. start_angle=-90,
  252. end_angle=180
  253. },
  254. {
  255. name='wireless_link_qual',
  256. arg='wlp16s0',
  257. max=100,
  258. bg_colour=0xC26666,
  259. bg_alpha=0.2,
  260. fg_colour=0x990000,
  261. fg_alpha=0.8,
  262. x=90, y=560,
  263. radius=20,
  264. thickness=4,
  265. start_angle=-90,
  266. end_angle=180
  267. },
  268. }
  269.  
  270. -- Use these settings to define the origin and extent of your clock.
  271.  
  272. clock_r=65
  273.  
  274. -- "clock_x" and "clock_y" are the coordinates of the centre of the clock, in pixels, from the top left of the Conky window.
  275.  
  276. clock_x=100
  277. clock_y=150
  278.  
  279. show_seconds=true
  280.  
  281. require 'cairo'
  282.  
  283. function rgb_to_r_g_b(colour,alpha)
  284. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  285. end
  286.  
  287. function draw_ring(cr,t,pt)
  288. local w,h=conky_window.width,conky_window.height
  289.  
  290. local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
  291. local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']
  292.  
  293. local angle_0=sa*(2*math.pi/360)-math.pi/2
  294. local angle_f=ea*(2*math.pi/360)-math.pi/2
  295. local t_arc=t*(angle_f-angle_0)
  296.  
  297. -- Draw background ring
  298.  
  299. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
  300. cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
  301. cairo_set_line_width(cr,ring_w)
  302. cairo_stroke(cr)
  303.  
  304. -- Draw indicator ring
  305.  
  306. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
  307. cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
  308. cairo_stroke(cr)
  309. end
  310.  
  311. function draw_clock_hands(cr,xc,yc)
  312. local secs,mins,hours,secs_arc,mins_arc,hours_arc
  313. local xh,yh,xm,ym,xs,ys
  314.  
  315. secs=os.date("%S")
  316. mins=os.date("%M")
  317. hours=os.date("%I")
  318.  
  319. secs_arc=(2*math.pi/60)*secs
  320. mins_arc=(2*math.pi/60)*mins+secs_arc/60
  321. hours_arc=(2*math.pi/12)*hours+mins_arc/12
  322.  
  323. -- Draw hour hand
  324.  
  325. xh=xc+0.7*clock_r*math.sin(hours_arc)
  326. yh=yc-0.7*clock_r*math.cos(hours_arc)
  327. cairo_move_to(cr,xc,yc)
  328. cairo_line_to(cr,xh,yh)
  329.  
  330. cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
  331. cairo_set_line_width(cr,5)
  332. cairo_set_source_rgba(cr,1.0,1.0,1.0,1.0)
  333. cairo_stroke(cr)
  334.  
  335. -- Draw minute hand
  336.  
  337. xm=xc+clock_r*math.sin(mins_arc)
  338. ym=yc-clock_r*math.cos(mins_arc)
  339. cairo_move_to(cr,xc,yc)
  340. cairo_line_to(cr,xm,ym)
  341.  
  342. cairo_set_line_width(cr,3)
  343. cairo_stroke(cr)
  344.  
  345. -- Draw seconds hand
  346.  
  347. if show_seconds then
  348. xs=xc+clock_r*math.sin(secs_arc)
  349. ys=yc-clock_r*math.cos(secs_arc)
  350. cairo_move_to(cr,xc,yc)
  351. cairo_line_to(cr,xs,ys)
  352.  
  353. cairo_set_line_width(cr,1)
  354. cairo_stroke(cr)
  355. end
  356. end
  357.  
  358. function conky_clock_rings()
  359. local function setup_rings(cr,pt)
  360. local str=''
  361. local value=0
  362.  
  363. str=string.format('${%s %s}',pt['name'],pt['arg'])
  364. str=conky_parse(str)
  365.  
  366. value=tonumber(str)
  367. pct=value/pt['max']
  368.  
  369. draw_ring(cr,pct,pt)
  370. end
  371.  
  372. -- Check that Conky has been running for at least 5s
  373.  
  374. if conky_window==nil then return end
  375. local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
  376.  
  377. local cr=cairo_create(cs)
  378.  
  379. local updates=conky_parse('${updates}')
  380. update_num=tonumber(updates)
  381.  
  382. if update_num>5 then
  383. for i in pairs(settings_table) do
  384. setup_rings(cr,settings_table[i])
  385. end
  386. end
  387.  
  388. draw_clock_hands(cr,clock_x,clock_y)
  389. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement