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 <julien@danjou.info>
This commit is contained in:
parent
76058c634f
commit
3c1f516758
|
@ -258,10 +258,10 @@ local function calculate_distance(dir, cA, cB)
|
||||||
return math.sqrt(math.pow(xB - xA, 2) + math.pow(yB - yA, 2))
|
return math.sqrt(math.pow(xB - xA, 2) + math.pow(yB - yA, 2))
|
||||||
end
|
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 dir The direction, can be either "up", "down", "left" or "right".
|
||||||
-- @param c Optional client.
|
-- @param c Optional client to get a client relative to. Else focussed is used.
|
||||||
function focus.bydirection(dir, c)
|
local function get_client_in_direction(dir, c)
|
||||||
local sel = c or capi.client.focus
|
local sel = c or capi.client.focus
|
||||||
if sel then
|
if sel then
|
||||||
local coords = sel:coords()
|
local coords = sel:coords()
|
||||||
|
@ -285,6 +285,18 @@ function focus.bydirection(dir, c)
|
||||||
end
|
end
|
||||||
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 we found a client to focus, then do it.
|
||||||
if target then
|
if target then
|
||||||
capi.client.focus = target
|
capi.client.focus = target
|
||||||
|
@ -307,6 +319,21 @@ function focus.byidx(i, c)
|
||||||
end
|
end
|
||||||
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.
|
--- Swap a client by its relative index.
|
||||||
-- @param i The index.
|
-- @param i The index.
|
||||||
-- @param c Optional client, otherwise focused one is used.
|
-- @param c Optional client, otherwise focused one is used.
|
||||||
|
|
Loading…
Reference in New Issue