placement: Fix incorect use of the border_width
The code and tests assumed the border was equaly applied around the geometry while the {x,y} pair of the geometry include the border.
This commit is contained in:
parent
798729ff11
commit
fe8beaeaac
|
@ -172,8 +172,8 @@ local function area_common(d, new_geo, ignore_border_width)
|
||||||
-- 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
|
||||||
geometry.x = geometry.x - border
|
geometry.x = geometry.x
|
||||||
geometry.y = geometry.y - border
|
geometry.y = geometry.y
|
||||||
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
|
||||||
|
@ -511,7 +511,10 @@ function placement.no_offscreen(c, screen)
|
||||||
geometry.y = screen_geometry.y
|
geometry.y = screen_geometry.y
|
||||||
end
|
end
|
||||||
|
|
||||||
return c:geometry({ x = geometry.x, y = geometry.y })
|
return c:geometry {
|
||||||
|
x = geometry.x,
|
||||||
|
y = geometry.y
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Place the client where there's place available with minimum overlap.
|
--- Place the client where there's place available with minimum overlap.
|
||||||
|
@ -656,8 +659,8 @@ function placement.align(d, args)
|
||||||
)
|
)
|
||||||
|
|
||||||
geometry_common(d, args, {
|
geometry_common(d, args, {
|
||||||
x = (pos.x and math.ceil(sgeo.x + pos.x) or dgeo.x) + bw ,
|
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) + bw ,
|
y = (pos.y and math.ceil(sgeo.y + pos.y) or dgeo.y) ,
|
||||||
width = math.ceil(dgeo.width ) - 2*bw,
|
width = math.ceil(dgeo.width ) - 2*bw,
|
||||||
height = math.ceil(dgeo.height ) - 2*bw,
|
height = math.ceil(dgeo.height ) - 2*bw,
|
||||||
})
|
})
|
||||||
|
@ -729,15 +732,15 @@ function placement.stretch(d, args)
|
||||||
local bw = d.border_width or 0
|
local bw = d.border_width or 0
|
||||||
|
|
||||||
if args.direction == "left" then
|
if args.direction == "left" then
|
||||||
ngeo.x = sgeo.x + bw
|
ngeo.x = sgeo.x
|
||||||
ngeo.width = dgeo.width + (dgeo.x - ngeo.x)
|
ngeo.width = dgeo.width + (dgeo.x - ngeo.x)
|
||||||
elseif args.direction == "right" then
|
elseif args.direction == "right" then
|
||||||
ngeo.width = sgeo.width - ngeo.x - bw
|
ngeo.width = sgeo.width - ngeo.x - 2*bw
|
||||||
elseif args.direction == "up" then
|
elseif args.direction == "up" then
|
||||||
ngeo.y = sgeo.y + bw
|
ngeo.y = sgeo.y
|
||||||
ngeo.height = dgeo.height + (dgeo.y - ngeo.y)
|
ngeo.height = dgeo.height + (dgeo.y - ngeo.y)
|
||||||
elseif args.direction == "down" then
|
elseif args.direction == "down" then
|
||||||
ngeo.height = sgeo.height - dgeo.y - bw
|
ngeo.height = sgeo.height - dgeo.y - 2*bw
|
||||||
else
|
else
|
||||||
assert(false)
|
assert(false)
|
||||||
end
|
end
|
||||||
|
@ -788,12 +791,12 @@ function placement.maximize(d, args)
|
||||||
local bw = d.border_width or 0
|
local bw = d.border_width or 0
|
||||||
|
|
||||||
if (not args.axis) or args.axis :match "vertical" then
|
if (not args.axis) or args.axis :match "vertical" then
|
||||||
ngeo.y = sgeo.y + bw
|
ngeo.y = sgeo.y
|
||||||
ngeo.height = sgeo.height - 2*bw
|
ngeo.height = sgeo.height - 2*bw
|
||||||
end
|
end
|
||||||
|
|
||||||
if (not args.axis) or args.axis :match "horizontal" then
|
if (not args.axis) or args.axis :match "horizontal" then
|
||||||
ngeo.x = sgeo.x + bw
|
ngeo.x = sgeo.x
|
||||||
ngeo.width = sgeo.width - 2*bw
|
ngeo.width = sgeo.width - 2*bw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.bottom(client.focus)
|
awful.placement.bottom(client.focus)
|
||||||
|
|
||||||
assert(c.x == screen[1].geometry.width/2-40/2--DOC_HIDE
|
assert(c.x == screen[1].geometry.width/2-40/2-c.border_width--DOC_HIDE
|
||||||
and c.y==screen[1].geometry.height-30-c.border_width--DOC_HIDE
|
and c.y==screen[1].geometry.height-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
|
||||||
|
|
|
@ -11,8 +11,8 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
awful.placement.bottom_left(client.focus)
|
awful.placement.bottom_left(client.focus)
|
||||||
|
|
||||||
assert( --DOC_HIDE
|
assert( --DOC_HIDE
|
||||||
c.x == c.border_width --DOC_HIDE
|
c.x == 0 --DOC_HIDE
|
||||||
and c.y == screen[1].geometry.height-30-c.border_width --DOC_HIDE
|
and c.y+2*c.border_width == screen[1].geometry.height-30 --DOC_HIDE
|
||||||
and c.width == 40--DOC_HIDE
|
and c.width == 40--DOC_HIDE
|
||||||
and c.height == 30--DOC_HIDE
|
and c.height == 30--DOC_HIDE
|
||||||
) --DOC_HIDE
|
) --DOC_HIDE
|
||||||
|
|
|
@ -10,6 +10,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.bottom_right(client.focus)
|
awful.placement.bottom_right(client.focus)
|
||||||
|
|
||||||
assert(c.x == screen[1].geometry.width-40-c.border_width) --DOC_HIDE
|
assert(c.x == screen[1].geometry.width-40-2*c.border_width) --DOC_HIDE
|
||||||
assert(c.y==screen[1].geometry.height-30-c.border_width) --DOC_HIDE
|
assert(c.y==screen[1].geometry.height-30-2*c.border_width) --DOC_HIDE
|
||||||
assert(c.width==40 and c.height==30)--DOC_HIDE
|
assert(c.width==40 and c.height==30)--DOC_HIDE
|
||||||
|
|
|
@ -9,6 +9,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.center_horizontal(client.focus)
|
awful.placement.center_horizontal(client.focus)
|
||||||
|
|
||||||
assert(c.x == screen[1].geometry.width/2-40/2)--DOC_HIDE
|
assert(c.x == screen[1].geometry.width/2-40/2-c.border_width)--DOC_HIDE
|
||||||
assert(c.y==35)--DOC_HIDE
|
assert(c.y==35)--DOC_HIDE
|
||||||
assert(c.width==40 and c.height==30)--DOC_HIDE
|
assert(c.width==40 and c.height==30)--DOC_HIDE
|
||||||
|
|
|
@ -10,5 +10,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.centered(client.focus)
|
awful.placement.centered(client.focus)
|
||||||
|
|
||||||
assert(c.x == screen[1].geometry.width/2-40/2 and c.y==screen[1].geometry.height/2-30/2--DOC_HIDE
|
assert(c.x == screen[1].geometry.width/2-40/2-c.border_width) --DOC_HIDE
|
||||||
and c.width==40 and c.height==30)--DOC_HIDE
|
assert(c.y==screen[1].geometry.height/2-30/2-c.border_width) --DOC_HIDE
|
||||||
|
assert(c.width==40 and c.height==30)--DOC_HIDE
|
||||||
|
|
|
@ -8,49 +8,50 @@ mouse.coords {x=100,y=100} --DOC_HIDE
|
||||||
-- Move the mouse to the closest corner of the focused client
|
-- Move the mouse to the closest corner of the focused client
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c})
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c})
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x-bw and mouse.coords().y == (c.y) + (c.height)/2) --DOC_HIDE
|
assert(mouse.coords().x == c.x) --DOC_HIDE
|
||||||
|
assert(mouse.coords().y == (c.y) + (c.height)/2+bw) --DOC_HIDE
|
||||||
|
|
||||||
-- Top left --DOC_HIDE
|
-- Top left --DOC_HIDE
|
||||||
mouse.coords {x=60,y=40} --DOC_HIDE
|
mouse.coords {x=60,y=40} --DOC_HIDE
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x-bw and mouse.coords().y == c.y-bw) --DOC_HIDE
|
assert(mouse.coords().x == c.x and mouse.coords().y == c.y) --DOC_HIDE
|
||||||
|
|
||||||
-- Top right --DOC_HIDE
|
-- Top right --DOC_HIDE
|
||||||
mouse.coords {x=230,y=50} --DOC_HIDE
|
mouse.coords {x=230,y=50} --DOC_HIDE
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x+c.width+bw and mouse.coords().y == c.y-bw) --DOC_HIDE
|
assert(mouse.coords().x == c.x+c.width+2*bw and mouse.coords().y == c.y) --DOC_HIDE
|
||||||
|
|
||||||
-- Right --DOC_HIDE
|
-- Right --DOC_HIDE
|
||||||
mouse.coords {x=240,y=140} --DOC_HIDE
|
mouse.coords {x=240,y=140} --DOC_HIDE
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x+c.width+bw and mouse.coords().y == c.y+c.height/2) --DOC_HIDE
|
assert(mouse.coords().x == c.x+c.width+2*bw and mouse.coords().y == c.y+c.height/2+bw) --DOC_HIDE
|
||||||
|
|
||||||
-- Bottom right --DOC_HIDE
|
-- Bottom right --DOC_HIDE
|
||||||
mouse.coords {x=210,y=190} --DOC_HIDE
|
mouse.coords {x=210,y=190} --DOC_HIDE
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x+c.width+bw and mouse.coords().y == c.y+c.height+bw) --DOC_HIDE
|
assert(mouse.coords().x == c.x+c.width+2*bw and mouse.coords().y == c.y+c.height+2*bw) --DOC_HIDE
|
||||||
|
|
||||||
-- Bottom --DOC_HIDE
|
-- Bottom --DOC_HIDE
|
||||||
mouse.coords {x=130,y=190} --DOC_HIDE
|
mouse.coords {x=130,y=190} --DOC_HIDE
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x+c.width/2 and mouse.coords().y == c.y + c.height + bw) --DOC_HIDE
|
assert(mouse.coords().x == c.x+c.width/2+bw and mouse.coords().y == c.y + c.height + 2*bw) --DOC_HIDE
|
||||||
|
|
||||||
-- Top --DOC_HIDE
|
-- Top --DOC_HIDE
|
||||||
mouse.coords {x=130,y=30} --DOC_HIDE
|
mouse.coords {x=130,y=30} --DOC_HIDE
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x + c.width/2 and mouse.coords().y == c.y-bw) --DOC_HIDE
|
assert(mouse.coords().x == c.x + c.width/2+bw and mouse.coords().y == c.y) --DOC_HIDE
|
||||||
|
|
||||||
-- Bottom left + outside of "c" --DOC_HIDE
|
-- Bottom left + outside of "c" --DOC_HIDE
|
||||||
mouse.coords {x=0,y=230} --DOC_HIDE
|
mouse.coords {x=0,y=230} --DOC_HIDE
|
||||||
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --DOC_HIDE
|
||||||
mouse.push_history() --DOC_HIDE
|
mouse.push_history() --DOC_HIDE
|
||||||
assert(mouse.coords().x == c.x-bw and mouse.coords().y == c.y+c.height+bw) --DOC_HIDE
|
assert(mouse.coords().x == c.x and mouse.coords().y == c.y+c.height+2*bw) --DOC_HIDE
|
||||||
|
|
||||||
-- It is possible to emulate the mouse API to get the closest corner of
|
-- It is possible to emulate the mouse API to get the closest corner of
|
||||||
-- random area
|
-- random area
|
||||||
|
|
|
@ -10,5 +10,5 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.left(client.focus)
|
awful.placement.left(client.focus)
|
||||||
|
|
||||||
assert(c.x == c.border_width and c.y==screen[1].geometry.height/2-30/2--DOC_HIDE
|
assert(c.x == 0 and c.y==screen[1].geometry.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
|
||||||
|
|
|
@ -10,6 +10,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.right(client.focus)
|
awful.placement.right(client.focus)
|
||||||
|
|
||||||
assert(c.x == screen[1].geometry.width-40-c.border_width --DOC_HIDE
|
assert(c.x == screen[1].geometry.width-40-2*c.border_width) --DOC_HIDE
|
||||||
and c.y==screen[1].geometry.height/2-30/2--DOC_HIDE
|
assert( c.y==screen[1].geometry.height/2-30/2-c.border_width)--DOC_HIDE
|
||||||
and c.width==40 and c.height==30)--DOC_HIDE
|
assert( c.width==40 and c.height==30)--DOC_HIDE
|
||||||
|
|
|
@ -13,5 +13,5 @@ placement.stretch_down(client.focus)
|
||||||
assert(c.x==45) --DOC_HIDE
|
assert(c.x==45) --DOC_HIDE
|
||||||
assert(c.y==35) --DOC_HIDE
|
assert(c.y==35) --DOC_HIDE
|
||||||
assert(c.width == 40) --DOC_HIDE
|
assert(c.width == 40) --DOC_HIDE
|
||||||
assert(c.y+c.height == --DOC_HIDE
|
assert(c.y+c.height+2*c.border_width == --DOC_HIDE
|
||||||
screen[1].geometry.y + screen[1].geometry.height) --DOC_HIDE
|
screen[1].geometry.y + screen[1].geometry.height) --DOC_HIDE
|
||||||
|
|
|
@ -10,5 +10,5 @@ local 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 = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
placement.stretch_left(client.focus)
|
placement.stretch_left(client.focus)
|
||||||
|
|
||||||
assert(c.x == c.border_width and c.y == 35 and c.height == 30 --DOC_HIDE
|
assert(c.x == 0 and c.y == 35 and c.height == 30) --DOC_HIDE
|
||||||
and c.width == 45+40) --DOC_HIDE
|
print(c.width-2*c.border_width == 45+40) --DOC_HIDE
|
||||||
|
|
|
@ -11,4 +11,4 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
placement.stretch_right(client.focus)
|
placement.stretch_right(client.focus)
|
||||||
|
|
||||||
local right = screen[1].geometry.x + screen[1].geometry.width --DOC_HIDE
|
local right = screen[1].geometry.x + screen[1].geometry.width --DOC_HIDE
|
||||||
assert(c.height == 30 and c.x == 45 and c.x+c.width+c.border_width == right) --DOC_HIDE
|
assert(c.height == 30 and c.x == 45 and c.x+c.width+2*c.border_width == right) --DOC_HIDE
|
||||||
|
|
|
@ -10,8 +10,8 @@ local 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 = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
placement.stretch_up(client.focus)
|
placement.stretch_up(client.focus)
|
||||||
|
|
||||||
assert(c.y==c.border_width) --DOC_HIDE
|
assert(c.y==0) --DOC_HIDE
|
||||||
assert(c.x==45) --DOC_HIDE
|
assert(c.x==45) --DOC_HIDE
|
||||||
assert(c.width == 40) --DOC_HIDE
|
assert(c.width == 40) --DOC_HIDE
|
||||||
print(c.height)
|
print(c.height-2*c.border_width,35+30)
|
||||||
assert(c.height == 35+30) --DOC_HIDE
|
assert(c.height-2*c.border_width == 35+30) --DOC_HIDE
|
||||||
|
|
|
@ -10,5 +10,7 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.top(client.focus)
|
awful.placement.top(client.focus)
|
||||||
|
|
||||||
assert(c.x == screen[1].geometry.width/2-40/2 and c.y==c.border_width--DOC_HIDE
|
assert(c.x == screen[1].geometry.width/2-40/2-c.border_width)
|
||||||
and c.width==40 and c.height==30)--DOC_HIDE
|
assert(c.y==0) --DOC_HIDE
|
||||||
|
assert( c.width==40) --DOC_HIDE
|
||||||
|
assert(c.height==30)--DOC_HIDE
|
||||||
|
|
|
@ -10,4 +10,4 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.top_left(client.focus)
|
awful.placement.top_left(client.focus)
|
||||||
|
|
||||||
assert(c.x == c.border_width and c.y==c.border_width and c.width==40 and c.height==30)--DOC_HIDE
|
assert(c.x == 0 and c.y==0 and c.width==40 and c.height==30)--DOC_HIDE
|
||||||
|
|
|
@ -10,5 +10,5 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE
|
||||||
|
|
||||||
awful.placement.top_right(client.focus)
|
awful.placement.top_right(client.focus)
|
||||||
|
|
||||||
assert(c.x == screen[1].geometry.width-40-c.border_width and c.y==c.border_width --DOC_HIDE
|
assert(c.x == screen[1].geometry.width-40-2*c.border_width and c.y==0 --DOC_HIDE
|
||||||
and c.width==40 and c.height==30)--DOC_HIDE
|
and c.width==40 and c.height==30)--DOC_HIDE
|
||||||
|
|
Loading…
Reference in New Issue