irenegr

.conky_grey.lua

Apr 20th, 2012
2,286
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ==============================================================================
  2. -- conky_grey.lua
  3. --
  4. -- author : SLK
  5. -- version : v2011011001
  6. -- license : Distributed under the terms of GNU GPL version 2 or later
  7. --
  8. --==============================================================================
  9.  
  10. require 'cairo'
  11.  
  12. --------------------------------------------------------------------------------
  13. -- clock DATA
  14. -- HOURS
  15. clock_h = {
  16. {
  17. name='time', arg='%H', max_value=12,
  18. x=110, y=80,
  19. graph_radius=53,
  20. graph_thickness=3,
  21. graph_unit_angle=30, graph_unit_thickness=30,
  22. graph_bg_colour=0xffffff, graph_bg_alpha=0.0,
  23. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.3,
  24. txt_radius=34,
  25. txt_weight=1, txt_size=10.0,
  26. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.6,
  27. graduation_radius=53,
  28. graduation_thickness=6, graduation_mark_thickness=2,
  29. graduation_unit_angle=30,
  30. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
  31. },
  32. }
  33. -- MINUTES
  34. clock_m = {
  35. {
  36. name='time', arg='%M', max_value=60,
  37. x=110, y=80,
  38. graph_radius=57,
  39. graph_thickness=2,
  40. graph_unit_angle=6, graph_unit_thickness=6,
  41. graph_bg_colour=0xffffff, graph_bg_alpha=0.1,
  42. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.3,
  43. txt_radius=70,
  44. txt_weight=0, txt_size=9.0,
  45. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.6,
  46. graduation_radius=57,
  47. graduation_thickness=0, graduation_mark_thickness=2,
  48. graduation_unit_angle=30,
  49. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
  50. },
  51. }
  52. -- SECONDS
  53. clock_s = {
  54. {
  55. name='time', arg='%S', max_value=60,
  56. x=110, y=80,
  57. graph_radius=50,
  58. graph_thickness=2,
  59. graph_unit_angle=6, graph_unit_thickness=2,
  60. graph_bg_colour=0xffffff, graph_bg_alpha=0.0,
  61. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.2,
  62. txt_radius=40,
  63. txt_weight=0, txt_size=12.0,
  64. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.3,
  65. graduation_radius=0,
  66. graduation_thickness=0, graduation_mark_thickness=0,
  67. graduation_unit_angle=0,
  68. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.0,
  69. },
  70. }
  71.  
  72. --------------------------------------------------------------------------------
  73. -- gauge DATA
  74. gauge = {
  75. {
  76. name='cpu', arg='cpu0', max_value=100,
  77. x=85, y=200,
  78. graph_radius=24,
  79. graph_thickness=5,
  80. graph_start_angle=180,
  81. graph_unit_angle=2.7, graph_unit_thickness=2.7,
  82. graph_bg_colour=0xffffff, graph_bg_alpha=0.1,
  83. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.5,
  84. hand_fg_colour=0xEF5A29, hand_fg_alpha=0.0,
  85. txt_radius=34,
  86. txt_weight=0, txt_size=8.0,
  87. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.3,
  88. graduation_radius=28,
  89. graduation_thickness=0, graduation_mark_thickness=1,
  90. graduation_unit_angle=27,
  91. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
  92. caption='',
  93. caption_weight=1, caption_size=8.0,
  94. caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.3,
  95. },
  96. {
  97. name='cpu', arg='cpu1', max_value=100,
  98. x=85, y=200,
  99. graph_radius=18,
  100. graph_thickness=5,
  101. graph_start_angle=180,
  102. graph_unit_angle=2.7, graph_unit_thickness=2.7,
  103. graph_bg_colour=0xffffff, graph_bg_alpha=0.1,
  104. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.5,
  105. hand_fg_colour=0xEF5A29, hand_fg_alpha=0.0,
  106. txt_radius=10,
  107. txt_weight=0, txt_size=8.0,
  108. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.3,
  109. graduation_radius=28,
  110. graduation_thickness=0, graduation_mark_thickness=1,
  111. graduation_unit_angle=27,
  112. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
  113. caption='',
  114. caption_weight=1, caption_size=8.0,
  115. caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.3,
  116. },
  117. {
  118. name='memperc', arg='', max_value=100,
  119. x=85, y=300,
  120. graph_radius=24,
  121. graph_thickness=5,
  122. graph_start_angle=180,
  123. graph_unit_angle=2.7, graph_unit_thickness=2.7,
  124. graph_bg_colour=0xffffff, graph_bg_alpha=0.1,
  125. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.5,
  126. hand_fg_colour=0xEF5A29, hand_fg_alpha=0.0,
  127. txt_radius=10,
  128. txt_weight=0, txt_size=8.0,
  129. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.3,
  130. graduation_radius=23,
  131. graduation_thickness=8, graduation_mark_thickness=2,
  132. graduation_unit_angle=27,
  133. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.5,
  134. caption='',
  135. caption_weight=1, caption_size=8.0,
  136. caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.3,
  137. },
  138. {
  139. name='fs_used_perc', arg='/', max_value=100,
  140. x=85, y=380,
  141. graph_radius=24,
  142. graph_thickness=5,
  143. graph_start_angle=180,
  144. graph_unit_angle=2.7, graph_unit_thickness=2.7,
  145. graph_bg_colour=0xffffff, graph_bg_alpha=0.1,
  146. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.5,
  147. hand_fg_colour=0xEF5A29, hand_fg_alpha=0.0,
  148. txt_radius=34,
  149. txt_weight=0, txt_size=8.0,
  150. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.5,
  151. graduation_radius=28,
  152. graduation_thickness=0, graduation_mark_thickness=1,
  153. graduation_unit_angle=27,
  154. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
  155. caption='/',
  156. caption_weight=1, caption_size=8.0,
  157. caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.5,
  158. },
  159. {
  160. name='fs_used_perc', arg='/media/dune/', max_value=100,
  161. x=85, y=380,
  162. graph_radius=18,
  163. graph_thickness=5,
  164. graph_start_angle=180,
  165. graph_unit_angle=2.7, graph_unit_thickness=2.7,
  166. graph_bg_colour=0xffffff, graph_bg_alpha=0.1,
  167. graph_fg_colour=0xFFFFFF, graph_fg_alpha=0.5,
  168. hand_fg_colour=0xEF5A29, hand_fg_alpha=0.0,
  169. txt_radius=10,
  170. txt_weight=0, txt_size=8.0,
  171. txt_fg_colour=0xFFFFFF, txt_fg_alpha=0.5,
  172. graduation_radius=28,
  173. graduation_thickness=0, graduation_mark_thickness=1,
  174. graduation_unit_angle=27,
  175. graduation_fg_colour=0xFFFFFF, graduation_fg_alpha=0.3,
  176. caption='/data',
  177. caption_weight=1, caption_size=8.0,
  178. caption_fg_colour=0xFFFFFF, caption_fg_alpha=0.5,
  179. },
  180. }
  181.  
  182. -------------------------------------------------------------------------------
  183. -- rgb_to_r_g_b
  184. -- converts color in hexa to decimal
  185. --
  186. function rgb_to_r_g_b(colour, alpha)
  187. return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  188. end
  189.  
  190. -------------------------------------------------------------------------------
  191. -- angle_to_position
  192. -- convert degree to rad and rotate (0 degree is top/north)
  193. --
  194. function angle_to_position(start_angle, current_angle)
  195. local pos = current_angle + start_angle
  196. return ( ( pos * (2 * math.pi / 360) ) - (math.pi / 2) )
  197. end
  198.  
  199. -------------------------------------------------------------------------------
  200. -- draw_clock_ring
  201. -- displays clock
  202. --
  203. function draw_clock_ring(display, data, value)
  204. local max_value = data['max_value']
  205. local x, y = data['x'], data['y']
  206. local graph_radius = data['graph_radius']
  207. local graph_thickness, graph_unit_thickness = data['graph_thickness'], data['graph_unit_thickness']
  208. local graph_unit_angle = data['graph_unit_angle']
  209. local graph_bg_colour, graph_bg_alpha = data['graph_bg_colour'], data['graph_bg_alpha']
  210. local graph_fg_colour, graph_fg_alpha = data['graph_fg_colour'], data['graph_fg_alpha']
  211.  
  212. -- background ring
  213. cairo_arc(display, x, y, graph_radius, 0, 2 * math.pi)
  214. cairo_set_source_rgba(display, rgb_to_r_g_b(graph_bg_colour, graph_bg_alpha))
  215. cairo_set_line_width(display, graph_thickness)
  216. cairo_stroke(display)
  217.  
  218. -- arc of value
  219. local val = (value % max_value)
  220. local i = 1
  221. while i <= val do
  222. cairo_arc(display, x, y, graph_radius,( ((graph_unit_angle * i) - graph_unit_thickness)*(2*math.pi/360) )-(math.pi/2),((graph_unit_angle * i) * (2*math.pi/360))-(math.pi/2))
  223. cairo_set_source_rgba(display,rgb_to_r_g_b(graph_fg_colour,graph_fg_alpha))
  224. cairo_stroke(display)
  225. i = i + 1
  226. end
  227. local angle = (graph_unit_angle * i) - graph_unit_thickness
  228.  
  229. -- graduations marks
  230. local graduation_radius = data['graduation_radius']
  231. local graduation_thickness, graduation_mark_thickness = data['graduation_thickness'], data['graduation_mark_thickness']
  232. local graduation_unit_angle = data['graduation_unit_angle']
  233. local graduation_fg_colour, graduation_fg_alpha = data['graduation_fg_colour'], data['graduation_fg_alpha']
  234. if graduation_radius > 0 and graduation_thickness > 0 and graduation_unit_angle > 0 then
  235. local nb_graduation = 360 / graduation_unit_angle
  236. local i = 1
  237. while i <= nb_graduation do
  238. cairo_set_line_width(display, graduation_thickness)
  239. cairo_arc(display, x, y, graduation_radius, (((graduation_unit_angle * i)-(graduation_mark_thickness/2))*(2*math.pi/360))-(math.pi/2),(((graduation_unit_angle * i)+(graduation_mark_thickness/2))*(2*math.pi/360))-(math.pi/2))
  240. cairo_set_source_rgba(display,rgb_to_r_g_b(graduation_fg_colour,graduation_fg_alpha))
  241. cairo_stroke(display)
  242. cairo_set_line_width(display, graph_thickness)
  243. i = i + 1
  244. end
  245. end
  246.  
  247. -- text
  248. local txt_radius = data['txt_radius']
  249. local txt_weight, txt_size = data['txt_weight'], data['txt_size']
  250. local txt_fg_colour, txt_fg_alpha = data['txt_fg_colour'], data['txt_fg_alpha']
  251. local movex = txt_radius * (math.cos((angle * 2 * math.pi / 360)-(math.pi/2)))
  252. local movey = txt_radius * (math.sin((angle * 2 * math.pi / 360)-(math.pi/2)))
  253. cairo_select_font_face (display, "ubuntu", CAIRO_FONT_SLANT_NORMAL, txt_weight);
  254. cairo_set_font_size (display, txt_size);
  255. cairo_set_source_rgba (display, rgb_to_r_g_b(txt_fg_colour, txt_fg_alpha));
  256. cairo_move_to (display, x + movex - (txt_size / 2), y + movey + 3);
  257. cairo_show_text (display, value);
  258. cairo_stroke (display);
  259. end
  260.  
  261. -------------------------------------------------------------------------------
  262. -- draw_gauge_ring
  263. -- displays gauges
  264. --
  265. function draw_gauge_ring(display, data, value)
  266. local max_value = data['max_value']
  267. local x, y = data['x'], data['y']
  268. local graph_radius = data['graph_radius']
  269. local graph_thickness, graph_unit_thickness = data['graph_thickness'], data['graph_unit_thickness']
  270. local graph_start_angle = data['graph_start_angle']
  271. local graph_unit_angle = data['graph_unit_angle']
  272. local graph_bg_colour, graph_bg_alpha = data['graph_bg_colour'], data['graph_bg_alpha']
  273. local graph_fg_colour, graph_fg_alpha = data['graph_fg_colour'], data['graph_fg_alpha']
  274. local hand_fg_colour, hand_fg_alpha = data['hand_fg_colour'], data['hand_fg_alpha']
  275. local graph_end_angle = (max_value * graph_unit_angle) % 360
  276.  
  277. -- background ring
  278. cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, 0), angle_to_position(graph_start_angle, graph_end_angle))
  279. cairo_set_source_rgba(display, rgb_to_r_g_b(graph_bg_colour, graph_bg_alpha))
  280. cairo_set_line_width(display, graph_thickness)
  281. cairo_stroke(display)
  282.  
  283. -- arc of value
  284. local val = value % (max_value + 1)
  285. local start_arc = 0
  286. local stop_arc = 0
  287. local i = 1
  288. while i <= val do
  289. start_arc = (graph_unit_angle * i) - graph_unit_thickness
  290. stop_arc = (graph_unit_angle * i)
  291. cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc))
  292. cairo_set_source_rgba(display, rgb_to_r_g_b(graph_fg_colour, graph_fg_alpha))
  293. cairo_stroke(display)
  294. i = i + 1
  295. end
  296. local angle = start_arc
  297.  
  298. -- hand
  299. start_arc = (graph_unit_angle * val) - (graph_unit_thickness * 2)
  300. stop_arc = (graph_unit_angle * val)
  301. cairo_arc(display, x, y, graph_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc))
  302. cairo_set_source_rgba(display, rgb_to_r_g_b(hand_fg_colour, hand_fg_alpha))
  303. cairo_stroke(display)
  304.  
  305. -- graduations marks
  306. local graduation_radius = data['graduation_radius']
  307. local graduation_thickness, graduation_mark_thickness = data['graduation_thickness'], data['graduation_mark_thickness']
  308. local graduation_unit_angle = data['graduation_unit_angle']
  309. local graduation_fg_colour, graduation_fg_alpha = data['graduation_fg_colour'], data['graduation_fg_alpha']
  310. if graduation_radius > 0 and graduation_thickness > 0 and graduation_unit_angle > 0 then
  311. local nb_graduation = graph_end_angle / graduation_unit_angle
  312. local i = 0
  313. while i < nb_graduation do
  314. cairo_set_line_width(display, graduation_thickness)
  315. start_arc = (graduation_unit_angle * i) - (graduation_mark_thickness / 2)
  316. stop_arc = (graduation_unit_angle * i) + (graduation_mark_thickness / 2)
  317. cairo_arc(display, x, y, graduation_radius, angle_to_position(graph_start_angle, start_arc), angle_to_position(graph_start_angle, stop_arc))
  318. cairo_set_source_rgba(display,rgb_to_r_g_b(graduation_fg_colour,graduation_fg_alpha))
  319. cairo_stroke(display)
  320. cairo_set_line_width(display, graph_thickness)
  321. i = i + 1
  322. end
  323. end
  324.  
  325. -- text
  326. local txt_radius = data['txt_radius']
  327. local txt_weight, txt_size = data['txt_weight'], data['txt_size']
  328. local txt_fg_colour, txt_fg_alpha = data['txt_fg_colour'], data['txt_fg_alpha']
  329. local movex = txt_radius * math.cos(angle_to_position(graph_start_angle, angle))
  330. local movey = txt_radius * math.sin(angle_to_position(graph_start_angle, angle))
  331. cairo_select_font_face (display, "ubuntu", CAIRO_FONT_SLANT_NORMAL, txt_weight)
  332. cairo_set_font_size (display, txt_size)
  333. cairo_set_source_rgba (display, rgb_to_r_g_b(txt_fg_colour, txt_fg_alpha))
  334. cairo_move_to (display, x + movex - (txt_size / 2), y + movey + 3)
  335. cairo_show_text (display, value)
  336. cairo_stroke (display)
  337.  
  338. -- caption
  339. local caption = data['caption']
  340. local caption_weight, caption_size = data['caption_weight'], data['caption_size']
  341. local caption_fg_colour, caption_fg_alpha = data['caption_fg_colour'], data['caption_fg_alpha']
  342. local tox = graph_radius * (math.cos((graph_start_angle * 2 * math.pi / 360)-(math.pi/2)))
  343. local toy = graph_radius * (math.sin((graph_start_angle * 2 * math.pi / 360)-(math.pi/2)))
  344. cairo_select_font_face (display, "ubuntu", CAIRO_FONT_SLANT_NORMAL, caption_weight);
  345. cairo_set_font_size (display, caption_size)
  346. cairo_set_source_rgba (display, rgb_to_r_g_b(caption_fg_colour, caption_fg_alpha))
  347. cairo_move_to (display, x + tox + 5, y + toy + 1)
  348. -- bad hack but not enough time !
  349. if graph_start_angle < 105 then
  350. cairo_move_to (display, x + tox - 30, y + toy + 1)
  351. end
  352. cairo_show_text (display, caption)
  353. cairo_stroke (display)
  354. end
  355.  
  356. -------------------------------------------------------------------------------
  357. -- go_clock_rings
  358. -- loads data and displays clock
  359. --
  360. function go_clock_rings(display)
  361. local function load_clock_rings(display, data)
  362. local str, value = '', 0
  363. str = string.format('${%s %s}',data['name'], data['arg'])
  364. str = conky_parse(str)
  365. value = tonumber(str)
  366. draw_clock_ring(display, data, value)
  367. end
  368.  
  369. for i in pairs(clock_h) do
  370. load_clock_rings(display, clock_h[i])
  371. end
  372. for i in pairs(clock_m) do
  373. load_clock_rings(display, clock_m[i])
  374. end
  375. for i in pairs(clock_s) do
  376. load_clock_rings(display, clock_s[i])
  377. end
  378. end
  379.  
  380. -------------------------------------------------------------------------------
  381. -- go_gauge_rings
  382. -- loads data and displays gauges
  383. --
  384. function go_gauge_rings(display)
  385. local function load_gauge_rings(display, data)
  386. local str, value = '', 0
  387. str = string.format('${%s %s}',data['name'], data['arg'])
  388. str = conky_parse(str)
  389. value = tonumber(str)
  390. draw_gauge_ring(display, data, value)
  391. end
  392.  
  393. for i in pairs(gauge) do
  394. load_gauge_rings(display, gauge[i])
  395. end
  396. end
  397.  
  398. -------------------------------------------------------------------------------
  399. -- MAIN
  400. function conky_main()
  401. if conky_window == nil then
  402. return
  403. end
  404.  
  405. local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  406. local display = cairo_create(cs)
  407.  
  408. local updates = conky_parse('${updates}')
  409. update_num = tonumber(updates)
  410.  
  411. if update_num > 5 then
  412. go_clock_rings(display)
  413. go_gauge_rings(display)
  414. end
  415.  
  416. end
RAW Paste Data