awful.placement: Add aliases for the `align` method
This re-use the `align` code for the existing `centered`, `center_horizontal` and `center_vertical` methods. It also add all the other edges and corners alias.
This commit is contained in:
parent
db2f545411
commit
d85b7eb3e5
|
@ -542,57 +542,38 @@ function placement.align(d, args)
|
||||||
attach(d, placement[args.position], args)
|
attach(d, placement[args.position], args)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Place the client centered with respect to a parent or the clients screen.
|
-- Add the alias functions
|
||||||
-- @param c The client.
|
for k in pairs(align_map) do
|
||||||
-- @param[opt] p The parent (nil for screen centering).
|
placement[k] = function(d, args)
|
||||||
-- @return The new client geometry.
|
local new_args = setmetatable({position = k}, {__index=args})
|
||||||
function placement.centered(c, p)
|
placement.align(d, new_args)
|
||||||
c = c or capi.client.focus
|
|
||||||
local c_geometry = area_common(c)
|
|
||||||
local screen = get_screen(c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y))
|
|
||||||
local s_geometry
|
|
||||||
if p then
|
|
||||||
s_geometry = area_common(p)
|
|
||||||
else
|
|
||||||
s_geometry = screen.geometry
|
|
||||||
end
|
end
|
||||||
return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2,
|
reverse_align_map[placement[k]] = k
|
||||||
y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Place the client centered on the horizontal axis with respect to a parent or the clients screen.
|
-- Add the documentation for align alias
|
||||||
-- @param c The client.
|
|
||||||
-- @param[opt] p The parent (nil for screen centering).
|
|
||||||
-- @return The new client geometry.
|
|
||||||
function placement.center_horizontal(c, p)
|
|
||||||
c = c or capi.client.focus
|
|
||||||
local c_geometry = area_common(c)
|
|
||||||
local screen = get_screen(c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y))
|
|
||||||
local s_geometry
|
|
||||||
if p then
|
|
||||||
s_geometry = area_common(p)
|
|
||||||
else
|
|
||||||
s_geometry = screen.geometry
|
|
||||||
end
|
|
||||||
return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 })
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Place the client centered on the vertical axis with respect to a parent or the clients screen.
|
---@DOC_awful_placement_top_left_EXAMPLE@
|
||||||
-- @param c The client.
|
|
||||||
-- @param[opt] p The parent (nil for screen centering).
|
---@DOC_awful_placement_top_right_EXAMPLE@
|
||||||
-- @return The new client geometry.
|
|
||||||
function placement.center_vertical(c, p)
|
---@DOC_awful_placement_bottom_left_EXAMPLE@
|
||||||
c = c or capi.client.focus
|
|
||||||
local c_geometry = area_common(c)
|
---@DOC_awful_placement_bottom_right_EXAMPLE@
|
||||||
local screen = get_screen(c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y))
|
|
||||||
local s_geometry
|
---@DOC_awful_placement_left_EXAMPLE@
|
||||||
if p then
|
|
||||||
s_geometry = area_common(p)
|
---@DOC_awful_placement_right_EXAMPLE@
|
||||||
else
|
|
||||||
s_geometry = screen.geometry
|
---@DOC_awful_placement_top_EXAMPLE@
|
||||||
end
|
|
||||||
return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 })
|
---@DOC_awful_placement_bottom_EXAMPLE@
|
||||||
end
|
|
||||||
|
---@DOC_awful_placement_centered_EXAMPLE@
|
||||||
|
|
||||||
|
---@DOC_awful_placement_center_vertical_EXAMPLE@
|
||||||
|
|
||||||
|
---@DOC_awful_placement_center_horizontal_EXAMPLE@
|
||||||
|
|
||||||
return placement
|
return placement
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue