2009-01-13 20:31:37 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Donald Ephraim Curtis <dcurtis@cs.uiowa.edu>
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Donald Ephraim Curtis
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
2014-10-23 01:30:19 +02:00
|
|
|
local tag = require("awful.tag")
|
|
|
|
local client = require("awful.client")
|
2009-01-13 20:31:37 +01:00
|
|
|
local ipairs = ipairs
|
|
|
|
local math = math
|
2014-10-23 01:30:19 +02:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
mouse = mouse,
|
|
|
|
screen = screen,
|
|
|
|
mousegrabber = mousegrabber
|
|
|
|
}
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
--- Tiled layouts module for awful
|
2012-06-14 02:45:17 +02:00
|
|
|
-- awful.layout.suit.tile
|
|
|
|
local tile = {}
|
2009-01-13 20:31:37 +01:00
|
|
|
|
2014-10-23 01:30:19 +02:00
|
|
|
local function mouse_resize_handler(c, corner, x, y, orientation)
|
|
|
|
local orientation = orientation or "tile"
|
|
|
|
local wa = capi.screen[c.screen].workarea
|
|
|
|
local mwfact = tag.getmwfact()
|
|
|
|
local cursor
|
|
|
|
local g = c:geometry()
|
|
|
|
local offset = 0
|
|
|
|
local x,y
|
|
|
|
if orientation == "tile" then
|
|
|
|
cursor = "cross"
|
|
|
|
if g.height+15 > wa.height then
|
|
|
|
offset = g.height * .5
|
|
|
|
cursor = "sb_h_double_arrow"
|
|
|
|
elseif not (g.y+g.height+15 > wa.y+wa.height) then
|
|
|
|
offset = g.height
|
|
|
|
end
|
|
|
|
capi.mouse.coords({ x = wa.x + wa.width * mwfact, y = g.y + offset })
|
|
|
|
elseif orientation == "left" then
|
|
|
|
cursor = "cross"
|
|
|
|
if g.height+15 >= wa.height then
|
|
|
|
offset = g.height * .5
|
|
|
|
cursor = "sb_h_double_arrow"
|
|
|
|
elseif not (g.y+g.height+15 > wa.y+wa.height) then
|
|
|
|
offset = g.height
|
|
|
|
end
|
|
|
|
capi.mouse.coords({ x = wa.x + wa.width * (1 - mwfact), y = g.y + offset })
|
|
|
|
elseif orientation == "bottom" then
|
|
|
|
cursor = "cross"
|
|
|
|
if g.width+15 >= wa.width then
|
|
|
|
offset = g.width * .5
|
|
|
|
cursor = "sb_v_double_arrow"
|
|
|
|
elseif not (g.x+g.width+15 > wa.x+wa.width) then
|
|
|
|
offset = g.width
|
|
|
|
end
|
|
|
|
capi.mouse.coords({ y = wa.y + wa.height * mwfact, x = g.x + offset})
|
|
|
|
else
|
|
|
|
cursor = "cross"
|
|
|
|
if g.width+15 >= wa.width then
|
|
|
|
offset = g.width * .5
|
|
|
|
cursor = "sb_v_double_arrow"
|
|
|
|
elseif not (g.x+g.width+15 > wa.x+wa.width) then
|
|
|
|
offset = g.width
|
|
|
|
end
|
|
|
|
capi.mouse.coords({ y = wa.y + wa.height * (1 - mwfact), x= g.x + offset })
|
|
|
|
end
|
|
|
|
|
|
|
|
capi.mousegrabber.run(function (_mouse)
|
|
|
|
for k, v in ipairs(_mouse.buttons) do
|
|
|
|
if v then
|
|
|
|
local fact_x = (_mouse.x - wa.x) / wa.width
|
|
|
|
local fact_y = (_mouse.y - wa.y) / wa.height
|
|
|
|
local mwfact
|
|
|
|
|
|
|
|
local g = c:geometry()
|
|
|
|
|
|
|
|
|
|
|
|
-- we have to make sure we're not on the last visible client where we have to use different settings.
|
|
|
|
local wfact
|
|
|
|
local wfact_x, wfact_y
|
|
|
|
if (g.y+g.height+15) > (wa.y+wa.height) then
|
|
|
|
wfact_y = (g.y + g.height - _mouse.y) / wa.height
|
|
|
|
else
|
|
|
|
wfact_y = (_mouse.y - g.y) / wa.height
|
|
|
|
end
|
|
|
|
|
|
|
|
if (g.x+g.width+15) > (wa.x+wa.width) then
|
|
|
|
wfact_x = (g.x + g.width - _mouse.x) / wa.width
|
|
|
|
else
|
|
|
|
wfact_x = (_mouse.x - g.x) / wa.width
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if orientation == "tile" then
|
|
|
|
mwfact = fact_x
|
|
|
|
wfact = wfact_y
|
|
|
|
elseif orientation == "left" then
|
|
|
|
mwfact = 1 - fact_x
|
|
|
|
wfact = wfact_y
|
|
|
|
elseif orientation == "bottom" then
|
|
|
|
mwfact = fact_y
|
|
|
|
wfact = wfact_x
|
|
|
|
else
|
|
|
|
mwfact = 1 - fact_y
|
|
|
|
wfact = wfact_x
|
|
|
|
end
|
|
|
|
|
|
|
|
tag.setmwfact(math.min(math.max(mwfact, 0.01), 0.99), tag.selected(c.screen))
|
|
|
|
client.setwfact(math.min(math.max(wfact,0.01), 0.99), c)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end, cursor)
|
|
|
|
end
|
|
|
|
|
2009-01-13 20:31:37 +01:00
|
|
|
local function tile_group(cls, wa, orientation, fact, group)
|
|
|
|
-- 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
|
|
|
|
|
|
|
|
-- make this more generic (not just width)
|
2012-06-17 14:52:06 +02:00
|
|
|
local available = wa[width] - (group.coord - wa[x])
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
-- 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)
|
|
|
|
|
|
|
|
local coord = wa[y]
|
|
|
|
local geom = {}
|
|
|
|
local used_size = 0
|
|
|
|
local unused = wa[height]
|
|
|
|
for c = group.first,group.last do
|
|
|
|
local i = c - group.first +1
|
2010-05-28 19:43:46 +02:00
|
|
|
geom[width] = size - cls[c].border_width * 2
|
|
|
|
geom[height] = math.floor(unused * fact[i] / total_fact) - cls[c].border_width * 2
|
2009-01-13 20:31:37 +01:00
|
|
|
geom[x] = group.coord
|
|
|
|
geom[y] = coord
|
|
|
|
geom = cls[c]:geometry(geom)
|
2010-05-29 00:31:52 +02:00
|
|
|
coord = coord + geom[height] + cls[c].border_width * 2
|
|
|
|
unused = unused - geom[height] - cls[c].border_width * 2
|
2009-01-13 20:31:37 +01:00
|
|
|
total_fact = total_fact - fact[i]
|
2013-01-30 09:23:28 +01:00
|
|
|
used_size = math.max(used_size, geom[width] + cls[c].border_width * 2)
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return used_size
|
|
|
|
end
|
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
local function do_tile(param, orientation)
|
2014-10-13 21:07:31 +02:00
|
|
|
local t = param.tag or tag.selected(param.screen)
|
2009-01-13 20:31:37 +01:00
|
|
|
orientation = orientation or "right"
|
|
|
|
|
2014-03-15 02:56:58 +01:00
|
|
|
-- This handles all different orientations.
|
2009-01-13 20:31:37 +01:00
|
|
|
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
|
|
|
|
|
2009-02-24 21:50:46 +01:00
|
|
|
local cls = param.clients
|
2009-08-07 15:50:45 +02:00
|
|
|
local nmaster = math.min(tag.getnmaster(t), #cls)
|
2009-01-13 20:31:37 +01:00
|
|
|
local nother = math.max(#cls - nmaster,0)
|
|
|
|
|
2009-08-07 15:50:45 +02:00
|
|
|
local mwfact = tag.getmwfact(t)
|
2009-02-24 21:50:46 +01:00
|
|
|
local wa = param.workarea
|
2009-08-07 15:50:45 +02:00
|
|
|
local ncol = tag.getncol(t)
|
2009-01-13 20:31:37 +01:00
|
|
|
|
2009-08-07 15:50:45 +02:00
|
|
|
local data = tag.getdata(t).windowfact
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
if not data then
|
|
|
|
data = {}
|
2009-08-07 15:50:45 +02:00
|
|
|
tag.getdata(t).windowfact = data
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
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) )
|
|
|
|
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
|
|
|
|
end
|
|
|
|
place_master = not place_master
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.right = {}
|
|
|
|
tile.right.name = "tile"
|
|
|
|
tile.right.arrange = do_tile
|
2014-10-23 01:30:19 +02:00
|
|
|
function tile.right.mouse_resize_handler(c, corner, x, y)
|
|
|
|
return mouse_resize_handler(c, corner, x, y)
|
|
|
|
end
|
2009-02-24 21:46:29 +01:00
|
|
|
|
2009-01-13 20:31:37 +01:00
|
|
|
--- The main tile algo, on left.
|
|
|
|
-- @param screen The screen number to tile.
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.left = {}
|
|
|
|
tile.left.name = "tileleft"
|
|
|
|
function tile.left.arrange(p)
|
|
|
|
return do_tile(p, "left")
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
2014-10-23 01:30:19 +02:00
|
|
|
function tile.left.mouse_resize_handler(c, corner, x, y)
|
|
|
|
return mouse_resize_handler(c, corner, x, y, "left")
|
|
|
|
end
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
--- The main tile algo, on bottom.
|
|
|
|
-- @param screen The screen number to tile.
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.bottom = {}
|
|
|
|
tile.bottom.name = "tilebottom"
|
|
|
|
function tile.bottom.arrange(p)
|
|
|
|
return do_tile(p, "bottom")
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
2014-10-23 01:30:19 +02:00
|
|
|
function tile.bottom.mouse_resize_handler(c, corner, x, y)
|
|
|
|
return mouse_resize_handler(c, corner, x, y, "bottom")
|
|
|
|
end
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
--- The main tile algo, on top.
|
|
|
|
-- @param screen The screen number to tile.
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.top = {}
|
|
|
|
tile.top.name = "tiletop"
|
|
|
|
function tile.top.arrange(p)
|
|
|
|
return do_tile(p, "top")
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
2014-10-23 01:30:19 +02:00
|
|
|
function tile.top.mouse_resize_handler(c, corner, x, y)
|
|
|
|
return mouse_resize_handler(c, corner, x, y, "top")
|
|
|
|
end
|
2009-01-13 20:31:37 +01:00
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.arrange = tile.right.arrange
|
2014-10-23 01:30:19 +02:00
|
|
|
tile.mouse_resize_handler = tile.right.mouse_resize_handler
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.name = tile.right.name
|
|
|
|
|
|
|
|
return tile
|