Transparency in conky (en)

From Conky PitStop

Revision as of 20:47, 10 August 2012 by Sector11 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Transparency in conky

 Language   English   Français   


DK75 started with ARGB Visual for true transparency with the conky command:

own_window_argb_visual yes

And it's good as long as you don't use LUA or IMLIB, the ${image} command built into new conky along with COMPIZ in your system.

This part looks at xcompmgr and compton composite managers in OpenBox

Conky and true transparency works different depending on the composite manager in use.

# compton start-up command used by CrunchBang's compositing pipemenu.
# See 'man compton' for details about how to modify these settings.

## Basic
#EXECXCOMP='compton -cC -G -b'

## Less basic - tip: uncomment below and comment out above, then restart
#EXECXCOMP='compton -cC -fF -I 0.065 -O 0.065 -D 6 -m 0.8 -G -b'

## Sector11 - transparent everything - no shadow
EXECXCOMP='compton -fF -I 0.8 -O 0.8 -D 1 -m 0.9 -G -b'[/code]

NO COMPOSITE MANAGER RUNNING

No-composite.png
# compton start-up command used by CrunchBang's compositing pipemenu.
# See 'man compton' for details about how to modify these settings.

## Basic
#EXECXCOMP='compton -cC -G -b'

## Less basic - tip: uncomment below and comment out above, then restart
#EXECXCOMP='compton -cC -fF -I 0.065 -O 0.065 -D 6 -m 0.8 -G -b'

## Sector11 - transparent everything - no shadow
EXECXCOMP='compton -fF -I 0.8 -O 0.8 -D 1 -m 0.9 -G -b'

it's a white background with white text - not nice.

The first conky is using two instances, above TEXT, of draw-bk.lua & no composite manager required, but limited to two if not using another lua script for the "_pre" & "_post" elements; one black one white:

lua_load ~/Conky/LUA/draw-bg.lua
lua_draw_hook_pre draw_bg 30 0 0 0 0 0x000000 0.5
lua_draw_hook_post draw_bg 30 15 15 175 340 0xFFFFFF 0.3
#
TEXT

The red conky I'm using three calls for draw-bk.lua under TEXT and it requires a composite manager or it blinks off-on as a window moved over it. Watch it blink video

lua_load ~/Conky/LUA/draw-bg.lua
TEXT
${lua conky_draw_bg 30 0 0 0 0 0xff0000 0.3}\
${lua conky_draw_bg 30 15 15 175 340 0x000000 0.4}\
${lua conky_draw_bg 0 20 60 160 30 0xff00ff 0.3}\
${alignc}${cpubar cpu0 0,20} Sector11 ${cpubar cpu0 0,20}

The third conky is using the normal transparency calls in conky and is transparent with or without a composite manager there is NO lua script running:

Notice that '# own_window_argb_visual yes' and '# own_window_argb_value 0' are commented out.

WITH A COMPOSITE MANAGER RUNNING


So what do we do for that last one. Turn on a composite manager and then:

That third step, with a value of 0, will give you 100% transparency, the real deal, not the pseudo transparency that conky 3 has (it redraws the background behind the conky window).

Here it is set to:

Composite.png

Last but not least: draw-bk.lua (once again)

--[[Background originally by londonali1010 (2009)
   ability to set any size for background mrpeachy 2011
   ability to set variables for bg in conkyrc dk75

the change is that if you set width and/or height to 0
then it assumes the width and/or height of the conky window

so:

Above and After TEXT  (requires a composite manager or it blinks!)

 lua_load ~/wea_conky/draw_bg.lua
 TEXT
 ${lua conky_draw_bg 10 0 0 0 0 0x000000 0.4}

OR Both above TEXT (no composite manager required - no blinking!)

 lua_load ~/wea_conky/draw_bg.lua
 lua_draw_hook_pre draw_bg 10 0 0 0 0 0x000000 0.5
 TEXT

Note
${lua conky_draw_bg 20 0 0 0 0 0x000000 0.4}
  See below:        1  2 3 4 5 6        7

${lua conky_draw_bg corner_radius x_position y_position width height color alpha}

covers the whole window and will change if you change the minimum_size setting

1 = 20             corner_radius
2 = 0             x_position
3 = 0             y_position
3 = 0             width
5 = 0             height
6 = 0x000000      color
7 = 0.4           alpha

]]

require 'cairo'
local    cs, cr = nil
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(r,x,y,w,h,color,alpha)
if conky_window == nil then return end
if cs == nil then cairo_surface_destroy(cs) end
if cr == nil then cairo_destroy(cr) end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
local cr = cairo_create(cs)
w=w
h=h
if w=="0" then w=tonumber(conky_window.width) end
if h=="0" then h=tonumber(conky_window.height) end
cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
--top left mid circle
local xtl=x+r
local ytl=y+r
--top right mid circle
local xtr=(x+r)+((w)-(2*r))
local ytr=y+r
--bottom right mid circle
local xbr=(x+r)+((w)-(2*r))
local ybr=(y+r)+((h)-(2*r))
--bottom right mid circle
local xbl=(x+r)
local ybl=(y+r)+((h)-(2*r))
-----------------------------
cairo_move_to (cr,xtl,ytl-r)
cairo_line_to (cr,xtr,ytr-r)
cairo_arc(cr,xtr,ytr,r,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+r,ybr)
cairo_arc(cr,xbr,ybr,r,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+r)
cairo_arc(cr,xbl,ybl,r,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-r,ytl)
cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_fill (cr)
------------------------------------------------------------
cairo_surface_destroy(cs)
cairo_destroy(cr)
return ""
end</code>

Different settings with compton:

Different-settings.png

Thanks to PackRat for reminding me I've wanted to do this for a while now, you gave me the perfect opening.

Personal tools
Namespaces
Variants
Actions
Navigation
English
Français
Toolbox