From f0546b900d3c0815fd98bac6cb91b3cf53c23b2d Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 23 Apr 2016 23:05:11 -0400 Subject: [PATCH] tests: Improve the placement compositing tests --- lib/awful/placement.lua | 35 +++++++++++++-------- tests/examples/awful/placement/compose.lua | 12 ++++--- tests/examples/awful/placement/compose2.lua | 19 +++++++++++ 3 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 tests/examples/awful/placement/compose2.lua diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 6e5df3f3f..426da79ed 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -9,14 +9,16 @@ -- * 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 -- --- +-- +--

Compositing

-- -- It is possible to compose placement function using the `+` or `*` operator: -- --- local f = (awful.placement.right + awful.placement.left) --- f(client.focus) +--@DOC_awful_placement_compose_EXAMPLE@ -- --- ### Common arguments +--@DOC_awful_placement_compose2_EXAMPLE@ +-- +--

Common arguments

-- -- **pretend** (*boolean*): -- @@ -86,6 +88,7 @@ local capi = local client = require("awful.client") local layout = require("awful.layout") local a_screen = require("awful.screen") +local util = require("awful.util") local dpi = require("beautiful").xresources.apply_dpi local function get_screen(s) @@ -137,7 +140,7 @@ local function compose(...) for k, f in ipairs(queue) do if k == #queue then - args.pretent = pretend_real + args.pretend = pretend_real or false end local r = {f(d, args, ...)} @@ -286,11 +289,19 @@ end -- @param d The drawin -- @tparam[opt=nil] table new_geo A new geometry -- @tparam[opt=false] boolean ignore_border_width Ignore the border +-- @tparam table args the method arguments -- @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 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 + + -- 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.height = geometry.height + 2 * border 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 if type(geo) == "function" then 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 if args.margins then local delta = type(args.margins) == "table" and args.margins or { @@ -1100,6 +1105,10 @@ function placement.scale(d, args) 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) attach(d, placement.maximize, args) diff --git a/tests/examples/awful/placement/compose.lua b/tests/examples/awful/placement/compose.lua index 28098677d..f67107625 100644 --- a/tests/examples/awful/placement/compose.lua +++ b/tests/examples/awful/placement/compose.lua @@ -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 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) -f(client.focus) + -- "right" will be replaced by "left" + 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 diff --git a/tests/examples/awful/placement/compose2.lua b/tests/examples/awful/placement/compose2.lua new file mode 100644 index 000000000..68cbf5b30 --- /dev/null +++ b/tests/examples/awful/placement/compose2.lua @@ -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