From 61d143fe98b9432387bbac49527bcc4126684cff Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 28 Mar 2016 01:16:51 -0400 Subject: [PATCH] tests: Test `awful.placement.closest_corner` The output image look fine, some `assert()` could be added. --- .../awful/placement/closest_mouse.lua | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/examples/awful/placement/closest_mouse.lua diff --git a/tests/examples/awful/placement/closest_mouse.lua b/tests/examples/awful/placement/closest_mouse.lua new file mode 100644 index 00000000..98e58abd --- /dev/null +++ b/tests/examples/awful/placement/closest_mouse.lua @@ -0,0 +1,61 @@ +local awful = {placement = require("awful.placement")} --DOC_HIDE + +local c = client.gen_fake {x = 20, y = 20, width= 280, height=200, screen =screen[1]} --DOC_HIDE +local bw = c.border_width --DOC_HIDE + +-- Left --DOC_HIDE +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 + +-- 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 + +-- 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 + +-- 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 + +-- 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 + +-- 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 + +-- 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 + +-- 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 + + -- It is possible to emulate the mouse API to get the closest corner of + -- random area +local corner = awful.placement.closest_corner( + {coords=function() return {x = 100, y=100} end}, + {include_sides = true, bounding_rect = {x=0, y=0, width=200, height=200}} +) +print("Closest corner:", corner)