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