From e7f4b96b934e51db17061897deeee410d4fed188 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Fri, 5 Jul 2019 17:04:18 -0400 Subject: [PATCH] resize handling --- layout.lua | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/layout.lua b/layout.lua index 324eb1c..8ef80ca 100644 --- a/layout.lua +++ b/layout.lua @@ -33,7 +33,7 @@ function do_arrange(p, priv) end function create_layout(name, regions) - local priv = {} + local priv = { regions = {} } local function set_regions(regions) priv.regions = regions @@ -43,6 +43,35 @@ function create_layout(name, regions) return priv.regions end + -- move the closest region regardingly to the center distance + local function resize_handler(c, context, h) + if context ~= "mouse.move" then return end + if #priv.regions == 0 then return end + + local center_x = h.x + h.width / 2 + local center_y = h.y + h.height / 2 + + local choice = 1 + local choice_value = nil + for i, r in ipairs(priv.regions) do + local r_x = r.x + r.width / 2 + local r_y = r.y + r.height / 2 + local dis = (r_x - center_x) * (r_x - center_x) + (r_y - center_y) * (r_y - center_y) + if choice_value == nil or choice_value > dis then + choice = i + choice_value = dis + end + end + + if c.machi_region ~= choice then + c.machi_region = choice + c.x = priv.regions[choice].x + c.y = priv.regions[choice].y + c.width = priv.regions[choice].width + c.height = priv.regions[choice].height + end + end + set_regions(regions) return {