From 9803af1b1fb778ae723c0f2886a506dbd6fd8745 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 2 Aug 2015 19:36:56 +0200 Subject: [PATCH 1/2] Add awful.placement.next_to_mouse --- lib/awful/placement.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 0aa3c58a..0c6338a7 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -21,6 +21,7 @@ local capi = local client = require("awful.client") local layout = require("awful.layout") local a_screen = require("awful.screen") +local dpi = require("beautiful").xresources.apply_dpi local placement = {} @@ -192,6 +193,42 @@ function placement.under_mouse(c) y = m_coords.y - c_geometry.height / 2 }) 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. -- @param c The client. -- @param[opt] p The parent (nil for screen centering). From 251673f8b23691af0fbc6b49f5c6a86b32080420 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 2 Aug 2015 19:38:26 +0200 Subject: [PATCH 2/2] tooltip: use new next_to_mouse placement This should take care of not placing the tooltip outside of the screen already, so the call to `awful.placement.no_offscreen` can be skipped. --- lib/awful/tooltip.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/awful/tooltip.lua b/lib/awful/tooltip.lua index 2f4b1248..e26326db 100644 --- a/lib/awful/tooltip.lua +++ b/lib/awful/tooltip.lua @@ -73,8 +73,7 @@ local data = setmetatable({}, { __mode = 'k' }) -- Place the tooltip on the screen. -- @tparam tooltip self A tooltip object. local function place(self) - a_placement.under_mouse(self.wibox) - a_placement.no_offscreen(self.wibox) + a_placement.next_to_mouse(self.wibox) end -- Place the tooltip under the mouse.