2009-01-13 20:31:37 +01:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 12:44:21 +02:00
|
|
|
--- Tiled layouts module for awful
|
|
|
|
--
|
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
|
2016-12-10 02:24:22 +01:00
|
|
|
-- @module awful.layout
|
2009-01-13 20:31:37 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
local tile = {}
|
2009-01-13 20:31:37 +01:00
|
|
|
|
2016-08-14 07:34:43 +02:00
|
|
|
--- The tile layout layoutbox icon.
|
|
|
|
-- @beautiful beautiful.layout_tile
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- The tile top layout layoutbox icon.
|
|
|
|
-- @beautiful beautiful.layout_tiletop
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- The tile bottom layout layoutbox icon.
|
|
|
|
-- @beautiful beautiful.layout_tilebottom
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- The tile left layout layoutbox icon.
|
|
|
|
-- @beautiful beautiful.layout_tileleft
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2015-08-11 22:43:17 +02:00
|
|
|
--- Jump mouse cursor to the client's corner when resizing it.
|
|
|
|
tile.resize_jump_to_corner = true
|
|
|
|
|
2016-02-07 15:24:08 +01:00
|
|
|
local function mouse_resize_handler(c, _, _, _, orientation)
|
|
|
|
orientation = orientation or "tile"
|
2016-09-11 08:08:38 +02:00
|
|
|
local wa = c.screen.workarea
|
2016-04-11 06:30:05 +02:00
|
|
|
local mwfact = c.screen.selected_tag.master_width_factor
|
2014-10-23 01:30:19 +02:00
|
|
|
local cursor
|
|
|
|
local g = c:geometry()
|
|
|
|
local offset = 0
|
2015-08-11 22:43:17 +02:00
|
|
|
local corner_coords
|
|
|
|
local coordinates_delta = {x=0,y=0}
|
|
|
|
|
2014-10-23 01:30:19 +02:00
|
|
|
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
|
2015-08-11 22:43:17 +02:00
|
|
|
corner_coords = { x = wa.x + wa.width * mwfact, y = g.y + offset }
|
2014-10-23 01:30:19 +02:00
|
|
|
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
|
2015-08-11 22:43:17 +02:00
|
|
|
corner_coords = { x = wa.x + wa.width * (1 - mwfact), y = g.y + offset }
|
2014-10-23 01:30:19 +02:00
|
|
|
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
|
2015-08-11 22:43:17 +02:00
|
|
|
corner_coords = { y = wa.y + wa.height * mwfact, x = g.x + offset}
|
2014-10-23 01:30:19 +02:00
|
|
|
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
|
2015-08-11 22:43:17 +02:00
|
|
|
corner_coords = { y = wa.y + wa.height * (1 - mwfact), x= g.x + offset }
|
|
|
|
end
|
|
|
|
if tile.resize_jump_to_corner then
|
|
|
|
capi.mouse.coords(corner_coords)
|
|
|
|
else
|
|
|
|
local mouse_coords = capi.mouse.coords()
|
|
|
|
coordinates_delta = {
|
|
|
|
x = corner_coords.x - mouse_coords.x,
|
|
|
|
y = corner_coords.y - mouse_coords.y,
|
|
|
|
}
|
2014-10-23 01:30:19 +02:00
|
|
|
end
|
|
|
|
|
2015-07-13 20:52:16 +02:00
|
|
|
local prev_coords = {}
|
2014-10-23 01:30:19 +02:00
|
|
|
capi.mousegrabber.run(function (_mouse)
|
2016-04-28 01:48:03 +02:00
|
|
|
if not c.valid then return false end
|
|
|
|
|
2015-08-11 22:43:17 +02:00
|
|
|
_mouse.x = _mouse.x + coordinates_delta.x
|
|
|
|
_mouse.y = _mouse.y + coordinates_delta.y
|
2016-02-07 15:24:08 +01:00
|
|
|
for _, v in ipairs(_mouse.buttons) do
|
2014-10-23 01:30:19 +02:00
|
|
|
if v then
|
2015-07-13 20:52:16 +02:00
|
|
|
prev_coords = { x =_mouse.x, y = _mouse.y }
|
2014-10-23 01:30:19 +02:00
|
|
|
local fact_x = (_mouse.x - wa.x) / wa.width
|
|
|
|
local fact_y = (_mouse.y - wa.y) / wa.height
|
2016-02-07 15:24:08 +01:00
|
|
|
local new_mwfact
|
2014-10-23 01:30:19 +02:00
|
|
|
|
2016-02-07 15:24:08 +01:00
|
|
|
local geom = c:geometry()
|
2014-10-23 01:30:19 +02:00
|
|
|
|
2017-03-03 23:11:06 +01:00
|
|
|
-- we have to make sure we're not on the last visible
|
|
|
|
-- client where we have to use different settings.
|
2014-10-23 01:30:19 +02:00
|
|
|
local wfact
|
|
|
|
local wfact_x, wfact_y
|
2016-02-07 15:24:08 +01:00
|
|
|
if (geom.y+geom.height+15) > (wa.y+wa.height) then
|
|
|
|
wfact_y = (geom.y + geom.height - _mouse.y) / wa.height
|
2014-10-23 01:30:19 +02:00
|
|
|
else
|
2016-02-07 15:24:08 +01:00
|
|
|
wfact_y = (_mouse.y - geom.y) / wa.height
|
2014-10-23 01:30:19 +02:00
|
|
|
end
|
|
|
|
|
2016-02-07 15:24:08 +01:00
|
|
|
if (geom.x+geom.width+15) > (wa.x+wa.width) then
|
|
|
|
wfact_x = (geom.x + geom.width - _mouse.x) / wa.width
|
2014-10-23 01:30:19 +02:00
|
|
|
else
|
2016-02-07 15:24:08 +01:00
|
|
|
wfact_x = (_mouse.x - geom.x) / wa.width
|
2014-10-23 01:30:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if orientation == "tile" then
|
2016-02-07 15:24:08 +01:00
|
|
|
new_mwfact = fact_x
|
2014-10-23 01:30:19 +02:00
|
|
|
wfact = wfact_y
|
|
|
|
elseif orientation == "left" then
|
2016-02-07 15:24:08 +01:00
|
|
|
new_mwfact = 1 - fact_x
|
2014-10-23 01:30:19 +02:00
|
|
|
wfact = wfact_y
|
|
|
|
elseif orientation == "bottom" then
|
2016-02-07 15:24:08 +01:00
|
|
|
new_mwfact = fact_y
|
2014-10-23 01:30:19 +02:00
|
|
|
wfact = wfact_x
|
|
|
|
else
|
2016-02-07 15:24:08 +01:00
|
|
|
new_mwfact = 1 - fact_y
|
2014-10-23 01:30:19 +02:00
|
|
|
wfact = wfact_x
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:30:05 +02:00
|
|
|
c.screen.selected_tag.master_width_factor
|
|
|
|
= math.min(math.max(new_mwfact, 0.01), 0.99)
|
2014-10-23 01:30:19 +02:00
|
|
|
client.setwfact(math.min(math.max(wfact,0.01), 0.99), c)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2015-07-13 20:52:16 +02:00
|
|
|
return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y
|
2014-10-23 01:30:19 +02:00
|
|
|
end, cursor)
|
|
|
|
end
|
|
|
|
|
2018-07-21 20:53:30 +02:00
|
|
|
local function apply_size_hints(c, width, height, useless_gap)
|
|
|
|
local bw = c.border_width
|
|
|
|
width, height = width - 2 * bw - useless_gap, height - 2 * bw - useless_gap
|
|
|
|
width, height = c:apply_size_hints(math.max(1, width), math.max(1, height))
|
|
|
|
return width + 2 * bw + useless_gap, height + 2 * bw + useless_gap
|
|
|
|
end
|
|
|
|
|
|
|
|
local function tile_group(gs, cls, wa, orientation, fact, group, useless_gap)
|
2009-01-13 20:31:37 +01:00
|
|
|
-- 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 = 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
|
2016-04-18 07:27:50 +02:00
|
|
|
size = math.max(1, math.min(size, available))
|
2009-01-13 20:31:37 +01:00
|
|
|
|
|
|
|
local coord = wa[y]
|
|
|
|
local used_size = 0
|
|
|
|
local unused = wa[height]
|
|
|
|
for c = group.first,group.last do
|
2015-02-15 17:25:11 +01:00
|
|
|
local geom = {}
|
|
|
|
local hints = {}
|
2009-01-13 20:31:37 +01:00
|
|
|
local i = c - group.first +1
|
2015-02-15 17:25:11 +01:00
|
|
|
geom[width] = size
|
2016-04-18 07:27:50 +02:00
|
|
|
geom[height] = math.max(1, math.floor(unused * fact[i] / total_fact))
|
2009-01-13 20:31:37 +01:00
|
|
|
geom[x] = group.coord
|
|
|
|
geom[y] = coord
|
2015-02-15 17:25:11 +01:00
|
|
|
gs[cls[c]] = geom
|
2018-07-21 20:53:30 +02:00
|
|
|
hints.width, hints.height = apply_size_hints(cls[c], geom.width, geom.height, useless_gap)
|
2015-02-15 17:25:11 +01:00
|
|
|
coord = coord + hints[height]
|
|
|
|
unused = unused - hints[height]
|
2009-01-13 20:31:37 +01:00
|
|
|
total_fact = total_fact - fact[i]
|
2015-02-15 17:25:11 +01:00
|
|
|
used_size = math.max(used_size, hints[width])
|
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)
|
2016-04-05 09:02:00 +02:00
|
|
|
local t = param.tag or capi.screen[param.screen].selected_tag
|
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 width = "width"
|
|
|
|
local x = "x"
|
|
|
|
if orientation == "top" or orientation == "bottom" then
|
|
|
|
width = "height"
|
|
|
|
x = "y"
|
|
|
|
end
|
|
|
|
|
2015-02-15 17:25:11 +01:00
|
|
|
local gs = param.geometries
|
2009-02-24 21:50:46 +01:00
|
|
|
local cls = param.clients
|
2018-07-21 20:53:30 +02:00
|
|
|
local useless_gap = param.useless_gap
|
2016-04-11 06:50:46 +02:00
|
|
|
local nmaster = math.min(t.master_count, #cls)
|
2009-01-13 20:31:37 +01:00
|
|
|
local nother = math.max(#cls - nmaster,0)
|
|
|
|
|
2016-04-11 06:30:05 +02:00
|
|
|
local mwfact = t.master_width_factor
|
2009-02-24 21:50:46 +01:00
|
|
|
local wa = param.workarea
|
2016-04-11 06:30:05 +02:00
|
|
|
local ncol = t.column_count
|
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
|
|
|
|
|
2016-04-05 09:02:00 +02:00
|
|
|
local grow_master = t.master_fill_policy == "expand"
|
2009-01-13 20:31:37 +01:00
|
|
|
-- this was easier than writing functions because there is a lot of data we need
|
2016-02-07 15:24:08 +01:00
|
|
|
for _ = 1,2 do
|
2009-01-13 20:31:37 +01:00
|
|
|
if place_master and nmaster > 0 then
|
|
|
|
local size = wa[width]
|
2015-07-16 11:48:18 +02:00
|
|
|
if nother > 0 or not grow_master then
|
2009-01-13 20:31:37 +01:00
|
|
|
size = math.min(wa[width] * mwfact, wa[width] - (coord - wa[x]))
|
|
|
|
end
|
2015-07-16 11:48:18 +02:00
|
|
|
if nother == 0 and not grow_master then
|
|
|
|
coord = coord + (wa[width] - size)/2
|
|
|
|
end
|
2009-01-13 20:31:37 +01:00
|
|
|
if not data[0] then
|
|
|
|
data[0] = {}
|
|
|
|
end
|
2017-03-03 23:11:06 +01:00
|
|
|
coord = coord + tile_group(gs, cls, wa, orientation, data[0],
|
2018-07-21 20:53:30 +02:00
|
|
|
{first=1, last=nmaster, coord = coord, size = size}, useless_gap)
|
2009-01-13 20:31:37 +01:00
|
|
|
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
|
2017-03-03 23:11:06 +01:00
|
|
|
coord = coord + tile_group(gs, cls, wa, orientation, data[i],
|
2018-07-21 20:53:30 +02:00
|
|
|
{ first = first, last = last, coord = coord, size = size }, useless_gap)
|
2009-01-13 20:31:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
place_master = not place_master
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-07-20 21:21:51 +02:00
|
|
|
function tile.skip_gap(nclients, t)
|
|
|
|
return nclients == 1 and t.master_fill_policy == "expand"
|
|
|
|
end
|
|
|
|
|
2016-12-10 02:24:22 +01:00
|
|
|
--- The main tile algo, on the right.
|
|
|
|
-- @param screen The screen number to tile.
|
2017-01-22 21:57:26 +01:00
|
|
|
-- @clientlayout awful.layout.suit.tile.right
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.right = {}
|
|
|
|
tile.right.name = "tile"
|
|
|
|
tile.right.arrange = do_tile
|
2017-07-20 21:21:51 +02:00
|
|
|
tile.right.skip_gap = tile.skip_gap
|
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
|
|
|
|
2016-12-10 02:24:22 +01:00
|
|
|
--- The main tile algo, on the left.
|
2009-01-13 20:31:37 +01:00
|
|
|
-- @param screen The screen number to tile.
|
2016-12-10 02:24:22 +01:00
|
|
|
-- @clientlayout awful.layout.suit.tile.left
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.left = {}
|
|
|
|
tile.left.name = "tileleft"
|
2017-07-20 21:21:51 +02:00
|
|
|
tile.left.skip_gap = tile.skip_gap
|
2012-06-14 02:45:17 +02:00
|
|
|
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
|
|
|
|
2016-12-10 02:24:22 +01:00
|
|
|
--- The main tile algo, on the bottom.
|
2009-01-13 20:31:37 +01:00
|
|
|
-- @param screen The screen number to tile.
|
2016-12-10 02:24:22 +01:00
|
|
|
-- @clientlayout awful.layout.suit.tile.bottom
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.bottom = {}
|
|
|
|
tile.bottom.name = "tilebottom"
|
2017-07-20 21:21:51 +02:00
|
|
|
tile.bottom.skip_gap = tile.skip_gap
|
2012-06-14 02:45:17 +02:00
|
|
|
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
|
|
|
|
2016-12-10 02:24:22 +01:00
|
|
|
--- The main tile algo, on the top.
|
2009-01-13 20:31:37 +01:00
|
|
|
-- @param screen The screen number to tile.
|
2016-12-10 02:24:22 +01:00
|
|
|
-- @clientlayout awful.layout.suit.tile.top
|
2012-06-14 02:45:17 +02:00
|
|
|
tile.top = {}
|
|
|
|
tile.top.name = "tiletop"
|
2017-07-20 21:21:51 +02:00
|
|
|
tile.top.skip_gap = tile.skip_gap
|
2012-06-14 02:45:17 +02:00
|
|
|
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
|
2015-12-12 17:42:33 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|