Merge branch 'tooltips'

Minor fixes / improvements to tooltips.

Closes https://github.com/awesomeWM/awesome/pull/373.
This commit is contained in:
Daniel Hahler 2015-08-02 15:38:38 +02:00
commit aa93a8eac9
2 changed files with 43 additions and 18 deletions

View File

@ -11,6 +11,7 @@ local error = error
local type = type
local abutton = require("awful.button")
local aclient = require("awful.client")
local atooltip = require("awful.tooltip")
local beautiful = require("beautiful")
local object = require("gears.object")
local drawable = require("wibox.drawable")
@ -177,12 +178,17 @@ end
-- then found in the theme as "titlebar_[name]_button_[normal/focus]_[state]".
-- If that value does not exist, the focused state is ignored for the next try.
-- @param c The client for which a button is created.
-- @param name Name of the button, used for accessing the theme.
-- @tparam string name Name of the button, used for accessing the theme and
-- in the tooltip.
-- @param selector A function that selects the image that should be displayed.
-- @param action Function that is called when the button is clicked.
-- @return The widget
function titlebar.widget.button(c, name, selector, action)
local ret = imagebox()
ret.tooltip = atooltip({ objects = {ret}, delay_show = 1 })
ret.tooltip:set_text(name)
local function update()
local img = selector(c)
if type(img) ~= "nil" then

View File

@ -45,6 +45,7 @@ local screen = screen
local timer = require("gears.timer")
local wibox = require("wibox")
local a_placement = require("awful.placement")
local abutton = require("awful.button")
local beautiful = require("beautiful")
local textbox = require("wibox.widget.textbox")
local background = require("wibox.widget.background")
@ -130,17 +131,21 @@ end
-- `wibox.widget.textbox.set_text`.
tooltip.set_text = function(self, text)
self.textbox:set_text(text)
set_geometry(self)
if self.visible then
set_geometry(self)
end
end
--- Change displayed text.
--- Change displayed markup.
--
-- @tparam tooltip self The tooltip object.
-- @tparam string text New tooltip markup, passed to
-- `wibox.widget.textbox.set_markup`.
tooltip.set_markup = function(self, text)
self.textbox:set_markup(text)
set_geometry(self)
if self.visible then
set_geometry(self)
end
end
--- Change the tooltip's update interval.
@ -198,21 +203,34 @@ tooltip.new = function(args)
}
-- private data
local delay_timeout
if args.delay_show then
local delay_timeout
delay_timeout = timer { timeout = args.delay_show }
delay_timeout:connect_signal("timeout", function () show(self) end)
delay_timeout:connect_signal("timeout", function ()
show(self)
delay_timeout:stop()
end)
data[self] = {
show = function()
if not delay_timeout.started then
delay_timeout:start()
end
end,
hide = function()
if delay_timeout.started then
delay_timeout:stop()
end
hide(self)
end,
}
else
data[self] = {
show = function() show(self) end,
hide = function() hide(self) end,
}
end
data[self] = {
show = function()
if delay_timeout then delay_timeout:start()
else show(self) end
end,
hide = function()
if delay_timeout then delay_timeout:stop() end
hide(self)
end,
}
-- export functions
self.set_text = tooltip.set_text
@ -253,8 +271,9 @@ tooltip.new = function(args)
self.marginbox = wibox.layout.margin(self.background, m_lr, m_lr, m_tb, m_tb)
self.wibox:set_widget(self.marginbox)
-- add some signals on both the tooltip and widget
self.wibox:connect_signal("mouse::enter", data[self].hide)
-- 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() data[self].hide() end))
-- Add tooltip to objects
if args.objects then