2017-08-13 08:50:19 +02:00
|
|
|
----------------------------------------------------------------------------
|
2021-12-21 06:54:15 +01:00
|
|
|
--- A notification title widget.
|
2017-08-13 08:50:19 +02:00
|
|
|
--
|
|
|
|
-- This widget is a specialized `wibox.widget.textbox` with the following extra
|
|
|
|
-- features:
|
|
|
|
--
|
|
|
|
-- * Honor the `beautiful` notification variables.
|
|
|
|
-- * React to the `naughty.notification` object title changes.
|
|
|
|
--
|
|
|
|
--@DOC_wibox_nwidget_title_simple_EXAMPLE@
|
|
|
|
--
|
|
|
|
-- @author Emmanuel Lepage Vallee <elv1313@gmail.com>
|
|
|
|
-- @copyright 2017 Emmanuel Lepage Vallee
|
|
|
|
-- @widgetmod naughty.widget.title
|
2021-12-21 06:54:15 +01:00
|
|
|
-- @supermodule wibox.widget.textbox
|
2017-08-13 08:50:19 +02:00
|
|
|
-- @see wibox.widget.textbox
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
local textbox = require("wibox.widget.textbox")
|
|
|
|
local gtable = require("gears.table")
|
|
|
|
local beautiful = require("beautiful")
|
2020-03-08 01:29:35 +01:00
|
|
|
local markup = require("naughty.widget._markup").set_markup
|
2017-08-13 08:50:19 +02:00
|
|
|
|
|
|
|
local title = {}
|
|
|
|
|
|
|
|
--- The attached notification.
|
|
|
|
-- @property notification
|
|
|
|
-- @tparam naughty.notification notification
|
2022-08-22 08:02:26 +02:00
|
|
|
-- @propertydefault This is usually set in the construtor.
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-08-13 08:50:19 +02:00
|
|
|
|
|
|
|
function title:set_notification(notif)
|
2021-11-01 03:30:17 +01:00
|
|
|
local old = self._private.notification[1]
|
2017-08-13 08:50:19 +02:00
|
|
|
|
2021-11-01 03:30:17 +01:00
|
|
|
if old == notif then return end
|
|
|
|
|
|
|
|
if old then
|
|
|
|
old:disconnect_signal("property::message",
|
2017-08-13 08:50:19 +02:00
|
|
|
self._private.title_changed_callback)
|
2021-11-01 03:30:17 +01:00
|
|
|
old:disconnect_signal("property::fg",
|
2017-08-13 08:50:19 +02:00
|
|
|
self._private.title_changed_callback)
|
|
|
|
end
|
|
|
|
|
2020-03-08 01:29:35 +01:00
|
|
|
markup(self, notif.title, notif.fg, notif.font)
|
2017-08-13 08:50:19 +02:00
|
|
|
|
2021-11-01 03:30:17 +01:00
|
|
|
self._private.notification = setmetatable({notif}, {__mode="v"})
|
2017-08-13 08:50:19 +02:00
|
|
|
self._private.title_changed_callback()
|
|
|
|
|
2019-07-09 07:23:11 +02:00
|
|
|
notif:connect_signal("property::title", self._private.title_changed_callback)
|
|
|
|
notif:connect_signal("property::fg" , self._private.title_changed_callback)
|
2020-01-13 08:32:28 +01:00
|
|
|
self:emit_signal("property::notification", notif)
|
2017-08-13 08:50:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new naughty.widget.title.
|
|
|
|
-- @tparam table args
|
|
|
|
-- @tparam naughty.notification args.notification The notification.
|
|
|
|
-- @constructorfct naughty.widget.title
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @usebeautiful beautiful.notification_fg
|
|
|
|
-- @usebeautiful beautiful.notification_font
|
2017-08-13 08:50:19 +02:00
|
|
|
|
|
|
|
local function new(args)
|
|
|
|
args = args or {}
|
|
|
|
local tb = textbox()
|
|
|
|
tb:set_wrap("word")
|
|
|
|
tb:set_font(beautiful.notification_font)
|
2021-11-01 03:30:17 +01:00
|
|
|
tb._private.notification = {}
|
2017-08-13 08:50:19 +02:00
|
|
|
|
|
|
|
gtable.crush(tb, title, true)
|
|
|
|
|
|
|
|
function tb._private.title_changed_callback()
|
2021-11-01 03:30:17 +01:00
|
|
|
local n = tb._private.notification[1]
|
|
|
|
|
|
|
|
if n then
|
|
|
|
markup(
|
|
|
|
tb,
|
|
|
|
n.title,
|
|
|
|
n.fg,
|
|
|
|
n.font
|
|
|
|
)
|
|
|
|
else
|
|
|
|
markup("", nil, nil)
|
|
|
|
end
|
2017-08-13 08:50:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if args.notification then
|
|
|
|
tb:set_notification(args.notification)
|
|
|
|
end
|
|
|
|
|
|
|
|
return tb
|
|
|
|
end
|
|
|
|
|
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
|
|
|
return setmetatable(title, {__call = function(_, ...) return new(...) end})
|