From 0cf3da1adca01c07a2d08c746501bc54c25cd940 Mon Sep 17 00:00:00 2001 From: Anurag Priyam Date: Sat, 31 Mar 2012 15:33:01 +0530 Subject: [PATCH] introduce awful.client.run_or_raise Jump to client if running, else launch it. Signed-off-by: Anurag Priyam Signed-off-by: Uli Schlachter --- lib/awful/client.lua.in | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in index 5e236247..8224ea3c 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")