2016-03-28 07:16:51 +02:00
|
|
|
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
|
2016-12-27 21:39:08 +01:00
|
|
|
-- Move the mouse to the closest corner of the focused client
|
2016-03-28 07:16:51 +02:00
|
|
|
awful.placement.closest_corner(mouse, {include_sides=true, parent=c})
|
|
|
|
mouse.push_history() --DOC_HIDE
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x) --DOC_HIDE
|
|
|
|
assert(mouse.coords().y == (c.y) + (c.height)/2+bw) --DOC_HIDE
|
2016-03-28 07:16:51 +02:00
|
|
|
|
|
|
|
-- 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
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x and mouse.coords().y == c.y) --DOC_HIDE
|
2016-03-28 07:16:51 +02:00
|
|
|
|
|
|
|
-- 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
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x+c.width+2*bw and mouse.coords().y == c.y) --DOC_HIDE
|
2016-03-28 07:16:51 +02:00
|
|
|
|
|
|
|
-- 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
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x+c.width+2*bw and mouse.coords().y == c.y+c.height/2+bw) --DOC_HIDE
|
2016-03-28 07:16:51 +02:00
|
|
|
|
|
|
|
-- 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
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x+c.width+2*bw and mouse.coords().y == c.y+c.height+2*bw) --DOC_HIDE
|
2016-03-28 07:16:51 +02:00
|
|
|
|
|
|
|
-- 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
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x+c.width/2+bw and mouse.coords().y == c.y + c.height + 2*bw) --DOC_HIDE
|
2016-03-28 07:16:51 +02:00
|
|
|
|
|
|
|
-- 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
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x + c.width/2+bw and mouse.coords().y == c.y) --DOC_HIDE
|
2016-03-28 07:16:51 +02:00
|
|
|
|
|
|
|
-- 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
|
2016-04-19 05:56:23 +02:00
|
|
|
assert(mouse.coords().x == c.x and mouse.coords().y == c.y+c.height+2*bw) --DOC_HIDE
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
-- It is possible to emulate the mouse API to get the closest corner of
|
|
|
|
-- random area
|
2016-04-21 03:48:46 +02:00
|
|
|
local _, corner = awful.placement.closest_corner(
|
2016-03-28 07:16:51 +02:00
|
|
|
{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)
|
2016-12-31 13:59:38 +01:00
|
|
|
|
|
|
|
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|