SEARCH

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

You are not logged in.

#1 2012-03-14 01:04:38

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

interactive conky

xdotool version 2.20110530.1

Last edited by mrpeachy (2014-01-22 22:43:57)

Offline

Be excellent to each other!

#2 2012-03-14 02:59:17

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

so here is a test script exploring the mouse over ability

--[[click with mouse over lua by mrpeachy - thanks to barrybarrykelly for the xdotool method and gmonti for finding the deb files for the xdotool
in conkyrc, in addition to regular settings:

own_window_title clicky
lua_load ~/lua/clicky.lua
lua_draw_hook_pre main
TEXT

3/13/12
]]

require 'cairo'

click_start=1-- this starts the clickfunction
buttons={}--this table ini9tially holds the values from the buttons

function conky_main()
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
--#################################################################################################
localx,localy,localnowx,localnowy=clickfunction()--this line activates the clickfunction and sets the click coordinates
--#################################################################################################
--SET DEFAULTS ##########################################################
--set defaults do not localise these defaults if you use a seperate display script
default_font="mono"--font must be in quotes
default_font_size=10
default_color=0xffffff--white
default_alpha=1--fully opaque
default_image_width=50
default_image_height=50
--#################################################################################################
--button setup - this section for an on/off button 
local button_name="cpu"
local blx=100.5--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
local bly=100.5--bottom left x coordinate of click area
local height=20--height of click area
local width=30--width of click area

--setup cpu section position, when setting up cpu function everything is relative to these points
local cpu_blx=blx+width+2
local cpu_bly=100.5
local overlap=width
--##############################################################
--calculate if click was inside box and set actions#############
--best to keep the button calculations seperate to the actions##
if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=0 end
--end of calculations ##########################################

--mouseover
if buttons["coresmo"]==1 or localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
    if buttons[tostring(button_name)]~=1 then
    cpusection(cpu_blx,cpu_bly,overlap)
    end
end

if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
color={0,0,0,1}
fill=1
buttondraw(blx,bly,height,width,color,fill)
end

--##############################################################
--button on off
if buttons[tostring(button_name)]==1 then
color={1,0,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
cpusection(cpu_blx,cpu_bly,overlap)
else
color={1,1,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
end--button on off
out({x=105,y=95,txt="CPU"})
--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

function cpusection(cpu_blx,cpu_bly,overlap)
--button setup - this section for an on/off button 
local button_name="cores"
local blx=cpu_blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
local bly=cpu_bly--bottom left x coordinate of click area
local height=20--height of click area
local width=60--width of click area
--setup cpu section position, when setting up cpu function everything is relative to these points
local cores_blx=blx+width+15
local cores_bly=bly
--##############################################################
--calculate if click was inside box and set actions#############
--best to keep the button calculations seperate to the actions##
if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=0 end
--end of calculations ##########################################
--mouseover
if buttons["processmo"]==1 or localnowx>=blx-overlap and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
buttons[tostring(button_name.."mo")]=1
--buttons["cpumo"]=1
--elseif localnowx<blx-overlap or localnowx>blx+width or localnowy>bly or localnowy<bly-height then
--buttons[tostring(button_name.."mo")]=0
else
buttons[tostring(button_name.."mo")]=0
end--mouseover

if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
color={0,0,0,1}
fill=1
buttondraw(blx,bly,height,width,color,fill)
--so that cpu isnt drawn twice
    if buttons[tostring(button_name)]~=1 then
    coressection(cores_blx,cores_bly)
    end
end
--##############################################################
--button on off
if buttons[tostring(button_name)]==1 then
color={1,0,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
coressection(cores_blx,cores_bly)
else
color={0,1,1,1}
fill=0
buttondraw(blx,bly,height,width,color,fill)
end--button on off
out({x=blx+5,y=bly-5,txt="CPU%:"..conky_parse("${cpu}")})
--##############################################################
--##############################################################
--##############################################################
--##############################################################
--##############################################################
--button controlling processes section
--button setup - this section for an on/off button 
local button_name="process"
local blx=blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
local bly=bly+height+2--bottom left x coordinate of click area
local height=20--height of click area
local width=60--width of click area
--setup cpu section position, when setting up cpu function everything is relative to these points
local process_blx=blx+width+15
local process_bly=bly
--##############################################################
--calculate if click was inside box and set actions#############
--best to keep the button calculations seperate to the actions##
if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=0 end
--end of calculations ##########################################
--mouseover
if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height-height then
buttons[tostring(button_name.."mo")]=1
elseif localnowx<blx or localnowx>blx+width or localnowy>bly or localnowy<bly-height-height then
buttons[tostring(button_name.."mo")]=0
end--mouseover

if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
color={0,0,0,1}
fill=1
buttondraw(blx,bly,height,width,color,fill)
--so that cpu isnt drawn twice
    if buttons[tostring(button_name)]~=1 then
    processsection(cores_blx,cores_bly)
    end
end
--##############################################################
--button on off
if buttons[tostring(button_name)]==1 then
color={1,0,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
processsection(cores_blx,cores_bly)
else
color={0,1,1,1}
fill=0
buttondraw(blx,bly,height,width,color,fill)
end--button on off
out({x=blx+5,y=bly-5,txt="PRO#:"..conky_parse("${processes}")})
end--cpu section

function coressection(blx,bly)
out({x=blx,y=bly-5,txt="CPU1:"..conky_parse("${cpu cpu1}").."%"})
out({x=blx,y=bly+15,txt="CPU2:"..conky_parse("${cpu cpu2}").."%"})
out({x=blx,y=bly+35,txt="CPU3:"..conky_parse("${cpu cpu3}").."%"})
--out({c=0x00ff00,x=255,y=155,txt="CPU:"..conky_parse("${cpu cpu4}").."%"})
end--coressection

function processsection(blx,bly)
out({x=blx+100,y=bly-5,txt="PROC1:"..conky_parse("${top name 1}")})
out({x=blx+100,y=bly+15,txt="PROC2:"..conky_parse("${top name 2}")})
out({x=blx+100,y=bly+35,txt="PROC3:"..conky_parse("${top name 3}")})
--out({c=0x00ff00,x=255,y=155,txt="CPU:"..conky_parse("${cpu cpu4}").."%"})
end--coressection

--button drawing function
function buttondraw(blx,bly,height,width,color,fill)
cairo_set_line_width (cr,1)
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
end--of buttondraw function
function xout(txj)--c,a,f,fs,x,y,txt,j ##################################################
c=nil
c=(txj.c or default_color)
a=nil
a=(txj.a or default_alpha)
f=nil
f=(txj.f or default_font)
fs=nil
fs=(txj.fs or default_font_size)
x=nil
x=(txj.x or 0)
y=nil
y=(txj.y or 0)
txt=nil
txt=(txj.txt or "set txt")
j=nil
j=(txj.j or "l")
    local function col(c,a)
    return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
    end--local function
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
local text=string.gsub(txt," ","_")
extents=cairo_text_extents_t:create()
cairo_text_extents(cr,text,extents)
local wx=extents.width
cairo_set_source_rgba (cr,col(c,a))
if j=="l" then
cairo_move_to (cr,x,y)
adx=wx
elseif j=="c" then
cairo_move_to (cr,x-(wx/2),y)
adx=wx/2
elseif j=="r" then
cairo_move_to (cr,x-wx,y)
adx=0
end
cairo_show_text (cr,txt)
cairo_stroke (cr)
nextx=nil
nextx=adx+x
return nextx
end--function xout ###################################################################
function out(tx)--####################################################################
c=nil
c=(tx.c or default_color)
a=nil
a=(tx.a or default_alpha)
f=nil
f=(tx.f or default_font)
fs=nil
fs=(tx.fs or default_font_size)
x=nil
x=(tx.x or 0)
y=nil
y=(tx.y or 0)
txt=nil
txt=(tx.txt or "set txt")
local function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
cairo_set_source_rgba (cr,col(c,a))
cairo_move_to (cr,x,y)
cairo_show_text (cr,txt)
cairo_stroke (cr)
end--function out ###################################################################
function image(im)--#################################################################
x=nil
x=(im.x or 0)
y=nil
y=(im.y or 0)
w=nil
w=(im.w or default_image_width)
h=nil
h=(im.h or default_image_height)
file=nil
file=tostring(im.file)
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(w)==0 then 
width=imlib_image_get_width() 
else
width=tonumber(w)
end
if tonumber(h)==0 then 
height=imlib_image_get_height() 
else
height=tonumber(h)
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width, height)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(x, y)
imlib_free_image()
show=nil
end--function image ##################################################################
--clickfunction, this runs xdotool and xwininfo and reads the coordinates of clicks
function clickfunction()
--start click logging and calculations ##########################################
if click_start==1 then
xdot=conky_parse("${if_running xdotool}1${else}0${endif}")
if tonumber(xdot)==1 then
os.execute("killall xdotool && echo 'xdo killed' &")
end
os.execute("xdotool search --name 'clicky' behave %@ mouse-click getmouselocation >> /tmp/xdo &")
local f = io.popen("xwininfo -name 'clicky' | grep 'Absolute'")
geometry = f:read("*a")
f:close()
local geometry=string.gsub(geometry,"[\n]","")
s,f,abstlx=string.find(geometry,"X%p%s*(%d*)")
s,f,abstly=string.find(geometry,"Y%p%s*(%d*)")
click_start=nil
end--if click_start=1 ######################################
--click calculations #################################
local f=io.open("/tmp/xdo")
click=f:read()
f:close()
if click~=nil then
local f = io.open("/tmp/xdo","w")
f:write("")
f:close() 
end--if click=nil
if click==nil then click="x:0 y:0 " end
--print (click)
local s,f,mousex=string.find(click,"x%p(%d*)%s")
local s,f,mousey=string.find(click,"y%p(%d*)%s")
localx=tonumber(mousex)-abstlx
localy=tonumber(mousey)-abstly
--get now location
os.execute("xdotool getmouselocation > /tmp/xdonow ")
local f=io.open("/tmp/xdonow")
mousenow=f:read()
f:close()
local s,f,mousenowx=string.find(mousenow,"x%p(%d*)%s")
local s,f,mousenowy=string.find(mousenow,"y%p(%d*)%s")
localnowx=tonumber(mousenowx)-abstlx
localnowy=tonumber(mousenowy)-abstly
--END CLICK CALCULATIONS #################################
return localx,localy,localnowx,localnowy
end--function

needs some cleaning up, can see some inconsistencies which are a simple result of messy script writing (what works is more important than how it looks when im starting out!)
took a while to figure out the interactions to allow the mouse to move from one button to the next without shutting off the first

Last edited by mrpeachy (2012-03-14 03:44:26)

Offline

#3 2012-03-14 03:57:38

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: interactive conky

Last edited by Sector11 (2012-03-14 03:58:04)

Offline

#4 2012-03-14 04:03:48

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Last edited by mrpeachy (2012-03-14 04:05:34)

Offline

#5 2012-03-14 12:42:25

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: interactive conky

Offline

#6 2012-03-14 14:35:13

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: interactive conky

    out({x=15,y=24,txt="GO:"})
   --#########################################################################################################
   end-- if updates>5
   cairo_destroy(cr)
   cairo_surface_destroy(cs)
   cr=nil
   end-- end main function

   [color=red]function cpusection[/color](cpu_blx,cpu_bly,overlap)
   --button setup - this section for an on/off button 
   local button_name="cores"
   local blx=cpu_blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
   local bly=cpu_bly--bottom left x coordinate of click area
   local height=20--height of click area
   local width=60--width of click area
   --setup cpu section position, when setting up cpu function everything is relative to these points
   local cores_blx=blx+width+15
   local cores_bly=bly
   --##############################################################
   --calculate if click was inside box and set actions#############
   --best to keep the button calculations seperate to the actions##
   if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=1
   elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
   buttons[tostring(button_name)]=0
   elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=0 end
   --end of calculations ##########################################
   --mouseover
   if buttons["processmo"]==1 or localnowx>=blx-overlap and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
   buttons[tostring(button_name.."mo")]=1
   --buttons["cpumo"]=1
   --elseif localnowx<blx-overlap or localnowx>blx+width or localnowy>bly or localnowy<bly-height then
   --buttons[tostring(button_name.."mo")]=0
   else
   buttons[tostring(button_name.."mo")]=0
   end--mouseover

   if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
   color={0,0,0,1}
   fill=1
   buttondraw(blx,bly,height,width,color,fill)
   --so that cpu isnt drawn twice
       if buttons[tostring(button_name)]~=1 then
       coressection(cores_blx,cores_bly)
       end
   end
   --##############################################################
   --button on off
   if buttons[tostring(button_name)]==1 then
   color={1,0,0,1}--if button is clicked on it will be drawn red
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   coressection(cores_blx,cores_bly)
   else
   color={0,1,1,1}
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   end--button on off
   out({x=blx+5,y=bly-5,txt="CPU%:"..conky_parse("${cpu}")})
   --##############################################################
   --##############################################################
   --##############################################################
   --##############################################################
   --##############################################################
   [color=teal]--button controlling processes section
   --button setup - this section for an on/off button 
   local button_name="process"[/color]
   local blx=blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
   local bly=bly+height+2--bottom left x coordinate of click area
   local height=20--height of click area
   local width=60--width of click area
   --[color=red]setup cpu section[/color] position, when setting up cpu function everything is relative to these points
   local process_blx=blx+width+15
   local process_bly=bly
   --##############################################################
   --calculate if click was inside box and set actions#############
   --best to keep the button calculations seperate to the actions##
   if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=1
   elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
   buttons[tostring(button_name)]=0
   elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=0 end
   --end of calculations ##########################################
   --mouseover ###
   if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height-height then
   buttons[tostring(button_name.."mo")]=1
   elseif localnowx<blx or localnowx>blx+width or localnowy>bly or localnowy<bly-height-height then
   buttons[tostring(button_name.."mo")]=0
   end--mouseover ###

   if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
   color={0,0,0,1}
   fill=1
   buttondraw(blx,bly,height,width,color,fill)
   --so that cpu isnt drawn twice
       if buttons[tostring(button_name)]~=1 then
       processsection(cores_blx,cores_bly)
       end
   end
   --##############################################################
   --button on off
   if buttons[tostring(button_name)]==1 then
   color={1,0,0,1} --if button is clicked on it will be drawn red
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   [color=green]processsection(cores_blx,cores_bly) --HUH???[/color] 
   else
   color={0,1,1,1}
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   end --button on off
   out({x=blx+5,y=bly-5,txt="Pro#:"..conky_parse("${processes}")})
   [color=red]end --cpu section[/color] 

Offline

#7 2012-03-14 19:23:58

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Offline

#8 2012-03-14 20:54:20

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: interactive conky

Last edited by Sector11 (2012-03-14 20:54:52)

Offline

#9 2012-03-15 19:01:02

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

The S-11 tux is cool as sh#! big_smile

Now I need to get my hands on the interactive launcher.. I have a few concepts that I want to throw at it.

Offline

#10 2012-03-16 03:10:15

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

here is the launcher script

--[[launcher icons

call in conkyrc in a similar manner to this above TEXT in addition to regular conky settings

lua_load ~/pathto/filename.lua
lua_draw_hook_pre draw_main

in the conkyrc you also need to add this setting

own_window_title clicky

or you can set your own window title then edit towards the bottom of the script
so that any instances of clicky are replaced with the title you set
avoid spaces in title name

]]

require 'cairo'
require 'imlib2'
start=1
buttons={}
buttons[1]=0
text_table={}
--------------------------------------------------------------------------------
function conky_main()
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
--#########################################################################################################
--get click coordinates
localx,localy=clickfunction()--dont edit
--##############################################
print (localx,localy)
--SETTINGS #####################################

icons={--enter locations of files enter command,icon_path
"/home/mcdowall/files/launcher/firefox.png",
"/home/mcdowall/files/launcher/gedit.png",
"/home/mcdowall/files/launcher/terminal.png",
"/home/mcdowall/files/launcher/gimp.png",
}
execute={
"firefox &",
"gedit &",
"gnome-terminal &",
"gimp &",
}

--set button top left corner coordinates and width/heioght
local main_tlx=20.5
local main_tly=20.5
local main_height=40
local main_width=40
--need to set the top left corner of the top button in the list
local list_height=40
local list_width=40
local list_start_deg=90
local list_deg_gap=30
local list_radius=80
--END OF SETTINGS ########################################
local number_in_list=#icons
--########################################################
--calculate if click was inside box
if localx>=main_tlx and localx<=main_tlx+main_width and localy>=main_tly and localy<=main_tly+main_height and buttons[1]~=1 then
buttons[1]=1
elseif localx>=main_tlx and localx<=main_tlx+main_width and localy>=main_tly and localy<=main_tly+main_height and buttons[1]==1 then
buttons[1]=0
elseif localx>main_tlx and localx>main_tlx+main_width and localy<main_tly and localy>main_tly+main_height and buttons[1]~=1 then
buttons[1]=0
end
if buttons[1]==1 then
image({x=main_tlx,y=main_tly,w=main_width,h=main_height,file="/home/mcdowall/files/launcher/off.png"})
elseif buttons[1]==0 then
image({x=main_tlx,y=main_tly,w=main_width,h=main_height,file="/home/mcdowall/files/launcher/on.png"})
end
cairo_set_source_rgba (cr,1,1,1,1)
--[[draw the box for positioning purposes, you can comment out the draw commands later
cairo_set_line_width (cr,1)
cairo_rectangle (cr,main_tlx,main_tly,main_width,main_height)
cairo_stroke (cr)--]]
--------------------------------------------------------------------------------------
--if the main button is clicked then all this stuff will happen
if buttons[1]==1 then 
        for i=1,number_in_list do --use a for loop to generate all the buttons with a single code chunk
        --calculate icon positions################################
        local point=(math.pi/180)*(list_start_deg+(list_deg_gap*(i-1)))
        local list_tlx=main_tlx+list_radius*(math.sin(point))
        local list_tly=main_tly-list_radius*(math.cos(point))
        --########################################################
        --calculate if click is inside buttons
        if localx>=list_tlx and localx<=list_tlx+list_width and localy>=list_tly and localy<=list_tly+list_height and buttons[tostring("button1_"..i)]~=1 then
        buttons[tostring("button1_"..i)]=1
        elseif localx>=list_tlx and localx<=list_tlx+list_width and localy>=list_tly and localy<=list_tly+list_height and buttons[tostring("button1_"..i)]==1 then
        buttons[tostring("button1_"..i)]=0
        end
        if buttons[tostring("button1_"..i)]==1 then
        os.execute(execute[i])
        n=i
            for i=1,number_in_list do
                buttons[tostring("button1_"..i)]=0
            end
            buttons[1]=0
        end
        image({x=list_tlx,y=list_tly,w=list_width,h=list_height,file=icons[i]})
        cairo_set_source_rgba (cr,1,1,1,1)
        --[[draw the box for positioning purposes, you can comment out the draw commands later
        cairo_set_line_width (cr,1)
        cairo_rectangle (cr,list_tlx,list_tly+((list_gap+height)*(i-1)),list_width,list_height)
        cairo_stroke (cr)--]]
    end--for loop
end--if main button=1

--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end--end main function

function string:split(delimiter)
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end--of function

function out(tx)--####################################################################
c=nil
c=(tx.c or default_color)
a=nil
a=(tx.a or default_alpha)
f=nil
f=(tx.f or default_font)
fs=nil
fs=(tx.fs or default_font_size)
x=nil
x=(tx.x or 0)
y=nil
y=(tx.y or 0)
txt=nil
txt=(tx.txt or "set txt")
local function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
cairo_set_source_rgba (cr,col(c,a))
cairo_move_to (cr,x,y)
cairo_show_text (cr,txt)
cairo_stroke (cr)
end--function out ###################################################################

function image(im)--#################################################################
x=nil
x=(im.x or 0)
y=nil
y=(im.y or 0)
w=nil
w=(im.w or default_image_width)
h=nil
h=(im.h or default_image_height)
file=nil
file=tostring(im.file)
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(w)==0 then 
width=imlib_image_get_width() 
else
width=tonumber(w)
end
if tonumber(h)==0 then 
height=imlib_image_get_height() 
else
height=tonumber(h)
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width, height)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(x, y)
imlib_free_image()
show=nil
end--function image ##################################################################

function clickfunction()
--start click logging and calculations ##########################################
if start==1 then
xdot=conky_parse("${if_running xdotool}1${else}0${endif}")
    if tonumber(xdot)==1 then
    os.execute("/usr/bin/killall xdotool && echo 'xdo killed' &")
    end
os.execute("xdotool search --name clicky behave %@ mouse-click getmouselocation >> /tmp/xdo &")
start=nil--]]
local f = io.popen("xwininfo -name 'clicky' | grep 'Absolute'")
geometry = f:read("*a")
f:close()
geometry=string.gsub(geometry,"[\n]","")
s,f,abstlx=string.find(geometry,"X%p%s*(%d*)")
s,f,abstly=string.find(geometry,"Y%p%s*(%d*)")
end--if start=1 ######################################
--click calculations #################################
local f=io.open("/tmp/xdo")
click=f:read()
f:close()
    if click~=nil then
    local f = io.open("/tmp/xdo","w")
    f:write("")
    f:close() 
    end--if click=nil
if click==nil then click="x:0 y:0 " end
s,f,mousex=string.find(click,"x%p(%d*)%s")
s,f,mousey=string.find(click,"y%p(%d*)%s")
mousex=tonumber(mousex)
mousey=tonumber(mousey)
localx=mousex-abstlx
localy=mousey-abstly
--END CLICK CALCULATIONS #################################
return localx,localy
end--function

one difference here is that i have moved to storing the click outcomes in tables which gives me the ability to generate multiple buttons through a for loop with just one chunk of code

im using this code in the for loop

        local point=(math.pi/180)*(list_start_deg+(list_deg_gap*(i-1)))
        local list_tlx=main_tlx+list_radius*(math.sin(point))
        local list_tly=main_tly-list_radius*(math.cos(point))

to arrange the icons around the start button in a circle

ive written a bit about working with for loops in the lua how to which might help

basically what i have is the main button is an on/off button which then turnes on the outer buttons that are the execute buttons

Offline

#11 2012-03-16 03:22:22

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

Offline

#12 2012-03-16 18:48:24

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Offline

#13 2012-03-16 18:54:31

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

Keep me up on your improvements with the system monitor SirPeachy.!
I'm getting a

Conky: llua_do_call: function conky_main execution failed: attempt to call a nil value

with the system monitor lua.

I added

own_window_title clicky

and its your weather_conkyrc so I'm not sure what I'm overlooking here big_smile

Last edited by falldown (2012-03-16 19:14:24)

Offline

#14 2012-03-16 19:13:03

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Conky: llua_do_call: function conky_main execution failed: attempt to call a nil value

Offline

#15 2012-03-16 19:21:53

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

Last edited by falldown (2012-03-16 19:41:08)

Offline

#16 2012-03-16 19:49:16

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Offline

#17 2012-03-16 19:58:57

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

Offline

#18 2012-03-17 18:24:48

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Offline

#19 2012-03-17 21:05:59

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Offline

#20 2012-03-17 21:15:29

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

Offline

#21 2012-03-17 21:17:28

VastOne
#! Ranger
From: V-Ger
Registered: 2011-04-26
Posts: 10,165
Website

Re: interactive conky

^That is amazing!  Wow!

What is that panel/launcher you are using bottom center?

Offline

#22 2012-03-17 21:18:16

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Last edited by mrpeachy (2012-03-17 21:19:53)

Offline

#23 2012-03-17 21:20:26

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

Last edited by falldown (2012-03-17 21:30:15)

Offline

#24 2012-03-17 21:28:54

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

what i was thinking about with the circle launcher is to have a couple of buttons that would let you turn the circle
so you can access other programs by spinning the circle round

not entirely sure how to do that right now, but its on my to do list smile

Offline

Be excellent to each other!

#25 2012-03-17 21:34:21

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: interactive conky

Last edited by falldown (2012-03-17 21:41:49)

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.
Server: bleh

Debian Logo