SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1126 2014-12-16 06:12:33

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Nope. Not working. sad

First I tried it like this:

button1=do_button({settings,settings,settings})
if button1==0 then
--do stuff when button is off
elseif button1==1 then
--do stuff if button is on
end

It started ok, but when you put the cursor on the corner button, all the other buttons started to slowly flicker, about 1/2 second off, 1/2 second on.

So I did it like this:

if tonumber(conky_parse('${updates}')) < 2 then
conky0_started = false
conky1_started = false
conky2_started = false
conky3_started = false
conky4_started = false
conky5_started = false
conky6_started = false
end

--setup buttons here
function button_settings()

	button0=do_button({btype=1,bname="conkybutton0",blx_off=0,bly_off=24,bw_off=45,bh_off=20,text=0,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={""},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={""}})
	if ((button0 == 0) and (conky0_started == true)) then
	elseif ((button0 == 1) and (conky0_started == false)) then

	button1=do_button({btype=1,bname="conkybutton1",blx_off=50,bly_off=24,bw_off=55,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"TINT2"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"TINT2"}})
	if ((button1 == 0) and (conky1_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.config/tint2/tint2rc'")--do stuff when button is off
	conky1_started = false
	elseif ((button1 == 1) and (conky1_started == false)) then
	os.execute("tint2 -c '/home/bernardo/.config/tint2/tint2rc' &")--do stuff if button is on
	conky1_started = true
	end

	button2=do_button({btype=2,bname="conkybutton2",blx_off=110,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"SYSTEM"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"SYSTEM"}})
	if ((button2 == 0) and (conky2_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/system.conky'")--do stuff when button is off
	conky2_started = false
	elseif ((button2 == 1) and (conky2_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/system.conky' &")--do stuff if button is on
	conky2_started = true
	end

	button3=do_button			({btype=2,bname="conkybutton3",blx_off=185,bly_off=24,bw_off=60,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CLOCK"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CLOCK"}})
	if ((button3 == 0) and (conky3_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/tintclock.conky'")--do stuff when button is off
	conky3_started = false
	elseif ((button3 == 1) and (conky3_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/tintclock.conky' &")--do stuff if button is on
	conky3_started = true
	end

	button4=do_button	({btype=2,bname="conkybutton4",blx_off=250,bly_off=24,bw_off=90,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CALENDAR"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CALENDAR"}})
	if ((button4 == 0) and (conky4_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/calendar.conky'")--do stuff when button is off
	conky4_started = false
	elseif ((button4 == 1) and (conky4_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/calendar.conky' &")--do stuff if button is on
	conky4_started = true
	end

	button5=do_button({btype=2,bname="conkybutton5",blx_off=345,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"MARKET"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"MARKET"}})
	if ((button5 == 0) and (conky5_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/dolar.conky'")--do stuff when button is off
	conky5_started = false
	elseif ((button5 == 1) and (conky5_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/dolar.conky' &")--do stuff if button is on
	conky5_started = true
	end

	button6=do_button		({btype=2,bname="conkybutton6",blx_off=420,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"BDATES"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"BDATES"}})
	if ((button6 == 0) and (conky6_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/dates.conky'")--do stuff when button is off
	conky6_started = false
	elseif ((button6 == 1) and (conky6_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/dates.conky' &")--do stuff if button is on
	conky6_started = true
	end
	conky0_started = true
	end
	
end--function button_settings

and it's even worse: it flickers once, and it's gone.

Sorry Arclance to be this dumb. Can you give me a hand? sad

Offline

Help fund CrunchBang, donate to the project!

#1127 2014-12-17 00:32:21

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 932

Re: interactive conky

You don't need to do the conky0_started stuff for the invisible button since it is not controlling any programs.
It will only run once the way you have it now because of that.

This should do what you want.

if tonumber(conky_parse('${updates}')) < 2 then
conky1_started = false
conky2_started = false
conky3_started = false
conky4_started = false
conky5_started = false
conky6_started = false
end

--setup buttons here
function button_settings()

	button0=do_button({btype=1,bname="conkybutton0",blx_off=0,bly_off=24,bw_off=45,bh_off=20,text=0,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={""},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={""}})
	if (button0 == 1) then -- Only Do something When Button is on
	
		button1=do_button({btype=1,bname="conkybutton1",blx_off=50,bly_off=24,bw_off=55,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"TINT2"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"TINT2"}})
		if ((button1 == 0) and (conky1_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.config/tint2/tint2rc'")--do stuff when button is off
			conky1_started = false
		elseif ((button1 == 1) and (conky1_started == false)) then
			os.execute("tint2 -c '/home/bernardo/.config/tint2/tint2rc' &")--do stuff if button is on
			conky1_started = true
		end

		button2=do_button({btype=2,bname="conkybutton2",blx_off=110,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"SYSTEM"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"SYSTEM"}})
		if ((button2 == 0) and (conky2_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/system.conky'")--do stuff when button is off
			conky2_started = false
		elseif ((button2 == 1) and (conky2_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/system.conky' &")--do stuff if button is on
			conky2_started = true
		end

		button3=do_button			({btype=2,bname="conkybutton3",blx_off=185,bly_off=24,bw_off=60,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CLOCK"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CLOCK"}})
		if ((button3 == 0) and (conky3_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/tintclock.conky'")--do stuff when button is off
			conky3_started = false
		elseif ((button3 == 1) and (conky3_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/tintclock.conky' &")--do stuff if button is on
			conky3_started = true
		end

		button4=do_button	({btype=2,bname="conkybutton4",blx_off=250,bly_off=24,bw_off=90,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CALENDAR"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CALENDAR"}})
		if ((button4 == 0) and (conky4_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/calendar.conky'")--do stuff when button is off
			conky4_started = false
		elseif ((button4 == 1) and (conky4_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/calendar.conky' &")--do stuff if button is on
			conky4_started = true
		end

		button5=do_button({btype=2,bname="conkybutton5",blx_off=345,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"MARKET"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"MARKET"}})
		if ((button5 == 0) and (conky5_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/dolar.conky'")--do stuff when button is off
			conky5_started = false
		elseif ((button5 == 1) and (conky5_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/dolar.conky' &")--do stuff if button is on
			conky5_started = true
		end

		button6=do_button		({btype=2,bname="conkybutton6",blx_off=420,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"BDATES"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"BDATES"}})
		if ((button6 == 0) and (conky6_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/dates.conky'")--do stuff when button is off
			conky6_started = false
		elseif ((button6 == 1) and (conky6_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/dates.conky' &")--do stuff if button is on
			conky6_started = true
		end

	end
	
end--function button_settings

I removed the if "button0==0" part of the if statement since you don't need it if you do nothing in that case.
You can add it back if that changes in the future.

Offline

#1128 2014-12-17 01:16:19

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

I tried the code you just posted. It keeps flickering... sad

Offline

#1129 2014-12-17 17:45:43

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 932

Re: interactive conky

^ I don't know then it might have something to do with the button script you are using with your code.

Offline

#1130 2014-12-18 23:13:54

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Ok, thank you Arclance for everything.
I'll keep on reading the Lua book, see if I can figure something out.

Offline

#1131 2014-12-19 01:49:34

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Ok, here's an update.
Being that I don't really know what I'm doing, I decided to go for broke, and pretty much start all over again... after backing up the file.
So I stripped the script, leaving only the invisible button, and one function button with no other function than to just show up on screen.
BTW: this IS the buttons.lua script.

Here's the whole script, then:

--[[buttons by mrpeachy - thanks to barrybarrykelly for the xdotool method, gmonti for finding the deb files for the xdotool and arclance for xdotool error catching
see here for instructions: http://crunchbanglinux.org/forums/post/245759/#p245759
]]

conky_name="interactiveconkyrc"
click_data_file ="/tmp/xdo"



--setup buttons here
function button_settings()

	button2=do_button({btype=1,bname="conkybutton2",blx_off=0,bly_off=24,bw_off=45,bh_off=30,text=0,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={""},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={""}})

 

	button1=do_button({btype=1,bname="conkybutton1",blx_off=50,bly_off=24,bw_off=55,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"TINT2"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"TINT2"}})

	
end--function button_settings

require 'cairo'
require 'imlib2'
function conky_start_xdo(rc_info)--######################################################
click_data_file=rc_info or click_data_file
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
os.execute("xdotool search --sync --classname 'conky' behave %@ mouse-click getmouselocation 2> /dev/null >> "..click_data_file.." &")
rc_info=nil
end--of function ########################################################################

function conky_stop_xdo()--##############################################################
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
end--of function ########################################################################

buttons={}--#############################################################################
click_table={}--#########################################################################
start=1
function conky_get_mouse(rc_info)--######################################################
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs)
--#######################################################################################
if rc_info~=nil then
rc_info=loadstring("return" .. rc_info)()
end
--start click logging and calculations ##################################################
--#######################################################################################
if start==1 then
current_update=tonumber(conky_parse("${updates}"))
start=0
end
local updates=tonumber(conky_parse("${updates}"))
if updates==(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
local conky_name=rc_info[1] or conky_name
print ("own_window_title="..conky_name)
local f=io.popen("xwininfo -all -int -tree -name '"..conky_name.."'")
windata = f:read("*a")
f:close()
local windata=string.lower(windata)
local s,f,x=string.find(windata,"absolute%supper%pleft%sx%p%s*(%p*%d*)")
local s,f,y=string.find(windata,"absolute%supper%pleft%sy%p%s*(%p*%d*)")
local s,f,p=string.find(windata,"parent%swindow%sid%p%s(%d*)%s")
local s,f,w=string.find(windata,"xwininfo%p%swindow%sid%p%s(%d*)%s")
xwin={x,y,p,w,click_data_file}--don't blank with nil
print (xwin[1],xwin[2],xwin[3],xwin[4],xwin[5])
elseif updates<(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
xwin={0,0,0,0,click_data_file}
end--if updates== #######################################################################
--click calculations ####################################################################
--get now location and window id ########################################################
local f = io.popen("xdotool getmouselocation 2> /dev/null")
mousenow=(f:read())
f:close()
local mousenow=string.lower(mousenow or "x:0 y:0 window:0 ")
local s,f,mousenowx=string.find(mousenow,"x%p(%d*)%s")
local s,f,mousenowy=string.find(mousenow,"y%p(%d*)%s")
local s,f,xwinid=string.find(mousenow,"window%p(%d*)")
local localnowx=(tonumber(mousenowx) or 0)-xwin[1]
local localnowy=(tonumber(mousenowy) or 0)-xwin[2]
--read file if windowid matches
if tonumber(xwin[3])==tonumber(xwinid) or tonumber(xwin[4])==tonumber(xwinid) then
	local f = io.open(xwin[5])
        click = f:read()
        f:close()
	--get click location
	if click==nil then click="x:0 y:0 window:0 " else print (click) end
	local s,f,mousex=string.find(click,"x%p(%d*)%s")
	local s,f,mousey=string.find(click,"y%p(%d*)%s")
	local localx=(tonumber(mousex) or 0)-xwin[1]
	local localy=(tonumber(mousey) or 0)-xwin[2]
	click_table[1]=localx
	click_table[2]=localy
	click_table[3]=localnowx
	click_table[4]=localnowy
	click=nil
	--blank file
	local f = io.open(xwin[5],"w")
	f:write("")
	f:close() 
else
	click_table[1]=0
	click_table[2]=0
	click_table[3]=0
	click_table[4]=0
end--window id matching
button_settings()
mousenow=nil
windata=nil
rc_info=nil
f=nil
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end-- end getmouse function #############################################################
--#######################################################################################

function do_button(bd)
if bd.btype==nil then
bd=loadstring("return" .. bd)()
end
local localx=click_table[1]	or 0
local localy=click_table[2]	or 0
local localnowx=click_table[3]	or 0
local localnowy=click_table[4]	or 0
local button_name=bd.bname
local st_type=bd.st_type	or 0
local btype=bd.btype		or 1
local on_on_on=bd.on_on_on	or {}
local on_on_off=bd.on_on_off	or {}
local off_on_on=bd.off_on_on	or {}
local off_on_off=bd.off_on_off	or {}
local return_co=bd.return_co	or 0
--#######################################################################################
--#######################################################################################
--initialize button
if buttons[tostring(button_name)]==nil then
	if btype~=4 and st_type==0 then --button is off on start
	buttons[tostring(button_name)]=0
	elseif btype~=4 and st_type==1 then --button is on on start
	buttons[tostring(button_name)]=1
	elseif btype==4 then
	buttons[tostring(button_name)]=1
	end
end
--set mouse point type
if btype==1 or btype==3 or btype==4 then
--on off execute or cycle
localx=localx
localy=localy
elseif btype==2 then
--mouse over
localx=localnowx
localy=localnowy
else
print ("button type not set")
end
--set click area if on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
--button is off
blx=bd.blx_off
bly=bd.bly_off
bw=bd.bw_off
bh=bd.bh_off
elseif btype~=4 and buttons[tostring(button_name)]==1 then
--button is on
blx=bd.blx_on or bd.blx_off
bly=bd.bly_on or bd.bly_off
bw=bd.bw_on or bd.bw_off
bh=bd.bh_on or bd.bh_off
elseif btype==4 then
local blxt=bd.blx_cyc
local blyt=bd.bly_cyc
local bwt=bd.bw_cyc
local bht=bd.bh_cyc
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
blx=blxt[set] or blxt[#blxt]
bly=blyt[set] or blyt[#blyt]
bw=bwt[set] or bwt[#bwt]
bh=bht[set] or bht[#bht]
end
--set mechanism based on button type
if btype==1 then --on off ###############################################################
--if click is inside box and button is not on - turn on
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
elseif localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end
end --if btype==1########################################################################
if btype==2 then --mouse over ###########################################################
--if mouse is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end --if mouse inside
end --if btype==3########################################################################
if btype==3 then --execte ###############################################################
--if mouse click is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse click is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end--if click inside
end --if btype==3########################################################################
if btype==4 then --cycle ################################################################
local cynum=bd.cynum
--if mouse click is inside box
	if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
		if buttons[tostring(button_name)]+1>cynum then
		buttons[tostring(button_name)]=1
		else
		buttons[tostring(button_name)]=buttons[tostring(button_name)]+1
		end
	end--if click inside
end --if btype==4########################################################################
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end
--draw ##################################################################################
local draw=bd.draw or 0
if draw==1 then--########################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
dtype=bd.dtype_off  or 1
--fill when off
dfblx=bd.dfxadj_off or 0
dfbly=bd.dfyadj_off or 0
dfw=bd.dfw_off      or bw
dfh=bd.dfh_off      or bh
dfcr=bd.dfcr_off    or 0
dfcol=bd.dfcol_off  or 0xffffff
dfal=bd.dfal_off    or 1
--outline when off
doblx=bd.doxadj_off or 0
dobly=bd.doyadj_off or 0
dow=bd.dow_off      or bw
doh=bd.doh_off      or bh
docr=bd.docr_off    or 0
docol=bd.docol_off  or 0xffffff
doal=bd.doal_off    or 1
dolw=bd.dolw_off    or 1
elseif btype~=4 and buttons[tostring(button_name)]==1 then--draw on and button on
dtype=bd.dtype_on  or bd.dtype_off or 1
--fill when on
dfblx=bd.dfxadj_on or 0
dfbly=bd.dfyadj_on or 0
dfw=bd.dfw_on      or bw
dfh=bd.dfh_on      or bh
dfcr=bd.dfcr_on    or 0
dfcol=bd.dfcol_on  or 0xff0000
dfal=bd.dfal_on    or 1
--outline when on
doblx=bd.doxadj_on or 0
dobly=bd.doyadj_on or 0
dow=bd.dow_on      or bw
doh=bd.doh_on      or bh
docr=bd.docr_on    or 0 
docol=bd.docol_on  or 0xff0000
doal=bd.doal_on    or 1
dolw=bd.dolw_on    or 1
--#######################################################################################
elseif btype==4 then --##################################################################
--#######################################################################################
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
--set draw type
dtypet=bd.dtype_cyc or {1}
dtype=dtypet[set] or dtypet[#dtypet]
--fill cycle
local dfblxt=bd.dfxadj_cyc or {0}
local dfblyt=bd.dfyadj_cyc or {0}
local dfwt=bd.dfw_cyc      or {bw}
local dfht=bd.dfh_cyc      or {bh}
local dfcrt=bd.dfcr_cyc    or {0}
local dfcolt=bd.dfcol_cyc  or {0xffffff}
local dfalt=bd.dfal_cyc    or {1}
dfblx=dfblxt[set] or dfblxt[#dfblxt] or 0
dfbly=dfblyt[set] or dfblyt[#dfblyt] or 0
dfw=dfwt[set]     or dfwt[#dfwt]     or bw
dfh=dfht[set]     or dfht[#dfht]     or bh
dfcr=dfcrt[set]   or dfcrt[#dfcrt]   or 0
dfcol=dfcolt[set] or dfcolt[#dfcolt] or 0xffffff
dfal=dfalt[set]   or dfalt[#dfalt]   or 1
--outline cycle
local doblxt=bd.doxadj_off or {0}
local doblyt=bd.doyadj_off or {0}
local dowt=bd.dow_off      or {bw}
local doht=bd.doh_off      or {bh}
local docrt=bd.docr_off    or {0}
local docolt=bd.docol_off  or {0xffffff}
local doalt=bd.doal_off    or {1}
local dolwt=bd.dolw_off    or {1}    
doblx=doblxt[set] or doblxt[#doblxt] or 0
dobly=doblyt[set] or doblyt[#doblyt] or 0
dow=dowt[set]     or dowt[#dowt]     or bw
doh=doht[set]     or doht[#doht]     or bh
docr=docrt[set]   or docrt[#docrt]   or 0
docol=docolt[set] or docolt[#docolt] or 0xff0000
doal=doalt[set]   or doalt[#doalt]   or 1
dolw=dolwt[set]   or dolwt[#dolwt]   or 1
else
print ("error4")
end--check btype and button on off
--#######################################################################################
--draw based on type
if dtype==1 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
elseif dtype==2 then
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
elseif dtype==3 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
end
end--if draw=1 ##########################################################################
local image=bd.image or 0
if image==1 then--#######################################################################
if btype~=4 and buttons[tostring(button_name)]==0 then
file=tostring(bd.im_file_off)
if file==nil then print("set image file") end
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype~=4 and buttons[tostring(button_name)]==1 then
file=tostring(bd.im_file_on)
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype==4 then
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local file=bd.im_file_cyc or {}
file=file[set]
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
end--btype test
end--if image ###########################################################################
local text=bd.text
if text==1 then --#######################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
local txt=bd.txt_off   or {"text"}
local font=bd.font_off or {"mono"}
local fs=bd.fs_off     or {12}
local fx=bd.fxadj_off  or {0}
local fy=bd.fyadj_off  or {0}
local fcol=bd.fcol_off or {0x000000}
local fal=bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype~=4 and buttons[tostring(button_name)]==1 then
local txt=bd.txt_on   or bd.txt_off   or {"text"}
local font=bd.font_on or bd.font_off  or {"mono"}
local fs=bd.fs_on     or bd.fs_off    or {12}
local fx=bd.fxadj_on  or bd.fxadj_off or {0}
local fy=bd.fyadj_on  or bd.fyadj_off or {0}
local fcol=bd.fcol_on or bd.fcol_off  or {0x000000}
local fal=bd.fal_on   or bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype==4 then
--text for cycle trype button
--into tables round 1
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local txtt=bd.txt_cyc   or {{"text"}}
local fontt=bd.font_cyc or {{"mono"}}
local fst=bd.fs_cyc     or {{12}}
local fxt=bd.fxadj_cyc  or {{0}}
local fyt=bd.fyadj_cyc  or {{0}}
local fcolt=bd.fcol_cyc or {{0x000000}}
local falt=bd.fal_cyc   or {{1}}
--into tables round 2
local txt=txtt[set]    or txtt[#txtt]
local font=fontt[set]  or fontt[#fontt]
local fs=fst[set]      or fst[#fst]
local fx=fxt[set]      or fxt[#fxt]
local fy=fyt[set]      or fyt[#fyt]
local fcol=fcolt[set]  or fcolt[#fcolt]
local fal=falt[set]    or falt[#falt]
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
else
print ("error with text")
end--if buttons[]==0
end--if text==1 #########################################################################
--#######################################################################################
if return_co==0 then
return tonumber(buttons[tostring(button_name)])
elseif return_co==1 then
return tonumber(buttons[tostring(button_name)]),localnowx,localnowy
end--return settings
end-- end button calculations function ##################################################
--#######################################################################################

function conky_rc_button(bd)--function to setup button in conkyrc
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
--#######################################################################################
send=do_button(bd)
--#######################################################################################
end--if updates>3
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return send or 0
end-- end main function

I've even changed the button number to 2, just in case the program had a problem with a button "0".
So, I started it, and... it worked. No functions, of course, but the button did show up on screen, and there was no flickering whatsoever.

So I then added the " if button2 == 1 then" line, and ended the function... and the flickering came back

So, somehow, it's the if-then branch that's causing the flickering. Don't ask me why (I'm not that good...yet), but the fact is that, when I add it, all hell breaks lose.

Now, on the tutorial on page 13, MrPeachy talks about some "off_on_on, off_on_off, etc." functions, for a button to control other buttons but offers no further explanation about them. Maybe those are the functions I should be using? In any case, what would be the right way to use those functions?

Offline

#1132 2014-12-20 01:39:49

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 932

Re: interactive conky

I don't know.
This must be a quirk of MrPeachys button script which I don't use as is so I don't know anything about it.

Offline

#1133 2014-12-20 03:26:28

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Don't worry about it. Thank you for trying.
I will figure it out... eventually.  tongue

Offline

#1134 2014-12-20 04:24:26

tknomanzr
#! CrunchBanger
From: Heavener, OK
Registered: 2014-12-09
Posts: 158

Re: interactive conky

local on_on_on=bd.on_on_on	or {}
local on_on_off=bd.on_on_off	or {}
local off_on_on=bd.off_on_on	or {}
local off_on_off=bd.off_on_off	or {}

those are locally declared variable to this function:

function do_button(bd)

As far as the code, I would suspect the draw function if you are getting flickering, like it is redrawing the whole window instead of just the buttons. You may need to check that function and start outputting variables to see if you are getting expected output. Sorry I can't be much more help. I am not very familiar with lua and am mostly just trying to translate from languages and concepts I do know.

Offline

#1135 2014-12-20 06:18:56

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Yeah, I could figure the on_on_off part already. It has nothing to do with the buttons showing or not. It's actually for the displayed information to be turned on or off.
As of now, I'm reading on MrPeachy's lua how-to. I will report back as soon as I can find a solution. smile

Offline

#1136 2014-12-20 15:12:50

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 13,284
Website

Re: interactive conky

^ just so you know I have been looking for an interactive conky here using the button lua script - that works.  I've found a few that don't work ... but I know someplace in the conky catacombs here there is one that does.

When I find it ....

Offline

#1137 2014-12-20 21:33:05

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Sector11 wrote:

When I find it ....

Well, if somebody CAN find it, it's you.
So, I will be waiting... tongue

Offline

#1138 2014-12-20 22:31:26

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 13,284
Website

Re: interactive conky

Can't find it here ... BUT I found it online here.  I'll have to download it and try it again  big_smile

Go figure .. I was looking for something else and there it was!

Offline

#1139 2014-12-20 23:33:05

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Hmmm... a few days ago I saw a video of a conky with a gazillion buttons. I would KILL to find it again, and to get my hands on its lua script.
I'd also love to get Falldown's interactive weather conky's lua script, but, as far as I know, he has never posted it... sad

Offline

#1140 2014-12-21 01:07:15

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 13,284
Website

Re: interactive conky

You Tube:
One by falldown and on the right - a few more.

Then there is this: Interactive Weather v9000 and of course the video  The problem is the tar.gz is no more.  sad

Offline

#1141 2014-12-21 01:18:48

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Sector11 wrote:

You Tube:
One by falldown and on the right - a few more.

I saw that one. The one I'm talking about was just rows upon rows of plain, square buttons with rounded corners. Nothing fancy. I even saw videos of it, but now I can't find it. sad

Ohhh, I would KILL to get my hands on Falldown's V9000 lua script...

Offline

#1142 2014-12-21 01:22:35

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 932

Re: interactive conky

My weather script has nested buttons that work correctly.
The button code in mine is only based on an early version of MrPeachys button code and does not use his actual button script though.
The script is quite large so it could be hard to figure out on your own since it was not written to be as user friendly as MrPeachys was.

Last edited by arclance (2014-12-21 01:24:40)

Offline

#1143 2014-12-25 22:24:03

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

Thank you Arclance, will look at it soon. Right now, I'm reading a book on Lua, see if I can figure out some things myself.

But meanwhile (and talking about figuring things out myself), I just ran into a bit of an issue, and it's got me completely puzzled:

A couple of days ago, I had an epiphany: what I had to do to switch the buttons on an off was to MAKE ANOTHER CONKY!!! cool

So that I did. I created an extra conky/lua combo, with the sole purpose of putting the master button (as I called it) on the screen, and to call the original conky/lua combo (with all the other buttons) on and off.

And here's the problem: the master button turns the other buttons on as soon as you put the cursor on it, as if it was a mouseover type button (and it's not), and keeps turning them on and off for as long as the cursor is over it. Now, if you click on it when the other buttons are on, and immediately move off of it, it will turn them on and off perfectly, but if you click when the other buttons are not showing, or if you click and keep the cursor on the master button, all the buttons will keep on flickering slowly (about twice a second, I'd say).

To make it even stranger, both the conky and lua scripts are copy/paste jobs of the scrips I'm using for the other buttons, which are working perfectly (including an on/off button I have to call tint2, which works exactly as expected).

So... is there something I may be missing? Here are the scripts:

This is the conky for the master button:

# killall conky && conky -c /home/bernardo/.iconky/Interactive.conky &

##############################################
#  Settings
##############################################
max_specials 10000
max_user_text 15000
background no
use_xft yes
xftfont sans:size=9
xftalpha 1
total_run_times 0
own_window yes
own_window_argb_visual yes
own_window_transparent yes
own_window_type normal
own_window_title Interactiveconky ##name must be unique from all other file names
own_window_hints undecorated,above,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 50 25
maximum_width 50
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders yes
default_color white
default_shade_color black
default_outline_color white
alignment top_left
gap_x 0
gap_y 0
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale yes
color1 86acad #darker blue
color2 b1c9c9 #lighter blue
text_buffer_size 100000
top_name_width 5
update_interval 1

## lua_functions setup ####################################################################################
## background #############################################################################################
# ${lua draw_bg {r=,x=,y=,w=,h=,dr=,fc=,fa=,lw=,lc=,la=}}
#	r=corner radius
#	x=x position top left
#	y=y position top left
#	w=width of background, set 0 to set to conky window width
#	h=height of background, set 0 to set to conky window height
#	dr=draw type, 1=filled in, 2=outline, 3=fill and outline
#	fc=fill color, eg 0xffffff=white, only need for fill type 1 or 3
#	fa=fill alpha, eg 1=full opaque, only need for fill type 1 or 3
#	lw=line width in, only need for fill type 2 or 3
#	lc=line color, eg 0xffffff=white, only need for fill type 2 or 3
#	la=line alpha, eg 1=full opaque, only need for fill type 2 or 3
## gradient bars ##########################################################################################
#${lua gradbar {x=,y=,v="",vmax=,dn=,dw=,dh=,dg=,bc=,ba=,sc=,sa=,mc=,ma=,ec=,ea=}}
#	x=x position top left
#	y=y position top left
#	v=conky value to display, eg "${cpu cu0}" or "${memperc}" conky object must be in quotes
#	vmax=max value of conky object set above
#	dn=number of divisions
#	dw=width of divisions
#	dh=height of divisions
#	dg=gap between divisions
#	bd=background color
#	ba=background alpha
#	sc=start color
#	sa=start alpha
#	mc=middle color
#	ma=middle alpha
#	ec=end color
#	ea=end alpha
## calendar ###############################################################################################
#${lua luacal {x=,y=,tf="",tfs=,tc=,ta=,bf="",bfs=,bc=,ba=,hf="",hfs=,hc=,ha=,sp="",gc=,gt=,gr=,sd=}}
#	x=x position top left
#	y=y position top left
#	tf=title font, eg "mono" must be in quotes
#	tfs=title font size
#	tc=title color
#	ta=title alpha
#	bf=body font, eg "mono" must be in quotes
#	bfs=body font size
#	bc=body color
#	ba=body alpha
#	hf=highlight font, eg "mono" must be in quotes
#	hfs=highlight font size
#	hc=highlight color
#	ha=highlight alpha
#	sp=spacer, eg " " ... 0,1 or 2 spaces can help with positioning of non-monospaced fonts
#	gt=gap from title to body
#	gh=gap horizontal between columns
#	gv=gap vertical between rows
#	sd=start day, 0=Sun, 1=Mon
## textured background ####################################################################################
#${lua tex_bg {r=,x=,y=,w=,h=,file=""}}
#	r=corner radius
#	x=x position top left
#	y=y position top left
#	w=width of background, set 0 to set to conky window width
#	h=height of background, set 0 to set to conky window height
#	file=path to texture file, eg "/home/username/image.png", must be in quotes, must be a .png file
## lua draw images ########################################################################################
#${lua luaimage {x=,y=,w=,h=,file=""}}
#	x=x position top left
#	y=y position top left
#	w=image width, set 0 for full image width
#	h=image height, set 0 for full image height
#	file=path to image file, eg "/home/username/image.png", must be in quotes
## lua draw text ##########################################################################################
#${lua luatext {x=,y=,c=,a=,f="",fs=,txt="",j=""}}
#	x=x position top left
#	y=y position top left
#	c=text color
#	a=text alpha
#	f=font, eg "mono" , must be in quotes
#	fs=font size
#	txt=text to show, eg "hello world", must be in quotes
#	j=justify can be "r" = right, "c" = center, "l" = left, must be in quotes
############################################################################################################
############################################
## Set the path to button_script.lua here ##
############################################
lua_load /home/bernardo/.iconky/master_button.lua
##################################
## activate mouse click logging ##
##################################
lua_draw_hook_pre get_mouse {"Interactiveconky","/tmp/xdo"} 
## after function call, table containing window title and path to click log file
## before running script create a blank log file first.  In the example above "/tmp/xdo" credate a blank file called xdo in your /tmp directory 
###################################################
## restart click logging on conkyrc save/startup ##
###################################################
lua_startup_hook start_xdo /tmp/xdo
## send click file location following function call if not set up in lua script
###################################################
## kill xdotool process on conkyrc save/shutdown ##
###################################################
lua_shutdown_hook stop_xdo
#######################################################
## Set the path to lua_functions.lua here (optional) ##
#######################################################
lua_load /home/bernardo/.iconky/lua_functions.lua


TEXT

## ${lua draw_bg {r=10,x=10,y=0,w=0,h=0,dr=1,fc=0x000000,fa=0.7,lw=,lc=,la=}}
## ${if_match ${template1}==0}${else}${goto 100}${/home/bernardo/.conky/system.conky}${endif}
## ${if_match ${template2}==0}${else}${goto 100}${/home/bernardo/.conky/system.conky}${endif}

And here's the lua script:

--[[buttons by mrpeachy - thanks to barrybarrykelly for the xdotool method, gmonti for finding the deb files for the xdotool and arclance for xdotool error catching
see here for instructions: http://crunchbanglinux.org/forums/post/245759/#p245759
]]

conky_name="Interactiveconky"
click_data_file ="/tmp/xdo"

if tonumber(conky_parse('${updates}')) < 2 then
conky0_started = false
end

--setup buttons here
function button_settings()

	button0=do_button({btype=1,bname="conkybutton0",st_type=0,blx_off=0,bly_off=24,bw_off=45,bh_off=20,text=0,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={""},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={""}})
	if ((button0 == 0) and (conky0_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.iconky/interactive_conky'")--do stuff when button is off
	conky0_started = false
	elseif ((button0 == 1) and (conky0_started == false)) then
	os.execute("conky -c '/home/bernardo/.iconky/interactive_conky' &")--do stuff if button is on
	conky0_started = true
	end


end--function button_settings

require 'cairo'
require 'imlib2'

function conky_start_xdo(rc_info)--##### if xdotool is up, kill it and restart it. If it's dead, start it up. 
click_data_file=rc_info or click_data_file
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
os.execute("xdotool search --sync --classname 'conky' behave %@ mouse-click getmouselocation 2> /dev/null >> "..click_data_file.." &")
rc_info=nil
end--of function #####

function conky_stop_xdo()--##### kill xdotool
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
end--of function #####

buttons={}--#############################################################################
click_table={}--#########################################################################
start=1
function conky_get_mouse(rc_info)--##### standard startup lua function
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs) -- end startup lua function
--#####
if rc_info~=nil then
rc_info=loadstring("return" .. rc_info)()
end
--start click logging and calculations ##################################################
--#######################################################################################
if start==1 then
current_update=tonumber(conky_parse("${updates}"))
start=0
end
local updates=tonumber(conky_parse("${updates}"))
if updates==(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
local conky_name=rc_info[1] or conky_name
print ("own_window_title="..conky_name)
local f=io.popen("xwininfo -all -int -tree -name '"..conky_name.."'")
windata = f:read("*a")
f:close()
local windata=string.lower(windata)
local s,f,x=string.find(windata,"absolute%supper%pleft%sx%p%s*(%p*%d*)")
local s,f,y=string.find(windata,"absolute%supper%pleft%sy%p%s*(%p*%d*)")
local s,f,p=string.find(windata,"parent%swindow%sid%p%s(%d*)%s")
local s,f,w=string.find(windata,"xwininfo%p%swindow%sid%p%s(%d*)%s")
xwin={x,y,p,w,click_data_file}--don't blank with nil
print (xwin[1],xwin[2],xwin[3],xwin[4],xwin[5])
elseif updates<(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
xwin={0,0,0,0,click_data_file}
end--if updates== #######################################################################
--click calculations ####################################################################
--get now location and window id ########################################################
local f = io.popen("xdotool getmouselocation 2> /dev/null")
mousenow=(f:read())
f:close()
local mousenow=string.lower(mousenow or "x:0 y:0 window:0 ")
local s,f,mousenowx=string.find(mousenow,"x%p(%d*)%s")
local s,f,mousenowy=string.find(mousenow,"y%p(%d*)%s")
local s,f,xwinid=string.find(mousenow,"window%p(%d*)")
local localnowx=(tonumber(mousenowx) or 0)-xwin[1]
local localnowy=(tonumber(mousenowy) or 0)-xwin[2]
--read file if windowid matches
if tonumber(xwin[3])==tonumber(xwinid) or tonumber(xwin[4])==tonumber(xwinid) then
	local f = io.open(xwin[5])
        click = f:read()
        f:close()
	--get click location
	if click==nil then click="x:0 y:0 window:0 " else print (click) end
	local s,f,mousex=string.find(click,"x%p(%d*)%s")
	local s,f,mousey=string.find(click,"y%p(%d*)%s")
	local localx=(tonumber(mousex) or 0)-xwin[1]
	local localy=(tonumber(mousey) or 0)-xwin[2]
	click_table[1]=localx
	click_table[2]=localy
	click_table[3]=localnowx
	click_table[4]=localnowy
	click=nil
	--blank file
	local f = io.open(xwin[5],"w")
	f:write("")
	f:close() 
else
	click_table[1]=0
	click_table[2]=0
	click_table[3]=0
	click_table[4]=0
end--window id matching
button_settings()
mousenow=nil
windata=nil
rc_info=nil
f=nil
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end-- end getmouse function #############################################################
--#######################################################################################

function do_button(bd)
if bd.btype==nil then
bd=loadstring("return" .. bd)()
end
local localx=click_table[1]	or 0
local localy=click_table[2]	or 0
local localnowx=click_table[3]	or 0
local localnowy=click_table[4]	or 0
local button_name=bd.bname
local st_type=bd.st_type	or 0
local btype=bd.btype		or 1
local on_on_on=bd.on_on_on	or {}
local on_on_off=bd.on_on_off	or {}
local off_on_on=bd.off_on_on	or {}
local off_on_off=bd.off_on_off	or {}
local return_co=bd.return_co	or 0
--#######################################################################################
--#######################################################################################
--initialize button
if buttons[tostring(button_name)]==nil then
	if btype~=4 and st_type==0 then --button is off on start
	buttons[tostring(button_name)]=0
	elseif btype~=4 and st_type==1 then --button is on on start
	buttons[tostring(button_name)]=1
	elseif btype==4 then
	buttons[tostring(button_name)]=1
	end
end
--set mouse point type
if btype==1 or btype==3 or btype==4 then
--on off execute or cycle
localx=localx
localy=localy
elseif btype==2 then
--mouse over
localx=localnowx
localy=localnowy
else
print ("button type not set")
end
--set click area if on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
--button is off
blx=bd.blx_off
bly=bd.bly_off
bw=bd.bw_off
bh=bd.bh_off
elseif btype~=4 and buttons[tostring(button_name)]==1 then
--button is on
blx=bd.blx_on or bd.blx_off
bly=bd.bly_on or bd.bly_off
bw=bd.bw_on or bd.bw_off
bh=bd.bh_on or bd.bh_off
elseif btype==4 then
local blxt=bd.blx_cyc
local blyt=bd.bly_cyc
local bwt=bd.bw_cyc
local bht=bd.bh_cyc
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
blx=blxt[set] or blxt[#blxt]
bly=blyt[set] or blyt[#blyt]
bw=bwt[set] or bwt[#bwt]
bh=bht[set] or bht[#bht]
end
--set mechanism based on button type
if btype==1 then --on off ###############################################################
--if click is inside box and button is not on - turn on
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
elseif localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end
end --if btype==1########################################################################
if btype==2 then --mouse over ###########################################################
--if mouse is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end --if mouse inside
end --if btype==3########################################################################
if btype==3 then --execte ###############################################################
--if mouse click is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse click is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end--if click inside
end --if btype==3########################################################################
if btype==4 then --cycle ################################################################
local cynum=bd.cynum
--if mouse click is inside box
	if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
		if buttons[tostring(button_name)]+1>cynum then
		buttons[tostring(button_name)]=1
		else
		buttons[tostring(button_name)]=buttons[tostring(button_name)]+1
		end
	end--if click inside
end --if btype==4########################################################################
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end
--draw ##################################################################################
local draw=bd.draw or 0
if draw==1 then--########################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
dtype=bd.dtype_off  or 1
--fill when off
dfblx=bd.dfxadj_off or 0
dfbly=bd.dfyadj_off or 0
dfw=bd.dfw_off      or bw
dfh=bd.dfh_off      or bh
dfcr=bd.dfcr_off    or 0
dfcol=bd.dfcol_off  or 0xffffff
dfal=bd.dfal_off    or 1
--outline when off
doblx=bd.doxadj_off or 0
dobly=bd.doyadj_off or 0
dow=bd.dow_off      or bw
doh=bd.doh_off      or bh
docr=bd.docr_off    or 0
docol=bd.docol_off  or 0xffffff
doal=bd.doal_off    or 1
dolw=bd.dolw_off    or 1
elseif btype~=4 and buttons[tostring(button_name)]==1 then--draw on and button on
dtype=bd.dtype_on  or bd.dtype_off or 1
--fill when on
dfblx=bd.dfxadj_on or 0
dfbly=bd.dfyadj_on or 0
dfw=bd.dfw_on      or bw
dfh=bd.dfh_on      or bh
dfcr=bd.dfcr_on    or 0
dfcol=bd.dfcol_on  or 0xff0000
dfal=bd.dfal_on    or 1
--outline when on
doblx=bd.doxadj_on or 0
dobly=bd.doyadj_on or 0
dow=bd.dow_on      or bw
doh=bd.doh_on      or bh
docr=bd.docr_on    or 0 
docol=bd.docol_on  or 0xff0000
doal=bd.doal_on    or 1
dolw=bd.dolw_on    or 1
--#######################################################################################
elseif btype==4 then --##################################################################
--#######################################################################################
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
--set draw type
dtypet=bd.dtype_cyc or {1}
dtype=dtypet[set] or dtypet[#dtypet]
--fill cycle
local dfblxt=bd.dfxadj_cyc or {0}
local dfblyt=bd.dfyadj_cyc or {0}
local dfwt=bd.dfw_cyc      or {bw}
local dfht=bd.dfh_cyc      or {bh}
local dfcrt=bd.dfcr_cyc    or {0}
local dfcolt=bd.dfcol_cyc  or {0xffffff}
local dfalt=bd.dfal_cyc    or {1}
dfblx=dfblxt[set] or dfblxt[#dfblxt] or 0
dfbly=dfblyt[set] or dfblyt[#dfblyt] or 0
dfw=dfwt[set]     or dfwt[#dfwt]     or bw
dfh=dfht[set]     or dfht[#dfht]     or bh
dfcr=dfcrt[set]   or dfcrt[#dfcrt]   or 0
dfcol=dfcolt[set] or dfcolt[#dfcolt] or 0xffffff
dfal=dfalt[set]   or dfalt[#dfalt]   or 1
--outline cycle
local doblxt=bd.doxadj_off or {0}
local doblyt=bd.doyadj_off or {0}
local dowt=bd.dow_off      or {bw}
local doht=bd.doh_off      or {bh}
local docrt=bd.docr_off    or {0}
local docolt=bd.docol_off  or {0xffffff}
local doalt=bd.doal_off    or {1}
local dolwt=bd.dolw_off    or {1}    
doblx=doblxt[set] or doblxt[#doblxt] or 0
dobly=doblyt[set] or doblyt[#doblyt] or 0
dow=dowt[set]     or dowt[#dowt]     or bw
doh=doht[set]     or doht[#doht]     or bh
docr=docrt[set]   or docrt[#docrt]   or 0
docol=docolt[set] or docolt[#docolt] or 0xff0000
doal=doalt[set]   or doalt[#doalt]   or 1
dolw=dolwt[set]   or dolwt[#dolwt]   or 1
else
print ("error4")
end--check btype and button on off
--#######################################################################################
--draw based on type
if dtype==1 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
elseif dtype==2 then
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
elseif dtype==3 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
end
end--if draw=1 ##########################################################################
local image=bd.image or 0
if image==1 then--#######################################################################
if btype~=4 and buttons[tostring(button_name)]==0 then
file=tostring(bd.im_file_off)
if file==nil then print("set image file") end
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype~=4 and buttons[tostring(button_name)]==1 then
file=tostring(bd.im_file_on)
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype==4 then
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local file=bd.im_file_cyc or {}
file=file[set]
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
end--btype test
end--if image ###########################################################################
local text=bd.text
if text==1 then --#######################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
local txt=bd.txt_off   or {"text"}
local font=bd.font_off or {"mono"}
local fs=bd.fs_off     or {12}
local fx=bd.fxadj_off  or {0}
local fy=bd.fyadj_off  or {0}
local fcol=bd.fcol_off or {0x000000}
local fal=bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype~=4 and buttons[tostring(button_name)]==1 then
local txt=bd.txt_on   or bd.txt_off   or {"text"}
local font=bd.font_on or bd.font_off  or {"mono"}
local fs=bd.fs_on     or bd.fs_off    or {12}
local fx=bd.fxadj_on  or bd.fxadj_off or {0}
local fy=bd.fyadj_on  or bd.fyadj_off or {0}
local fcol=bd.fcol_on or bd.fcol_off  or {0x000000}
local fal=bd.fal_on   or bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype==4 then
--text for cycle trype button
--into tables round 1
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local txtt=bd.txt_cyc   or {{"text"}}
local fontt=bd.font_cyc or {{"mono"}}
local fst=bd.fs_cyc     or {{12}}
local fxt=bd.fxadj_cyc  or {{0}}
local fyt=bd.fyadj_cyc  or {{0}}
local fcolt=bd.fcol_cyc or {{0x000000}}
local falt=bd.fal_cyc   or {{1}}
--into tables round 2
local txt=txtt[set]    or txtt[#txtt]
local font=fontt[set]  or fontt[#fontt]
local fs=fst[set]      or fst[#fst]
local fx=fxt[set]      or fxt[#fxt]
local fy=fyt[set]      or fyt[#fyt]
local fcol=fcolt[set]  or fcolt[#fcolt]
local fal=falt[set]    or falt[#falt]
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
else
print ("error with text")
end--if buttons[]==0
end--if text==1 #########################################################################
--#######################################################################################
if return_co==0 then
return tonumber(buttons[tostring(button_name)])
elseif return_co==1 then
return tonumber(buttons[tostring(button_name)]),localnowx,localnowy
end--return settings
end-- end button calculations function ##################################################
--#######################################################################################

function conky_rc_button(bd)--function to setup button in conkyrc
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
--#######################################################################################
send=do_button(bd)
--#######################################################################################
end--if updates>3
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return send or 0
end-- end main function

And here's the conky for all the other buttons:

# killall conky && conky -c /home/bernardo/.iconky/interactive_conky &

##############################################
#  Settings
##############################################
max_specials 10000
max_user_text 15000
background no
use_xft yes
xftfont sans:size=9
xftalpha 1
total_run_times 0
own_window yes
own_window_argb_visual yes
own_window_transparent yes
own_window_type normal
own_window_title interactiveconkyrc ##name must be unique from all other file names
own_window_hints undecorated,above,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 1150 15
maximum_width 1150
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders yes
default_color white
default_shade_color black
default_outline_color white
alignment top_left
gap_x 0
gap_y 0
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale yes
color1 86acad #darker blue
color2 b1c9c9 #lighter blue
text_buffer_size 100000
top_name_width 5
update_interval 1

## lua_functions setup ####################################################################################
## background #############################################################################################
# ${lua draw_bg {r=,x=,y=,w=,h=,dr=,fc=,fa=,lw=,lc=,la=}}
#	r=corner radius
#	x=x position top left
#	y=y position top left
#	w=width of background, set 0 to set to conky window width
#	h=height of background, set 0 to set to conky window height
#	dr=draw type, 1=filled in, 2=outline, 3=fill and outline
#	fc=fill color, eg 0xffffff=white, only need for fill type 1 or 3
#	fa=fill alpha, eg 1=full opaque, only need for fill type 1 or 3
#	lw=line width in, only need for fill type 2 or 3
#	lc=line color, eg 0xffffff=white, only need for fill type 2 or 3
#	la=line alpha, eg 1=full opaque, only need for fill type 2 or 3
## gradient bars ##########################################################################################
#${lua gradbar {x=,y=,v="",vmax=,dn=,dw=,dh=,dg=,bc=,ba=,sc=,sa=,mc=,ma=,ec=,ea=}}
#	x=x position top left
#	y=y position top left
#	v=conky value to display, eg "${cpu cu0}" or "${memperc}" conky object must be in quotes
#	vmax=max value of conky object set above
#	dn=number of divisions
#	dw=width of divisions
#	dh=height of divisions
#	dg=gap between divisions
#	bd=background color
#	ba=background alpha
#	sc=start color
#	sa=start alpha
#	mc=middle color
#	ma=middle alpha
#	ec=end color
#	ea=end alpha
## calendar ###############################################################################################
#${lua luacal {x=,y=,tf="",tfs=,tc=,ta=,bf="",bfs=,bc=,ba=,hf="",hfs=,hc=,ha=,sp="",gc=,gt=,gr=,sd=}}
#	x=x position top left
#	y=y position top left
#	tf=title font, eg "mono" must be in quotes
#	tfs=title font size
#	tc=title color
#	ta=title alpha
#	bf=body font, eg "mono" must be in quotes
#	bfs=body font size
#	bc=body color
#	ba=body alpha
#	hf=highlight font, eg "mono" must be in quotes
#	hfs=highlight font size
#	hc=highlight color
#	ha=highlight alpha
#	sp=spacer, eg " " ... 0,1 or 2 spaces can help with positioning of non-monospaced fonts
#	gt=gap from title to body
#	gh=gap horizontal between columns
#	gv=gap vertical between rows
#	sd=start day, 0=Sun, 1=Mon
## textured background ####################################################################################
#${lua tex_bg {r=,x=,y=,w=,h=,file=""}}
#	r=corner radius
#	x=x position top left
#	y=y position top left
#	w=width of background, set 0 to set to conky window width
#	h=height of background, set 0 to set to conky window height
#	file=path to texture file, eg "/home/username/image.png", must be in quotes, must be a .png file
## lua draw images ########################################################################################
#${lua luaimage {x=,y=,w=,h=,file=""}}
#	x=x position top left
#	y=y position top left
#	w=image width, set 0 for full image width
#	h=image height, set 0 for full image height
#	file=path to image file, eg "/home/username/image.png", must be in quotes
## lua draw text ##########################################################################################
#${lua luatext {x=,y=,c=,a=,f="",fs=,txt="",j=""}}
#	x=x position top left
#	y=y position top left
#	c=text color
#	a=text alpha
#	f=font, eg "mono" , must be in quotes
#	fs=font size
#	txt=text to show, eg "hello world", must be in quotes
#	j=justify can be "r" = right, "c" = center, "l" = left, must be in quotes
############################################################################################################
############################################
## Set the path to button_script.lua here ##
############################################
lua_load /home/bernardo/.iconky/button_script.lua
##################################
## activate mouse click logging ##
##################################
lua_draw_hook_pre get_mouse {"interactiveconkyrc","/tmp/xdo"} 
## after function call, table containing window title and path to click log file
## before running script create a blank log file first.  In the example above "/tmp/xdo" credate a blank file called xdo in your /tmp directory 
###################################################
## restart click logging on conkyrc save/startup ##
###################################################
lua_startup_hook start_xdo /tmp/xdo
## send click file location following function call if not set up in lua script
###################################################
## kill xdotool process on conkyrc save/shutdown ##
###################################################
lua_shutdown_hook stop_xdo
#######################################################
## Set the path to lua_functions.lua here (optional) ##
#######################################################
lua_load /home/bernardo/.iconky/lua_functions.lua


TEXT

## ${lua draw_bg {r=10,x=10,y=0,w=0,h=0,dr=1,fc=0x000000,fa=0.7,lw=,lc=,la=}}
## ${if_match ${template1}==0}${else}${goto 100}${/home/bernardo/.conky/system.conky}${endif}
## ${if_match ${template2}==0}${else}${goto 100}${/home/bernardo/.conky/system.conky}${endif}

...and its corresponding lua script:

--[[buttons by mrpeachy - thanks to barrybarrykelly for the xdotool method, gmonti for finding the deb files for the xdotool and arclance for xdotool error catching
see here for instructions: http://crunchbanglinux.org/forums/post/245759/#p245759
]]

conky_name="interactiveconkyrc"
click_data_file ="/tmp/xdo"

if tonumber(conky_parse('${updates}')) < 2 then
conky1_started = false
conky2_started = false
conky3_started = false
conky4_started = false
conky5_started = false
conky6_started = false
end

--setup buttons here
function button_settings()


	button1=do_button({btype=1,bname="conkybutton1",blx_off=50,bly_off=24,bw_off=55,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"TINT2"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"TINT2"}})
	if ((button1 == 0) and (conky1_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.config/tint2/tint2rc'")--do stuff when button is off
	conky1_started = false
	elseif ((button1 == 1) and (conky1_started == false)) then
	os.execute("tint2 -c '/home/bernardo/.config/tint2/tint2rc' &")--do stuff if button is on
	conky1_started = true
	end

	button2=do_button({btype=2,bname="conkybutton2",blx_off=110,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"SYSTEM"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"SYSTEM"}})
	if ((button2 == 0) and (conky2_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/system.conky'")--do stuff when button is off
	conky2_started = false
	elseif ((button2 == 1) and (conky2_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/system.conky' &")--do stuff if button is on
	conky2_started = true
	end

	button3=do_button			({btype=2,bname="conkybutton3",blx_off=185,bly_off=24,bw_off=60,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CLOCK"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CLOCK"}})
	if ((button3 == 0) and (conky3_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/tintclock.conky'")--do stuff when button is off
	conky3_started = false
	elseif ((button3 == 1) and (conky3_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/tintclock.conky' &")--do stuff if button is on
	conky3_started = true
	end

	button4=do_button	({btype=2,bname="conkybutton4",blx_off=250,bly_off=24,bw_off=90,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CALENDAR"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CALENDAR"}})
	if ((button4 == 0) and (conky4_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/calendar.conky'")--do stuff when button is off
	conky4_started = false
	elseif ((button4 == 1) and (conky4_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/calendar.conky' &")--do stuff if button is on
	conky4_started = true
	end

	button5=do_button({btype=2,bname="conkybutton5",blx_off=345,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"MARKET"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"MARKET"}})
	if ((button5 == 0) and (conky5_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/dolar.conky'")--do stuff when button is off
	conky5_started = false
	elseif ((button5 == 1) and (conky5_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/dolar.conky' &")--do stuff if button is on
	conky5_started = true
	end

	button6=do_button		({btype=2,bname="conkybutton6",blx_off=420,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"BDATES"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"BDATES"}})
	if ((button6 == 0) and (conky6_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/dates.conky'")--do stuff when button is off
	conky6_started = false
	elseif ((button6 == 1) and (conky6_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/dates.conky' &")--do stuff if button is on
	conky6_started = true
	end
	
end--function button_settings

require 'cairo'
require 'imlib2'

function conky_start_xdo(rc_info)--##### if xdotool is up, kill it and restart it. If it's dead, start it up. 
click_data_file=rc_info or click_data_file
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
os.execute("xdotool search --sync --classname 'conky' behave %@ mouse-click getmouselocation 2> /dev/null >> "..click_data_file.." &")
rc_info=nil
end--of function #####

function conky_stop_xdo()--##### kill xdotool
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
end--of function #####

buttons={}--#############################################################################
click_table={}--#########################################################################
start=1
function conky_get_mouse(rc_info)--##### standard startup lua function
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs) -- end startup lua function
--#####
if rc_info~=nil then
rc_info=loadstring("return" .. rc_info)()
end
--start click logging and calculations ##################################################
--#######################################################################################
if start==1 then
current_update=tonumber(conky_parse("${updates}"))
start=0
end
local updates=tonumber(conky_parse("${updates}"))
if updates==(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
local conky_name=rc_info[1] or conky_name
print ("own_window_title="..conky_name)
local f=io.popen("xwininfo -all -int -tree -name '"..conky_name.."'")
windata = f:read("*a")
f:close()
local windata=string.lower(windata)
local s,f,x=string.find(windata,"absolute%supper%pleft%sx%p%s*(%p*%d*)")
local s,f,y=string.find(windata,"absolute%supper%pleft%sy%p%s*(%p*%d*)")
local s,f,p=string.find(windata,"parent%swindow%sid%p%s(%d*)%s")
local s,f,w=string.find(windata,"xwininfo%p%swindow%sid%p%s(%d*)%s")
xwin={x,y,p,w,click_data_file}--don't blank with nil
print (xwin[1],xwin[2],xwin[3],xwin[4],xwin[5])
elseif updates<(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
xwin={0,0,0,0,click_data_file}
end--if updates== #######################################################################
--click calculations ####################################################################
--get now location and window id ########################################################
local f = io.popen("xdotool getmouselocation 2> /dev/null")
mousenow=(f:read())
f:close()
local mousenow=string.lower(mousenow or "x:0 y:0 window:0 ")
local s,f,mousenowx=string.find(mousenow,"x%p(%d*)%s")
local s,f,mousenowy=string.find(mousenow,"y%p(%d*)%s")
local s,f,xwinid=string.find(mousenow,"window%p(%d*)")
local localnowx=(tonumber(mousenowx) or 0)-xwin[1]
local localnowy=(tonumber(mousenowy) or 0)-xwin[2]
--read file if windowid matches
if tonumber(xwin[3])==tonumber(xwinid) or tonumber(xwin[4])==tonumber(xwinid) then
	local f = io.open(xwin[5])
        click = f:read()
        f:close()
	--get click location
	if click==nil then click="x:0 y:0 window:0 " else print (click) end
	local s,f,mousex=string.find(click,"x%p(%d*)%s")
	local s,f,mousey=string.find(click,"y%p(%d*)%s")
	local localx=(tonumber(mousex) or 0)-xwin[1]
	local localy=(tonumber(mousey) or 0)-xwin[2]
	click_table[1]=localx
	click_table[2]=localy
	click_table[3]=localnowx
	click_table[4]=localnowy
	click=nil
	--blank file
	local f = io.open(xwin[5],"w")
	f:write("")
	f:close() 
else
	click_table[1]=0
	click_table[2]=0
	click_table[3]=0
	click_table[4]=0
end--window id matching
button_settings()
mousenow=nil
windata=nil
rc_info=nil
f=nil
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end-- end getmouse function #############################################################
--#######################################################################################

function do_button(bd)
if bd.btype==nil then
bd=loadstring("return" .. bd)()
end
local localx=click_table[1]	or 0
local localy=click_table[2]	or 0
local localnowx=click_table[3]	or 0
local localnowy=click_table[4]	or 0
local button_name=bd.bname
local st_type=bd.st_type	or 0
local btype=bd.btype		or 1
local on_on_on=bd.on_on_on	or {}
local on_on_off=bd.on_on_off	or {}
local off_on_on=bd.off_on_on	or {}
local off_on_off=bd.off_on_off	or {}
local return_co=bd.return_co	or 0
--#######################################################################################
--#######################################################################################
--initialize button
if buttons[tostring(button_name)]==nil then
	if btype~=4 and st_type==0 then --button is off on start
	buttons[tostring(button_name)]=0
	elseif btype~=4 and st_type==1 then --button is on on start
	buttons[tostring(button_name)]=1
	elseif btype==4 then
	buttons[tostring(button_name)]=1
	end
end
--set mouse point type
if btype==1 or btype==3 or btype==4 then
--on off execute or cycle
localx=localx
localy=localy
elseif btype==2 then
--mouse over
localx=localnowx
localy=localnowy
else
print ("button type not set")
end
--set click area if on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
--button is off
blx=bd.blx_off
bly=bd.bly_off
bw=bd.bw_off
bh=bd.bh_off
elseif btype~=4 and buttons[tostring(button_name)]==1 then
--button is on
blx=bd.blx_on or bd.blx_off
bly=bd.bly_on or bd.bly_off
bw=bd.bw_on or bd.bw_off
bh=bd.bh_on or bd.bh_off
elseif btype==4 then
local blxt=bd.blx_cyc
local blyt=bd.bly_cyc
local bwt=bd.bw_cyc
local bht=bd.bh_cyc
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
blx=blxt[set] or blxt[#blxt]
bly=blyt[set] or blyt[#blyt]
bw=bwt[set] or bwt[#bwt]
bh=bht[set] or bht[#bht]
end
--set mechanism based on button type
if btype==1 then --on off ###############################################################
--if click is inside box and button is not on - turn on
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
elseif localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end
end --if btype==1########################################################################
if btype==2 then --mouse over ###########################################################
--if mouse is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end --if mouse inside
end --if btype==3########################################################################
if btype==3 then --execte ###############################################################
--if mouse click is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse click is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end--if click inside
end --if btype==3########################################################################
if btype==4 then --cycle ################################################################
local cynum=bd.cynum
--if mouse click is inside box
	if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
		if buttons[tostring(button_name)]+1>cynum then
		buttons[tostring(button_name)]=1
		else
		buttons[tostring(button_name)]=buttons[tostring(button_name)]+1
		end
	end--if click inside
end --if btype==4########################################################################
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end
--draw ##################################################################################
local draw=bd.draw or 0
if draw==1 then--########################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
dtype=bd.dtype_off  or 1
--fill when off
dfblx=bd.dfxadj_off or 0
dfbly=bd.dfyadj_off or 0
dfw=bd.dfw_off      or bw
dfh=bd.dfh_off      or bh
dfcr=bd.dfcr_off    or 0
dfcol=bd.dfcol_off  or 0xffffff
dfal=bd.dfal_off    or 1
--outline when off
doblx=bd.doxadj_off or 0
dobly=bd.doyadj_off or 0
dow=bd.dow_off      or bw
doh=bd.doh_off      or bh
docr=bd.docr_off    or 0
docol=bd.docol_off  or 0xffffff
doal=bd.doal_off    or 1
dolw=bd.dolw_off    or 1
elseif btype~=4 and buttons[tostring(button_name)]==1 then--draw on and button on
dtype=bd.dtype_on  or bd.dtype_off or 1
--fill when on
dfblx=bd.dfxadj_on or 0
dfbly=bd.dfyadj_on or 0
dfw=bd.dfw_on      or bw
dfh=bd.dfh_on      or bh
dfcr=bd.dfcr_on    or 0
dfcol=bd.dfcol_on  or 0xff0000
dfal=bd.dfal_on    or 1
--outline when on
doblx=bd.doxadj_on or 0
dobly=bd.doyadj_on or 0
dow=bd.dow_on      or bw
doh=bd.doh_on      or bh
docr=bd.docr_on    or 0 
docol=bd.docol_on  or 0xff0000
doal=bd.doal_on    or 1
dolw=bd.dolw_on    or 1
--#######################################################################################
elseif btype==4 then --##################################################################
--#######################################################################################
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
--set draw type
dtypet=bd.dtype_cyc or {1}
dtype=dtypet[set] or dtypet[#dtypet]
--fill cycle
local dfblxt=bd.dfxadj_cyc or {0}
local dfblyt=bd.dfyadj_cyc or {0}
local dfwt=bd.dfw_cyc      or {bw}
local dfht=bd.dfh_cyc      or {bh}
local dfcrt=bd.dfcr_cyc    or {0}
local dfcolt=bd.dfcol_cyc  or {0xffffff}
local dfalt=bd.dfal_cyc    or {1}
dfblx=dfblxt[set] or dfblxt[#dfblxt] or 0
dfbly=dfblyt[set] or dfblyt[#dfblyt] or 0
dfw=dfwt[set]     or dfwt[#dfwt]     or bw
dfh=dfht[set]     or dfht[#dfht]     or bh
dfcr=dfcrt[set]   or dfcrt[#dfcrt]   or 0
dfcol=dfcolt[set] or dfcolt[#dfcolt] or 0xffffff
dfal=dfalt[set]   or dfalt[#dfalt]   or 1
--outline cycle
local doblxt=bd.doxadj_off or {0}
local doblyt=bd.doyadj_off or {0}
local dowt=bd.dow_off      or {bw}
local doht=bd.doh_off      or {bh}
local docrt=bd.docr_off    or {0}
local docolt=bd.docol_off  or {0xffffff}
local doalt=bd.doal_off    or {1}
local dolwt=bd.dolw_off    or {1}    
doblx=doblxt[set] or doblxt[#doblxt] or 0
dobly=doblyt[set] or doblyt[#doblyt] or 0
dow=dowt[set]     or dowt[#dowt]     or bw
doh=doht[set]     or doht[#doht]     or bh
docr=docrt[set]   or docrt[#docrt]   or 0
docol=docolt[set] or docolt[#docolt] or 0xff0000
doal=doalt[set]   or doalt[#doalt]   or 1
dolw=dolwt[set]   or dolwt[#dolwt]   or 1
else
print ("error4")
end--check btype and button on off
--#######################################################################################
--draw based on type
if dtype==1 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
elseif dtype==2 then
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
elseif dtype==3 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
end
end--if draw=1 ##########################################################################
local image=bd.image or 0
if image==1 then--#######################################################################
if btype~=4 and buttons[tostring(button_name)]==0 then
file=tostring(bd.im_file_off)
if file==nil then print("set image file") end
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype~=4 and buttons[tostring(button_name)]==1 then
file=tostring(bd.im_file_on)
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype==4 then
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local file=bd.im_file_cyc or {}
file=file[set]
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
end--btype test
end--if image ###########################################################################
local text=bd.text
if text==1 then --#######################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
local txt=bd.txt_off   or {"text"}
local font=bd.font_off or {"mono"}
local fs=bd.fs_off     or {12}
local fx=bd.fxadj_off  or {0}
local fy=bd.fyadj_off  or {0}
local fcol=bd.fcol_off or {0x000000}
local fal=bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype~=4 and buttons[tostring(button_name)]==1 then
local txt=bd.txt_on   or bd.txt_off   or {"text"}
local font=bd.font_on or bd.font_off  or {"mono"}
local fs=bd.fs_on     or bd.fs_off    or {12}
local fx=bd.fxadj_on  or bd.fxadj_off or {0}
local fy=bd.fyadj_on  or bd.fyadj_off or {0}
local fcol=bd.fcol_on or bd.fcol_off  or {0x000000}
local fal=bd.fal_on   or bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype==4 then
--text for cycle trype button
--into tables round 1
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local txtt=bd.txt_cyc   or {{"text"}}
local fontt=bd.font_cyc or {{"mono"}}
local fst=bd.fs_cyc     or {{12}}
local fxt=bd.fxadj_cyc  or {{0}}
local fyt=bd.fyadj_cyc  or {{0}}
local fcolt=bd.fcol_cyc or {{0x000000}}
local falt=bd.fal_cyc   or {{1}}
--into tables round 2
local txt=txtt[set]    or txtt[#txtt]
local font=fontt[set]  or fontt[#fontt]
local fs=fst[set]      or fst[#fst]
local fx=fxt[set]      or fxt[#fxt]
local fy=fyt[set]      or fyt[#fyt]
local fcol=fcolt[set]  or fcolt[#fcolt]
local fal=falt[set]    or falt[#falt]
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
else
print ("error with text")
end--if buttons[]==0
end--if text==1 #########################################################################
--#######################################################################################
if return_co==0 then
return tonumber(buttons[tostring(button_name)])
elseif return_co==1 then
return tonumber(buttons[tostring(button_name)]),localnowx,localnowy
end--return settings
end-- end button calculations function ##################################################
--#######################################################################################

function conky_rc_button(bd)--function to setup button in conkyrc
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
--#######################################################################################
send=do_button(bd)
--#######################################################################################
end--if updates>3
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return send or 0
end-- end main function

So... can anybody tell me what's going on?

Offline

#1144 2014-12-26 01:16:22

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 932

Re: interactive conky

I don't think this version of the button script will work well if you run it in two separate conkys and close and open one of them periodically.
It might work if you leave both of them open and there is no overlap between the conky windows but I don't have time to go through the whole script right now to be sure.

Offline

#1145 2014-12-26 01:33:26

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

arclance wrote:

I don't think this version of the button script will work well if you run it in two separate conkys and close and open one of them periodically.

I may be wrong (wouldn't be the first time), but I don't think that's the problem.
After I killall conky, there's no conky running at all, yet when I start that conky, the moment I put the cursor on the button, it starts behaving like a mouseover type button.
I'm pretty sure I messed up something, but, for the life of me, I can't figure it out... mad

Back in the day (a looooong time ago) when I was learning BASIC on my TI99-a/4 computer, there was an instruction ("trace") that would show which line of a script was running, and therefore would tell you which was the last line that ran before it all went to hell.
Is there an instruction like that in Lua?

Offline

#1146 2014-12-26 01:48:48

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 932

Re: interactive conky

Inodoro Pereyra wrote:

I may be wrong (wouldn't be the first time), but I don't think that's the problem.

It probably will cause problems later if it is not causing this because closing the second conky with the master button will kill xdotool and the mouse position will no longer be updated.
That could cause your mouseover problem because the "/tmp/xdo" file is not deleted so it can get stuck on the last click position that triggered a button and will always cause it to go off when the mouse is over the window.

My weather script has some logic that prevents this from happening since I have another conky with buttons in it and you only need one click detection xdotool running since it can be set to only report clicks on conky windows.

Inodoro Pereyra wrote:

Is there an instruction like that in Lua?

Not that I know of but you can put "print()" statements printing different things like 1, 2, 3, etc. in suspicious parts of your code to see which ones run and which ones don't to tell you where things are going wrong.


This is all there is to my button code.

--# button drawing function
function buttondraw(CR, BLX,BLY,HEIGHT,WIDTH,COLOR,FILL,LINE_WIDTH)
	--cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER) --# in case of wacky defaults
	--cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE) --# don't antialias outline it is too thin and gets blurred
	cairo_set_line_width (CR,LINE_WIDTH)
	cairo_set_source_rgba (CR,color3_R,color3_G,color3_B,color3_A)
	cairo_rectangle (CR,(BLX + 1),(BLY + 1),WIDTH,-HEIGHT)
	if FILL == 0 then
		cairo_stroke (CR)
	elseif FILL == 1 then
		cairo_fill (CR)
	end --# if FILL == 0 then
	cairo_set_source_rgba (CR,COLOR[1],COLOR[2],COLOR[3],COLOR[4])
	cairo_rectangle (CR,BLX,BLY,WIDTH,-HEIGHT)
	if FILL == 0 then
		cairo_stroke (CR)
	elseif FILL == 1 then
		cairo_fill (CR)
	end --# if FILL == 0 then
	return CR
	--cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT) --# reset antialias method to default
end --# function buttondraw(CR, BLX,BLY,HEIGHT,WIDTH,COLOR,FILL,LINE_WIDTH)

--#### Button code based on interactive conky by mrpeachy ####
--#### http://crunchbanglinux.org/forums/topic/18419/interactive-conky/ ####
function clickfunction()
	--################################################################################################
	if tonumber(conky_parse('${updates}')) < 2 then
		local s = nil
		local f = io.popen("xwininfo -all -int -tree -name '"..conkyWindowTitle.."'")
		local winData = f:read("*a")
		f:close()
		f = nil
		s,f,xdotool_window_number2 = string.find(winData,"xwininfo.%s.indow%sid.%s(%d+)%s") --# some window mangers use this (Cinnamon, Compiz (Unity))
		s,f,xdotool_window_number = string.find(winData,"Parent%swindow%sid.%s(%d+)%s") --# some window managers use this (Fluxbox, Openbox)
		s,f,abstlx = string.find(winData,"Absolute%supper.left%sX%p%s*(%p*%d*)")
		s,f,abstly = string.find(winData,"Absolute%supper.left%sY%p%s*(%p*%d*)")
		print("abstlx: "..tostring(abstlx).." abstly: "..tostring(abstly).." winNum_Parent: "..tostring(xdotool_window_number).." winNum_2: "..tostring(xdotool_window_number2))
	end --# if tonumber(conky_parse('${updates}')) < 2 then
	--#################################################################################################
    --######### start click logging and calculations ##################################################
    local s = nil
    --######### Get Current Mouse Location ###################
	local f = io.popen("xdotool getmouselocation 2> /dev/null")
	local mousenow = f:read("*a")
	f:close()
	f = nil
	local mousenowx = nil
	local mousenowy = nil
	local mousex = nil
	local mousey = nil
	if ((mousenow == nil) or (mousenow == "")) then --# check for failure of xdotool getmouselocation command (crashes script but usually only lasts one or two updates)
		print("error: could not get mouse location")
		mousenowx = "0"
		mousenowy = "0"
		mousex = "0"
		mousey = "0"
	elseif ((string.find(mousenow, xdotool_window_number) ~= nil) or (string.find(mousenow, xdotool_window_number2) ~= nil)) then --# check if mouse is in this conky window
		--print("debug: mouse is in this window")
		s,f,mousenowx = string.find(mousenow,"x%p(%d*)%s")
		s,f,mousenowy = string.find(mousenow,"y%p(%d*)%s")
		--#### Get Click Location
		f = io.popen("tail --lines=1 /tmp/"..tempFileName)
		local click = f:read("*a")
		f:close()
		f = nil
		if ((click == nil) or (click == "")) then --# xdotool log file does not exist or is empty (prevents crash before first click or if you specify the wrong file)
			print("error: could not read xdotool logfile")
			mousex = "0"
			mousey = "0"
		elseif (click:gsub("\n","") == "Command failed.") then --# this is does not crash xdotool (probably a communication error between xdotool and some part of the system)
			print("error: xdotool error")
			mousex = "0"
			mousey = "0"
		else --# no problems reading the xdotool log file
			if ((string.find(click, xdotool_window_number) ~= nil) or (string.find(click, xdotool_window_number2) ~= nil)) then --# last click was in this window
				print("debug: click was in this window")
				s,f,mousex = string.find(click,"x%p(%d*)")
				s,f,mousey = string.find(click,"y%p(%d*)")
				--### Reset xdotool log file
				f = io.open("/tmp/"..tempFileName,"w")
				f:write("x:0 y:0 screen:0 window:0\n")
				f:close()
				f = nil
			else --# last click was not in this window
				--print("debug: click not in this window")
				mousex = "0"
				mousey = "0"
			end --# if string.find(click, xdotool_window_number) ~= nil then
		end --# if ((click == nil) or (click == "")) then
	else --# mouse not in this window
		mousenowx = "0"
		mousenowy = "0"
		mousex = "0"
		mousey = "0"
	end --# if string.find(mousenow, xdotool_window_number) then
	local localx = tonumber(mousex) - abstlx
	local localy = tonumber(mousey) - abstly
	local localnowx = tonumber(mousenowx) - abstlx
	local localnowy = tonumber(mousenowy) - abstly
    --END CLICK CALCULATIONS #################################
    return localx,localy,localnowx,localnowy
end --# function clickfunction()

function conky_start_xdotool()
    os.execute("pkill -f \"xdotool search --sync --classname conky behave %@ mouse-click getmouselocation\"")
    os.execute("xdotool search --sync --classname 'conky' behave %@ mouse-click getmouselocation 2> /dev/null >> /tmp/"..tempFileName.." &")
end --# function conky_start_xdotool()

function conky_stop_xdotool()
	local stdout = io.popen("ps --no-headers -C conky -O cmd")
	local conkyCount = 0
	local rconkyData = stdout:read("*l")
	while rconkyData ~= nil do
		if ((string.find(rconkyData,"conky1") ~= nil) or (string.find(rconkyData,"conky2") ~= nil)) then --# is one of the conkys to check for (could use something generic like "button" here)
			print("found")
			conkyCount = conkyCount + 1
		end --# if string.find("conky1") ~= nil then
		rconkyData = stdout:read("*l")
	end --# while rconkyData ~= nil do
	stdout:close()
    if conkyCount == 1 then
		print("killing xdotool")
		os.execute("pkill -f \"xdotool search --sync --classname conky behave %@ mouse-click getmouselocation\"")
	end --# if conkyCount == 1 then
end --# function conky_stop_xdotool()

You have to write all the logic and other stuff as needed so you can do more complex things without the problems you are having but it makes it much harder to just pick up and use.
My weather script has in context examples of its setup and use that might help in understanding it.

Last edited by arclance (2014-12-26 02:04:07)

Offline

#1147 2014-12-26 02:29:06

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 478

Re: interactive conky

arclance wrote:

My weather script has in context examples of its setup and use that might help in understanding it.

I'll check it out. Thanks again. smile

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo