tests: Improve the placement compositing tests
This commit is contained in:
parent
bb0a2addb4
commit
f0546b900d
|
@ -9,14 +9,16 @@
|
||||||
-- * Turn each function into an API with various common customization parameters.
|
-- * Turn each function into an API with various common customization parameters.
|
||||||
-- * Re-use the same functions for the `mouse`, `client`s, `screen`s and `wibox`es
|
-- * Re-use the same functions for the `mouse`, `client`s, `screen`s and `wibox`es
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
|
-- <h3>Compositing</h3>
|
||||||
--
|
--
|
||||||
-- It is possible to compose placement function using the `+` or `*` operator:
|
-- It is possible to compose placement function using the `+` or `*` operator:
|
||||||
--
|
--
|
||||||
-- local f = (awful.placement.right + awful.placement.left)
|
--@DOC_awful_placement_compose_EXAMPLE@
|
||||||
-- f(client.focus)
|
|
||||||
--
|
--
|
||||||
-- ### Common arguments
|
--@DOC_awful_placement_compose2_EXAMPLE@
|
||||||
|
--
|
||||||
|
-- <h3>Common arguments</h3>
|
||||||
--
|
--
|
||||||
-- **pretend** (*boolean*):
|
-- **pretend** (*boolean*):
|
||||||
--
|
--
|
||||||
|
@ -86,6 +88,7 @@ local capi =
|
||||||
local client = require("awful.client")
|
local client = require("awful.client")
|
||||||
local layout = require("awful.layout")
|
local layout = require("awful.layout")
|
||||||
local a_screen = require("awful.screen")
|
local a_screen = require("awful.screen")
|
||||||
|
local util = require("awful.util")
|
||||||
local dpi = require("beautiful").xresources.apply_dpi
|
local dpi = require("beautiful").xresources.apply_dpi
|
||||||
|
|
||||||
local function get_screen(s)
|
local function get_screen(s)
|
||||||
|
@ -137,7 +140,7 @@ local function compose(...)
|
||||||
|
|
||||||
for k, f in ipairs(queue) do
|
for k, f in ipairs(queue) do
|
||||||
if k == #queue then
|
if k == #queue then
|
||||||
args.pretent = pretend_real
|
args.pretend = pretend_real or false
|
||||||
end
|
end
|
||||||
|
|
||||||
local r = {f(d, args, ...)}
|
local r = {f(d, args, ...)}
|
||||||
|
@ -286,11 +289,19 @@ end
|
||||||
-- @param d The drawin
|
-- @param d The drawin
|
||||||
-- @tparam[opt=nil] table new_geo A new geometry
|
-- @tparam[opt=nil] table new_geo A new geometry
|
||||||
-- @tparam[opt=false] boolean ignore_border_width Ignore the border
|
-- @tparam[opt=false] boolean ignore_border_width Ignore the border
|
||||||
|
-- @tparam table args the method arguments
|
||||||
-- @treturn The drawin's area.
|
-- @treturn The drawin's area.
|
||||||
local function area_common(d, new_geo, ignore_border_width)
|
local function area_common(d, new_geo, ignore_border_width, args)
|
||||||
-- The C side expect no arguments, nil isn't valid
|
-- The C side expect no arguments, nil isn't valid
|
||||||
local geometry = new_geo and d:geometry(new_geo) or d:geometry()
|
local geometry = new_geo and d:geometry(new_geo) or d:geometry()
|
||||||
local border = ignore_border_width and 0 or d.border_width or 0
|
local border = ignore_border_width and 0 or d.border_width or 0
|
||||||
|
|
||||||
|
-- When using the placement composition along with the "pretend"
|
||||||
|
-- option, it is necessary to keep a "virtual" geometry.
|
||||||
|
if args and args.override_geometry then
|
||||||
|
geometry = util.table.clone(args.override_geometry)
|
||||||
|
end
|
||||||
|
|
||||||
geometry.width = geometry.width + 2 * border
|
geometry.width = geometry.width + 2 * border
|
||||||
geometry.height = geometry.height + 2 * border
|
geometry.height = geometry.height + 2 * border
|
||||||
return geometry
|
return geometry
|
||||||
|
@ -322,15 +333,9 @@ local function geometry_common(obj, args, new_geo, ignore_border_width)
|
||||||
-- It is either a drawable or something that implement its API
|
-- It is either a drawable or something that implement its API
|
||||||
if type(geo) == "function" then
|
if type(geo) == "function" then
|
||||||
local dgeo = area_common(
|
local dgeo = area_common(
|
||||||
obj, fix_new_geometry(new_geo, args), ignore_border_width
|
obj, fix_new_geometry(new_geo, args), ignore_border_width, args
|
||||||
)
|
)
|
||||||
|
|
||||||
-- When using the placement composition along with the "pretend"
|
|
||||||
-- option, it is necessary to keep a "virtual" geometry.
|
|
||||||
if args.override_geometry then
|
|
||||||
dgeo = args.override_geometry
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Apply the margins
|
-- Apply the margins
|
||||||
if args.margins then
|
if args.margins then
|
||||||
local delta = type(args.margins) == "table" and args.margins or {
|
local delta = type(args.margins) == "table" and args.margins or {
|
||||||
|
@ -1100,6 +1105,10 @@ function placement.scale(d, args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local bw = d.border_width or 0
|
||||||
|
ngeo.width = ngeo.width - 2*bw
|
||||||
|
ngeo.height = ngeo.height - 2*bw
|
||||||
|
|
||||||
geometry_common(d, args, ngeo)
|
geometry_common(d, args, ngeo)
|
||||||
|
|
||||||
attach(d, placement.maximize, args)
|
attach(d, placement.maximize, args)
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
screen[1]._resize {width = 128, height = 96} --DOC_HIDE
|
screen[1]._resize {x = 175, width = 128, height = 96} --DOC_NO_USAGE --DOC_HIDE
|
||||||
local awful = {placement = require("awful.placement")} --DOC_HIDE
|
local awful = {placement = require("awful.placement")} --DOC_HIDE
|
||||||
local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
local c = client.gen_fake {x = 220, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
local f = (awful.placement.right + awful.placement.left)
|
-- "right" will be replaced by "left"
|
||||||
f(client.focus)
|
local f = (awful.placement.right + awful.placement.left)
|
||||||
|
f(client.focus)
|
||||||
|
|
||||||
assert(c.x == 0 and c.y==screen[1].geometry.height/2-30/2-c.border_width--DOC_HIDE
|
local sg = screen[1].geometry--DOC_HIDE
|
||||||
|
assert(c.x == sg.x and c.y==sg.height/2-30/2-c.border_width--DOC_HIDE
|
||||||
and c.width==40 and c.height==30)--DOC_HIDE
|
and c.width==40 and c.height==30)--DOC_HIDE
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
screen[1]._resize {x = 175, width = 128, height = 96} --DOC_NO_USAGE --DOC_HIDE
|
||||||
|
local awful = {placement = require("awful.placement")} --DOC_HIDE
|
||||||
|
local c = client.gen_fake {x = 220, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
|
|
||||||
|
-- Simulate Windows 7 "edge snap" (also called aero snap) feature
|
||||||
|
local axis = "vertically"
|
||||||
|
|
||||||
|
local f = awful.placement.scale
|
||||||
|
+ awful.placement.left
|
||||||
|
+ (axis and awful.placement["maximize_"..axis] or nil)
|
||||||
|
|
||||||
|
local geo = f(client.focus, {honor_workarea=true, to_percent = 0.5})
|
||||||
|
|
||||||
|
local wa = screen[1].workarea--DOC_HIDE
|
||||||
|
assert(c.x == wa.x and geo.x == wa.x)--DOC_HIDE
|
||||||
|
assert(c.y == wa.y) --DOC_HIDE
|
||||||
|
assert(c.width == wa.width/2 - 2*c.border_width)--DOC_HIDE
|
||||||
|
assert(c.height == wa.height - 2*c.border_width)--DOC_HIDE
|
Loading…
Reference in New Issue