From: luke bonham Date: Sun, 11 Jan 2015 12:16:37 +0000 (+0100) Subject: Merge branch 'worron-master' X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/3cd8b2001381997e1556c95c12eb0736fe6f7ebc?hp=600b44f5bae5110a2b31cf5f46208d973d6dd2d1 Merge branch 'worron-master' --- diff --git a/layout/uselessfair.lua b/layout/uselessfair.lua index 6a386c3..ee3aa40 100644 --- a/layout/uselessfair.lua +++ b/layout/uselessfair.lua @@ -1,121 +1,108 @@ --[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile - * (c) 2013, Luke Bonham - * (c) 2012, Josh Komoroske - * (c) 2010-2012, Peter Hofmann - + + Licensed under GNU General Public License v2 + * (c) 2014, projektile, worron + * (c) 2013, Luke Bonham + * (c) 2012, Josh Komoroske + * (c) 2010-2012, Peter Hofmann + --]] local beautiful = require("beautiful") local ipairs = ipairs -local math = { ceil = math.ceil, sqrt = math.sqrt } +local math = { ceil = math.ceil, sqrt = math.sqrt, floor = math.floor, max = math.max } local tonumber = tonumber local uselessfair = {} -local function fair(p, orientation) - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width. - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - if useless_gap < 0 then useless_gap = 0 end +-- Transformation functions +local function swap(geometry) + return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width } +end + +-- Client geometry correction depending on useless gap and window border +local function size_correction(c, geometry, useless_gap) + geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1) + geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1) + geometry.x = geometry.x + useless_gap / 2 + geometry.y = geometry.y + useless_gap / 2 +end - -- A global border can be defined with - -- beautiful.global_border_width. - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end +-- Main tiling function +local function fair(p, orientation) - -- Themes border width requires an offset. - local bw = tonumber(beautiful.border_width) or 0 + -- Theme vars + local useless_gap = beautiful.useless_gap_width or 0 + local global_border = beautiful.global_border_width or 0 - -- get our orientation right. + -- Aliases local wa = p.workarea local cls = p.clients - wa.height = wa.height - ((global_border * 2) + (bw * 2)) - wa.width = wa.width - ((global_border * 2) + (bw * 2)) - - if #cls > 0 then - local cells = math.ceil(math.sqrt(#cls)) - local strips = math.ceil(#cls / cells) - - local cell = 0 - local strip = 0 - for k, c in ipairs(cls) do - local g = {} - -- Save actual grid index for use in the useless_gap - -- routine. - local this_x = 0 - local this_y = 0 - if ( orientation == "east" and #cls > 2 ) - or ( orientation == "south" and #cls <= 2 ) then - if #cls < (strips * cells) and strip == strips - 1 then - g.width = wa.width / (cells - ((strips * cells) - #cls)) - else - g.width = wa.width / cells - end - g.height = wa.height / strips - - this_x = cell - this_y = strip - - g.x = wa.x + cell * g.width + global_border - g.y = wa.y + strip * g.height + global_border - - else - if #cls < (strips * cells) and strip == strips - 1 then - g.height = wa.height / (cells - ((strips * cells) - #cls)) - else - g.height = wa.height / cells - end - g.width = wa.width / strips - - this_x = strip - this_y = cell - - g.x = wa.x + strip * g.width + global_border - g.y = wa.y + cell * g.height + global_border - - end - - -- Useless gap. - if useless_gap > 0 - then - -- All clients tile evenly. - g.width = g.width - useless_gap - g.x = g.x + (useless_gap / 2) - g.height = g.height - useless_gap - g.y = g.y + (useless_gap / 2) - - end - -- End of useless gap. - - c:geometry(g) - - cell = cell + 1 - if cell == cells then - cell = 0 - strip = strip + 1 - end + -- Nothing to tile here + if #cls == 0 then return 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 + wa.x = wa.x + useless_gap / 2 + global_border + wa.y = wa.y + useless_gap / 2 + global_border + + -- Geometry calculation + local row, col = 0, 0 + + local rows = math.ceil(math.sqrt(#cls)) + local cols = math.ceil(#cls / rows) + + for i, c in ipairs(cls) do + local g = {} + + -- find tile orientation for current client and swap geometry if need + local need_swap = (orientation == "east" and #cls <= 2) or (orientation == "south" and #cls > 2) + local area = need_swap and swap(wa) or wa + + -- calculate geometry + if #cls < (cols * rows) and row == cols - 1 then + g.width = area.width / (rows - ((cols * rows) - #cls)) + else + g.width = area.width / rows end + + g.height = area.height / cols + g.x = area.x + col * g.width + g.y = area.y + row * g.height + + -- turn back to real if geometry was swapped + if need_swap then g = swap(g) end + + -- window size correction depending on useless gap and window border + size_correction(c, g, useless_gap) + + -- set geometry + c:geometry(g) + + -- update tile grid coordinates + col = i % rows + row = math.floor(i / rows) end end ---- Horizontal fair layout. --- @param screen The screen to arrange. -uselessfair.horizontal = {} -uselessfair.horizontal.name = "uselessfairh" -function uselessfair.horizontal.arrange(p) - return fair(p, "east") +-- Layout constructor +local function construct_layout(name, direction) + return { + name = name, + -- @p screen The screen number to tile + arrange = function(p) return fair(p, direction) end + } end --- Vertical fair layout. --- @param screen The screen to arrange. -uselessfair.name = "uselessfair" -function uselessfair.arrange(p) - return fair(p, "south") -end +-- Build layouts with different tile direction +uselessfair.vertical = construct_layout("uselessfair", "south") +uselessfair.horizontal = construct_layout("uselessfairh", "east") + +-- Module aliase +uselessfair.arrange = uselessfair.vertical.arrange +uselessfair.name = uselessfair.vertical.name return uselessfair diff --git a/layout/uselesstile.lua b/layout/uselesstile.lua index 65ce9b5..d244f43 100644 --- a/layout/uselesstile.lua +++ b/layout/uselesstile.lua @@ -1,239 +1,192 @@ --[[ - - Licensed under GNU General Public License v2 - * (c) 2014 projektile - * (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") local beautiful = require("beautiful") local ipairs = ipairs local math = { floor = math.floor, + ceil = math.ceil, max = math.max, min = math.min } local tonumber = tonumber local uselesstile = {} -local function tile_group(cls, wa, orientation, fact, group) - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width . - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - if useless_gap < 0 then useless_gap = 0 end - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - - -- Themes border width requires an offset - local bw = tonumber(beautiful.border_width) or 0 - - -- get our orientation right - local height = "height" - local width = "width" - local x = "x" - local y = "y" - if orientation == "top" or orientation == "bottom" then - height = "width" - width = "height" - x = "y" - y = "x" - end +-- Transformation functions +local function flip(canvas, geometry) + return { + -- vertical only + x = 2 * canvas.x + canvas.width - geometry.x - geometry.width, + y = geometry.y, + width = geometry.width, + height = geometry.height + } +end - -- make this more generic (not just width) - --if for top - available = wa[width] - (group.coord - wa[x]) -- it's truly not here - - -- find our total values - local total_fact = 0 - local min_fact = 1 - local size = group.size - for c = group.first,group.last do - -- determine the width/height based on the size_hint - local i = c - group.first +1 - local size_hints = cls[c].size_hints - local size_hint = size_hints["min_"..width] or size_hints["base_"..width] or 0 - size_hint = size_hint + cls[c].border_width*2 - size = math.max(size_hint, size) - - -- calculate the height - if not fact[i] then - fact[i] = min_fact - else - min_fact = math.min(fact[i],min_fact) - end - total_fact = total_fact + fact[i] - end - size = math.min(size, (available - global_border)) - local coord = wa[y] - local geom = {} - local used_size = 0 - local unused = wa[height] - (global_border * 2) - local stat_coord = wa[x] - --stat_coord = size - for c = group.first,group.last do - local i = c - group.first +1 - geom[width] = size - global_border - (bw * 2) - geom[height] = math.floor(unused * fact[i] / total_fact) - (bw * 2) - geom[x] = group.coord + global_border - geom[y] = coord + global_border - - coord = coord + geom[height] - unused = unused - geom[height] - total_fact = total_fact - fact[i] - used_size = math.max(used_size, geom[width]) - - -- Useless gap - if useless_gap > 0 - then - -- Top and left clients are shrinked by two steps and - -- get moved away from the border. Other clients just - -- get shrinked in one direction. - - top = false - left = false - - if geom[y] == wa[y] then - top = true - end - - if geom[x] == 0 or geom[x] == wa[x] then - left = true - end - - if top then - geom[height] = geom[height] - (2 * useless_gap) - geom[y] = geom[y] + useless_gap - else - geom[height] = geom[height] - useless_gap - end - - if left then - geom[width] = geom[width] - (2 * useless_gap) - geom[x] = geom[x] + useless_gap - else - geom[width] = geom[width] - useless_gap - end - end - -- End of useless gap. +local function swap(geometry) + return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width } +end - geom = cls[c]:geometry(geom) - 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 + + local area = { + x = wa.x, + y = wa.y + (index - 1) * height, + width = wa.width, + height = height + } + + if is_horizontal then area = swap(area) end - return used_size + return area end -local function tile(param, orientation) - local t = tag.selected(param.screen) - orientation = orientation or "right" - - -- this handles are different orientations - local height = "height" - local width = "width" - local x = "x" - local y = "y" - if orientation == "top" or orientation == "bottom" then - height = "width" - width = "height" - x = "y" - y = "x" - end +-- Client geometry correction depending on useless gap and window border +local function size_correction(c, geometry, useless_gap) + geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1) + geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1) + geometry.x = geometry.x + useless_gap / 2 + geometry.y = geometry.y + useless_gap / 2 +end - local cls = param.clients - local nmaster = math.min(tag.getnmaster(t), #cls) - local nother = math.max(#cls - nmaster,0) +-- Tile group of clients in given area +-- @canvas need for proper transformation only +local function tile_column(canvas, area, list, useless_gap, transformation) + for i, c in ipairs(list) do + local g = cut_area(area, #list, i) - local mwfact = tag.getmwfact(t) - local wa = param.workarea - local ncol = tag.getncol(t) + -- swap workarea dimensions + if transformation.flip then g = flip(canvas, g) end + if transformation.swap then g = swap(g) end - local data = tag.getdata(t).windowfact + -- useless gap and border correction + size_correction(c, g, useless_gap) - if not data then - data = {} - tag.getdata(t).windowfact = data + c:geometry(g) end +end + +--Main tile function +local function tile(p, orientation) - local coord = wa[x] - local place_master = true - if orientation == "left" or orientation == "top" then - -- if we are on the left or top we need to render the other windows first - place_master = false + -- Theme vars + local useless_gap = beautiful.useless_gap_width or 0 + local global_border = beautiful.global_border_width or 0 + + -- Aliases + local wa = p.workarea + local cls = p.clients + local t = tag.selected(p.screen) + + -- Nothing to tile here + if #cls == 0 then return end + + -- Get tag prop + local nmaster = math.min(tag.getnmaster(t), #cls) + local mwfact = tag.getmwfact(t) + + if nmaster == 0 then + mwfact = 0 + elseif nmaster == #cls then + mwfact = 1 end - -- this was easier than writing functions because there is a lot of data we need - for d = 1,2 do - if place_master and nmaster > 0 then - local size = wa[width] - if nother > 0 then - size = math.min(wa[width] * mwfact, wa[width] - (coord - wa[x])) - end - if not data[0] then - data[0] = {} - end - coord = coord + tile_group(cls, wa, orientation, data[0], {first=1, last=nmaster, coord = coord, size = size}) - 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 + wa.x = wa.x + useless_gap / 2 + global_border + wa.y = wa.y + useless_gap / 2 + global_border + + -- Find which transformation we need for given orientation + local transformation = { + swap = orientation == 'top' or orientation == 'bottom', + flip = orientation == 'left' or orientation == 'top' + } + + -- Swap workarea dimensions if orientation vertical + if transformation.swap then wa = swap(wa) end - if not place_master and nother > 0 then - local last = nmaster - - -- we have to modify the work area size to consider left and top views - local wasize = wa[width] - if nmaster > 0 and (orientation == "left" or orientation == "top") then - wasize = wa[width] - wa[width]*mwfact - end - for i = 1,ncol do - -- Try to get equal width among remaining columns - local size = math.min((wasize - (coord - wa[x])) / (ncol - i + 1)) --+ (global_border/(ncol))/(ncol+i^2) - local first = last + 1 - last = last + math.floor((#cls - last)/(ncol - i + 1)) - -- tile the column and update our current x coordinate - if not data[i] then - data[i] = {} - end - coord = coord + tile_group(cls, wa, orientation, data[i], { first = first, last = last, coord = coord, size = size }) - end + -- Split master and other windows + local cls_master, cls_other = {}, {} + + for i, c in ipairs(cls) do + if i <= nmaster then + table.insert(cls_master, c) + else + table.insert(cls_other, c) end - place_master = not place_master end -end - -uselesstile.right = {} -uselesstile.right.name = "uselesstile" -uselesstile.right.arrange = tile + -- Tile master windows + local master_area = { + x = wa.x, + y = wa.y, + width = nmaster > 0 and wa.width * mwfact or 0, + height = wa.height + } + + tile_column(wa, master_area, cls_master, useless_gap, transformation) + + -- Tile other windows + local other_area = { + x = wa.x + master_area.width, + y = wa.y, + width = wa.width - master_area.width, + height = wa.height + } + + -- get column number for other windows + local ncol = math.min(tag.getncol(t), #cls_other) + + -- 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 + 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 + local column = {} + + for j = 1, rows do + table.insert(column, cls_other[client_index]) + client_index = client_index + 1 + end ---- The main tile algo, on left. --- @param screen The screen number to tile. -uselesstile.left = {} -uselesstile.left.name = "uselesstileleft" -function uselesstile.left.arrange(p) - return tile(p, "left") + -- and tile + local column_area = cut_area(other_area, ncol, position, true) + tile_column(wa, column_area, column, useless_gap, transformation) + end end ---- The main tile algo, on bottom. --- @param screen The screen number to tile. -uselesstile.bottom = {} -uselesstile.bottom.name = "uselesstilebottom" -function uselesstile.bottom.arrange(p) - return tile(p, "bottom") +-- Layout constructor +local function construct_layout(name, orientation) + return { + name = name, + -- @p screen number to tile + arrange = function(p) return tile(p, orientation) end + } end ---- The main tile algo, on top. --- @param screen The screen number to tile. -uselesstile.top = {} -uselesstile.top.name = "uselesstiletop" -function uselesstile.top.arrange(p) - return tile(p, "top") -end +-- Build layouts with different tile direction +uselesstile.right = construct_layout("uselesstile", "right") +uselesstile.left = construct_layout("uselesstileleft", "left") +uselesstile.bottom = construct_layout("uselesstilebottom", "bottom") +uselesstile.top = construct_layout("uselesstiletop", "top") +-- Module aliase uselesstile.arrange = uselesstile.right.arrange uselesstile.name = uselesstile.right.name return uselesstile -