2017-08-13 08:50:19 +02:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
--- A notification content message.
|
|
|
|
--
|
|
|
|
-- This widget is a specialized `wibox.widget.textbox` with the following extra
|
|
|
|
-- features:
|
|
|
|
--
|
|
|
|
-- * Honor the `beautiful` notification variables.
|
|
|
|
-- * React to the `naughty.notification` object message changes.
|
|
|
|
--
|
|
|
|
--@DOC_wibox_nwidget_message_simple_EXAMPLE@
|
|
|
|
--
|
|
|
|
-- @author Emmanuel Lepage Vallee <elv1313@gmail.com>
|
|
|
|
-- @copyright 2017 Emmanuel Lepage Vallee
|
|
|
|
-- @widgetmod naughty.widget.message
|
|
|
|
-- @see wibox.widget.textbox
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
local textbox = require("wibox.widget.textbox")
|
|
|
|
local gtable = require("gears.table")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
|
|
|
|
local message = {}
|
|
|
|
|
|
|
|
local function markup(notif, wdg)
|
|
|
|
local ret = notif.message or ""
|
|
|
|
local fg = notif.fg or beautiful.notification_fg
|
|
|
|
|
|
|
|
wdg:set_font(notif.font or beautiful.notification_font)
|
|
|
|
|
|
|
|
if fg then
|
|
|
|
ret = "<span color='" .. fg .. "'>" .. ret .. "</span>"
|
|
|
|
end
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--- The attached notification.
|
|
|
|
-- @property notification
|
|
|
|
-- @tparam naughty.notification notification
|
|
|
|
|
|
|
|
function message:set_notification(notif)
|
|
|
|
if self._private.notification == notif then return end
|
|
|
|
|
|
|
|
if self._private.notification then
|
2019-07-09 07:23:11 +02:00
|
|
|
self._private.notification:disconnect_signal("property::message",
|
2017-08-13 08:50:19 +02:00
|
|
|
self._private.message_changed_callback)
|
2019-07-09 07:23:11 +02:00
|
|
|
self._private.notification:disconnect_signal("property::fg",
|
2017-08-13 08:50:19 +02:00
|
|
|
self._private.message_changed_callback)
|
|
|
|
end
|
|
|
|
|
|
|
|
self:set_markup(markup(notif, self))
|
|
|
|
|
|
|
|
self._private.notification = notif
|
|
|
|
|
2019-07-09 07:23:11 +02:00
|
|
|
notif:connect_signal("property::message", self._private.message_changed_callback)
|
|
|
|
notif:connect_signal("property::fg" , self._private.message_changed_callback)
|
2017-08-13 08:50:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new naughty.widget.message.
|
|
|
|
-- @tparam table args
|
|
|
|
-- @tparam naughty.notification args.notification The notification.
|
|
|
|
-- @constructorfct naughty.widget.message
|
|
|
|
|
|
|
|
local function new(args)
|
|
|
|
args = args or {}
|
|
|
|
local tb = textbox()
|
|
|
|
tb:set_wrap("word")
|
|
|
|
tb:set_font(beautiful.notification_font)
|
|
|
|
|
|
|
|
gtable.crush(tb, message, true)
|
|
|
|
|
|
|
|
function tb._private.message_changed_callback()
|
|
|
|
tb:set_markup(markup(tb._private.notification, tb))
|
|
|
|
end
|
|
|
|
|
|
|
|
if args.notification then
|
|
|
|
tb:set_notification(args.notification)
|
|
|
|
end
|
|
|
|
|
|
|
|
return tb
|
|
|
|
end
|
|
|
|
|
|
|
|
--@DOC_widget_COMMON@
|
|
|
|
|
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
|
|
|
return setmetatable(message, {__call = function(_, ...) return new(...) end})
|