I have lua code (included below) to go to a window that matches a given
class, or if not found, execute a command.  The equivalent code to match
based on title is simple, given the lookup_clientwin function, but the
class-based match seems a bit unpleasant.  I'm getting a list of window
names (complete_clientwin), getting a list of windows based on that, and
then filtering by class.

Is there a better way to do this?  I'm brand new to lua (I haven't used
ion since the pre-lua days), so I welcome any pointers at all.

function managed_windows()
   local names = complete_clientwin()
   local wins = {}
   for i, name in pairs(names) do
      table.insert(wins, lookup_clientwin(name))
   end
   return wins
end

function match_class(class)
   local wins = managed_windows()
   local result = {}
   for i, win in pairs(wins) do
      if class == win:get_ident().class then
         table.insert(result, win)
      end
   end
   return result
end

function byclass(prog, class)
   local win = match_class(class)[1]
   if win then
      win:goto()
   else
      exec(prog)
   end
end

function make_byclass_fn(prog, class)
   local function fn(frame)
            byclass(prog, class)
         end
   return fn
end

-- 
Jeremy Hankins <[EMAIL PROTECTED]>
PGP fingerprint: 748F 4D16 538E 75D6 8333  9E10 D212 B5ED 37D0 0A03

Reply via email to