diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in index 5e236247e..8224ea3c4 100644 --- a/lib/awful/client.lua.in +++ b/lib/awful/client.lua.in @@ -897,6 +897,38 @@ function iterate(filter, start, s) return util.table.iterate(clients, filter, start) end +--- +--

Switch to a client matching the given condition if running, else spawn it. +-- If multiple clients match the given condition then the next one is +-- focussed.

+-- +-- @param cmd the command to execute +-- @param matcher a function that returns true to indicate a matching client +-- @param merge if true then merge tags when clients are not visible +-- +-- @usage run or raise urxvt (perhaps, with tabs) on modkey + semicolon +--

+-- awful.key({ modkey, }, 'semicolon', function ()
+-- local matcher = function (c)
+-- return awful.rules.match(c, {class = 'URxvt'})
+-- end
+-- awful.client.run_or_raise('urxvt', matcher) +-- end); +--

+function run_or_raise(cmd, matcher, merge) + local clients = capi.client.get() + local findex = util.table.hasitem(clients, capi.client.focus) or 1 + local start = util.cycle(#clients, findex + 1) + + for c in iterate(matcher, start) do + jumpto(c, merge) + return + end + + -- client not found, spawn it + util.spawn(cmd) +end + -- Register standards signals capi.client.add_signal("property::floating_geometry") capi.client.add_signal("property::floating")