(Sorry for opening a new thread. I read this list via gmane.org and
can't post to it via the gateway, so i don't have the proper references)
Hi,
here is the version of goto_or_run i'm using currently.
Regards,
Johannes
--
"Wir m�ssen die Rechte der Andersdenkenden selbst dann beachten, wenn sie
Idioten oder sch�dlich sind." (Wau Holland)
function lookup_complete_clientwin(title)
local names=complete_clientwin(title)
local cwins={}
for i, name in names do
cwins[i]=lookup_clientwin(name)
end
return cwins
end
function goto_or_run(mplex, title, command, maxnum, where)
-- title : caption of windows we are looking for
-- command : command to execute if we can't find window with title
-- maxnum : see below
-- where : if command isn't running and where is given switch to WRegion
named
-- where after executing command
local cwins=lookup_complete_clientwin(title)
local ncwins=table.getn(cwins)
if ncwins>0 then
local acti=ncwins
for i, cwin in ipairs(cwins) do
-- Unfortunately there's no is_active function. It is to be
-- added. For now the test mplex:current()==cwin should do it
-- supposing we're working with a simple setup with no full
-- screen client windows and nested frames and mplex is
-- itself active.
if mplex:current()==cwin then
--if cwin:is_active() then
acti=i
break
end
end
-- get current WIonWS
local ws1 = mplex:current()
while ws1 and not obj_is(ws1, "WIonWS") do
ws1 = ws1:manager()
end
-- get WIonWS in which command is running
local ws2 = cwins[math.mod(acti, ncwins)+1]
while ws2 and not obj_is(ws2, "WIonWS") do
ws2 = ws2:manager()
end
-- if they are equal and maxnum==0 or command running less than
-- maxnum times run command
if ws1 and ws2 and ws1==ws2 and (maxnum==0 or ncwins<maxnum) then
exec_in(mplex, command)
else
-- else switch to WIonFrame running commmand
cwins[math.mod(acti, ncwins)+1]:goto()
end
else
exec_in(mplex, command)
-- We can't lookup where command gets started because exec_in returns
-- before command is started so we have to (?) use this ugly hack to
go to
-- the started application immediately
if where then
local regions=lookup_region(where, "WRegion")
regions:goto()
end
end
end