Merge branch 'tooltips'
Minor fixes / improvements to tooltips. Closes https://github.com/awesomeWM/awesome/pull/373.
This commit is contained in:
commit
aa93a8eac9
|
@ -11,6 +11,7 @@ local error = error
|
||||||
local type = type
|
local type = type
|
||||||
local abutton = require("awful.button")
|
local abutton = require("awful.button")
|
||||||
local aclient = require("awful.client")
|
local aclient = require("awful.client")
|
||||||
|
local atooltip = require("awful.tooltip")
|
||||||
local beautiful = require("beautiful")
|
local beautiful = require("beautiful")
|
||||||
local object = require("gears.object")
|
local object = require("gears.object")
|
||||||
local drawable = require("wibox.drawable")
|
local drawable = require("wibox.drawable")
|
||||||
|
@ -177,12 +178,17 @@ end
|
||||||
-- then found in the theme as "titlebar_[name]_button_[normal/focus]_[state]".
|
-- 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.
|
-- 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 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 selector A function that selects the image that should be displayed.
|
||||||
-- @param action Function that is called when the button is clicked.
|
-- @param action Function that is called when the button is clicked.
|
||||||
-- @return The widget
|
-- @return The widget
|
||||||
function titlebar.widget.button(c, name, selector, action)
|
function titlebar.widget.button(c, name, selector, action)
|
||||||
local ret = imagebox()
|
local ret = imagebox()
|
||||||
|
|
||||||
|
ret.tooltip = atooltip({ objects = {ret}, delay_show = 1 })
|
||||||
|
ret.tooltip:set_text(name)
|
||||||
|
|
||||||
local function update()
|
local function update()
|
||||||
local img = selector(c)
|
local img = selector(c)
|
||||||
if type(img) ~= "nil" then
|
if type(img) ~= "nil" then
|
||||||
|
|
|
@ -45,6 +45,7 @@ local screen = screen
|
||||||
local timer = require("gears.timer")
|
local timer = require("gears.timer")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local a_placement = require("awful.placement")
|
local a_placement = require("awful.placement")
|
||||||
|
local abutton = require("awful.button")
|
||||||
local beautiful = require("beautiful")
|
local beautiful = require("beautiful")
|
||||||
local textbox = require("wibox.widget.textbox")
|
local textbox = require("wibox.widget.textbox")
|
||||||
local background = require("wibox.widget.background")
|
local background = require("wibox.widget.background")
|
||||||
|
@ -130,18 +131,22 @@ end
|
||||||
-- `wibox.widget.textbox.set_text`.
|
-- `wibox.widget.textbox.set_text`.
|
||||||
tooltip.set_text = function(self, text)
|
tooltip.set_text = function(self, text)
|
||||||
self.textbox:set_text(text)
|
self.textbox:set_text(text)
|
||||||
|
if self.visible then
|
||||||
set_geometry(self)
|
set_geometry(self)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Change displayed text.
|
--- Change displayed markup.
|
||||||
--
|
--
|
||||||
-- @tparam tooltip self The tooltip object.
|
-- @tparam tooltip self The tooltip object.
|
||||||
-- @tparam string text New tooltip markup, passed to
|
-- @tparam string text New tooltip markup, passed to
|
||||||
-- `wibox.widget.textbox.set_markup`.
|
-- `wibox.widget.textbox.set_markup`.
|
||||||
tooltip.set_markup = function(self, text)
|
tooltip.set_markup = function(self, text)
|
||||||
self.textbox:set_markup(text)
|
self.textbox:set_markup(text)
|
||||||
|
if self.visible then
|
||||||
set_geometry(self)
|
set_geometry(self)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Change the tooltip's update interval.
|
--- Change the tooltip's update interval.
|
||||||
--
|
--
|
||||||
|
@ -198,21 +203,34 @@ tooltip.new = function(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- private data
|
-- private data
|
||||||
local delay_timeout
|
|
||||||
if args.delay_show then
|
if args.delay_show then
|
||||||
|
local delay_timeout
|
||||||
|
|
||||||
delay_timeout = timer { timeout = args.delay_show }
|
delay_timeout = timer { timeout = args.delay_show }
|
||||||
delay_timeout:connect_signal("timeout", function () show(self) end)
|
delay_timeout:connect_signal("timeout", function ()
|
||||||
end
|
show(self)
|
||||||
|
delay_timeout:stop()
|
||||||
|
end)
|
||||||
|
|
||||||
data[self] = {
|
data[self] = {
|
||||||
show = function()
|
show = function()
|
||||||
if delay_timeout then delay_timeout:start()
|
if not delay_timeout.started then
|
||||||
else show(self) end
|
delay_timeout:start()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
hide = function()
|
hide = function()
|
||||||
if delay_timeout then delay_timeout:stop() end
|
if delay_timeout.started then
|
||||||
|
delay_timeout:stop()
|
||||||
|
end
|
||||||
hide(self)
|
hide(self)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
data[self] = {
|
||||||
|
show = function() show(self) end,
|
||||||
|
hide = function() hide(self) end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
-- export functions
|
-- export functions
|
||||||
self.set_text = tooltip.set_text
|
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.marginbox = wibox.layout.margin(self.background, m_lr, m_lr, m_tb, m_tb)
|
||||||
self.wibox:set_widget(self.marginbox)
|
self.wibox:set_widget(self.marginbox)
|
||||||
|
|
||||||
-- add some signals on both the tooltip and widget
|
-- Close the tooltip when clicking it. This gets done on release, to not
|
||||||
self.wibox:connect_signal("mouse::enter", data[self].hide)
|
-- 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
|
-- Add tooltip to objects
|
||||||
if args.objects then
|
if args.objects then
|
||||||
|
|
Loading…
Reference in New Issue