From: Sébastien Gross <seb•ɱɩɲʋʃ•awesome•ɑƬ•chezwam•ɖɵʈ•org>
Tooltip can be added to any object having add_signal() method.
To add a tooltip:
clock_t = awful.tooltip(myclocktext)
The tooltip text can be changed using:
clock_t.set_text("This is myclocktext toolip")
The tooltip text can also be dynamicaly modified, using a string-returning
function when creating the tooltip:
clock_t = awful.tooltip(myclocktext, function()
return os.date("Today is %A %B %d %Y\nThe time is %T")
end)
Signed-off-by: Sébastien Gross <seb•ɱɩɲʋʃ•awesome•ɑƬ•chezwam•ɖɵʈ•org>
---
lib/awful/tooltip.lua | 134 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 134 insertions(+), 0 deletions(-)
create mode 100644 lib/awful/tooltip.lua
diff --git a/lib/awful/tooltip.lua b/lib/awful/tooltip.lua
new file mode 100644
index 0000000..5350efa
--- /dev/null
+++ b/lib/awful/tooltip.lua
@@ -0,0 +1,134 @@
+-------------------------------------------------------------------------
+-- Toolip module for Awesome
+-- @author Sébastien Gross <seb•ɱɩɲʋʃ•awesome•ɑƬ•chezwam•ɖɵʈ•org>
+-- @copyright 2009 Sébastien Gross
+-- @release @AWESOME_VERSION@
+-------------------------------------------------------------------------
+
+local mouse = mouse
+local widget = widget
+local screen = screen
+local awful = require("awful")
+local beautiful = require("beautiful")
+local setmetatable = setmetatable
+
+module("awful.tooltip")
+
+-- compute coords
+local function set_geometry(obj)
+ local scr = mouse.screen
+ local s_geometry = screen[scr].workarea
+ local scr_w = s_geometry.x + s_geometry.width
+ local scr_h = s_geometry.y + s_geometry.height
+ local m_c = mouse.coords()
+ -- wibox size
+ local w_b = obj.tt_wibox.border_width
+ local w_h = obj.tt_wibox.height + 2 * w_b
+ local w_w = obj.tt_wibox.width + 2 * w_b
+
+ local w = obj.tt_textbox:extents().width + obj.x_margin
+ local h = obj.tt_textbox:extents().height + obj.y_margin
+
+ local x = m_c.x + obj.x_offset < s_geometry.x and s_geometry.x or m_c.x +
obj.x_offset
+ local y = m_c.y + obj.y_offset < s_geometry.y and s_geometry.y or m_c.y +
obj.y_offset
+
+ y = y + w_h > scr_h and scr_h - w_h or y
+ x = x + w_w > scr_w and scr_w - w_w or x
+
+ obj.tt_wibox:geometry({x = x, y = y, width = w, height = h})
+end
+
+--- show
+-- @param obj tooltip object
+-- Show the tooltip
+local function show(obj)
+ if obj.update_func ~= nil then
+ obj:set_text(obj.update_func())
+ end
+ set_geometry(obj)
+ obj.tt_wibox.visible = true
+end
+
+--- hide
+-- @param obj tooltip object
+-- Hide the tooltip
+local function hide(obj)
+ obj.tt_wibox.visible = false
+end
+
+--- hide
+-- @param obj tooltip object
+-- @param text new tooltip text
+-- Change the tooltip's text
+local function set_text(obj, text)
+ obj.tt_textbox.text = '<span color="' .. obj.fg .. '" font_desc="'
+ .. obj.font .. '">' .. text .. "</span>"
+end
+
+--- set_offset
+-- @param obj tooltip object
+-- @param x x offset
+-- @param y y offset
+-- Change the tooltip's offsets
+local function set_offset(obj, x, y)
+ obj.x_offset = x
+ obj.y_offset = y
+end
+
+--- set_margin
+-- @param obj tooltip object
+-- @param x x margin
+-- @param y y margin
+-- Change the tooltip's margins
+local function set_margin(obj, x, y)
+ obj.x_margin = x
+ obj.y_margin = y
+end
+
+local function set_defaults(obj)
+ obj.tt_wibox.border_width = beautiful.tooltip_border_width or
beautiful.border_width or 1
+ obj.tt_wibox.border_color = beautiful.tooltip_border_color or
beautiful.border_normal
+ obj.tt_wibox.opacity = beautiful.tooltip_opacity or 1
+ obj.tt_wibox.bg = beautiful.tooltip_bg_color or beautiful.bg_focus or
"#ffcb60"
+ obj.fg = beautiful.tooltip_fg_color or beautiful.fg_focus or "#000000"
+ obj.font = beautiful.tooltip_font or beautiful.font or "terminus 6"
+end
+
+
+--- create
+-- @param _
+-- @param on_widget the widget to be linked with the tooltip
+-- @param func a function to dynamicaly change the tooltip text
+-- Create a new tooltip and link it to a widget
+local function create(_, on_widget, func)
+ local obj = {
+ x_offset = 1,
+ y_offset = 1,
+ x_margin = 2,
+ y_margin = 2,
+
+ tt_wibox = awful.wibox({
+ position = "float",
+ }),
+ tt_textbox = widget({type = "textbox", name = "tt", align="right"}),
+ update_func = func
+ }
+ set_defaults(obj)
+ obj.tt_wibox.visible = false
+ obj.tt_wibox.ontop = true
+ obj.tt_wibox.widgets = { obj.tt_textbox }
+ obj.tt_wibox:add_signal("mouse::enter", function () hide(obj) end)
+ on_widget:add_signal("mouse::enter", function () show(obj) end)
+ on_widget:add_signal("mouse::leave", function () hide(obj) end)
+
+ obj.show = function(obj) show(obj) end
+ obj.hide = function(obj) hide(obj) end
+ obj.set_text = function(obj, t) set_text(obj, t) end
+ obj.set_offset = function(obj, x, y) set_offset(obj, x, y) end
+ obj.set_margin = function(obj, x, y) set_margin(obj, x, y) end
+ return obj
+end
+
+setmetatable(_M, { __call = create })
+
+-- vim: ft=lua:et:sw=4:ts=4:sts=4:enc=utf-8:tw=78
--
1.5.6.5
--
To unsubscribe, send mail to [email protected].