Advertisement
FrankRizz0

Untitled

Jan 18th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.81 KB | None | 0 0
  1. --[[
  2. Ring Meters by londonali1010 (2009)
  3. Modified by La-Manoue (2016)
  4.  
  5. This script draws percentage meters as rings. It is fully customisable; all options are described in the script.
  6.  
  7. IMPORTANT: if you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away. The if statement near the end of the script uses a delay to make sure that this doesn't happen. It calculates the length of the delay by the number of updates since Conky started. Generally, a value of 5s is long enough, so if you update Conky every 1s, use update_num > 5 in that if statement (the default). If you only update Conky every 2s, you should change it to update_num > 3; conversely if you update Conky every 0.5s, you should use update_num > 10. ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it, otherwise the update_num will not be reset and you will get an error.
  8.  
  9. To call this script in Conky, use the following (assuming that you save this script to ~/scripts/rings.lua):
  10. lua_load ~/scripts/rings-v1.2.1.lua
  11. lua_draw_hook_pre ring_stats
  12.  
  13. Changelog:
  14. + v1.2.2 -- Added color change for near-limits values / modified placement
  15. + v1.2.1 -- Fixed minor bug that caused script to crash if conky_parse() returns a nil value (20.10.2009)
  16. + v1.2 -- Added option for the ending angle of the rings (07.10.2009)
  17. + v1.1 -- Added options for the starting angle of the rings, and added the "max" variable, to allow for variables that output a numerical value rather than a percentage (29.09.2009)
  18. + v1.0 -- Original release (28.09.2009)
  19.  
  20. ]]
  21.  
  22. normal="0x725f8f"
  23. warn="0xff7200"
  24. crit="0xff000d"
  25.  
  26. -- seulement quand fond nécessaire
  27. corner_r=35
  28. bg_colour=0x3b3b3b
  29. bg_alpha=0.2
  30.  
  31.  
  32. settings_table = {
  33. {
  34. name='acpitemp',
  35. arg='',
  36. max=110,
  37. bg_colour=0x3b3b3b,
  38. bg_alpha=0.8,
  39. fg_colour=0x725f8f,
  40. fg_alpha=0.8,
  41. x=200, y=120,
  42. radius=97,
  43. thickness=4,
  44. start_angle=0,
  45. end_angle=0,
  46. },
  47. {
  48. name='cpu',
  49. arg='cpu0',
  50. max=100,
  51. bg_colour=0xd5d5d5,
  52. bg_alpha=0.7,
  53. fg_colour=0x958E9A,
  54. fg_alpha=0.8,
  55. x=126, y=195,
  56. radius=30,
  57. thickness=8,
  58. start_angle=270,
  59. end_angle=720
  60. },
  61. {
  62. name='memperc',
  63. arg='',
  64. max=100,
  65. bg_colour=0xd5d5d5,
  66. bg_alpha=0.8,
  67. fg_colour=0x958E9A,
  68. fg_alpha=0.8,
  69. x=240, y=420,
  70. radius=30,
  71. thickness=8,
  72. start_angle=270,
  73. end_angle=720
  74. },
  75. {
  76. name='swapperc',
  77. arg='',
  78. max=100,
  79. bg_colour=0x3b3b3b,
  80. bg_alpha=0.4,
  81. fg_colour=0x725f8f,
  82. fg_alpha=0.8,
  83. x=340, y=234,
  84. radius=45,
  85. thickness=10,
  86. start_angle=0,
  87. end_angle=0
  88. },
  89. {
  90. name='fs_used_perc',
  91. arg='/',
  92. max=100,
  93. bg_colour=0x3b3b3b,
  94. bg_alpha=0.8,
  95. fg_colour=0x725f8f,
  96. fg_alpha=0.8,
  97. x=220, y=280,
  98. radius=40,
  99. thickness=10,
  100. start_angle=0,
  101. end_angle=0
  102. },
  103. {
  104. name='fs_used_perc',
  105. arg='/home',
  106. max=100,
  107. bg_colour=0x3b3b3b,
  108. bg_alpha=0.6,
  109. fg_colour=0x725f8f,
  110. fg_alpha=0.8,
  111. x=220, y=280,
  112. radius=28,
  113. thickness=10,
  114. start_angle=0,
  115. end_angle=0
  116. },
  117. {
  118. name='fs_used_perc',
  119. arg='/home/bry2k200/Media',
  120. max=100,
  121. bg_colour=0x3b3b3b,
  122. bg_alpha=0.4,
  123. fg_colour=0x725f8f,
  124. fg_alpha=0.8,
  125. x=220, y=280,
  126. radius=16,
  127. thickness=10,
  128. start_angle=0,
  129. end_angle=0
  130. },
  131. {
  132. name='time',
  133. arg='%S',
  134. max=60,
  135. bg_colour=0xffffff,
  136. bg_alpha=0.8,
  137. fg_colour=0xd5d5d5,
  138. fg_alpha=0.8,
  139. x=58, y=68,
  140. radius=42,
  141. thickness=6,
  142. start_angle=0,
  143. end_angle=360
  144. },
  145. {
  146. name='time',
  147. arg='%M',
  148. max=60,
  149. bg_colour=0xffffff,
  150. bg_alpha=0.6,
  151. fg_colour=0xd5d5d5,
  152. fg_alpha=0.8,
  153. x=58, y=68,
  154. radius=34,
  155. thickness=2,
  156. start_angle=0,
  157. end_angle=360
  158. },
  159. {
  160. name='time',
  161. arg='%H',
  162. max=24,
  163. bg_colour=0xffffff,
  164. bg_alpha=0.4,
  165. fg_colour=0xd5d5d5,
  166. fg_alpha=0.8,
  167. x=58, y=68,
  168. radius=50,
  169. thickness=2,
  170. start_angle=0,
  171. end_angle=360
  172. },
  173. {
  174. name='downspeedf',
  175. arg='',
  176. max=2000,
  177. bg_colour=0x3b3b3b,
  178. bg_alpha=0.8,
  179. fg_colour=0x725f8f,
  180. fg_alpha=0.8,
  181. x=290, y=346,
  182. radius=30,
  183. thickness=12,
  184. start_angle=0,
  185. end_angle=0
  186. },
  187. {
  188. name='upspeedf',
  189. arg='',
  190. max=200,
  191. bg_colour=0x3b3b3b,
  192. bg_alpha=0.6,
  193. fg_colour=0x725f8f,
  194. fg_alpha=0.8,
  195. x=290, y=346,
  196. radius=18,
  197. thickness=8,
  198. start_angle=0,
  199. end_angle=0
  200. },
  201. }
  202.  
  203. -- Use these settings to define the origin and extent of your clock.
  204.  
  205. clock_r=65
  206.  
  207. -- "clock_x" and "clock_y" are the coordinates of the centre of the clock, in pixels, from the top left of the Conky window.
  208.  
  209. clock_x=78
  210. clock_y=88
  211.  
  212. show_seconds=true
  213.  
  214. require 'cairo'
  215.  
  216. function rgb_to_r_g_b(colour,alpha)
  217. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  218. end
  219.  
  220. function draw_ring(cr,t,pt)
  221.  
  222. local w,h=conky_window.width,conky_window.height
  223.  
  224. local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
  225. local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']
  226.  
  227. local angle_0=sa*(2*math.pi/360)-math.pi/2
  228. local angle_f=ea*(2*math.pi/360)-math.pi/2
  229. local t_arc=t*(angle_f-angle_0)
  230.  
  231. -- Draw background ring
  232.  
  233. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
  234. cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
  235. cairo_set_line_width(cr,ring_w)
  236. cairo_stroke(cr)
  237.  
  238. -- Draw indicator ring
  239.  
  240. cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
  241. cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
  242. cairo_stroke(cr)
  243. end
  244.  
  245. function draw_clock_hands(cr,xc,yc)
  246. local secs,mins,hours,secs_arc,mins_arc,hours_arc
  247. local xh,yh,xm,ym,xs,ys
  248.  
  249. secs=os.date("%S")
  250. mins=os.date("%M")
  251. hours=os.date("%I")
  252.  
  253. secs_arc=(2*math.pi/60)*secs
  254. mins_arc=(2*math.pi/60)*mins+secs_arc/60
  255. hours_arc=(2*math.pi/12)*hours+mins_arc/12
  256.  
  257. -- Draw hour hand
  258.  
  259. xh=xc+0.7*clock_r*math.sin(hours_arc)
  260. yh=yc-0.7*clock_r*math.cos(hours_arc)
  261. cairo_move_to(cr,xc,yc)
  262. cairo_line_to(cr,xh,yh)
  263.  
  264. cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
  265. cairo_set_line_width(cr,5)
  266. cairo_set_source_rgba(cr,1.0,1.0,1.0,1.0)
  267. cairo_stroke(cr)
  268.  
  269. -- Draw minute hand
  270.  
  271. xm=xc+clock_r*math.sin(mins_arc)
  272. ym=yc-clock_r*math.cos(mins_arc)
  273. cairo_move_to(cr,xc,yc)
  274. cairo_line_to(cr,xm,ym)
  275.  
  276. cairo_set_line_width(cr,3)
  277. cairo_stroke(cr)
  278.  
  279. -- Draw seconds hand
  280.  
  281. if show_seconds then
  282. xs=xc+clock_r*math.sin(secs_arc)
  283. ys=yc-clock_r*math.cos(secs_arc)
  284. cairo_move_to(cr,xc,yc)
  285. cairo_line_to(cr,xs,ys)
  286.  
  287. cairo_set_line_width(cr,1)
  288. cairo_stroke(cr)
  289. end
  290. end
  291.  
  292. function conky_ring_stats()
  293. local function setup_rings(cr,pt)
  294. local str=''
  295. local value=0
  296.  
  297. str=string.format('${%s %s}',pt['name'],pt['arg'])
  298. str=conky_parse(str)
  299.  
  300. value=tonumber(str)
  301. if value == nil then value = 0 end
  302. pct=value/pt['max']
  303.  
  304. draw_ring(cr,pct,pt)
  305. end
  306.  
  307. if conky_window==nil then return end
  308. local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
  309.  
  310. local cr=cairo_create(cs)
  311.  
  312. local updates=conky_parse('${updates}')
  313. update_num=tonumber(updates)
  314.  
  315. if update_num>5 then
  316. for i in pairs(settings_table) do
  317. display_temp=temp_watch()
  318. setup_rings(cr,settings_table[i])
  319. end
  320. end
  321. cairo_surface_destroy(cs)
  322. cairo_destroy(cr)
  323. end
  324.  
  325. -- Contrôle de l'espace disque
  326. function disk_watch()
  327.  
  328. warn_disk=93
  329. crit_disk=98
  330.  
  331. -- poser une boucle plus tard... pas simple
  332.  
  333. disk=tonumber(conky_parse("${fs_used_perc /}"))
  334.  
  335. if disk<warn_disk then
  336. settings_table[8]['fg_colour']=normal
  337. elseif disk<crit_disk then
  338. settings_table[8]['fg_colour']=warn
  339. else
  340. settings_table[8]['fg_colour']=crit
  341. end
  342.  
  343. disk=tonumber(conky_parse("${fs_used_perc /home}"))
  344.  
  345. if disk<warn_disk then
  346. settings_table[9]['fg_colour']=normal
  347. elseif disk<crit_disk then
  348. settings_table[9]['fg_colour']=warn
  349. else
  350. settings_table[9]['fg_colour']=crit
  351. end
  352.  
  353. disk=tonumber(conky_parse("${fs_used_perc /usr}"))
  354.  
  355. if disk<warn_disk then
  356. settings_table[10]['fg_colour']=normal
  357. elseif disk<crit_disk then
  358. settings_table[10]['fg_colour']=warn
  359. else
  360. settings_table[10]['fg_colour']=crit
  361. end
  362. end
  363.  
  364. -- Contrôle de la température
  365. function temp_watch()
  366.  
  367. warn_value=70
  368. crit_value=80
  369.  
  370. temperature=tonumber(conky_parse("${acpitemp}"))
  371.  
  372. if temperature<warn_value then
  373. settings_table[1]['fg_colour']=normal
  374. elseif temperature<crit_value then
  375. settings_table[1]['fg_colour']=warn
  376. else
  377. settings_table[1]['fg_colour']=crit
  378. end
  379. end
  380.  
  381. -- Contrôle de l'interface active
  382. function iface_watch()
  383.  
  384. iface=conky_parse("${if_existing /proc/net/route eth0}eth0${else}wlan0${endif}")
  385.  
  386. settings_table[11]['arg']=iface
  387. settings_table[12]['arg']=iface
  388. end
  389.  
  390. function conky_draw_bg()
  391. if conky_window==nil then return end
  392. local w=conky_window.width
  393. local h=conky_window.height
  394. local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
  395. cr=cairo_create(cs)
  396.  
  397. cairo_move_to(cr,corner_r,0)
  398. cairo_line_to(cr,w-corner_r,0)
  399. cairo_curve_to(cr,w,0,w,0,w,corner_r)
  400. cairo_line_to(cr,w,h-corner_r)
  401. cairo_curve_to(cr,w,h,w,h,w-corner_r,h)
  402. cairo_line_to(cr,corner_r,h)
  403. cairo_curve_to(cr,0,h,0,h,0,h-corner_r)
  404. cairo_line_to(cr,0,corner_r)
  405. cairo_curve_to(cr,0,0,0,0,corner_r,0)
  406. cairo_close_path(cr)
  407.  
  408. cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha))
  409. cairo_fill(cr)
  410. end
  411.  
  412.  
  413. function conky_main()
  414. draw_clock_hands(cr,clock_x,clock_y)
  415. temp_watch()
  416. disk_watch()
  417. iface_watch()
  418. conky_ring_stats()
  419. -- quand fond nécessaire
  420. -- conky_draw_bg()
  421. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement