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 <psychon@znc.in>
This commit is contained in:
parent
1578957355
commit
b4224a651f
|
@ -58,20 +58,33 @@ local ipairs = ipairs
|
||||||
-- @tfield boolean visible True if tooltip is visible.
|
-- @tfield boolean visible True if tooltip is visible.
|
||||||
local tooltip = { mt = {} }
|
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.
|
-- Place the tooltip under the mouse.
|
||||||
--
|
--
|
||||||
-- @tparam tooltip self A tooltip object.
|
-- @tparam tooltip self A tooltip object.
|
||||||
local function set_geometry(self)
|
local function set_geometry(self)
|
||||||
local my_geo = self.wibox:geometry()
|
local wb = get_wibox(self)
|
||||||
|
local my_geo = wb:geometry()
|
||||||
-- calculate width / height
|
-- calculate width / height
|
||||||
local n_w, n_h = self.textbox:get_preferred_size(mouse.screen)
|
local n_w, n_h = self.textbox:get_preferred_size(mouse.screen)
|
||||||
n_w = n_w + self.marginbox.left + self.marginbox.right
|
n_w = n_w + self.marginbox.left + self.marginbox.right
|
||||||
n_h = n_h + self.marginbox.top + self.marginbox.bottom
|
n_h = n_h + self.marginbox.top + self.marginbox.bottom
|
||||||
if my_geo.width ~= n_w or my_geo.height ~= n_h then
|
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
|
end
|
||||||
a_placement.next_to_mouse(self.wibox)
|
a_placement.next_to_mouse(wb)
|
||||||
a_placement.no_offscreen(self.wibox, mouse.screen)
|
a_placement.no_offscreen(wb, mouse.screen)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Show a tooltip.
|
-- Show a tooltip.
|
||||||
|
@ -87,7 +100,7 @@ local function show(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
set_geometry(self)
|
set_geometry(self)
|
||||||
self.wibox.visible = true
|
get_wibox(self).visible = true
|
||||||
self.visible = true
|
self.visible = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,8 +115,8 @@ local function hide(self)
|
||||||
self.timer:stop()
|
self.timer:stop()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
get_wibox(self).visible = false
|
||||||
self.visible = false
|
self.visible = false
|
||||||
self.wibox.visible = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Change displayed text.
|
--- Change displayed text.
|
||||||
|
@ -180,7 +193,6 @@ end
|
||||||
-- @see set_markup
|
-- @see set_markup
|
||||||
tooltip.new = function(args)
|
tooltip.new = function(args)
|
||||||
local self = {
|
local self = {
|
||||||
wibox = wibox({ }),
|
|
||||||
visible = false,
|
visible = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,17 +243,17 @@ tooltip.new = function(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set default properties
|
-- Set default properties
|
||||||
self.wibox.border_width = beautiful.tooltip_border_width or beautiful.border_width or 1
|
self.wibox_properties = {
|
||||||
self.wibox.border_color = beautiful.tooltip_border_color or beautiful.border_normal or "#ffcb60"
|
visible = false,
|
||||||
self.wibox.opacity = beautiful.tooltip_opacity or 1
|
ontop = true,
|
||||||
self.wibox:set_bg(beautiful.tooltip_bg_color or beautiful.bg_focus or "#ffcb60")
|
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 fg = beautiful.tooltip_fg_color or beautiful.fg_focus or "#000000"
|
||||||
local font = beautiful.tooltip_font or beautiful.font or "terminus 6"
|
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 = textbox()
|
||||||
self.textbox:set_font(font)
|
self.textbox:set_font(font)
|
||||||
self.background = background(self.textbox)
|
self.background = background(self.textbox)
|
||||||
|
@ -251,11 +263,6 @@ tooltip.new = function(args)
|
||||||
local m_lr = args.margin_leftright or dpi(5)
|
local m_lr = args.margin_leftright or dpi(5)
|
||||||
local m_tb = args.margin_topbottom or dpi(3)
|
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.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
|
-- Add tooltip to objects
|
||||||
if args.objects then
|
if args.objects then
|
||||||
|
|
Loading…
Reference in New Issue