2014-05-20 13:02:39 +02:00
|
|
|
|
-------------------------------------------------------------------------
|
2009-09-09 14:57:27 +02:00
|
|
|
|
--- Tooltip module for awesome objects.
|
2015-02-14 20:31:53 +01:00
|
|
|
|
--
|
2009-09-09 14:57:27 +02:00
|
|
|
|
-- A tooltip is a small hint displayed when the mouse cursor
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- hovers over a specific item.
|
2009-09-09 14:57:27 +02:00
|
|
|
|
-- In awesome, a tooltip can be linked with almost any
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- object having a `:connect_signal()` method and receiving
|
|
|
|
|
-- `mouse::enter` and `mouse::leave` signals.
|
|
|
|
|
--
|
|
|
|
|
-- How to create a tooltip?
|
|
|
|
|
-- ---
|
|
|
|
|
--
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @DOC_awful_tooltip_textclock_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- Alternatively, you can use `mouse::enter` signal:
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_textclock2_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- How to create a tooltip without objects?
|
|
|
|
|
-- ---
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_mouse_EXAMPLE@
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2016-06-03 00:40:02 +02:00
|
|
|
|
-- How to add the same tooltip to multiple objects?
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- ---
|
|
|
|
|
--
|
|
|
|
|
-- myclock_t:add_to_object(obj1)
|
|
|
|
|
-- myclock_t:add_to_object(obj2)
|
|
|
|
|
--
|
|
|
|
|
-- Now the same tooltip is attached to `myclock`, `obj1`, `obj2`.
|
|
|
|
|
--
|
2016-06-03 00:40:02 +02:00
|
|
|
|
-- How to remove a tooltip from several objects?
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- ---
|
|
|
|
|
--
|
|
|
|
|
-- myclock_t:remove_from_object(obj1)
|
|
|
|
|
-- myclock_t:remove_from_object(obj2)
|
|
|
|
|
--
|
|
|
|
|
-- Now the same tooltip is only attached to `myclock`.
|
|
|
|
|
--
|
|
|
|
|
-- @author Sébastien Gross <seb•ɱɩɲʋʃ•awesome•ɑƬ•chezwam•ɖɵʈ•org>
|
2015-02-14 20:31:53 +01:00
|
|
|
|
-- @copyright 2009 Sébastien Gross
|
2019-06-06 08:44:00 +02:00
|
|
|
|
-- @popupmod awful.tooltip
|
2015-02-14 20:31:53 +01:00
|
|
|
|
-------------------------------------------------------------------------
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
2015-02-14 20:31:53 +01:00
|
|
|
|
local timer = require("gears.timer")
|
2017-03-08 21:18:33 +01:00
|
|
|
|
local gtable = require("gears.table")
|
2016-03-02 20:04:19 +01:00
|
|
|
|
local object = require("gears.object")
|
2016-05-30 21:05:57 +02:00
|
|
|
|
local color = require("gears.color")
|
2015-02-14 20:31:53 +01:00
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
local a_placement = require("awful.placement")
|
2018-05-29 02:54:14 +02:00
|
|
|
|
local a_button = require("awful.button")
|
2016-05-30 21:05:57 +02:00
|
|
|
|
local shape = require("gears.shape")
|
2015-02-14 20:31:53 +01:00
|
|
|
|
local beautiful = require("beautiful")
|
2015-07-15 18:47:20 +02:00
|
|
|
|
local dpi = require("beautiful").xresources.apply_dpi
|
2015-02-14 20:31:53 +01:00
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
local ipairs = ipairs
|
2016-05-30 21:05:57 +02:00
|
|
|
|
local capi = {mouse=mouse, awesome=awesome}
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
local tooltip = { mt = {} }
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
2016-05-29 23:40:39 +02:00
|
|
|
|
-- The mouse point is 1x1, so anything aligned based on it as parent
|
|
|
|
|
-- geometry will go out of bound. To get the desired placement, it is
|
|
|
|
|
-- necessary to swap left with right and top with bottom
|
|
|
|
|
local align_convert = {
|
|
|
|
|
top_left = "bottom_right",
|
|
|
|
|
left = "right",
|
|
|
|
|
bottom_left = "top_right",
|
|
|
|
|
right = "left",
|
|
|
|
|
top_right = "bottom_left",
|
|
|
|
|
bottom_right = "top_left",
|
|
|
|
|
top = "bottom",
|
|
|
|
|
bottom = "top",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- If the wibox is under the cursor, it will trigger a mouse::leave
|
|
|
|
|
local offset = {
|
|
|
|
|
top_left = {x = 0, y = 0 },
|
|
|
|
|
left = {x = 0, y = 0 },
|
|
|
|
|
bottom_left = {x = 0, y = 0 },
|
|
|
|
|
right = {x = 1, y = 0 },
|
|
|
|
|
top_right = {x = 0, y = 0 },
|
|
|
|
|
bottom_right = {x = 1, y = 1 },
|
|
|
|
|
top = {x = 0, y = 0 },
|
|
|
|
|
bottom = {x = 0, y = 1 },
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-30 21:05:57 +02:00
|
|
|
|
--- The tooltip border color.
|
|
|
|
|
-- @beautiful beautiful.tooltip_border_color
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param color
|
2016-05-30 21:05:57 +02:00
|
|
|
|
|
|
|
|
|
--- The tooltip background color.
|
|
|
|
|
-- @beautiful beautiful.tooltip_bg
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param color
|
2016-05-30 21:05:57 +02:00
|
|
|
|
|
|
|
|
|
--- The tooltip foregound (text) color.
|
|
|
|
|
-- @beautiful beautiful.tooltip_fg
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param color
|
2016-05-30 21:05:57 +02:00
|
|
|
|
|
|
|
|
|
--- The tooltip font.
|
|
|
|
|
-- @beautiful beautiful.tooltip_font
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param string
|
2016-05-30 21:05:57 +02:00
|
|
|
|
|
|
|
|
|
--- The tooltip border width.
|
|
|
|
|
-- @beautiful beautiful.tooltip_border_width
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param number
|
2016-05-30 21:05:57 +02:00
|
|
|
|
|
|
|
|
|
--- The tooltip opacity.
|
|
|
|
|
-- @beautiful beautiful.tooltip_opacity
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param number opacity Between 0 and 1
|
2016-05-30 21:05:57 +02:00
|
|
|
|
|
|
|
|
|
--- The default tooltip shape.
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- The default shape for all tooltips is a rectangle. However, by setting
|
|
|
|
|
-- this variable they can default to rounded rectangle or stretched octogons.
|
2016-05-30 21:05:57 +02:00
|
|
|
|
-- @beautiful beautiful.tooltip_shape
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @tparam[opt=gears.shape.rectangle] gears.shape shape A `gears.shape`
|
|
|
|
|
-- compatible function
|
2016-05-30 21:05:57 +02:00
|
|
|
|
-- @see shape
|
|
|
|
|
-- @see gears.shape
|
|
|
|
|
|
2016-07-21 02:15:13 +02:00
|
|
|
|
local function apply_mouse_mode(self)
|
|
|
|
|
local w = self:get_wibox()
|
|
|
|
|
local align = self._private.align
|
|
|
|
|
local real_placement = align_convert[align]
|
|
|
|
|
|
|
|
|
|
a_placement[real_placement](w, {
|
|
|
|
|
parent = capi.mouse,
|
|
|
|
|
offset = offset[align]
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function apply_outside_mode(self)
|
|
|
|
|
local w = self:get_wibox()
|
|
|
|
|
|
|
|
|
|
local _, position = a_placement.next_to(w, {
|
|
|
|
|
geometry = self._private.widget_geometry,
|
|
|
|
|
preferred_positions = self.preferred_positions,
|
2018-12-22 03:29:56 +01:00
|
|
|
|
preferred_anchors = self.preferred_alignments,
|
2016-07-21 02:15:13 +02:00
|
|
|
|
honor_workarea = true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
self.current_position = position
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Place the tooltip under the mouse.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self A tooltip object.
|
2009-09-09 14:57:27 +02:00
|
|
|
|
local function set_geometry(self)
|
|
|
|
|
-- calculate width / height
|
2018-05-29 02:54:14 +02:00
|
|
|
|
local n_w, n_h = self.textbox:get_preferred_size(capi.mouse.screen)
|
2015-07-15 18:47:20 +02:00
|
|
|
|
n_w = n_w + self.marginbox.left + self.marginbox.right
|
|
|
|
|
n_h = n_h + self.marginbox.top + self.marginbox.bottom
|
2016-05-29 05:26:33 +02:00
|
|
|
|
|
2016-05-29 23:40:39 +02:00
|
|
|
|
local w = self:get_wibox()
|
|
|
|
|
w:geometry({ width = n_w, height = n_h })
|
|
|
|
|
|
2016-07-21 02:15:13 +02:00
|
|
|
|
local mode = self.mode
|
2016-05-29 23:40:39 +02:00
|
|
|
|
|
2016-07-21 02:15:13 +02:00
|
|
|
|
if mode == "outside" and self._private.widget_geometry then
|
|
|
|
|
apply_outside_mode(self)
|
|
|
|
|
else
|
|
|
|
|
apply_mouse_mode(self)
|
|
|
|
|
end
|
2016-05-29 23:40:39 +02:00
|
|
|
|
|
|
|
|
|
a_placement.no_offscreen(w)
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Show a tooltip.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self The tooltip to show.
|
2009-09-09 14:57:27 +02:00
|
|
|
|
local function show(self)
|
|
|
|
|
-- do nothing if the tooltip is already shown
|
2016-05-29 21:22:07 +02:00
|
|
|
|
if self._private.visible then return end
|
2015-09-27 16:04:20 +02:00
|
|
|
|
if self.timer then
|
|
|
|
|
if not self.timer.started then
|
|
|
|
|
self.timer:start()
|
2019-07-22 01:07:33 +02:00
|
|
|
|
self:timer_function()
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2009-11-07 20:09:39 +01:00
|
|
|
|
set_geometry(self)
|
2016-03-02 20:00:44 +01:00
|
|
|
|
self.wibox.visible = true
|
2016-05-29 21:22:07 +02:00
|
|
|
|
self._private.visible = true
|
2016-03-02 20:04:19 +01:00
|
|
|
|
self:emit_signal("property::visible")
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Hide a tooltip.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self The tooltip to hide.
|
2009-09-09 14:57:27 +02:00
|
|
|
|
local function hide(self)
|
|
|
|
|
-- do nothing if the tooltip is already hidden
|
2016-05-29 21:22:07 +02:00
|
|
|
|
if not self._private.visible then return end
|
2015-09-27 16:04:20 +02:00
|
|
|
|
if self.timer then
|
|
|
|
|
if self.timer.started then
|
|
|
|
|
self.timer:stop()
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-03-02 20:00:44 +01:00
|
|
|
|
self.wibox.visible = false
|
2016-05-29 21:22:07 +02:00
|
|
|
|
self._private.visible = false
|
2016-03-02 20:04:19 +01:00
|
|
|
|
self:emit_signal("property::visible")
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
--- The wibox containing the tooltip widgets.
|
2016-05-29 05:26:33 +02:00
|
|
|
|
-- @property wibox
|
|
|
|
|
-- @param `wibox`
|
|
|
|
|
|
|
|
|
|
function tooltip:get_wibox()
|
|
|
|
|
if self._private.wibox then
|
|
|
|
|
return self._private.wibox
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local wb = wibox(self.wibox_properties)
|
2018-05-29 02:54:14 +02:00
|
|
|
|
wb:set_widget(self.widget)
|
2016-05-29 05:26:33 +02:00
|
|
|
|
|
|
|
|
|
-- 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.
|
2018-05-29 02:54:14 +02:00
|
|
|
|
wb:buttons(a_button({}, 1, nil, self.hide))
|
2016-05-29 05:26:33 +02:00
|
|
|
|
|
|
|
|
|
self._private.wibox = wb
|
|
|
|
|
|
|
|
|
|
return wb
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Is the tooltip visible?
|
|
|
|
|
-- @property visible
|
|
|
|
|
-- @param boolean
|
|
|
|
|
|
2016-05-29 21:22:07 +02:00
|
|
|
|
function tooltip:get_visible()
|
|
|
|
|
return self._private.visible
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function tooltip:set_visible(value)
|
|
|
|
|
if self._private.visible == value then return end
|
|
|
|
|
|
|
|
|
|
if value then
|
|
|
|
|
show(self)
|
|
|
|
|
else
|
|
|
|
|
hide(self)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-05-29 23:40:39 +02:00
|
|
|
|
--- The horizontal alignment.
|
|
|
|
|
--
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- This is valid for the mouse mode only. For the outside mode, use
|
|
|
|
|
-- `preferred_positions`.
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_align_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_align2_EXAMPLE@
|
|
|
|
|
--
|
2016-05-29 23:40:39 +02:00
|
|
|
|
-- The following values are valid:
|
|
|
|
|
--
|
|
|
|
|
-- * top_left
|
|
|
|
|
-- * left
|
|
|
|
|
-- * bottom_left
|
|
|
|
|
-- * right
|
|
|
|
|
-- * top_right
|
|
|
|
|
-- * bottom_right
|
|
|
|
|
-- * bottom
|
|
|
|
|
-- * top
|
|
|
|
|
--
|
|
|
|
|
-- @property align
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param string
|
2016-05-29 23:40:39 +02:00
|
|
|
|
-- @see beautiful.tooltip_align
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @see mode
|
|
|
|
|
-- @see preferred_positions
|
2016-05-29 23:40:39 +02:00
|
|
|
|
|
|
|
|
|
--- The default tooltip alignment.
|
|
|
|
|
-- @beautiful beautiful.tooltip_align
|
|
|
|
|
-- @param string
|
|
|
|
|
-- @see align
|
|
|
|
|
|
|
|
|
|
function tooltip:get_align()
|
|
|
|
|
return self._private.align
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function tooltip:set_align(value)
|
|
|
|
|
if not align_convert[value] then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self._private.align = value
|
|
|
|
|
|
|
|
|
|
set_geometry(self)
|
|
|
|
|
self:emit_signal("property::align")
|
|
|
|
|
end
|
|
|
|
|
|
2016-05-30 21:05:57 +02:00
|
|
|
|
--- The shape of the tooltip window.
|
2018-09-30 08:12:57 +02:00
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_shape_EXAMPLE@
|
|
|
|
|
--
|
2016-05-30 21:05:57 +02:00
|
|
|
|
-- @property shape
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @tparam gears.shape shape
|
2016-05-30 21:05:57 +02:00
|
|
|
|
-- @see gears.shape
|
|
|
|
|
-- @see beautiful.tooltip_shape
|
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
function tooltip:set_shape(s)
|
|
|
|
|
self.backgroundbox:set_shape(s)
|
2016-05-30 21:05:57 +02:00
|
|
|
|
end
|
|
|
|
|
|
2016-07-21 02:15:13 +02:00
|
|
|
|
--- Set the tooltip positioning mode.
|
|
|
|
|
-- This affects how the tooltip is placed. By default, the tooltip is `align`ed
|
|
|
|
|
-- close to the mouse cursor. It is also possible to place the tooltip relative
|
|
|
|
|
-- to the widget geometry.
|
|
|
|
|
--
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- **mouse:**
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_mode_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- **outside:**
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_mode2_EXAMPLE@
|
|
|
|
|
--
|
2016-07-21 02:15:13 +02:00
|
|
|
|
-- Valid modes are:
|
|
|
|
|
--
|
|
|
|
|
-- * "mouse": Next to the mouse cursor
|
|
|
|
|
-- * "outside": Outside of the widget
|
|
|
|
|
--
|
|
|
|
|
-- @property mode
|
|
|
|
|
-- @param string
|
|
|
|
|
|
|
|
|
|
function tooltip:set_mode(mode)
|
|
|
|
|
self._private.mode = mode
|
|
|
|
|
|
|
|
|
|
set_geometry(self)
|
|
|
|
|
self:emit_signal("property::mode")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function tooltip:get_mode()
|
|
|
|
|
return self._private.mode or "mouse"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- The preferred positions when in `outside` mode.
|
|
|
|
|
--
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @DOC_awful_tooltip_preferred_positions_EXAMPLE@
|
|
|
|
|
--
|
2016-07-21 02:15:13 +02:00
|
|
|
|
-- If the tooltip fits on multiple sides of the drawable, then this defines the
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- priority.
|
|
|
|
|
--
|
|
|
|
|
-- The valid table values are:
|
|
|
|
|
--
|
|
|
|
|
-- * "top"
|
|
|
|
|
-- * "right"
|
|
|
|
|
-- * "left"
|
|
|
|
|
-- * "bottom"
|
2016-07-21 02:15:13 +02:00
|
|
|
|
--
|
|
|
|
|
-- The default is:
|
|
|
|
|
--
|
|
|
|
|
-- {"top", "right", "left", "bottom"}
|
|
|
|
|
--
|
|
|
|
|
-- @property preferred_positions
|
|
|
|
|
-- @tparam table preferred_positions The position, ordered by priorities
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @see align
|
|
|
|
|
-- @see mode
|
|
|
|
|
-- @see preferred_alignments
|
2016-07-21 02:15:13 +02:00
|
|
|
|
|
|
|
|
|
function tooltip:get_preferred_positions()
|
|
|
|
|
return self._private.preferred_positions or
|
|
|
|
|
{"top", "right", "left", "bottom"}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function tooltip:set_preferred_positions(value)
|
|
|
|
|
self._private.preferred_positions = value
|
|
|
|
|
|
|
|
|
|
set_geometry(self)
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-30 08:12:57 +02:00
|
|
|
|
--- The preferred alignment when using the `outside` mode.
|
|
|
|
|
--
|
|
|
|
|
-- The values of the table are ordered by priority, the first one that fits
|
|
|
|
|
-- will be used.
|
|
|
|
|
--
|
|
|
|
|
-- **front:**
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_preferred_alignment_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- **middle:**
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_preferred_alignment2_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- **back:**
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_preferred_alignment3_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- The valid table values are:
|
|
|
|
|
--
|
|
|
|
|
-- * front
|
|
|
|
|
-- * middle
|
|
|
|
|
-- * back
|
|
|
|
|
--
|
|
|
|
|
-- The default is:
|
|
|
|
|
--
|
|
|
|
|
-- {"front", "back", "middle"}
|
|
|
|
|
--
|
|
|
|
|
-- @property preferred_alignments
|
|
|
|
|
-- @param string
|
|
|
|
|
-- @see preferred_positions
|
2018-12-22 03:29:56 +01:00
|
|
|
|
|
|
|
|
|
function tooltip:get_preferred_alignments()
|
|
|
|
|
return self._private.preferred_alignments or
|
|
|
|
|
{"front", "back", "middle"}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function tooltip:set_preferred_alignments(value)
|
|
|
|
|
self._private.preferred_alignments = value
|
|
|
|
|
|
|
|
|
|
set_geometry(self)
|
|
|
|
|
end
|
|
|
|
|
|
2009-09-09 14:57:27 +02:00
|
|
|
|
--- Change displayed text.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2016-05-29 05:26:33 +02:00
|
|
|
|
-- @property text
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self The tooltip object.
|
|
|
|
|
-- @tparam string text New tooltip text, passed to
|
|
|
|
|
-- `wibox.widget.textbox.set_text`.
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- @see wibox.widget.textbox
|
2016-05-29 05:26:33 +02:00
|
|
|
|
|
|
|
|
|
function tooltip:set_text(text)
|
2014-03-16 13:25:01 +01:00
|
|
|
|
self.textbox:set_text(text)
|
2016-05-29 21:22:07 +02:00
|
|
|
|
if self._private.visible then
|
2015-07-29 18:50:02 +02:00
|
|
|
|
set_geometry(self)
|
|
|
|
|
end
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2015-07-29 19:02:01 +02:00
|
|
|
|
--- Change displayed markup.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2016-05-29 05:26:33 +02:00
|
|
|
|
-- @property markup
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self The tooltip object.
|
|
|
|
|
-- @tparam string text New tooltip markup, passed to
|
|
|
|
|
-- `wibox.widget.textbox.set_markup`.
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- @see wibox.widget.textbox
|
2016-05-29 05:26:33 +02:00
|
|
|
|
|
|
|
|
|
function tooltip:set_markup(text)
|
2014-03-30 23:35:35 +02:00
|
|
|
|
self.textbox:set_markup(text)
|
2016-05-29 21:22:07 +02:00
|
|
|
|
if self._private.visible then
|
2015-07-29 18:50:02 +02:00
|
|
|
|
set_geometry(self)
|
|
|
|
|
end
|
2014-03-30 23:35:35 +02:00
|
|
|
|
end
|
|
|
|
|
|
2009-09-09 14:57:27 +02:00
|
|
|
|
--- Change the tooltip's update interval.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2016-05-29 05:26:33 +02:00
|
|
|
|
-- @property timeout
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self A tooltip object.
|
|
|
|
|
-- @tparam number timeout The timeout value.
|
2016-05-29 05:26:33 +02:00
|
|
|
|
|
|
|
|
|
function tooltip:set_timeout(timeout)
|
2015-09-27 16:04:20 +02:00
|
|
|
|
if self.timer then
|
|
|
|
|
self.timer.timeout = timeout
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
--- Set all margins around the tooltip textbox
|
|
|
|
|
--
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @DOC_awful_tooltip_margins_EXAMPLE@
|
|
|
|
|
--
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- @property margins
|
|
|
|
|
-- @tparam tooltip self A tooltip object
|
|
|
|
|
-- @tparam number New margins value
|
|
|
|
|
|
|
|
|
|
function tooltip:set_margins(val)
|
|
|
|
|
self.marginbox:set_margins(val)
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-30 08:12:57 +02:00
|
|
|
|
--- The border width.
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_border_width_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- @property border_width
|
|
|
|
|
-- @param number
|
2018-12-22 03:34:29 +01:00
|
|
|
|
|
|
|
|
|
function tooltip:set_border_width(val)
|
2019-04-05 22:52:01 +02:00
|
|
|
|
self.widget.border_width = val
|
2018-12-22 03:34:29 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-09-30 08:12:57 +02:00
|
|
|
|
--- The border color.
|
|
|
|
|
--
|
|
|
|
|
-- @DOC_awful_tooltip_border_color_EXAMPLE@
|
|
|
|
|
--
|
|
|
|
|
-- @property border_color
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @param color
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @param gears.color
|
2018-12-22 03:34:29 +01:00
|
|
|
|
|
|
|
|
|
function tooltip:set_border_color(val)
|
2019-04-05 22:52:01 +02:00
|
|
|
|
self.widget.border_color = val
|
2018-12-22 03:34:29 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
--- Set the margins around the left and right of the tooltip textbox
|
|
|
|
|
--
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @DOC_awful_tooltip_margins_leftright_EXAMPLE@
|
|
|
|
|
--
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- @property margins_leftright
|
|
|
|
|
-- @tparam tooltip self A tooltip object
|
|
|
|
|
-- @tparam number New margins value
|
|
|
|
|
|
|
|
|
|
function tooltip:set_margin_leftright(val)
|
2018-12-22 03:31:26 +01:00
|
|
|
|
self.marginbox:set_left(val)
|
|
|
|
|
self.marginbox:set_right(val)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--TODO v5 deprecate this
|
|
|
|
|
function tooltip:set_margins_leftright(val)
|
|
|
|
|
self:set_margin_leftright(val)
|
2018-05-29 02:54:14 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Set the margins around the top and bottom of the tooltip textbox
|
|
|
|
|
--
|
2018-09-30 08:12:57 +02:00
|
|
|
|
-- @DOC_awful_tooltip_margins_topbottom_EXAMPLE@
|
|
|
|
|
--
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- @property margins_topbottom
|
|
|
|
|
-- @tparam tooltip self A tooltip object
|
|
|
|
|
-- @tparam number New margins value
|
|
|
|
|
|
|
|
|
|
function tooltip:set_margin_topbottom(val)
|
2018-12-22 03:31:26 +01:00
|
|
|
|
self.marginbox:set_top(val)
|
|
|
|
|
self.marginbox:set_bottom(val)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--TODO v5 deprecate this
|
|
|
|
|
function tooltip:set_margins_topbottom(val)
|
|
|
|
|
self:set_margin_topbottom(val)
|
2018-05-29 02:54:14 +02:00
|
|
|
|
end
|
|
|
|
|
|
2009-09-09 14:57:27 +02:00
|
|
|
|
--- Add tooltip to an object.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self The tooltip.
|
2016-03-02 20:04:19 +01:00
|
|
|
|
-- @tparam gears.object obj An object with `mouse::enter` and
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- `mouse::leave` signals.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @method add_to_object
|
2016-05-29 05:26:33 +02:00
|
|
|
|
function tooltip:add_to_object(obj)
|
2016-07-21 02:15:13 +02:00
|
|
|
|
if not obj then return end
|
|
|
|
|
|
2016-03-02 20:04:19 +01:00
|
|
|
|
obj:connect_signal("mouse::enter", self.show)
|
|
|
|
|
obj:connect_signal("mouse::leave", self.hide)
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Remove tooltip from an object.
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam tooltip self The tooltip.
|
2016-03-02 20:04:19 +01:00
|
|
|
|
-- @tparam gears.object obj An object with `mouse::enter` and
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- `mouse::leave` signals.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @method remove_from_object
|
2016-05-29 05:26:33 +02:00
|
|
|
|
function tooltip:remove_from_object(obj)
|
2016-03-02 20:04:19 +01:00
|
|
|
|
obj:disconnect_signal("mouse::enter", self.show)
|
|
|
|
|
obj:disconnect_signal("mouse::leave", self.hide)
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2016-07-21 02:15:13 +02:00
|
|
|
|
-- Tooltip can be applied to both widgets, wibox and client, their geometry
|
|
|
|
|
-- works differently.
|
2018-05-29 02:54:14 +02:00
|
|
|
|
|
2016-07-21 02:15:13 +02:00
|
|
|
|
local function get_parent_geometry(arg1, arg2)
|
|
|
|
|
if type(arg2) == "table" and arg2.width then
|
|
|
|
|
return arg2
|
|
|
|
|
elseif type(arg1) == "table" and arg1.width then
|
|
|
|
|
return arg1
|
|
|
|
|
end
|
|
|
|
|
end
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
|
|
|
|
--- Create a new tooltip and link it to a widget.
|
2016-03-02 20:04:19 +01:00
|
|
|
|
-- Tooltips emit `property::visible` when their visibility changes.
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam table args Arguments for tooltip creation.
|
|
|
|
|
-- @tparam function args.timer_function A function to dynamically set the
|
|
|
|
|
-- tooltip text. Its return value will be passed to
|
|
|
|
|
-- `wibox.widget.textbox.set_markup`.
|
2016-06-03 00:40:02 +02:00
|
|
|
|
-- @tparam[opt=1] number args.timeout The timeout value for
|
|
|
|
|
-- `timer_function`.
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @tparam[opt] table args.objects A list of objects linked to the tooltip.
|
|
|
|
|
-- @tparam[opt] number args.delay_show Delay showing the tooltip by this many
|
|
|
|
|
-- seconds.
|
|
|
|
|
-- @tparam[opt=apply_dpi(5)] integer args.margin_leftright The left/right margin for the text.
|
|
|
|
|
-- @tparam[opt=apply_dpi(3)] integer args.margin_topbottom The top/bottom margin for the text.
|
2016-05-30 21:05:57 +02:00
|
|
|
|
-- @tparam[opt=nil] gears.shape args.shape The shape
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- @tparam[opt] string args.bg The background color
|
|
|
|
|
-- @tparam[opt] string args.fg The foreground color
|
|
|
|
|
-- @tparam[opt] string args.border_color The tooltip border color
|
|
|
|
|
-- @tparam[opt] number args.border_width The tooltip border width
|
|
|
|
|
-- @tparam[opt] string args.align The horizontal alignment
|
|
|
|
|
-- @tparam[opt] string args.font The tooltip font
|
|
|
|
|
-- @tparam[opt] number args.opacity The tooltip opacity
|
2015-07-30 20:29:07 +02:00
|
|
|
|
-- @treturn awful.tooltip The created tooltip.
|
2009-09-09 14:57:27 +02:00
|
|
|
|
-- @see add_to_object
|
2016-05-29 05:26:33 +02:00
|
|
|
|
-- @see timeout
|
|
|
|
|
-- @see text
|
|
|
|
|
-- @see markup
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- @see align
|
2019-06-07 20:59:34 +02:00
|
|
|
|
-- @constructorfct awful.tooltip
|
2016-05-29 05:26:33 +02:00
|
|
|
|
function tooltip.new(args)
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- gears.object, properties are linked to set_/get_ functions
|
2016-05-29 05:26:33 +02:00
|
|
|
|
local self = object {
|
|
|
|
|
enable_properties = true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rawset(self,"_private", {})
|
|
|
|
|
|
2016-05-29 21:22:07 +02:00
|
|
|
|
self._private.visible = false
|
2016-05-30 21:05:57 +02:00
|
|
|
|
self._private.align = args.align or beautiful.tooltip_align or "right"
|
|
|
|
|
self._private.shape = args.shape or beautiful.tooltip_shape
|
|
|
|
|
or shape.rectangle
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
|
|
|
|
-- private data
|
2015-02-14 20:37:30 +01:00
|
|
|
|
if args.delay_show then
|
2015-07-29 18:55:22 +02:00
|
|
|
|
local delay_timeout
|
|
|
|
|
|
2015-02-14 20:37:30 +01:00
|
|
|
|
delay_timeout = timer { timeout = args.delay_show }
|
2015-07-29 18:55:22 +02:00
|
|
|
|
delay_timeout:connect_signal("timeout", function ()
|
|
|
|
|
show(self)
|
|
|
|
|
delay_timeout:stop()
|
|
|
|
|
end)
|
|
|
|
|
|
2016-07-21 02:15:13 +02:00
|
|
|
|
function self.show(other, geo)
|
|
|
|
|
-- Auto detect clients and wiboxes
|
|
|
|
|
if other.drawable or other.pid then
|
|
|
|
|
geo = other:geometry()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Cache the geometry in case it is needed later
|
|
|
|
|
self._private.widget_geometry = get_parent_geometry(other, geo)
|
|
|
|
|
|
2015-09-27 16:04:20 +02:00
|
|
|
|
if not delay_timeout.started then
|
|
|
|
|
delay_timeout:start()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
function self.hide()
|
|
|
|
|
if delay_timeout.started then
|
|
|
|
|
delay_timeout:stop()
|
|
|
|
|
end
|
|
|
|
|
hide(self)
|
|
|
|
|
end
|
2015-07-29 18:55:22 +02:00
|
|
|
|
else
|
2016-07-21 02:15:13 +02:00
|
|
|
|
function self.show(other, geo)
|
|
|
|
|
-- Auto detect clients and wiboxes
|
|
|
|
|
if other.drawable or other.pid then
|
2018-12-22 03:32:19 +01:00
|
|
|
|
geo = other
|
2016-07-21 02:15:13 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Cache the geometry in case it is needed later
|
|
|
|
|
self._private.widget_geometry = get_parent_geometry(other, geo)
|
|
|
|
|
|
2015-09-27 16:04:20 +02:00
|
|
|
|
show(self)
|
|
|
|
|
end
|
|
|
|
|
function self.hide()
|
|
|
|
|
hide(self)
|
|
|
|
|
end
|
2015-02-14 20:37:30 +01:00
|
|
|
|
end
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
|
|
|
|
-- export functions
|
2017-03-08 21:18:33 +01:00
|
|
|
|
gtable.crush(self, tooltip, true)
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
|
|
|
|
-- setup the timer action only if needed
|
|
|
|
|
if args.timer_function then
|
2015-09-27 16:04:20 +02:00
|
|
|
|
self.timer = timer { timeout = args.timeout and args.timeout or 1 }
|
|
|
|
|
self.timer_function = function()
|
2014-03-30 23:35:35 +02:00
|
|
|
|
self:set_markup(args.timer_function())
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
2015-09-27 16:04:20 +02:00
|
|
|
|
self.timer:connect_signal("timeout", self.timer_function)
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- collect tooltip properties
|
|
|
|
|
-- wibox
|
|
|
|
|
local fg = args.fg or beautiful.tooltip_fg or beautiful.fg_focus or "#000000"
|
|
|
|
|
local opacity = args.opacity or beautiful.tooltip_opacity or 1
|
|
|
|
|
-- textbox
|
|
|
|
|
local font = args.font or beautiful.tooltip_font or beautiful.font
|
|
|
|
|
-- marginbox
|
|
|
|
|
local m_lr = args.margin_leftright or dpi(5)
|
|
|
|
|
local m_tb = args.margin_topbottom or dpi(3)
|
|
|
|
|
-- backgroundbox
|
|
|
|
|
local bg = args.bg or beautiful.tooltip_bg
|
|
|
|
|
or beautiful.bg_focus or "#ffcb60"
|
|
|
|
|
local border_width = args.border_width or beautiful.tooltip_border_width or 0
|
|
|
|
|
local border_color = args.border_color or beautiful.tooltip_border_color
|
|
|
|
|
or beautiful.border_normal or "#ffcb60"
|
2016-05-30 21:05:57 +02:00
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
-- Set wibox default properties
|
2016-02-28 15:34:43 +01:00
|
|
|
|
self.wibox_properties = {
|
|
|
|
|
visible = false,
|
|
|
|
|
ontop = true,
|
2016-05-30 21:05:57 +02:00
|
|
|
|
border_width = 0,
|
|
|
|
|
fg = fg,
|
|
|
|
|
bg = color.transparent,
|
2018-05-29 02:54:14 +02:00
|
|
|
|
opacity = opacity,
|
2017-07-24 07:52:55 +02:00
|
|
|
|
type = "tooltip",
|
2016-02-28 15:34:43 +01:00
|
|
|
|
}
|
2014-03-30 23:31:38 +02:00
|
|
|
|
|
2018-05-29 02:54:14 +02:00
|
|
|
|
self.widget = wibox.widget {
|
|
|
|
|
{
|
|
|
|
|
{
|
2019-04-05 22:52:01 +02:00
|
|
|
|
id = 'text_role',
|
|
|
|
|
font = font,
|
2018-05-29 02:54:14 +02:00
|
|
|
|
widget = wibox.widget.textbox,
|
|
|
|
|
},
|
2019-04-05 22:52:01 +02:00
|
|
|
|
id = 'margin_role',
|
|
|
|
|
left = m_lr,
|
|
|
|
|
right = m_lr,
|
|
|
|
|
top = m_tb,
|
2018-05-29 02:54:14 +02:00
|
|
|
|
bottom = m_tb,
|
|
|
|
|
widget = wibox.container.margin,
|
|
|
|
|
},
|
2019-04-05 22:52:01 +02:00
|
|
|
|
id = 'background_role',
|
|
|
|
|
bg = bg,
|
|
|
|
|
shape = self._private.shape,
|
|
|
|
|
border_width = border_width,
|
|
|
|
|
border_color = border_color,
|
|
|
|
|
widget = wibox.container.background,
|
2018-05-29 02:54:14 +02:00
|
|
|
|
}
|
|
|
|
|
self.textbox = self.widget:get_children_by_id('text_role')[1]
|
|
|
|
|
self.marginbox = self.widget:get_children_by_id('margin_role')[1]
|
|
|
|
|
self.backgroundbox = self.widget:get_children_by_id('background_role')[1]
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
|
|
|
|
-- Add tooltip to objects
|
|
|
|
|
if args.objects then
|
2016-03-02 20:04:19 +01:00
|
|
|
|
for _, obj in ipairs(args.objects) do
|
|
|
|
|
self:add_to_object(obj)
|
2009-09-09 14:57:27 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-01 20:21:23 +02:00
|
|
|
|
-- Apply the properties
|
|
|
|
|
for k, v in pairs(args) do
|
|
|
|
|
if tooltip["set_"..k] then
|
|
|
|
|
self[k] = v
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2009-09-09 14:57:27 +02:00
|
|
|
|
return self
|
|
|
|
|
end
|
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
|
function tooltip.mt:__call(...)
|
2015-02-14 20:31:53 +01:00
|
|
|
|
return tooltip.new(...)
|
2012-06-12 20:13:09 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return setmetatable(tooltip, tooltip.mt)
|
2009-09-09 14:57:27 +02:00
|
|
|
|
|
2015-12-12 17:42:33 +01:00
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|