From 3c1f51675822b5f3fc2a8a9a5f8e988bfbc7ddff Mon Sep 17 00:00:00 2001 From: Andrei Thorp Date: Mon, 6 Oct 2008 15:55:06 -0400 Subject: [PATCH] Added swapbydirection to client.lua.in in awful. Works similar to focus.bydirection, but swaps windows instead. Also, added a generic local method get_client_in_direction for use by (swap|focus)\.?bydirection. Signed-off-by: Julien Danjou --- lib/awful/client.lua.in | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/awful/client.lua.in b/lib/awful/client.lua.in index 44f15bf8..e6e4cf92 100644 --- a/lib/awful/client.lua.in +++ b/lib/awful/client.lua.in @@ -258,10 +258,10 @@ local function calculate_distance(dir, cA, cB) return math.sqrt(math.pow(xB - xA, 2) + math.pow(yB - yA, 2)) end ---- Focus a client by the given direction. +--- Get the nearest client in the given direction -- @param dir The direction, can be either "up", "down", "left" or "right". --- @param c Optional client. -function focus.bydirection(dir, c) +-- @param c Optional client to get a client relative to. Else focussed is used. +local function get_client_in_direction(dir, c) local sel = c or capi.client.focus if sel then local coords = sel:coords() @@ -285,6 +285,18 @@ function focus.bydirection(dir, c) end end + return target + end +end + +--- Focus a client by the given direction. +-- @param dir The direction, can be either "up", "down", "left" or "right". +-- @param c Optional client. +function focusbydirection(dir, c) + local sel = c or capi.client.focus + if sel then + local target = get_client_in_direction(dir, sel) + -- If we found a client to focus, then do it. if target then capi.client.focus = target @@ -307,6 +319,21 @@ function focus.byidx(i, c) end end +--- Swap a client with another client in the given direction +-- @param dir The direction, can be either "up", "down", "left" or "right". +-- @param c Optional client. +function swapbydirection(dir, c) + local sel = c or capi.client.focus + if sel then + local target = get_client_in_direction(dir, sel) + + -- If we found a client to swap with, then go for it + if target then + target:swap(sel) + end + end +end + --- Swap a client by its relative index. -- @param i The index. -- @param c Optional client, otherwise focused one is used.