From 9f2a79a2d069402585557f90f6788fb1d0dc00ac Mon Sep 17 00:00:00 2001 From: Anurag Priyam Date: Fri, 17 Feb 2012 02:32:28 +0530 Subject: [PATCH] add awful.client.cycle add awful.client.cycle to iterate through clients that match a given condition A common use case is to cycle through clients that match a given rule and take certain action on them: raise, set or get property, etc.; see usage example in the docs. Signed-off-by: Anurag Priyam Signed-off-by: Uli Schlachter --- lib/awful/client.lua.in | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in index b63a6465..fa605663 100644 --- a/lib/awful/client.lua.in +++ b/lib/awful/client.lua.in @@ -862,6 +862,30 @@ function property.set(c, prop, value) c:emit_signal("property::" .. prop) end +--- +-- Returns an iterator to cycle through, starting from the client in focus or +-- the given index, all clients that match a given criteria. +-- @param filter a function that returns true to indicate a positive match +-- @param start what index to start iterating from. Defaults to using the +-- index of the currently focused client. +-- @param s which screen to use. nil means all screens. +-- @usage e.g.: un-minimize all urxvt instances +--

+-- local urxvt = function (c)
+-- return awful.rules.match(c, {class = "URxvt"})
+-- end
+--
+-- for c in awful.client.cycle(urxvt) do
+-- c.minimized = false
+-- end
+--

+function cycle(filter, start, s) + local clients = capi.client.get(s) + local focused = capi.client.focus + local start = start or util.table.hasitem(clients, focused) + return util.table.cycle(clients, filter, start) +end + -- Register standards signals capi.client.add_signal("focus", focus.history.add) capi.client.add_signal("unmanage", focus.history.delete)