Created
March 26, 2015 22:23
-
-
Save y0an/24677808fbdbc1e20a50 to your computer and use it in GitHub Desktop.
draw_bg.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Background by londonali1010 (2009) | |
This script draws a background to the Conky window. It covers the whole of the Conky window, but you can specify rounded corners, if you wish. | |
To call this script in Conky, use (assuming you have saved this script to ~/scripts/): | |
lua_load ~/scripts/draw_bg.lua | |
lua_draw_hook_pre draw_bg | |
Changelog: | |
+ v1.0 -- Original release (07.10.2009) | |
]] | |
-- Change these settings to affect your background. | |
-- "corner_r" is the radius, in pixels, of the rounded corners. If you don't want rounded corners, use 0. | |
corner_r=35 | |
-- Set the colour and transparency (alpha) of your background. | |
bg_colour=0x333333 | |
bg_alpha=0.6 | |
require 'cairo' | |
function rgb_to_r_g_b(colour,alpha) | |
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha | |
end | |
function conky_draw_bg() | |
if conky_window==nil then return end | |
local w=conky_window.width | |
local h=conky_window.height | |
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h) | |
cr=cairo_create(cs) | |
cairo_move_to(cr,corner_r,0) | |
cairo_line_to(cr,w-corner_r,0) | |
cairo_curve_to(cr,w,0,w,0,w,corner_r) | |
cairo_line_to(cr,w,h-corner_r) | |
cairo_curve_to(cr,w,h,w,h,w-corner_r,h) | |
cairo_line_to(cr,corner_r,h) | |
cairo_curve_to(cr,0,h,0,h,0,h-corner_r) | |
cairo_line_to(cr,0,corner_r) | |
cairo_curve_to(cr,0,0,0,0,corner_r,0) | |
cairo_close_path(cr) | |
cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha)) | |
cairo_fill(cr) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment