awful.layout: do not use global env
Layouts are passed a data structure that holds all the information they need to render the clients. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
a2fe3919f2
commit
2a2166d856
|
@ -9,6 +9,7 @@ local ipairs = ipairs
|
||||||
local tag = require("awful.tag")
|
local tag = require("awful.tag")
|
||||||
local util = require("awful.util")
|
local util = require("awful.util")
|
||||||
local suit = require("awful.layout.suit")
|
local suit = require("awful.layout.suit")
|
||||||
|
local client = require("awful.client")
|
||||||
local capi =
|
local capi =
|
||||||
{
|
{
|
||||||
hooks = hooks,
|
hooks = hooks,
|
||||||
|
@ -59,7 +60,16 @@ end
|
||||||
|
|
||||||
-- Register an arrange hook.
|
-- Register an arrange hook.
|
||||||
local function on_arrange (screen)
|
local function on_arrange (screen)
|
||||||
get(screen).arrange(screen)
|
local t = tag.selected(screen)
|
||||||
|
local p = {}
|
||||||
|
p.workarea = capi.screen[screen].workarea
|
||||||
|
p.geometry = capi.screen[screen].geometry
|
||||||
|
p.clients = client.tiled(screen)
|
||||||
|
p.ncol = tag.getncol(t)
|
||||||
|
p.nmaster = tag.getnmaster(t)
|
||||||
|
p.mwfact = tag.getmwfact(t)
|
||||||
|
p.tagdata = tag.getdata(t)
|
||||||
|
get(screen).arrange(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the current layout name.
|
--- Get the current layout name.
|
||||||
|
|
|
@ -7,18 +7,13 @@
|
||||||
-- Grab environment we need
|
-- Grab environment we need
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local math = math
|
local math = math
|
||||||
local client = require("awful.client")
|
|
||||||
local capi =
|
|
||||||
{
|
|
||||||
screen = screen
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Fair layouts module for awful
|
--- Fair layouts module for awful
|
||||||
module("awful.layout.suit.fair")
|
module("awful.layout.suit.fair")
|
||||||
|
|
||||||
local function fair(screen, orientation)
|
local function fair(p, orientation)
|
||||||
local wa = capi.screen[screen].workarea
|
local wa = p.workarea
|
||||||
local cls = client.tiled(screen)
|
local cls = p.clients
|
||||||
|
|
||||||
if #cls > 0 then
|
if #cls > 0 then
|
||||||
local cells = math.ceil(math.sqrt(#cls))
|
local cells = math.ceil(math.sqrt(#cls))
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
--- Dummy function for floating layout
|
--- Dummy function for floating layout
|
||||||
module("awful.layout.suit.floating")
|
module("awful.layout.suit.floating")
|
||||||
|
|
||||||
function arrange(screen)
|
function arrange(p)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,12 @@ local client = require("awful.client")
|
||||||
--- Magnifier layout module for awful
|
--- Magnifier layout module for awful
|
||||||
module("awful.layout.suit.magnifier")
|
module("awful.layout.suit.magnifier")
|
||||||
|
|
||||||
function arrange(screen)
|
function arrange(p)
|
||||||
-- Fullscreen?
|
-- Fullscreen?
|
||||||
local area = capi.screen[screen].workarea
|
local area = p.workarea
|
||||||
local cls = client.tiled(screen)
|
local cls = p.clients
|
||||||
local focus = capi.client.focus
|
local focus = capi.client.focus
|
||||||
local t = tag.selected(screen)
|
local mwfact = p.mwfact
|
||||||
local mwfact = tag.getmwfact(t)
|
|
||||||
local fidx -- Focus client index in cls table
|
|
||||||
|
|
||||||
-- Check that the focused window is on the right screen
|
-- Check that the focused window is on the right screen
|
||||||
if focus and focus.screen ~= screen then focus = nil end
|
if focus and focus.screen ~= screen then focus = nil end
|
||||||
|
|
|
@ -7,41 +7,35 @@
|
||||||
-- Grab environment we need
|
-- Grab environment we need
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local client = require("awful.client")
|
local client = require("awful.client")
|
||||||
local capi =
|
|
||||||
{
|
|
||||||
screen = screen
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Maximized and fullscreen layouts module for awful
|
--- Maximized and fullscreen layouts module for awful
|
||||||
module("awful.layout.suit.max")
|
module("awful.layout.suit.max")
|
||||||
|
|
||||||
local function fmax(screen, fs)
|
local function fmax(p, fs)
|
||||||
-- Fullscreen?
|
-- Fullscreen?
|
||||||
local area
|
local area
|
||||||
if fs then
|
if fs then
|
||||||
area = capi.screen[screen].geometry
|
area = p.geometry
|
||||||
else
|
else
|
||||||
area = capi.screen[screen].workarea
|
area = p.workarea
|
||||||
end
|
end
|
||||||
|
|
||||||
for k, c in pairs(client.visible(screen)) do
|
for k, c in pairs(p.clients) do
|
||||||
if not client.floating.get(c) then
|
|
||||||
c:geometry(area)
|
c:geometry(area)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Maximized layout.
|
--- Maximized layout.
|
||||||
-- @param screen The screen to arrange.
|
-- @param screen The screen to arrange.
|
||||||
name = "max"
|
name = "max"
|
||||||
function arrange(screen)
|
function arrange(p)
|
||||||
return fmax(screen, false)
|
return fmax(p, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fullscreen layout.
|
--- Fullscreen layout.
|
||||||
-- @param screen The screen to arrange.
|
-- @param screen The screen to arrange.
|
||||||
fullscreen = {}
|
fullscreen = {}
|
||||||
fullscreen.name = "fullscreen"
|
fullscreen.name = "fullscreen"
|
||||||
function fullscreen.arrange(screen)
|
function fullscreen.arrange(p)
|
||||||
return fmax(screen, true)
|
return fmax(p, true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,12 +9,6 @@
|
||||||
-- Grab environment we need
|
-- Grab environment we need
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local math = math
|
local math = math
|
||||||
local client = require("awful.client")
|
|
||||||
local tag = require("awful.tag")
|
|
||||||
local capi =
|
|
||||||
{
|
|
||||||
screen = screen
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Tiled layouts module for awful
|
--- Tiled layouts module for awful
|
||||||
module("awful.layout.suit.tile")
|
module("awful.layout.suit.tile")
|
||||||
|
@ -75,10 +69,9 @@ local function tile_group(cls, wa, orientation, fact, group)
|
||||||
end
|
end
|
||||||
|
|
||||||
return used_size
|
return used_size
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tile(screen, orientation)
|
local function tile(param, orientation)
|
||||||
orientation = orientation or "right"
|
orientation = orientation or "right"
|
||||||
|
|
||||||
-- this handles are different orientations
|
-- this handles are different orientations
|
||||||
|
@ -93,23 +86,21 @@ local function tile(screen, orientation)
|
||||||
y = "x"
|
y = "x"
|
||||||
end
|
end
|
||||||
|
|
||||||
local t = tag.selected(screen)
|
local cls = param.clients
|
||||||
local cls = client.tiled(screen)
|
local nmaster = math.min(param.nmaster, #cls)
|
||||||
local nmaster = math.min(tag.getnmaster(t), #cls)
|
|
||||||
local nother = math.max(#cls - nmaster,0)
|
local nother = math.max(#cls - nmaster,0)
|
||||||
|
|
||||||
local mwfact = tag.getmwfact(t)
|
local mwfact = param.mwfact
|
||||||
local wa = capi.screen[screen].workarea
|
local wa = param.workarea
|
||||||
local ncol = tag.getncol(t)
|
local ncol = param.ncol
|
||||||
|
|
||||||
local data = tag.getproperty(t,"windowfact")
|
local data = param.tagdata.windowfact
|
||||||
|
|
||||||
if not data then
|
if not data then
|
||||||
data = {}
|
data = {}
|
||||||
tag.setproperty(t,"windowfact", data)
|
param.tagdata.windowfact = data
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
|
||||||
local coord = wa[x]
|
local coord = wa[x]
|
||||||
local place_master = true
|
local place_master = true
|
||||||
if orientation == "left" or orientation == "top" then
|
if orientation == "left" or orientation == "top" then
|
||||||
|
@ -163,24 +154,24 @@ right.arrange = tile
|
||||||
-- @param screen The screen number to tile.
|
-- @param screen The screen number to tile.
|
||||||
left = {}
|
left = {}
|
||||||
left.name = "tileleft"
|
left.name = "tileleft"
|
||||||
function left.arrange(screen)
|
function left.arrange(p)
|
||||||
return tile(screen, "left")
|
return tile(p, "left")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- The main tile algo, on bottom.
|
--- The main tile algo, on bottom.
|
||||||
-- @param screen The screen number to tile.
|
-- @param screen The screen number to tile.
|
||||||
bottom = {}
|
bottom = {}
|
||||||
bottom.name = "tilebottom"
|
bottom.name = "tilebottom"
|
||||||
function bottom.arrange(screen)
|
function bottom.arrange(p)
|
||||||
return tile(screen, "bottom")
|
return tile(p, "bottom")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- The main tile algo, on top.
|
--- The main tile algo, on top.
|
||||||
-- @param screen The screen number to tile.
|
-- @param screen The screen number to tile.
|
||||||
top = {}
|
top = {}
|
||||||
top.name = "tiletop"
|
top.name = "tiletop"
|
||||||
function top.arrange(screen)
|
function top.arrange(p)
|
||||||
return tile(screen, "top")
|
return tile(p, "top")
|
||||||
end
|
end
|
||||||
|
|
||||||
arrange = right.arrange
|
arrange = right.arrange
|
||||||
|
|
|
@ -244,6 +244,13 @@ local function hook_tags(screen, tag, action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get tag data table.
|
||||||
|
-- @param tag The Tag.
|
||||||
|
-- @return The data table.
|
||||||
|
function getdata(tag)
|
||||||
|
return data.tags[tag]
|
||||||
|
end
|
||||||
|
|
||||||
--- Get a tag property.
|
--- Get a tag property.
|
||||||
-- @param tag The tag.
|
-- @param tag The tag.
|
||||||
-- @param prop The property name.
|
-- @param prop The property name.
|
||||||
|
|
Loading…
Reference in New Issue