Hi, On Mon, Jan 12, 2009 at 02:46:07PM +0100, Julien Danjou wrote: > - Implements mouse support; should be trivial, should be like tile. Hum, where is mouse support code in tile ? I think I missed something > - Implements equivalent to tileup/bottom/left; not a big deal I guess. Still working on finding a clean way to do that, tried different approach but none was good enough > - Add more documentation. Done, I hope it's not over commented now > - Use size hints directly. Done > Thank you very much for your work. No problems
Cheers, Mawww. --- lib/awful/layout/suit/adaptile.lua.in | 126 +++++++++++++++++++++++++++++++++ 1 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 lib/awful/layout/suit/adaptile.lua.in diff --git a/lib/awful/layout/suit/adaptile.lua.in b/lib/awful/layout/suit/adaptile.lua.in new file mode 100644 index 0000000..180a0e7 --- /dev/null +++ b/lib/awful/layout/suit/adaptile.lua.in @@ -0,0 +1,126 @@ +--------------------------------------------------------------------------- +-- @author Maxime Coste <[email protected]> +-- @copyright 2009 Maxime Coste +-- @release @AWESOME_VERSION@ +-- based upon tile.lua by Julien Danjou +--------------------------------------------------------------------------- + +-- Grab environment +local setmetatable = setmetatable +local ipairs = ipairs +local print = print +local pairs = pairs +local table = table +local math = math +local client = require("awful.client") +local tag = require("awful.tag") +local capi = +{ + screen = screen +} + +module("awful.layout.suit.adaptile") + +-- Tile a column +-- @param cls a table of client +-- @param col a table defining a column with following fields: +-- first: first client index in cls +-- last: last client index in cls +-- x: x coordinate of the column +-- width: queried width +-- @param wa the workarea of the screen +-- @return the effective width of the column +local function tile_column(cls, col, wa) + -- width available for the column + local available_width = wa.width - (col.x - wa.x) + + -- compute the needed width of the column, which is the greatest between + -- the asked width and each client minimal width (but limited by the + -- available width) + local width = col.width + for c = col.first,col.last do + local size_hints = cls[c].size_hints + -- minimum width of a window according to ICCCM + local min_width = size_hints.min_width or size_hints.base_width or 0 + min_width = min_width + cls[c].border_width*2 + width = math.max(min_width, width) + end + width = math.min(width, available_width) + + -- the y coordinate for the next client in this column + local y = wa.y + -- effective width used by the column + local used_width = 0 + for c = col.first,col.last do + -- divide the remaining height by the number of clients yet to resize + local height = (wa.height - (y - wa.y)) / (col.last - c + 1) + -- resize the client and get it's effective size back + local geom = cls[c]:geometry({ x = col.x, y = y, height = height, width = width }) + y = geom.y + geom.height + used_width = math.max(used_width, geom.width) + end + return used_width +end + +-- Apply the adaptile layout to the screen +-- @param _ unused, but needed by metatable ? +-- @param screen the screen to arrange +local function tile(_, screen, position) + position = position or "right" + local cls = client.tiled(screen) + local t = tag.selected() + + -- compute the number of window in the master column and child columns + local masterwin = math.min(tag.getnmaster(t), #cls) + local otherwin = math.max(#cls - masterwin, 0) + + -- number of child columns + local ncol = math.min(math.max(tag.getncol(t), 1), otherwin) + + -- rotate the work area so we can work on it as if we were tiling on the + -- right + local wa = capi.screen[screen].workarea + + -- the x coordinate of the current column + local x = wa.x + if masterwin > 0 then + local width = wa.width + if otherwin > 0 then + -- respect the mwfact setting when there is actually windows out of + -- the master area + width = wa.width * tag.getmwfact(t) + end + -- tile the column and update our current x coordinate + x = x + tile_column(cls, { first = 1, last = masterwin, x = x, width = width }, wa) + end + -- + local last = masterwin + for i = 1,ncol do + -- Try to get equal width among remaining columns + local width = (wa.width - (x - wa.x)) / (ncol - i + 1) + local first = last + 1 + last = last + math.floor((#cls - last)/(ncol - i + 1)) + -- tile the column and update our current x coordinate + x = x + tile_column(cls, { first = first, last = last, x = x, width = width }, wa) + end +end + +-- adaptile with the child columns on the left +-- @param screen The screen number to tile +function left(screen) + tile(nil, screen, "left") +end + +-- adaptile with the child columns on the top +-- @param screen The screen number to tile +function top(screen) + tile(nil, screen, "top") +end + +-- adaptile with the child columns on the bottom +-- @param screen The screen number to tile +function bottom(screen) + tile(nil, screen, "bottom") +end + +setmetatable(_M, { __call = tile }) -- 1.6.0.6 -- To unsubscribe, send mail to [email protected].
