From fe8beaeaacf1011e0de82da95e6eb65c53f0e2e9 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 18 Apr 2016 23:56:23 -0400 Subject: [PATCH] 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. --- lib/awful/placement.lua | 25 +++++++++++-------- tests/examples/awful/placement/bottom.lua | 4 +-- .../examples/awful/placement/bottom_left.lua | 4 +-- .../examples/awful/placement/bottom_right.lua | 4 +-- .../awful/placement/center_horizontal.lua | 2 +- tests/examples/awful/placement/centered.lua | 5 ++-- .../awful/placement/closest_mouse.lua | 17 +++++++------ tests/examples/awful/placement/left.lua | 2 +- tests/examples/awful/placement/right.lua | 6 ++--- .../examples/awful/placement/stretch_down.lua | 2 +- .../examples/awful/placement/stretch_left.lua | 4 +-- .../awful/placement/stretch_right.lua | 2 +- tests/examples/awful/placement/stretch_up.lua | 6 ++--- tests/examples/awful/placement/top.lua | 6 +++-- tests/examples/awful/placement/top_left.lua | 2 +- tests/examples/awful/placement/top_right.lua | 2 +- 16 files changed, 50 insertions(+), 43 deletions(-) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 139d25740..b98079c9f 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -172,8 +172,8 @@ local function area_common(d, new_geo, ignore_border_width) -- 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 - geometry.x = geometry.x - border - geometry.y = geometry.y - border + geometry.x = geometry.x + geometry.y = geometry.y geometry.width = geometry.width + 2 * border geometry.height = geometry.height + 2 * border return geometry @@ -511,7 +511,10 @@ function placement.no_offscreen(c, screen) geometry.y = screen_geometry.y end - return c:geometry({ x = geometry.x, y = geometry.y }) + return c:geometry { + x = geometry.x, + y = geometry.y + } end --- Place the client where there's place available with minimum overlap. @@ -656,8 +659,8 @@ function placement.align(d, args) ) geometry_common(d, args, { - x = (pos.x and math.ceil(sgeo.x + pos.x) or dgeo.x) + bw , - y = (pos.y and math.ceil(sgeo.y + pos.y) or dgeo.y) + 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) , width = math.ceil(dgeo.width ) - 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 if args.direction == "left" then - ngeo.x = sgeo.x + bw + ngeo.x = sgeo.x ngeo.width = dgeo.width + (dgeo.x - ngeo.x) 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 - ngeo.y = sgeo.y + bw + ngeo.y = sgeo.y ngeo.height = dgeo.height + (dgeo.y - ngeo.y) elseif args.direction == "down" then - ngeo.height = sgeo.height - dgeo.y - bw + ngeo.height = sgeo.height - dgeo.y - 2*bw else assert(false) end @@ -788,12 +791,12 @@ function placement.maximize(d, args) local bw = d.border_width or 0 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 end 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 end diff --git a/tests/examples/awful/placement/bottom.lua b/tests/examples/awful/placement/bottom.lua index 814d3546c..10dff9ab8 100644 --- a/tests/examples/awful/placement/bottom.lua +++ b/tests/examples/awful/placement/bottom.lua @@ -10,6 +10,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE awful.placement.bottom(client.focus) -assert(c.x == screen[1].geometry.width/2-40/2--DOC_HIDE - and c.y==screen[1].geometry.height-30-c.border_width--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-2*c.border_width--DOC_HIDE and c.width==40 and c.height==30)--DOC_HIDE diff --git a/tests/examples/awful/placement/bottom_left.lua b/tests/examples/awful/placement/bottom_left.lua index f1da60450..a9ebc0629 100644 --- a/tests/examples/awful/placement/bottom_left.lua +++ b/tests/examples/awful/placement/bottom_left.lua @@ -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) assert( --DOC_HIDE - c.x == c.border_width --DOC_HIDE - and c.y == screen[1].geometry.height-30-c.border_width --DOC_HIDE + c.x == 0 --DOC_HIDE + and c.y+2*c.border_width == screen[1].geometry.height-30 --DOC_HIDE and c.width == 40--DOC_HIDE and c.height == 30--DOC_HIDE ) --DOC_HIDE diff --git a/tests/examples/awful/placement/bottom_right.lua b/tests/examples/awful/placement/bottom_right.lua index 1c6d7b20b..0ad1072e5 100644 --- a/tests/examples/awful/placement/bottom_right.lua +++ b/tests/examples/awful/placement/bottom_right.lua @@ -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) -assert(c.x == screen[1].geometry.width-40-c.border_width) --DOC_HIDE -assert(c.y==screen[1].geometry.height-30-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-2*c.border_width) --DOC_HIDE assert(c.width==40 and c.height==30)--DOC_HIDE diff --git a/tests/examples/awful/placement/center_horizontal.lua b/tests/examples/awful/placement/center_horizontal.lua index c8e2874c4..b9d1d6bb0 100644 --- a/tests/examples/awful/placement/center_horizontal.lua +++ b/tests/examples/awful/placement/center_horizontal.lua @@ -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) -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.width==40 and c.height==30)--DOC_HIDE diff --git a/tests/examples/awful/placement/centered.lua b/tests/examples/awful/placement/centered.lua index 5b97a16f1..af1a1c84b 100644 --- a/tests/examples/awful/placement/centered.lua +++ b/tests/examples/awful/placement/centered.lua @@ -10,5 +10,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE 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 - and c.width==40 and c.height==30)--DOC_HIDE +assert(c.x == screen[1].geometry.width/2-40/2-c.border_width) --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 diff --git a/tests/examples/awful/placement/closest_mouse.lua b/tests/examples/awful/placement/closest_mouse.lua index 98e58abd4..906426415 100644 --- a/tests/examples/awful/placement/closest_mouse.lua +++ b/tests/examples/awful/placement/closest_mouse.lua @@ -8,49 +8,50 @@ mouse.coords {x=100,y=100} --DOC_HIDE -- Move the mouse to the closest corner of the focused client awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) 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 mouse.coords {x=60,y=40} --DOC_HIDE awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --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 mouse.coords {x=230,y=50} --DOC_HIDE awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --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 mouse.coords {x=240,y=140} --DOC_HIDE awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --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 mouse.coords {x=210,y=190} --DOC_HIDE awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --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 mouse.coords {x=130,y=190} --DOC_HIDE awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --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 mouse.coords {x=130,y=30} --DOC_HIDE awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --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 mouse.coords {x=0,y=230} --DOC_HIDE awful.placement.closest_corner(mouse, {include_sides=true, parent=c}) --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 -- random area diff --git a/tests/examples/awful/placement/left.lua b/tests/examples/awful/placement/left.lua index f7e8c8cfd..49cf93ac4 100644 --- a/tests/examples/awful/placement/left.lua +++ b/tests/examples/awful/placement/left.lua @@ -10,5 +10,5 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE 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 diff --git a/tests/examples/awful/placement/right.lua b/tests/examples/awful/placement/right.lua index 1ba092c97..d24501161 100644 --- a/tests/examples/awful/placement/right.lua +++ b/tests/examples/awful/placement/right.lua @@ -10,6 +10,6 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE awful.placement.right(client.focus) -assert(c.x == screen[1].geometry.width-40-c.border_width --DOC_HIDE - and c.y==screen[1].geometry.height/2-30/2--DOC_HIDE - and c.width==40 and c.height==30)--DOC_HIDE +assert(c.x == screen[1].geometry.width-40-2*c.border_width) --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 diff --git a/tests/examples/awful/placement/stretch_down.lua b/tests/examples/awful/placement/stretch_down.lua index 12a074b10..258647f8a 100644 --- a/tests/examples/awful/placement/stretch_down.lua +++ b/tests/examples/awful/placement/stretch_down.lua @@ -13,5 +13,5 @@ placement.stretch_down(client.focus) assert(c.x==45) --DOC_HIDE assert(c.y==35) --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 diff --git a/tests/examples/awful/placement/stretch_left.lua b/tests/examples/awful/placement/stretch_left.lua index 7db11c77a..51364697f 100644 --- a/tests/examples/awful/placement/stretch_left.lua +++ b/tests/examples/awful/placement/stretch_left.lua @@ -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 placement.stretch_left(client.focus) -assert(c.x == c.border_width and c.y == 35 and c.height == 30 --DOC_HIDE - and c.width == 45+40) --DOC_HIDE +assert(c.x == 0 and c.y == 35 and c.height == 30) --DOC_HIDE +print(c.width-2*c.border_width == 45+40) --DOC_HIDE diff --git a/tests/examples/awful/placement/stretch_right.lua b/tests/examples/awful/placement/stretch_right.lua index 79b2687d7..9965d1a61 100644 --- a/tests/examples/awful/placement/stretch_right.lua +++ b/tests/examples/awful/placement/stretch_right.lua @@ -11,4 +11,4 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE placement.stretch_right(client.focus) 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 diff --git a/tests/examples/awful/placement/stretch_up.lua b/tests/examples/awful/placement/stretch_up.lua index 87bea473b..817a11d5e 100644 --- a/tests/examples/awful/placement/stretch_up.lua +++ b/tests/examples/awful/placement/stretch_up.lua @@ -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 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.width == 40) --DOC_HIDE -print(c.height) -assert(c.height == 35+30) --DOC_HIDE +print(c.height-2*c.border_width,35+30) +assert(c.height-2*c.border_width == 35+30) --DOC_HIDE diff --git a/tests/examples/awful/placement/top.lua b/tests/examples/awful/placement/top.lua index ab1bdc0b6..f84ea3066 100644 --- a/tests/examples/awful/placement/top.lua +++ b/tests/examples/awful/placement/top.lua @@ -10,5 +10,7 @@ local c = client.gen_fake {x = 45, y = 35, width=40, height=30} --DOC_HIDE awful.placement.top(client.focus) -assert(c.x == screen[1].geometry.width/2-40/2 and c.y==c.border_width--DOC_HIDE - and c.width==40 and c.height==30)--DOC_HIDE +assert(c.x == screen[1].geometry.width/2-40/2-c.border_width) +assert(c.y==0) --DOC_HIDE +assert( c.width==40) --DOC_HIDE +assert(c.height==30)--DOC_HIDE diff --git a/tests/examples/awful/placement/top_left.lua b/tests/examples/awful/placement/top_left.lua index 208e86eb0..a2bb3b586 100644 --- a/tests/examples/awful/placement/top_left.lua +++ b/tests/examples/awful/placement/top_left.lua @@ -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) -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 diff --git a/tests/examples/awful/placement/top_right.lua b/tests/examples/awful/placement/top_right.lua index 9655032fd..a94890c98 100644 --- a/tests/examples/awful/placement/top_right.lua +++ b/tests/examples/awful/placement/top_right.lua @@ -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) -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