From 157895735533e3d8c9293bdd8437d68b52028554 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 28 Feb 2016 14:43:40 +0100 Subject: [PATCH 1/3] awful.tooltip: Inline place() into set_geometry() Signed-off-by: Uli Schlachter --- lib/awful/tooltip.lua | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/awful/tooltip.lua b/lib/awful/tooltip.lua index 72af21fed..0ddeeb487 100644 --- a/lib/awful/tooltip.lua +++ b/lib/awful/tooltip.lua @@ -58,13 +58,6 @@ local ipairs = ipairs -- @tfield boolean visible True if tooltip is visible. local tooltip = { mt = {} } --- Place the tooltip on the screen. --- @tparam tooltip self A tooltip object. -local function place(self) - a_placement.next_to_mouse(self.wibox) - a_placement.no_offscreen(self.wibox, mouse.screen) -end - -- Place the tooltip under the mouse. -- -- @tparam tooltip self A tooltip object. @@ -77,6 +70,8 @@ local function set_geometry(self) if my_geo.width ~= n_w or my_geo.height ~= n_h then self.wibox:geometry({ width = n_w, height = n_h }) end + a_placement.next_to_mouse(self.wibox) + a_placement.no_offscreen(self.wibox, mouse.screen) end -- Show a tooltip. @@ -92,7 +87,6 @@ local function show(self) end end set_geometry(self) - place(self) self.wibox.visible = true self.visible = true end @@ -263,10 +257,6 @@ tooltip.new = function(args) -- emit the release event on an underlying object, e.g. the titlebar icon. self.wibox:buttons(abutton({}, 1, nil, function() self.hide() end)) - -- Re-place when the geometry of the wibox changes. - self.wibox:connect_signal("property::width", function() place(self) end) - self.wibox:connect_signal("property::height", function() place(self) end) - -- Add tooltip to objects if args.objects then for _, object in ipairs(args.objects) do From b4224a651f5a1bd28f9835e5fbc0342e696d7067 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 28 Feb 2016 15:34:43 +0100 Subject: [PATCH 2/3] awful.tooltip: Create wibox lazily This makes awful.tooltip create its tooltip lazily when it is first needed instead of immediately when the tooltip is created. Fixes: https://github.com/awesomeWM/awesome/issues/591 Signed-off-by: Uli Schlachter --- lib/awful/tooltip.lua | 47 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/awful/tooltip.lua b/lib/awful/tooltip.lua index 0ddeeb487..38eb84ad9 100644 --- a/lib/awful/tooltip.lua +++ b/lib/awful/tooltip.lua @@ -58,20 +58,33 @@ local ipairs = ipairs -- @tfield boolean visible True if tooltip is visible. local tooltip = { mt = {} } +local function get_wibox(self) + if not self.wibox then + self.wibox = wibox(self.wibox_properties) + self.wibox:set_widget(self.marginbox) + + -- Close the tooltip when clicking it. This gets done on release, to not + -- emit the release event on an underlying object, e.g. the titlebar icon. + self.wibox:buttons(abutton({}, 1, nil, function() self.hide() end)) + end + return self.wibox +end + -- Place the tooltip under the mouse. -- -- @tparam tooltip self A tooltip object. local function set_geometry(self) - local my_geo = self.wibox:geometry() + local wb = get_wibox(self) + local my_geo = wb:geometry() -- calculate width / height local n_w, n_h = self.textbox:get_preferred_size(mouse.screen) n_w = n_w + self.marginbox.left + self.marginbox.right n_h = n_h + self.marginbox.top + self.marginbox.bottom if my_geo.width ~= n_w or my_geo.height ~= n_h then - self.wibox:geometry({ width = n_w, height = n_h }) + wb:geometry({ width = n_w, height = n_h }) end - a_placement.next_to_mouse(self.wibox) - a_placement.no_offscreen(self.wibox, mouse.screen) + a_placement.next_to_mouse(wb) + a_placement.no_offscreen(wb, mouse.screen) end -- Show a tooltip. @@ -87,7 +100,7 @@ local function show(self) end end set_geometry(self) - self.wibox.visible = true + get_wibox(self).visible = true self.visible = true end @@ -102,8 +115,8 @@ local function hide(self) self.timer:stop() end end + get_wibox(self).visible = false self.visible = false - self.wibox.visible = false end --- Change displayed text. @@ -180,7 +193,6 @@ end -- @see set_markup tooltip.new = function(args) local self = { - wibox = wibox({ }), visible = false, } @@ -231,17 +243,17 @@ tooltip.new = function(args) end -- Set default properties - self.wibox.border_width = beautiful.tooltip_border_width or beautiful.border_width or 1 - self.wibox.border_color = beautiful.tooltip_border_color or beautiful.border_normal or "#ffcb60" - self.wibox.opacity = beautiful.tooltip_opacity or 1 - self.wibox:set_bg(beautiful.tooltip_bg_color or beautiful.bg_focus or "#ffcb60") + self.wibox_properties = { + visible = false, + ontop = true, + border_width = beautiful.tooltip_border_width or beautiful.border_width or 1, + border_color = beautiful.tooltip_border_color or beautiful.border_normal or "#ffcb60", + opacity = beautiful.tooltip_opacity or 1, + bg = beautiful.tooltip_bg_color or beautiful.bg_focus or "#ffcb60" + } local fg = beautiful.tooltip_fg_color or beautiful.fg_focus or "#000000" local font = beautiful.tooltip_font or beautiful.font or "terminus 6" - -- set tooltip properties - self.wibox.visible = false - -- Who wants a non ontop tooltip ? - self.wibox.ontop = true self.textbox = textbox() self.textbox:set_font(font) self.background = background(self.textbox) @@ -251,11 +263,6 @@ tooltip.new = function(args) local m_lr = args.margin_leftright or dpi(5) local m_tb = args.margin_topbottom or dpi(3) self.marginbox = wibox.layout.margin(self.background, m_lr, m_lr, m_tb, m_tb) - self.wibox:set_widget(self.marginbox) - - -- Close the tooltip when clicking it. This gets done on release, to not - -- emit the release event on an underlying object, e.g. the titlebar icon. - self.wibox:buttons(abutton({}, 1, nil, function() self.hide() end)) -- Add tooltip to objects if args.objects then From e49b1de0b2968d6101857e2c336be0f7a2718281 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 28 Feb 2016 15:38:06 +0100 Subject: [PATCH 3/3] awful.tooltip: Some minor optimizations Signed-off-by: Uli Schlachter --- lib/awful/tooltip.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/awful/tooltip.lua b/lib/awful/tooltip.lua index 38eb84ad9..ab520f125 100644 --- a/lib/awful/tooltip.lua +++ b/lib/awful/tooltip.lua @@ -65,7 +65,7 @@ local function get_wibox(self) -- Close the tooltip when clicking it. This gets done on release, to not -- emit the release event on an underlying object, e.g. the titlebar icon. - self.wibox:buttons(abutton({}, 1, nil, function() self.hide() end)) + self.wibox:buttons(abutton({}, 1, nil, self.hide)) end return self.wibox end @@ -75,14 +75,11 @@ end -- @tparam tooltip self A tooltip object. local function set_geometry(self) local wb = get_wibox(self) - local my_geo = wb:geometry() -- calculate width / height local n_w, n_h = self.textbox:get_preferred_size(mouse.screen) n_w = n_w + self.marginbox.left + self.marginbox.right n_h = n_h + self.marginbox.top + self.marginbox.bottom - if my_geo.width ~= n_w or my_geo.height ~= n_h then - wb:geometry({ width = n_w, height = n_h }) - end + wb:geometry({ width = n_w, height = n_h }) a_placement.next_to_mouse(wb) a_placement.no_offscreen(wb, mouse.screen) end