Merge pull request #388 from blueyed/placement-next-to-mouse
Add placement.next_to_mouse, use it for tooltips. Closes https://github.com/awesomeWM/awesome/pull/388.
This commit is contained in:
commit
9cbab8fa08
|
@ -21,6 +21,7 @@ local capi =
|
||||||
local client = require("awful.client")
|
local client = require("awful.client")
|
||||||
local layout = require("awful.layout")
|
local layout = require("awful.layout")
|
||||||
local a_screen = require("awful.screen")
|
local a_screen = require("awful.screen")
|
||||||
|
local dpi = require("beautiful").xresources.apply_dpi
|
||||||
|
|
||||||
local placement = {}
|
local placement = {}
|
||||||
|
|
||||||
|
@ -192,6 +193,42 @@ function placement.under_mouse(c)
|
||||||
y = m_coords.y - c_geometry.height / 2 })
|
y = m_coords.y - c_geometry.height / 2 })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Place the client next to the mouse.
|
||||||
|
--
|
||||||
|
-- It will place `c` next to the mouse pointer, trying the following positions
|
||||||
|
-- in this order: right, left, above and below.
|
||||||
|
-- @client[opt=focused] c The client.
|
||||||
|
-- @tparam[opt=apply_dpi(5)] integer offset The offset from the mouse position.
|
||||||
|
-- @return The new client geometry.
|
||||||
|
function placement.next_to_mouse(c, offset)
|
||||||
|
c = c or capi.client.focus
|
||||||
|
offset = offset or dpi(5)
|
||||||
|
local c_geometry = c:geometry()
|
||||||
|
local c_width = c_geometry.width + (c.border_width * 2)
|
||||||
|
local c_height = c_geometry.height + (c.border_width * 2)
|
||||||
|
local m_coords = capi.mouse.coords()
|
||||||
|
local screen_geometry = capi.screen[capi.mouse.screen].workarea
|
||||||
|
|
||||||
|
-- Prefer it to be on the right.
|
||||||
|
local x = m_coords.x + offset
|
||||||
|
if x + c_width > screen_geometry.width then
|
||||||
|
-- Then to the left.
|
||||||
|
x = m_coords.x - c_width - offset
|
||||||
|
end
|
||||||
|
if x < screen_geometry.x then
|
||||||
|
-- Then above.
|
||||||
|
x = m_coords.x - math.ceil(c_width / 2)
|
||||||
|
y = m_coords.y - c_height - offset
|
||||||
|
if y < screen_geometry.y then
|
||||||
|
-- Finally below.
|
||||||
|
y = m_coords.y + offset
|
||||||
|
end
|
||||||
|
else
|
||||||
|
y = m_coords.y - math.ceil(c_height / 2)
|
||||||
|
end
|
||||||
|
return c:geometry({ x = x, y = y })
|
||||||
|
end
|
||||||
|
|
||||||
--- Place the client centered with respect to a parent or the clients screen.
|
--- Place the client centered with respect to a parent or the clients screen.
|
||||||
-- @param c The client.
|
-- @param c The client.
|
||||||
-- @param[opt] p The parent (nil for screen centering).
|
-- @param[opt] p The parent (nil for screen centering).
|
||||||
|
|
|
@ -73,8 +73,7 @@ local data = setmetatable({}, { __mode = 'k' })
|
||||||
-- Place the tooltip on the screen.
|
-- Place the tooltip on the screen.
|
||||||
-- @tparam tooltip self A tooltip object.
|
-- @tparam tooltip self A tooltip object.
|
||||||
local function place(self)
|
local function place(self)
|
||||||
a_placement.under_mouse(self.wibox)
|
a_placement.next_to_mouse(self.wibox)
|
||||||
a_placement.no_offscreen(self.wibox)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Place the tooltip under the mouse.
|
-- Place the tooltip under the mouse.
|
||||||
|
|
Loading…
Reference in New Issue