add centerwork.{focus,swap}.byidx that behaves like other layouts #447

This commit is contained in:
Neville Li 2020-03-05 21:31:39 -05:00
parent 33c0e0c236
commit 52a6258b72
1 changed files with 73 additions and 0 deletions

View File

@ -191,4 +191,77 @@ function centerwork.horizontal.mouse_resize_handler(c, corner, x, y)
return mouse_resize_handler(c, corner, x, y, 'horizontal') return mouse_resize_handler(c, corner, x, y, 'horizontal')
end end
-------------------------------------------------------------------------------
-- make focus.byidx and swap.byidx behave more consistently with other layouts
local awful = require("awful")
local gears = require("gears")
local function compare_position(a, b)
if a.x == b.x then
return a.y < b.y
else
return a.x < b.x
end
end
local function clients_by_position()
local this = client.focus
if this then
sorted = client.focus.first_tag:clients()
table.sort(sorted, compare_position)
local idx = 0
for i, that in ipairs(sorted) do
if this.window == that.window then
idx = i
end
end
if idx > 0 then
return { sorted = sorted, idx = idx }
end
end
return {}
end
local function in_centerwork()
return client.focus and client.focus.first_tag.layout.name == "centerwork"
end
centerwork.focus = {}
--[[
Drop in replacements for awful.client.focus.byidx and awful.client.swap.byidx
that behaves consistently with other layouts
--]]
function centerwork.focus.byidx(i)
if in_centerwork() then
local cls = clients_by_position()
if cls.idx then
local target = cls.sorted[gears.math.cycle(#cls.sorted, cls.idx + i)]
awful.client.focus.byidx(0, target)
end
else
awful.client.focus.byidx(i)
end
end
centerwork.swap = {}
function centerwork.swap.byidx(i)
if in_centerwork() then
local cls = clients_by_position()
if cls.idx then
local target = cls.sorted[gears.math.cycle(#cls.sorted, cls.idx + i)]
client.focus:swap(target)
end
else
awful.client.swap.byidx(i)
end
end
return centerwork return centerwork