From c1ab5bc81b2706d09b1da4e38e9bec7f45ecdb6b Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Fri, 12 Jul 2019 16:17:34 -0400 Subject: [PATCH] internal refactoring --- editor.lua | 4 ++-- layout.lua | 28 ++++++++++++++++++---------- switcher.lua | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/editor.lua b/editor.lua index e39dcf2..724c942 100644 --- a/editor.lua +++ b/editor.lua @@ -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, diff --git a/layout.lua b/layout.lua index f3a156d..5ec8a20 100644 --- a/layout.lua +++ b/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 diff --git a/switcher.lua b/switcher.lua index 04cc10c..170b299 100644 --- a/switcher.lua +++ b/switcher.lua @@ -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,