internal refactoring
This commit is contained in:
parent
f65b161ab4
commit
c1ab5bc81b
|
@ -88,7 +88,7 @@ end
|
|||
-- @return whether any actions have been taken on the client
|
||||
local function fit_region(c, cycle)
|
||||
local layout = api.layout.get(c.screen)
|
||||
local regions = layout.machi_get_regions and layout.machi_get_regions(c.screen.workarea)
|
||||
local regions = layout.machi_get_regions and layout.machi_get_regions(c.screen.workarea, c.screen)
|
||||
if type(regions) ~= "table" or #regions < 1 then
|
||||
return false
|
||||
end
|
||||
|
@ -681,7 +681,7 @@ local function create(data)
|
|||
if to_exit then
|
||||
print("interactive layout editing ends")
|
||||
if to_apply then
|
||||
layout.machi_set_cmd(current_cmd)
|
||||
layout.machi_set_cmd(current_cmd, screen)
|
||||
api.layout.arrange(screen)
|
||||
api.gears.timer{
|
||||
timeout = 1,
|
||||
|
|
28
layout.lua
28
layout.lua
|
@ -1,3 +1,7 @@
|
|||
local api = {
|
||||
screen = screen,
|
||||
}
|
||||
|
||||
local function min(a, b)
|
||||
if a < b then return a else return b end
|
||||
end
|
||||
|
@ -6,6 +10,10 @@ local function max(a, b)
|
|||
if a < b then return b else return a end
|
||||
end
|
||||
|
||||
local function get_screen(s)
|
||||
return s and api.screen[s]
|
||||
end
|
||||
|
||||
--- find the best region for the area-like object
|
||||
-- @param c area-like object - table with properties x, y, width, and height
|
||||
-- @param regions array of area-like objects
|
||||
|
@ -44,7 +52,7 @@ local function create(name, editor)
|
|||
regions_cache = {}
|
||||
}
|
||||
|
||||
local function get_regions(workarea)
|
||||
local function get_regions(workarea, _screen)
|
||||
if priv.cmd == nil then return {} end
|
||||
local key = tostring(workarea.width) .. "x" .. tostring(workarea.height) .. "+" .. tostring(workarea.x) .. "+" .. tostring(workarea.y)
|
||||
if priv.regions_cache[key] == nil then
|
||||
|
@ -53,10 +61,17 @@ local function create(name, editor)
|
|||
return priv.regions_cache[key]
|
||||
end
|
||||
|
||||
local function set_cmd(cmd, _screen)
|
||||
if priv.cmd ~= cmd then
|
||||
priv.cmd = cmd
|
||||
priv.regions_cache = {}
|
||||
end
|
||||
end
|
||||
|
||||
local function arrange(p)
|
||||
local wa = p.workarea
|
||||
local cls = p.clients
|
||||
local regions = get_regions(wa)
|
||||
local regions = get_regions(wa, get_screen(p.screen))
|
||||
|
||||
|
||||
if #regions == 0 then return end
|
||||
|
@ -87,19 +102,12 @@ local function create(name, editor)
|
|||
end
|
||||
end
|
||||
|
||||
local function set_cmd(cmd)
|
||||
if priv.cmd ~= cmd then
|
||||
priv.cmd = cmd
|
||||
priv.regions_cache = {}
|
||||
end
|
||||
end
|
||||
|
||||
-- move the closest region regardingly to the center distance
|
||||
local function resize_handler(c, context, h)
|
||||
if context ~= "mouse.move" then return end
|
||||
|
||||
local workarea = c.screen.workarea
|
||||
local regions = get_regions(workarea)
|
||||
local regions = get_regions(workarea, c.screen)
|
||||
|
||||
if #regions == 0 then return end
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ local function start(c)
|
|||
local layout = api.layout.get(screen)
|
||||
if c.floating or layout.machi_get_regions == nil then return end
|
||||
|
||||
local regions = layout.machi_get_regions(c.screen.workarea)
|
||||
local regions = layout.machi_get_regions(c.screen.workarea, c.screen)
|
||||
|
||||
local infobox = api.wibox({
|
||||
screen = screen,
|
||||
|
|
Loading…
Reference in New Issue