From fec8d6aa8fe257f2d1fbab9a908b1e3a9a98bed3 Mon Sep 17 00:00:00 2001 From: actionless Date: Sat, 9 Sep 2017 23:00:36 +0200 Subject: [PATCH 1/2] fix(awful: placement: no_offsceen): use new placement infrastructure fix(tests: examples: awful: placement: no_offscreen): uncomment context fix(awful: placement): common function to remove border from geometries --- lib/awful/placement.lua | 51 +++++++++---------- .../examples/awful/placement/no_offscreen.lua | 2 +- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 273bbbf7..e439336b 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -774,6 +774,13 @@ local function fit_in_bounding(obj, geo, args) return geo2.width == geo.width and geo2.height == geo.height end +-- Remove border from drawable geometry +local function remove_border(drawable, args, geo) + local bw = (not args.ignore_border_width) and drawable.border_width or 0 + geo.width = geo.width - 2*bw + geo.height = geo.height - 2*bw +end + --- Move a drawable to the closest corner of the parent geometry (such as the -- screen). -- @@ -827,17 +834,19 @@ end --- Place the client so no part of it will be outside the screen (workarea). --@DOC_awful_placement_no_offscreen_EXAMPLE@ -- @client c The client. --- @tparam[opt=client's screen] integer screen The screen. +-- @tparam[opt={}] table args The arguments +-- @tparam[opt=client's screen] integer args.screen The screen. -- @treturn table The new client geometry. -function placement.no_offscreen(c, screen) +function placement.no_offscreen(c, args) --HACK necessary for composition to work. The API will be changed soon - if type(screen) == "table" then - screen = nil + if type(args) == "number" or type(args) == "screen" then + args = { screen = args } end c = c or capi.client.focus + args = add_context(args, "no_offscreen") local geometry = area_common(c) - screen = get_screen(screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y)) + local screen = get_screen(args.screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y)) local screen_geometry = screen.workarea if geometry.x + geometry.width > screen_geometry.x + screen_geometry.width then @@ -854,10 +863,9 @@ function placement.no_offscreen(c, screen) geometry.y = screen_geometry.y end - return c:geometry { - x = geometry.x, - y = geometry.y - } + remove_border(c, args, geometry) + geometry_common(c, args, geometry) + return fix_new_geometry(geometry, args, true) end --- Place the client where there's place available with minimum overlap. @@ -946,10 +954,7 @@ function placement.under_mouse(d, args) ngeo.x = math.floor(m_coords.x - ngeo.width / 2) ngeo.y = math.floor(m_coords.y - ngeo.height / 2) - local bw = (not args.ignore_border_width) and d.border_width or 0 - ngeo.width = ngeo.width - 2*bw - ngeo.height = ngeo.height - 2*bw - + remove_border(d, args, ngeo) geometry_common(d, args, ngeo) return fix_new_geometry(ngeo, args, true) @@ -1051,11 +1056,7 @@ function placement.resize_to_mouse(d, args) pts.x_only and ngeo.y + ngeo.height or math.max(p2.y, p1.y) ) - local bw = (not args.ignore_border_width) and d.border_width or 0 - - for _, a in ipairs {"width", "height"} do - ngeo[a] = ngeo[a] - 2*bw - end + remove_border(d, args, ngeo) -- Now, correct the geometry by the given size_hints offset if d.apply_size_hints then @@ -1101,7 +1102,6 @@ function placement.align(d, args) local sgeo = get_parent_geometry(d, args) local dgeo = geometry_common(d, args) - local bw = (not args.ignore_border_width) and d.border_width or 0 local pos = align_map[args.position]( sgeo.width , @@ -1113,10 +1113,10 @@ function placement.align(d, args) local ngeo = { x = (pos.x and math.ceil(sgeo.x + pos.x) or dgeo.x) , y = (pos.y and math.ceil(sgeo.y + pos.y) or dgeo.y) , - width = math.ceil(dgeo.width ) - 2*bw, - height = math.ceil(dgeo.height ) - 2*bw, + width = math.ceil(dgeo.width ) , + height = math.ceil(dgeo.height ) , } - + remove_border(d, args, ngeo) geometry_common(d, args, ngeo) attach(d, placement[args.position], args) @@ -1325,10 +1325,7 @@ function placement.scale(d, args) end end - local bw = (not args.ignore_border_width) and d.border_width or 0 - ngeo.width = ngeo.width - 2*bw - ngeo.height = ngeo.height - 2*bw - + remove_border(d, args, ngeo) geometry_common(d, args, ngeo) attach(d, placement.maximize, args) @@ -1342,7 +1339,7 @@ end -- -- {"top", "right", "left", "bottom"} -- --- In that case, if there is room on the top of the geomtry, then it will have +-- In that case, if there is room on the top of the geometry, then it will have -- priority, followed by all the others, in order. -- -- @tparam drawable d A wibox or client diff --git a/tests/examples/awful/placement/no_offscreen.lua b/tests/examples/awful/placement/no_offscreen.lua index b596ab26..0208f15b 100644 --- a/tests/examples/awful/placement/no_offscreen.lua +++ b/tests/examples/awful/placement/no_offscreen.lua @@ -4,7 +4,7 @@ local c = client.gen_fake {x = -30, y = -30, width= 100, height=100} --DOC_HIDE print("Before:", "x="..c.x..", y="..c.y..", width="..c.width..", height="..c.height) --DOC_HIDE -awful.placement.no_offscreen(c)--, {honor_workarea=true, margins=40}) +awful.placement.no_offscreen(c, {honor_workarea=true, margins=40}) print("After:", "x="..c.x..", y="..c.y..", width="..c.width..", height="..c.height) --DOC_HIDE From 492d07a9cd90abb2d3924356e757077a142275cb Mon Sep 17 00:00:00 2001 From: actionless Date: Wed, 25 Jul 2018 14:31:51 +0200 Subject: [PATCH 2/2] fixup! fix(awful: placement: no_offsceen): use new placement infrastructure doc(awful: placement: no_offscreen): update comment and print deprecation warning --- lib/awful/placement.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index e439336b..41334bc4 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -838,8 +838,14 @@ end -- @tparam[opt=client's screen] integer args.screen The screen. -- @treturn table The new client geometry. function placement.no_offscreen(c, args) - --HACK necessary for composition to work. The API will be changed soon + + --compatibility with the old API if type(args) == "number" or type(args) == "screen" then + gdebug.deprecate( + "awful.placement.no_offscreen screen argument is deprecated".. + " use awful.placement.no_offscreen(c, {screen=...})", + {deprecated_in=5} + ) args = { screen = args } end