bling/layout/equalarea.lua

97 lines
2.8 KiB
Lua
Raw Normal View History

2021-03-03 12:24:56 +01:00
local gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
2021-08-27 20:01:22 +02:00
local math = math
local screen = screen
2021-03-03 12:24:56 +01:00
local mylayout = {}
mylayout.name = "equalarea"
2021-08-27 20:01:22 +02:00
local function divide(p, g, low, high, cls, mwfact, mcount)
if low == high then
p.geometries[cls[low]] = g
else
2021-08-27 20:01:22 +02:00
local masters = math.max(0, math.min(mcount, high) - low + 1)
local numblock = high - low + 1
local slaves = numblock - masters
local smalldiv
if numblock > 5 and (numblock % 5) == 0 then
smalldiv = math.floor(numblock / 5)
else
if (numblock % 3) == 0 then
smalldiv = math.floor(numblock / 3)
else
smalldiv = math.floor(numblock / 2)
end
end
local bigdiv = numblock - smalldiv
local smallmasters = math.min(masters, smalldiv)
local bigmasters = masters - smallmasters
local smallg = {}
local bigg = {}
smallg.x = g.x
smallg.y = g.y
if g.width > (g.height * 1.3) then
smallg.height = g.height
bigg.height = g.height
bigg.width = math.floor(
g.width
* (bigmasters * (mwfact - 1) + bigdiv)
/ (slaves + mwfact * masters)
)
smallg.width = g.width - bigg.width
bigg.y = g.y
bigg.x = g.x + smallg.width
else
smallg.width = g.width
bigg.width = g.width
bigg.height = math.floor(
g.height
* (bigmasters * (mwfact - 1) + bigdiv)
/ (slaves + mwfact * masters)
)
smallg.height = g.height - bigg.height
bigg.x = g.x
bigg.y = g.y + smallg.height
end
divide(p, smallg, low, high - bigdiv, cls, mwfact, mcount)
divide(p, bigg, low + smalldiv, high, cls, mwfact, mcount)
end
2021-08-27 20:01:22 +02:00
return
end
2021-03-03 12:24:56 +01:00
function mylayout.arrange(p)
2021-08-27 20:01:22 +02:00
local t = p.tag or screen[p.screen].selected_tag
local wa = p.workarea
local cls = p.clients
2021-08-27 20:01:22 +02:00
if #cls == 0 then
return
end
local mwfact = t.master_width_factor * 2
local mcount = t.master_count
local g = {}
g.height = wa.height
g.width = wa.width
g.x = wa.x
g.y = wa.y
divide(p, g, 1, #cls, cls, mwfact, mcount)
end
2021-08-27 20:01:22 +02:00
local icon_raw = gears.filesystem.get_configuration_dir()
.. tostring(...):match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/equalarea.png"
2021-03-03 12:24:56 +01:00
local function get_icon()
2021-08-27 20:01:22 +02:00
if icon_raw ~= nil then
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
2021-03-03 12:24:56 +01:00
return {
2021-08-27 20:01:22 +02:00
layout = mylayout,
icon_raw = icon_raw,
get_icon = get_icon,
2021-03-03 12:24:56 +01:00
}