X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/605ab1f899b8cc5b1c3257b64f9076a755879e0a..0a6274b4343fa5b9ed9fb83ac72cbe9fc89610b0:/layout/uselesstile.lua?ds=inline diff --git a/layout/uselesstile.lua b/layout/uselesstile.lua index d244f43..ee33060 100644 --- a/layout/uselesstile.lua +++ b/layout/uselesstile.lua @@ -1,12 +1,12 @@ --[[ - - Licensed under GNU General Public License v2 - * (c) 2014 projektile, worron - * (c) 2013 Luke Bonham - * (c) 2009 Donald Ephraim Curtis - * (c) 2008 Julien Danjolu - + + Licensed under GNU General Public License v2 + * (c) 2014, projektile, worron + * (c) 2013, Luke Bonham + * (c) 2009, Donald Ephraim Curtis + * (c) 2008, Julien Danjolu + --]] local tag = require("awful.tag") @@ -35,19 +35,18 @@ local function swap(geometry) return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width } end --- Find geometry for column/row tiling -local function cut_area(wa, total, index, is_horizontal) - local wa = is_horizontal and swap(wa) or wa - local height = wa.height / total +-- Find geometry for secondary windows column +local function cut_column(wa, n, index) + local width = math.floor(wa.width / n) + local area = { x = wa.x + (index - 1) * width, y = wa.y, width = width, height = wa.height } - local area = { - x = wa.x, - y = wa.y + (index - 1) * height, - width = wa.width, - height = height - } + return area +end - if is_horizontal then area = swap(area) end +-- Find geometry for certain window in column +local function cut_row(wa, factor, index, used) + local height = math.floor(wa.height * factor.window[index] / factor.total) + local area = { x = wa.x, y = wa.y + used, width = wa.width, height = height } return area end @@ -60,11 +59,34 @@ local function size_correction(c, geometry, useless_gap) geometry.y = geometry.y + useless_gap / 2 end +-- Check size factor for group of clients and calculate total +local function calc_factor(n, winfactors) + local factor = { window = winfactors, total = 0, min = 1 } + + for i = 1, n do + if not factor.window[i] then + factor.window[i] = factor.min + else + factor.min = math.min(factor.window[i], factor.min) + if factor.window[i] < 0.05 then factor.window[i] = 0.05 end + end + factor.total = factor.total + factor.window[i] + end + + return factor +end + -- Tile group of clients in given area -- @canvas need for proper transformation only -local function tile_column(canvas, area, list, useless_gap, transformation) +-- @winfactors table with clients size factors +local function tile_column(canvas, area, list, useless_gap, transformation, winfactors) + local used = 0 + local factor = calc_factor(#list, winfactors) + for i, c in ipairs(list) do - local g = cut_area(area, #list, i) + local g = cut_row(area, factor, i, used) + if i == #list then g.height = area.height - used end + used = used + g.height -- swap workarea dimensions if transformation.flip then g = flip(canvas, g) end @@ -73,6 +95,7 @@ local function tile_column(canvas, area, list, useless_gap, transformation) -- useless gap and border correction size_correction(c, g, useless_gap) + c:geometry(g) end end @@ -102,6 +125,14 @@ local function tile(p, orientation) mwfact = 1 end + -- clients size factor + local data = tag.getdata(t).windowfact + + if not data then + data = {} + tag.getdata(t).windowfact = data + end + -- Workarea size correction depending on useless gap and global border wa.height = wa.height - 2 * global_border - useless_gap wa.width = wa.width - 2 * global_border - useless_gap @@ -132,11 +163,12 @@ local function tile(p, orientation) local master_area = { x = wa.x, y = wa.y, - width = nmaster > 0 and wa.width * mwfact or 0, + width = nmaster > 0 and math.floor(wa.width * mwfact) or 0, height = wa.height } - tile_column(wa, master_area, cls_master, useless_gap, transformation) + if not data[0] then data[0] = {} end + tile_column(wa, master_area, cls_master, useless_gap, transformation, data[0]) -- Tile other windows local other_area = { @@ -149,11 +181,14 @@ local function tile(p, orientation) -- get column number for other windows local ncol = math.min(tag.getncol(t), #cls_other) + if ncol == 0 then ncol = 1 end + -- split other windows to column groups local last_small_column = ncol - #cls_other % ncol local rows_min = math.floor(#cls_other / ncol) local client_index = 1 + local used = 0 for i = 1, ncol do local position = transformation.flip and ncol - i + 1 or i local rows = i <= last_small_column and rows_min or rows_min + 1 @@ -164,9 +199,13 @@ local function tile(p, orientation) client_index = client_index + 1 end - -- and tile - local column_area = cut_area(other_area, ncol, position, true) - tile_column(wa, column_area, column, useless_gap, transformation) + -- and tile + local column_area = cut_column(other_area, ncol, position) + if i == ncol then column_area.width = other_area.width - used end + used = used + column_area.width + + if not data[i] then data[i] = {} end + tile_column(wa, column_area, column, useless_gap, transformation, data[i]) end end