Merge pull request #445 from exzombie/master

termfair.stable layout
This commit is contained in:
Luca CPZ 2020-11-27 12:21:28 +00:00 committed by GitHub
commit 11db4c4e2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 66 additions and 21 deletions

View File

@ -14,6 +14,7 @@ local tonumber = tonumber
local termfair = { name = "termfair" } local termfair = { name = "termfair" }
termfair.center = { name = "centerfair" } termfair.center = { name = "centerfair" }
termfair.stable = { name = "stablefair" }
local function do_fair(p, orientation) local function do_fair(p, orientation)
local t = p.tag or screen[p.screen].selected_tag local t = p.tag or screen[p.screen].selected_tag
@ -22,33 +23,32 @@ local function do_fair(p, orientation)
if #cls == 0 then return end if #cls == 0 then return end
-- How many vertical columns? Read from nmaster on the tag.
local num_x = tonumber(termfair.nmaster) or t.master_count
local ncol = tonumber(termfair.ncol) or t.column_count
if num_x <= 2 then num_x = 2 end
if ncol <= 1 then ncol = 1 end
local width = math.floor(wa.width/num_x)
if orientation == "west" then if orientation == "west" then
-- Layout with fixed number of vertical columns (read from nmaster). -- Layout with fixed number of vertical columns (read from nmaster).
-- New windows align from left to right. When a row is full, a now -- New windows align from left to right. When a row is full, a new
-- one above it is created. Like this: -- one above it is created. Like this:
-- (1) (2) (3) -- (1) (2) (3)
-- +---+---+---+ +---+---+---+ +---+---+---+ -- +---+---+---+ +---+---+---+ +---+---+---+
-- | | | | | | | | | | | | -- | | | | | | | | | | | |
-- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | -> -- | 1 | | | -> | 1 | 2 | | -> | 1 | 2 | 3 | ->
-- | | | | | | | | | | | | -- | | | | | | | | | | | |
-- +---+---+---+ +---+---+---+ +---+---+---+ -- +---+---+---+ +---+---+---+ +---+---+---+
-- (4) (5) (6) -- (4) (5) (6)
-- +---+---+---+ +---+---+---+ +---+---+---+ -- +---+---+---+ +---+---+---+ +---+---+---+
-- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 | -- | 1 | | | | 1 | 2 | | | 1 | 2 | 3 |
-- +---+---+---+ -> +---+---+---+ -> +---+---+---+ -- +---+---+---+ -> +---+---+---+ -> +---+---+---+
-- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 | -- | 2 | 3 | 4 | | 3 | 4 | 5 | | 4 | 5 | 6 |
-- +---+---+---+ +---+---+---+ +---+---+---+ -- +---+---+---+ +---+---+---+ +---+---+---+
-- How many vertical columns? Read from nmaster on the tag.
local num_x = tonumber(termfair.nmaster) or t.master_count
local ncol = tonumber(termfair.ncol) or t.column_count
if num_x <= 2 then num_x = 2 end
if ncol <= 1 then ncol = 1 end
local width = math.floor(wa.width/num_x)
local num_y = math.max(math.ceil(#cls / num_x), ncol) local num_y = math.max(math.ceil(#cls / num_x), ncol)
local height = math.floor(wa.height/num_y) local height = math.floor(wa.height/num_y)
local cur_num_x = num_x local cur_num_x = num_x
@ -107,6 +107,56 @@ local function do_fair(p, orientation)
end end
end end
end end
elseif orientation == "stable" then
-- Layout with fixed number of vertical columns (read from nmaster).
-- New windows align from left to right. When a row is full, a new
-- one below it is created. Like this:
-- (1) (2) (3)
-- +---+---+---+ +---+---+---+ +---+---+---+
-- | | | | | | | | | | | |
-- | 1 | | | -> | 1 | 2 | | -> | 1 | 2 | 3 | ->
-- | | | | | | | | | | | |
-- +---+---+---+ +---+---+---+ +---+---+---+
-- (4) (5) (6)
-- +---+---+---+ +---+---+---+ +---+---+---+
-- | 1 | 2 | 3 | | 1 | 2 | 3 | | 1 | 2 | 3 |
-- +---+---+---+ +---+---+---+ +---+---+---+
-- | 4 | | | | 4 | 5 | | | 4 | 5 | 6 |
-- +---+---+---+ -> +---+---+---+ -> +---+---+---+
local num_y = math.max(math.ceil(#cls / num_x), ncol)
local height = math.floor(wa.height/num_y)
for i = #cls,1,-1 do
-- Get x and y position.
local c = cls[i]
local this_x = (i - 1) % num_x
local this_y = math.floor((i - this_x - 1) / num_x)
-- Calculate geometry.
local g = {}
if this_x == (num_x - 1) then
g.width = wa.width - (num_x - 1)*width
else
g.width = width
end
if this_y == (num_y - 1) then
g.height = wa.height - (num_y - 1)*height
else
g.height = height
end
g.x = wa.x + this_x*width
g.y = wa.y + this_y*height
if g.width < 1 then g.width = 1 end
if g.height < 1 then g.height = 1 end
p.geometries[c] = g
end
elseif orientation == "center" then elseif orientation == "center" then
-- Layout with fixed number of vertical columns (read from nmaster). -- Layout with fixed number of vertical columns (read from nmaster).
-- Cols are centerded until there is nmaster columns, then windows -- Cols are centerded until there is nmaster columns, then windows
@ -128,15 +178,6 @@ local function do_fair(p, orientation)
-- | | | 4 | | | 3 | 5 | -- | | | 4 | | | 3 | 5 |
-- +---+---+---+ +---+---+---+ -- +---+---+---+ +---+---+---+
-- How many vertical columns? Read from nmaster on the tag.
local num_x = tonumber(termfair.center.nmaster) or t.master_count
local ncol = tonumber(termfair.center.ncol) or t.column_count
if num_x <= 2 then num_x = 2 end
if ncol <= 1 then ncol = 1 end
local width = math.floor(wa.width / num_x)
if #cls < num_x then if #cls < num_x then
-- Less clients than the number of columns, let's center it! -- Less clients than the number of columns, let's center it!
local offset_x = wa.x + (wa.width - #cls*width) / 2 local offset_x = wa.x + (wa.width - #cls*width) / 2
@ -230,6 +271,10 @@ function termfair.center.arrange(p)
return do_fair(p, "center") return do_fair(p, "center")
end end
function termfair.stable.arrange(p)
return do_fair(p, "stable")
end
function termfair.arrange(p) function termfair.arrange(p)
return do_fair(p, "west") return do_fair(p, "west")
end end