Merge pull request #714 from psychon/tooltip-windows
Less tooltip windows
This commit is contained in:
commit
9503110e44
|
@ -58,25 +58,30 @@ 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 = {} }
|
||||||
|
|
||||||
-- Place the tooltip on the screen.
|
local function get_wibox(self)
|
||||||
-- @tparam tooltip self A tooltip object.
|
if not self.wibox then
|
||||||
local function place(self)
|
self.wibox = wibox(self.wibox_properties)
|
||||||
a_placement.next_to_mouse(self.wibox)
|
self.wibox:set_widget(self.marginbox)
|
||||||
a_placement.no_offscreen(self.wibox, mouse.screen)
|
|
||||||
|
-- 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, self.hide))
|
||||||
|
end
|
||||||
|
return self.wibox
|
||||||
end
|
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)
|
||||||
-- 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
|
wb:geometry({ width = n_w, height = n_h })
|
||||||
self.wibox:geometry({ width = n_w, height = n_h })
|
a_placement.next_to_mouse(wb)
|
||||||
end
|
a_placement.no_offscreen(wb, mouse.screen)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Show a tooltip.
|
-- Show a tooltip.
|
||||||
|
@ -92,8 +97,7 @@ local function show(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
set_geometry(self)
|
set_geometry(self)
|
||||||
place(self)
|
get_wibox(self).visible = true
|
||||||
self.wibox.visible = true
|
|
||||||
self.visible = true
|
self.visible = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,8 +112,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.
|
||||||
|
@ -186,7 +190,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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,17 +240,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)
|
||||||
|
@ -257,15 +260,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))
|
|
||||||
|
|
||||||
-- 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
|
-- Add tooltip to objects
|
||||||
if args.objects then
|
if args.objects then
|
||||||
|
|
Loading…
Reference in New Issue