2008-10-17 22:38:01 +02:00
|
|
|
----------------------------------------------------------------------------
|
2017-08-06 07:28:21 +02:00
|
|
|
--- Notification library.
|
|
|
|
--
|
|
|
|
-- For more details on how to create notifications, see `naughty.notification`.
|
|
|
|
--
|
|
|
|
-- To send notifications from the terminal, use `notify-send`.
|
2014-05-19 13:28:57 +02:00
|
|
|
--
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @author koniu <gkusnierz@gmail.com>
|
|
|
|
-- @copyright 2008 koniu
|
2014-05-20 23:39:31 +02:00
|
|
|
-- @module naughty
|
2008-10-17 22:38:01 +02:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
2017-03-03 23:11:06 +01:00
|
|
|
--luacheck: no max line length
|
|
|
|
|
2008-10-17 22:38:01 +02:00
|
|
|
-- Package environment
|
2017-07-02 04:43:26 +02:00
|
|
|
local capi = { screen = screen }
|
2019-05-06 05:00:58 +02:00
|
|
|
local gdebug = require("gears.debug")
|
|
|
|
local screen = require("awful.screen")
|
|
|
|
local gtable = require("gears.table")
|
|
|
|
local gobject = require("gears.object")
|
2020-03-15 11:04:42 +01:00
|
|
|
local gsurface = require("gears.surface")
|
2016-02-26 18:30:42 +01:00
|
|
|
|
2012-06-12 03:48:41 +02:00
|
|
|
local naughty = {}
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Naughty configuration - a table containing common popup settings.
|
|
|
|
--
|
|
|
|
-- @table naughty.config
|
|
|
|
-- @tfield[opt=apply_dpi(4)] int padding Space between popups and edge of the
|
|
|
|
-- workarea.
|
|
|
|
-- @tfield[opt=apply_dpi(1)] int spacing Spacing between popups.
|
|
|
|
-- @tfield[opt={"/usr/share/pixmaps/"}] table icon_dirs List of directories
|
|
|
|
-- that will be checked by `getIcon()`.
|
|
|
|
-- @tfield[opt={ "png", "gif" }] table icon_formats List of formats that will be
|
|
|
|
-- checked by `getIcon()`.
|
|
|
|
-- @tfield[opt] function notify_callback Callback used to modify or reject
|
|
|
|
-- notifications, e.g.
|
|
|
|
-- naughty.config.notify_callback = function(args)
|
|
|
|
-- args.text = 'prefix: ' .. args.text
|
|
|
|
-- return args
|
|
|
|
-- end
|
|
|
|
-- To reject a notification return `nil` from the callback.
|
|
|
|
-- If the notification is a freedesktop notification received via DBUS, you can
|
|
|
|
-- access the freedesktop hints via `args.freedesktop_hints` if any where
|
|
|
|
-- specified.
|
2014-05-20 23:39:31 +02:00
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @tfield table presets Notification presets. See `config.presets`.
|
|
|
|
--
|
|
|
|
-- @tfield table defaults Default values for the params to `notify()`. These can
|
|
|
|
-- optionally be overridden by specifying a preset. See `config.defaults`.
|
|
|
|
|
|
|
|
-- It's done that way to preserve compatibility with Awesome 4.0 while allowing
|
|
|
|
-- the naughty submodules to use the contants without creating a circular
|
|
|
|
-- dependency.
|
|
|
|
gtable.crush(naughty, require("naughty.constants"))
|
2014-05-25 14:25:01 +02:00
|
|
|
|
2015-07-27 15:54:47 +02:00
|
|
|
--- Notification presets for `naughty.notify`.
|
|
|
|
-- This holds presets for different purposes. A preset is a table of any
|
|
|
|
-- parameters for `notify()`, overriding the default values
|
|
|
|
-- (`naughty.config.defaults`).
|
|
|
|
--
|
|
|
|
-- You have to pass a reference of a preset in your `notify()` as the `preset`
|
|
|
|
-- argument.
|
|
|
|
--
|
|
|
|
-- The presets `"low"`, `"normal"` and `"critical"` are used for notifications
|
|
|
|
-- over DBUS.
|
|
|
|
--
|
|
|
|
-- @table config.presets
|
|
|
|
-- @tfield table low The preset for notifications with low urgency level.
|
|
|
|
-- @tfield[opt=5] int low.timeout
|
|
|
|
-- @tfield[opt=empty] table normal The default preset for every notification without a
|
|
|
|
-- preset that will also be used for normal urgency level.
|
|
|
|
-- @tfield table critical The preset for notifications with a critical urgency
|
|
|
|
-- level.
|
|
|
|
-- @tfield[opt="#ff0000"] string critical.bg
|
|
|
|
-- @tfield[opt="#ffffff"] string critical.fg
|
|
|
|
-- @tfield[opt=0] string critical.timeout
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2015-07-27 15:54:47 +02:00
|
|
|
--- Defaults for `naughty.notify`.
|
|
|
|
--
|
|
|
|
-- @table config.defaults
|
|
|
|
-- @tfield[opt=5] int timeout
|
|
|
|
-- @tfield[opt=""] string text
|
|
|
|
-- @tfield[opt] int screen Defaults to `awful.screen.focused`.
|
|
|
|
-- @tfield[opt=true] boolean ontop
|
2015-07-15 18:35:52 +02:00
|
|
|
-- @tfield[opt=apply_dpi(5)] int margin
|
|
|
|
-- @tfield[opt=apply_dpi(1)] int border_width
|
2015-07-27 15:54:47 +02:00
|
|
|
-- @tfield[opt="top_right"] string position
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- The reason why a notification is to be closed.
|
|
|
|
-- See [the specification](https://developer.gnome.org/notification-spec/#signals)
|
|
|
|
-- for more details.
|
|
|
|
-- @tfield number silent
|
|
|
|
-- @tfield number expired
|
|
|
|
-- @tfield number dismissed_by_user
|
|
|
|
-- @tfield number dismissed_by_command
|
|
|
|
-- @tfield number undefined
|
|
|
|
-- @table notification_closed_reason
|
|
|
|
|
|
|
|
--- The global suspension state.
|
|
|
|
--
|
|
|
|
-- When suspended, no notification widget should interrupt the user. This is
|
|
|
|
-- useful when watching movies or doing presentations.
|
|
|
|
--
|
|
|
|
-- @property suspended
|
|
|
|
-- @param boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @emits added
|
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
--- Do not allow notifications to auto-expire.
|
|
|
|
--
|
|
|
|
-- When navigating the notifications, for example on mouse over or when
|
|
|
|
-- keyboard navigation is enabled, it is very annoying when notifications
|
|
|
|
-- just vanish.
|
|
|
|
--
|
|
|
|
-- @property expiration_paused
|
|
|
|
-- @param[opt=false] boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-01-03 07:52:13 +01:00
|
|
|
|
2019-03-07 05:30:46 +01:00
|
|
|
--- A table with all active notifications.
|
|
|
|
--
|
|
|
|
-- Please note that this list is kept up-to-date even in suspended mode.
|
|
|
|
--
|
|
|
|
-- **Signal:**
|
|
|
|
--
|
|
|
|
-- * property::active
|
|
|
|
--
|
|
|
|
-- @property active
|
|
|
|
-- @param table
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits false false
|
2019-03-07 05:30:46 +01:00
|
|
|
|
2019-03-08 20:39:38 +01:00
|
|
|
--- True when there is a handler connected to `request::display`.
|
|
|
|
-- @property has_display_handler
|
|
|
|
-- @param boolean
|
|
|
|
|
2019-07-11 06:45:55 +02:00
|
|
|
--- If the timeout needs to be reset when a property changes.
|
|
|
|
--
|
|
|
|
-- This is the global variant of the `naughty.notification` `auto_reset_timeout`
|
|
|
|
-- property.
|
|
|
|
--
|
|
|
|
-- @property auto_reset_timeout
|
|
|
|
-- @tparam[opt=true] boolean auto_reset_timeout
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-11 06:45:55 +02:00
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
--- Enable or disable naughty ability to claim to support animations.
|
|
|
|
--
|
|
|
|
-- When this is true, applications which query `naughty` feature support
|
|
|
|
-- will see that animations are supported. Note that there is *very little*
|
2019-09-23 18:39:12 +02:00
|
|
|
-- support for this and enabling it will cause bugs.
|
2019-07-14 06:03:12 +02:00
|
|
|
--
|
|
|
|
-- @property image_animations_enabled
|
|
|
|
-- @param[opt=false] boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
|
|
|
--- Enable or disable the persistent notifications.
|
|
|
|
--
|
|
|
|
-- This is very annoying when using `naughty.layout.box` popups, but tolerable
|
|
|
|
-- when using `naughty.list.notifications`.
|
|
|
|
--
|
|
|
|
-- Note that enabling this **does nothing** in `naughty` itself. The timeouts
|
|
|
|
-- are still honored and notifications still destroyed. It is the user
|
|
|
|
-- responsibility to disable the dismiss timer. However, this tells the
|
|
|
|
-- applications that notification persistence is supported so they might
|
|
|
|
-- stop using systray icons for the sake of displaying or other changes like
|
|
|
|
-- that.
|
|
|
|
--
|
|
|
|
-- @property persistence_enabled
|
|
|
|
-- @param[opt=false] boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
local properties = {
|
2019-07-14 06:03:12 +02:00
|
|
|
suspended = false,
|
|
|
|
expiration_paused = false,
|
|
|
|
auto_reset_timeout = true,
|
|
|
|
image_animations_enabled = false,
|
|
|
|
persistence_enabled = false,
|
2019-01-03 07:52:13 +01:00
|
|
|
}
|
2010-02-16 17:54:45 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--TODO v5 Deprecate the public `naughty.notifications` (to make it private)
|
|
|
|
|
2014-05-20 23:39:31 +02:00
|
|
|
--- Index of notifications per screen and position.
|
2014-05-26 21:43:39 +02:00
|
|
|
-- See config table for valid 'position' values.
|
|
|
|
-- Each element is a table consisting of:
|
|
|
|
--
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @field box Wibox object containing the popup
|
2008-11-15 17:55:38 +01:00
|
|
|
-- @field height Popup height
|
2008-11-19 03:16:44 +01:00
|
|
|
-- @field width Popup width
|
2008-11-15 17:55:38 +01:00
|
|
|
-- @field die Function to be executed on timeout
|
2008-11-22 15:46:51 +01:00
|
|
|
-- @field id Unique notification id based on a counter
|
2014-05-20 23:39:31 +02:00
|
|
|
-- @table notifications
|
2019-01-03 07:52:13 +01:00
|
|
|
naughty.notifications = { suspended = { }, _expired = {{}} }
|
2019-03-07 05:30:46 +01:00
|
|
|
|
|
|
|
naughty._active = {}
|
|
|
|
|
2021-09-20 07:21:38 +02:00
|
|
|
local function get_screen(s)
|
|
|
|
return s and capi.screen[s]
|
|
|
|
end
|
|
|
|
|
2021-07-05 10:26:33 +02:00
|
|
|
local function init_screen(s)
|
|
|
|
if naughty.notifications[s] then return end
|
|
|
|
|
2016-03-26 18:36:04 +01:00
|
|
|
naughty.notifications[s] = {
|
2008-11-20 17:13:23 +01:00
|
|
|
top_left = {},
|
2015-02-21 23:37:30 +01:00
|
|
|
top_middle = {},
|
2008-11-20 17:13:23 +01:00
|
|
|
top_right = {},
|
|
|
|
bottom_left = {},
|
2015-02-21 23:37:30 +01:00
|
|
|
bottom_middle = {},
|
2008-11-20 17:13:23 +01:00
|
|
|
bottom_right = {},
|
2019-06-08 22:10:14 +02:00
|
|
|
middle = {},
|
2008-11-20 17:13:23 +01:00
|
|
|
}
|
2021-07-05 10:26:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
screen.connect_for_each_screen(init_screen)
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2016-05-05 16:46:40 +02:00
|
|
|
capi.screen.connect_signal("removed", function(scr)
|
2020-02-10 08:51:06 +01:00
|
|
|
-- Allow the notifications to be moved to another screen.
|
|
|
|
|
|
|
|
for _, list in pairs(naughty.notifications[scr]) do
|
|
|
|
-- Clone the list to avoid having an iterator while mutating.
|
|
|
|
list = gtable.clone(list, false)
|
|
|
|
|
|
|
|
for _, n in ipairs(list) do
|
|
|
|
naughty.emit_signal("request::screen", n, "removed", {})
|
|
|
|
end
|
|
|
|
end
|
2021-09-20 07:21:38 +02:00
|
|
|
|
|
|
|
for _, n in ipairs(naughty._active) do
|
|
|
|
if n._private.args and get_screen(n._private.args.screen) == scr then
|
|
|
|
n._private.args.screen = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-05 16:46:40 +02:00
|
|
|
-- Destroy all notifications on this screen
|
2017-06-29 00:11:07 +02:00
|
|
|
naughty.destroy_all_notifications({scr})
|
2016-05-05 16:46:40 +02:00
|
|
|
naughty.notifications[scr] = nil
|
|
|
|
end)
|
|
|
|
|
2019-07-09 07:29:33 +02:00
|
|
|
local function remove_from_index(n)
|
|
|
|
for _, positions in pairs(naughty.notifications) do
|
|
|
|
for _, ns in pairs(positions) do
|
|
|
|
for k, n2 in ipairs(ns) do
|
|
|
|
if n2 == n then
|
2020-02-09 10:00:36 +01:00
|
|
|
assert(ns[k+1] ~= n, "The notification index is corrupted")
|
2019-07-09 07:29:33 +02:00
|
|
|
table.remove(ns, k)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- When id or screen are set after the object is created, update the indexing.
|
|
|
|
local function update_index(n)
|
2020-02-09 10:00:36 +01:00
|
|
|
-- Do things in the right order.
|
|
|
|
if not n._private.registered then return end
|
|
|
|
|
|
|
|
assert(not n._private.is_destroyed, "The notification index is corrupted")
|
|
|
|
|
2019-07-09 07:29:33 +02:00
|
|
|
-- Find the only index and remove it (there's an useless loop, but it's small).
|
|
|
|
remove_from_index(n)
|
|
|
|
|
|
|
|
-- Add to the index again
|
2019-07-15 06:55:34 +02:00
|
|
|
local s = get_screen(n.screen
|
|
|
|
or (n.preset and n.preset.screen)
|
|
|
|
or screen.focused())
|
2019-07-09 07:29:33 +02:00
|
|
|
naughty.notifications[s] = naughty.notifications[s] or {}
|
|
|
|
table.insert(naughty.notifications[s][n.position], n)
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Notification state.
|
|
|
|
--
|
|
|
|
-- This function is deprecated, use `naughty.suspended`.
|
|
|
|
--
|
|
|
|
-- @deprecated naughty.is_suspended
|
2015-05-13 05:36:05 +02:00
|
|
|
function naughty.is_suspended()
|
2017-07-02 04:43:26 +02:00
|
|
|
gdebug.deprecate("Use naughty.suspended", {deprecated_in=5})
|
2019-01-03 07:52:13 +01:00
|
|
|
return properties.suspended
|
2015-05-13 05:36:05 +02:00
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Suspend notifications.
|
|
|
|
--
|
|
|
|
-- This function is deprecated, use `naughty.suspended = true`.
|
|
|
|
--
|
|
|
|
-- @deprecated naughty.suspend
|
2012-06-12 03:48:41 +02:00
|
|
|
function naughty.suspend()
|
2017-07-02 04:43:26 +02:00
|
|
|
gdebug.deprecate("Use naughty.suspended = true", {deprecated_in=5})
|
2019-01-03 07:52:13 +01:00
|
|
|
properties.suspended = true
|
2010-02-16 17:54:45 +01:00
|
|
|
end
|
|
|
|
|
2020-03-15 09:10:08 +01:00
|
|
|
local conns = gobject._setup_class_signals(
|
|
|
|
naughty, {allow_chain_of_responsibility=true}
|
|
|
|
)
|
2017-07-16 04:54:41 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
local function resume()
|
2019-01-03 07:52:13 +01:00
|
|
|
properties.suspended = false
|
2021-09-20 06:52:47 +02:00
|
|
|
for _, v in ipairs(naughty.notifications.suspended) do
|
2019-01-03 07:52:13 +01:00
|
|
|
local args = v._private.args
|
|
|
|
assert(args)
|
|
|
|
v._private.args = nil
|
|
|
|
|
2021-09-20 06:52:47 +02:00
|
|
|
v:emit_signal("property::suspended", false)
|
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
naughty.emit_signal("added", v, args)
|
2020-02-16 08:22:34 +01:00
|
|
|
naughty.emit_signal("request::display", v, "resume", args)
|
2010-02-16 17:54:45 +01:00
|
|
|
if v.timer then v.timer:start() end
|
2021-09-20 06:52:47 +02:00
|
|
|
|
|
|
|
if not v._private.args then
|
|
|
|
v._private.args = args
|
|
|
|
end
|
2010-02-16 17:54:45 +01:00
|
|
|
end
|
2012-12-15 20:58:18 +01:00
|
|
|
naughty.notifications.suspended = { }
|
2010-02-16 17:54:45 +01:00
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Resume notifications.
|
|
|
|
--
|
|
|
|
-- This function is deprecated, use `naughty.suspended = false`.
|
|
|
|
--
|
|
|
|
-- @deprecated naughty.resume
|
|
|
|
function naughty.resume()
|
|
|
|
gdebug.deprecate("Use naughty.suspended = false", {deprecated_in=5})
|
|
|
|
resume()
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle notification state.
|
|
|
|
--
|
|
|
|
-- This function is deprecated, use `naughty.suspended = not naughty.suspended`.
|
|
|
|
--
|
|
|
|
-- @deprecated naughty.toggle
|
2012-06-12 03:48:41 +02:00
|
|
|
function naughty.toggle()
|
2017-07-02 04:43:26 +02:00
|
|
|
gdebug.deprecate("Use naughty.suspended = not naughty.suspended", {deprecated_in=5})
|
2019-01-03 07:52:13 +01:00
|
|
|
if properties.suspended then
|
2012-06-12 03:48:41 +02:00
|
|
|
naughty.resume()
|
2011-07-23 09:17:34 +02:00
|
|
|
else
|
2012-06-12 03:48:41 +02:00
|
|
|
naughty.suspend()
|
2011-07-23 09:17:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-16 20:16:17 +01:00
|
|
|
--- Destroy notification by notification object
|
2014-05-26 21:43:39 +02:00
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- This function is deprecated in favor of
|
|
|
|
-- `notification:destroy(reason, keep_visible)`.
|
|
|
|
--
|
2008-11-25 09:45:28 +01:00
|
|
|
-- @param notification Notification object to be destroyed
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @param reason One of the reasons from `notification_closed_reason`
|
2017-05-23 15:37:46 +02:00
|
|
|
-- @param[opt=false] keep_visible If true, keep the notification visible
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @return True if the popup was successfully destroyed, nil otherwise
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @deprecated naughty.destroy
|
2017-05-23 15:37:46 +02:00
|
|
|
function naughty.destroy(notification, reason, keep_visible)
|
2017-07-02 04:43:26 +02:00
|
|
|
gdebug.deprecate("Use notification:destroy(reason, keep_visible)", {deprecated_in=5})
|
2017-05-23 15:37:46 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
if not notification then return end
|
2017-05-23 15:37:46 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
return notification:destroy(reason, keep_visible)
|
2008-10-17 22:38:01 +02:00
|
|
|
end
|
|
|
|
|
2017-06-29 00:11:07 +02:00
|
|
|
--- Destroy all notifications on given screens.
|
|
|
|
--
|
|
|
|
-- @tparam table screens Table of screens on which notifications should be
|
|
|
|
-- destroyed. If nil, destroy notifications on all screens.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @tparam naughty.notification_closed_reason reason Reason for closing
|
2017-06-29 00:11:07 +02:00
|
|
|
-- notifications.
|
|
|
|
-- @treturn true|nil True if all notifications were successfully destroyed, nil
|
|
|
|
-- otherwise.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @see notification_closed_reason
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct naughty.destroy_all_notifications
|
2017-06-29 00:11:07 +02:00
|
|
|
function naughty.destroy_all_notifications(screens, reason)
|
|
|
|
if not screens then
|
|
|
|
screens = {}
|
|
|
|
for key, _ in pairs(naughty.notifications) do
|
|
|
|
table.insert(screens, key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local ret = true
|
|
|
|
for _, scr in pairs(screens) do
|
|
|
|
for _, list in pairs(naughty.notifications[scr]) do
|
|
|
|
while #list > 0 do
|
2020-02-09 10:00:36 +01:00
|
|
|
-- Better cause an error than risk an infinite loop.
|
|
|
|
assert(not list[1]._private.is_destroyed)
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
ret = ret and list[1]:destroy(reason)
|
2017-06-29 00:11:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Get notification by ID
|
2014-05-26 21:43:39 +02:00
|
|
|
--
|
2008-11-20 17:51:29 +01:00
|
|
|
-- @param id ID of the notification
|
|
|
|
-- @return notification object if it was found, nil otherwise
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @deprecated naughty.getById
|
2015-01-10 21:06:30 +01:00
|
|
|
function naughty.getById(id)
|
2017-07-02 04:43:26 +02:00
|
|
|
gdebug.deprecate("Use naughty.get_by_id", {deprecated_in=5})
|
|
|
|
return naughty.get_by_id(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Get notification by ID
|
|
|
|
--
|
|
|
|
-- @param id ID of the notification
|
|
|
|
-- @return notification object if it was found, nil otherwise
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct naughty.get_by_id
|
2017-07-02 04:43:26 +02:00
|
|
|
function naughty.get_by_id(id)
|
2008-11-20 17:51:29 +01:00
|
|
|
-- iterate the notifications to get the notfications with the correct ID
|
2021-10-05 21:55:01 +02:00
|
|
|
for s in capi.screen do
|
|
|
|
for p in pairs(naughty.notifications[s] or {}) do
|
2016-02-07 14:19:42 +01:00
|
|
|
for _, notification in pairs(naughty.notifications[s][p]) do
|
2008-11-20 17:51:29 +01:00
|
|
|
if notification.id == id then
|
|
|
|
return notification
|
2019-03-07 05:30:46 +01:00
|
|
|
end
|
2008-11-20 17:51:29 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-07 05:30:46 +01:00
|
|
|
-- Use an explicit getter to make it read only.
|
|
|
|
function naughty.get_active()
|
|
|
|
return naughty._active
|
|
|
|
end
|
|
|
|
|
2019-03-08 20:39:38 +01:00
|
|
|
function naughty.get_has_display_handler()
|
|
|
|
return conns["request::display"] and #conns["request::display"] > 0 or false
|
|
|
|
end
|
|
|
|
|
2019-07-15 06:55:34 +02:00
|
|
|
-- Presets are "deprecated" when notification rules are used.
|
|
|
|
function naughty.get__has_preset_handler()
|
|
|
|
return conns["request::preset"] and #conns["request::preset"] > 0 or false
|
|
|
|
end
|
|
|
|
|
2019-12-16 06:05:21 +01:00
|
|
|
function naughty._reset_display_handlers()
|
|
|
|
conns["request::display"] = nil
|
|
|
|
end
|
|
|
|
|
2015-02-27 21:45:03 +01:00
|
|
|
--- Set new notification timeout.
|
2017-07-02 04:43:26 +02:00
|
|
|
--
|
|
|
|
-- This function is deprecated, use `notification:reset_timeout(new_timeout)`.
|
|
|
|
--
|
2015-02-27 21:45:03 +01:00
|
|
|
-- @tparam notification notification Notification object, which timer is to be reset.
|
|
|
|
-- @tparam number new_timeout Time in seconds after which notification disappears.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @deprecated naughty.reset_timeout
|
2015-02-27 21:45:03 +01:00
|
|
|
function naughty.reset_timeout(notification, new_timeout)
|
2017-07-02 04:43:26 +02:00
|
|
|
gdebug.deprecate("Use notification:reset_timeout(new_timeout)", {deprecated_in=5})
|
2015-02-27 21:45:03 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
if not notification then return end
|
2015-02-27 21:45:03 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
notification:reset_timeout(new_timeout)
|
2015-02-27 21:45:03 +01:00
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Replace title and text of an existing notification.
|
|
|
|
--
|
2019-01-04 10:39:07 +01:00
|
|
|
-- This function is deprecated, use `notification.message = new_text` and
|
2017-07-02 04:43:26 +02:00
|
|
|
-- `notification.title = new_title`
|
|
|
|
--
|
|
|
|
-- @tparam notification notification Notification object, which contents are to be replaced.
|
|
|
|
-- @tparam string new_title New title of notification. If not specified, old title remains unchanged.
|
|
|
|
-- @tparam string new_text New text of notification. If not specified, old text remains unchanged.
|
2015-02-27 21:45:03 +01:00
|
|
|
-- @return None.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @deprecated naughty.replace_text
|
|
|
|
function naughty.replace_text(notification, new_title, new_text)
|
|
|
|
gdebug.deprecate(
|
|
|
|
"Use notification.text = new_text; notification.title = new_title",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
2015-02-27 21:45:03 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
if not notification then return end
|
2015-02-27 21:45:03 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
notification.title = new_title or notification.title
|
|
|
|
notification.text = new_text or notification.text
|
|
|
|
end
|
2015-02-27 21:45:03 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Remove the notification from the internal list(s)
|
|
|
|
local function cleanup(self, reason)
|
2019-03-02 18:59:24 +01:00
|
|
|
assert(reason, "Use n:destroy() instead of emitting the signal directly")
|
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
if properties.suspended then
|
2021-09-20 06:52:47 +02:00
|
|
|
for k, v in ipairs(naughty.notifications.suspended) do
|
2017-07-02 04:43:26 +02:00
|
|
|
if v == self then
|
2019-01-03 07:52:13 +01:00
|
|
|
table.remove(naughty.notifications.suspended, k)
|
2017-07-02 04:43:26 +02:00
|
|
|
break
|
2015-02-27 21:45:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-02 04:43:26 +02:00
|
|
|
local scr = self.screen
|
2017-05-07 18:01:35 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
assert(naughty.notifications[scr][self.position][self.idx] == self)
|
2019-07-09 07:29:33 +02:00
|
|
|
remove_from_index(self)
|
2017-05-07 18:01:35 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Update all indices
|
|
|
|
for k, n in ipairs(naughty.notifications[scr][self.position]) do
|
|
|
|
n.idx = k
|
2017-05-07 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
2019-03-07 05:30:46 +01:00
|
|
|
-- Remove from the global active list.
|
|
|
|
for k, n in ipairs(naughty._active) do
|
|
|
|
if n == self then
|
|
|
|
table.remove(naughty._active, k)
|
|
|
|
naughty.emit_signal("property::active")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
-- `self.timer.started` will be false if the expiration was paused.
|
|
|
|
if self.timer and self.timer.started then
|
2017-07-02 04:43:26 +02:00
|
|
|
self.timer:stop()
|
2017-05-07 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
if self.destroy_cb and reason ~= naughty.notification_closed_reason.silent then
|
|
|
|
self.destroy_cb(reason or naughty.notification_closed_reason.undefined)
|
2017-05-07 18:01:35 +02:00
|
|
|
end
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
2017-05-07 18:01:35 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
naughty.connect_signal("destroyed", cleanup)
|
2017-05-07 18:01:35 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Proxy the global suspension state on all notification objects
|
|
|
|
local function get_suspended(self)
|
2019-01-03 07:52:13 +01:00
|
|
|
return properties.suspended and not self.ignore_suspend
|
|
|
|
end
|
|
|
|
|
2021-09-20 06:52:47 +02:00
|
|
|
function naughty.set_suspended(value)
|
|
|
|
if properties["suspended"] == value then return end
|
|
|
|
|
|
|
|
properties["suspended"] = value
|
|
|
|
|
|
|
|
if value then
|
|
|
|
for _, n in pairs(naughty._active) do
|
2021-10-14 22:58:11 +02:00
|
|
|
if not n.ignore_suspend then
|
|
|
|
if n.timer and n.timer.started then
|
|
|
|
n.timer:stop()
|
|
|
|
end
|
2021-09-20 06:52:47 +02:00
|
|
|
|
2021-10-14 22:58:11 +02:00
|
|
|
n:emit_signal("property::suspended", true)
|
|
|
|
table.insert(naughty.notifications.suspended, n)
|
|
|
|
end
|
2021-09-20 06:52:47 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
resume()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
function naughty.set_expiration_paused(p)
|
|
|
|
properties.expiration_paused = p
|
|
|
|
|
|
|
|
if not p then
|
|
|
|
for _, n in ipairs(naughty.notifications._expired[1]) do
|
|
|
|
n:destroy(naughty.notification_closed_reason.expired)
|
|
|
|
end
|
|
|
|
end
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
2020-02-10 08:51:06 +01:00
|
|
|
--- The default handler for `request::screen`.
|
|
|
|
--
|
|
|
|
-- It selects `awful.screen.focused()`.
|
|
|
|
--
|
|
|
|
-- @signalhandler naughty.default_screen_handler
|
|
|
|
|
|
|
|
function naughty.default_screen_handler(n)
|
|
|
|
if n.screen and n.screen.valid then return end
|
|
|
|
|
|
|
|
n.screen = screen.focused()
|
|
|
|
end
|
|
|
|
|
|
|
|
naughty.connect_signal("request::screen", naughty.default_screen_handler)
|
|
|
|
|
2019-04-28 22:08:31 +02:00
|
|
|
--- Emitted when an error occurred and requires attention.
|
|
|
|
-- @signal request::display_error
|
|
|
|
-- @tparam string message The error message.
|
|
|
|
-- @tparam boolean startup If the error occurred during the initial loading of
|
|
|
|
-- rc.lua (and thus caused the fallback to kick in).
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Emitted when a notification is created.
|
|
|
|
-- @signal added
|
|
|
|
-- @tparam naughty.notification notification The notification object
|
|
|
|
|
|
|
|
--- Emitted when a notification is destroyed.
|
|
|
|
-- @signal destroyed
|
|
|
|
-- @tparam naughty.notification notification The notification object
|
|
|
|
|
|
|
|
--- Emitted when a notification has to be displayed.
|
|
|
|
--
|
2019-03-08 20:39:38 +01:00
|
|
|
-- To add a handler, use:
|
2017-07-02 04:43:26 +02:00
|
|
|
--
|
|
|
|
-- naughty.connect_signal("request::display", function(notification, args)
|
|
|
|
-- -- do something
|
|
|
|
-- end)
|
|
|
|
--
|
|
|
|
-- @tparam table notification The `naughty.notification` object.
|
2020-02-16 08:22:34 +01:00
|
|
|
-- @tparam string context Why is the signal sent.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @tparam table args Any arguments passed to the `naughty.notify` function,
|
|
|
|
-- including, but not limited to, all `naughty.notification` properties.
|
|
|
|
-- @signal request::display
|
|
|
|
|
|
|
|
--- Emitted when a notification needs pre-display configuration.
|
|
|
|
--
|
|
|
|
-- @tparam table notification The `naughty.notification` object.
|
2020-02-16 08:22:34 +01:00
|
|
|
-- @tparam string context Why is the signal sent.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @tparam table args Any arguments passed to the `naughty.notify` function,
|
|
|
|
-- including, but not limited to, all `naughty.notification` properties.
|
|
|
|
-- @signal request::preset
|
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
--- Emitted when an action requires an icon it doesn't know.
|
|
|
|
--
|
|
|
|
-- The implementation should look in the icon theme for an action icon or
|
|
|
|
-- provide something natively.
|
|
|
|
--
|
|
|
|
-- If an icon is found, the handler must set the `icon` property on the `action`
|
|
|
|
-- object to a path or a `gears.surface`.
|
|
|
|
--
|
2020-03-15 01:21:35 +01:00
|
|
|
-- There is no implementation by default. To use the XDG-icon, the common
|
|
|
|
-- implementation will be:
|
|
|
|
--
|
|
|
|
-- naughty.connect_signal("request::action_icon", function(a, context, hints)
|
|
|
|
-- a.icon = menubar.utils.lookup_icon(hints.id)
|
|
|
|
-- end)
|
|
|
|
--
|
|
|
|
-- @signal request::action_icon
|
2019-07-14 06:03:12 +02:00
|
|
|
-- @tparam naughty.action action The action.
|
2020-03-15 01:21:35 +01:00
|
|
|
-- @tparam string context The context.
|
|
|
|
-- @tparam table hints
|
|
|
|
-- @tparam string args.id The action id. This will often by the (XDG) icon name.
|
2019-07-14 06:03:12 +02:00
|
|
|
|
2020-03-15 08:35:40 +01:00
|
|
|
--- Emitted when a notification icon could not be loaded.
|
|
|
|
--
|
|
|
|
-- When an icon is passed in some "encoded" formats, such as XDG icon names or
|
|
|
|
-- network URLs, AwesomeWM will not attempt to load it. If you wish to see the
|
|
|
|
-- icon displayed, you must provide an handler. It is highly recommended for
|
|
|
|
-- handler to only set `n.icon` when they *found* the icon. That way multiple
|
|
|
|
-- handlers can be attached for multiple protocols.
|
|
|
|
--
|
|
|
|
-- The `context` argument is the origin of the icon to decode. If an handler
|
|
|
|
-- only supports one if them, it should check the `context` and return if it
|
|
|
|
-- doesn't handle it. The currently valid contexts are:
|
|
|
|
--
|
|
|
|
-- * app_icon
|
|
|
|
-- * clients
|
2020-03-15 11:04:42 +01:00
|
|
|
-- * path
|
2020-03-15 08:35:40 +01:00
|
|
|
-- * image
|
|
|
|
-- * images
|
2020-03-16 08:15:10 +01:00
|
|
|
-- * dbus_clear
|
2020-03-15 08:35:40 +01:00
|
|
|
--
|
|
|
|
-- For example, an implementation which uses the `app_icon` to perform an XDG
|
|
|
|
-- icon lookup will look like:
|
|
|
|
--
|
|
|
|
-- naughty.connect_signal("request::icon", function(n, context, hints)
|
|
|
|
-- if context ~= "app_icon" then return end
|
|
|
|
--
|
|
|
|
-- local path = menubar.utils.lookup_icon(hints.app_icon) or
|
|
|
|
-- menubar.utils.lookup_icon(hints.app_icon:lower())
|
|
|
|
--
|
|
|
|
-- if path then
|
|
|
|
-- n.icon = path
|
|
|
|
-- end
|
|
|
|
-- end)
|
|
|
|
--
|
2020-03-15 11:04:42 +01:00
|
|
|
-- The `images` context has no handler. It is part of the specification to
|
|
|
|
-- handle animations. This is not supported by default.
|
|
|
|
--
|
2020-03-15 08:35:40 +01:00
|
|
|
-- @signal request::icon
|
|
|
|
-- @tparam notification n The notification.
|
|
|
|
-- @tparam string context The source of the icon to look for.
|
|
|
|
-- @tparam table hints The hints.
|
|
|
|
-- @tparam string hints.app_icon The name of the icon to look for.
|
2020-03-15 11:04:42 +01:00
|
|
|
-- @tparam string hints.path The path of the icon.
|
|
|
|
-- @tparam string hints.image The path or pixmap of the icon.
|
|
|
|
-- @see naughty.icon_path_handler
|
|
|
|
-- @see naughty.client_icon_handler
|
2020-03-15 08:35:40 +01:00
|
|
|
|
2020-02-09 10:00:36 +01:00
|
|
|
--- Emitted when the screen is not defined or being removed.
|
|
|
|
-- @signal request::screen
|
|
|
|
-- @tparam table notification The `naughty.notification` object. This is
|
|
|
|
-- currently either "new" or "removed".
|
|
|
|
-- @tparam string context Why is the signal sent.
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Register a new notification object.
|
|
|
|
local function register(notification, args)
|
2020-02-09 10:00:36 +01:00
|
|
|
assert(not notification._private.registered)
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Add the some more properties
|
|
|
|
rawset(notification, "get_suspended", get_suspended)
|
|
|
|
|
2019-12-16 01:55:37 +01:00
|
|
|
local s = get_screen(notification.screen or args.screen
|
2020-02-09 10:00:36 +01:00
|
|
|
or (notification.preset and notification.preset.screen))
|
|
|
|
|
|
|
|
if not s then
|
|
|
|
naughty.emit_signal("request::screen", notification, "new", {})
|
|
|
|
s = notification.screen
|
|
|
|
end
|
|
|
|
|
|
|
|
assert(s)
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2021-07-05 10:26:33 +02:00
|
|
|
if not naughty.notifications[s] then
|
|
|
|
init_screen(get_screen(s))
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- insert the notification to the table
|
2019-03-07 05:30:46 +01:00
|
|
|
table.insert(naughty._active, notification)
|
2017-07-02 04:43:26 +02:00
|
|
|
table.insert(naughty.notifications[s][notification.position], notification)
|
|
|
|
notification.idx = #naughty.notifications[s][notification.position]
|
|
|
|
notification.screen = s
|
|
|
|
|
2020-02-09 10:00:36 +01:00
|
|
|
notification._private.registered = true
|
|
|
|
|
2021-09-20 06:52:47 +02:00
|
|
|
notification._private.args = args
|
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
if properties.suspended and not args.ignore_suspend then
|
2017-07-02 04:43:26 +02:00
|
|
|
table.insert(naughty.notifications.suspended, notification)
|
2019-01-03 07:52:13 +01:00
|
|
|
else
|
|
|
|
naughty.emit_signal("added", notification, args)
|
2017-05-07 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
2019-07-15 06:55:34 +02:00
|
|
|
assert(rawget(notification, "preset") or naughty._has_preset_handler)
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-03-07 05:30:46 +01:00
|
|
|
naughty.emit_signal("property::active")
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- return the notification
|
|
|
|
return notification
|
2017-05-07 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
naughty.connect_signal("new", register)
|
2015-02-27 21:45:03 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
local function index_miss(_, key)
|
2019-01-03 07:52:13 +01:00
|
|
|
if rawget(naughty, "get_"..key) then
|
|
|
|
return rawget(naughty, "get_"..key)()
|
|
|
|
elseif properties[key] ~= nil then
|
|
|
|
return properties[key]
|
2017-07-02 04:43:26 +02:00
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
2015-02-27 21:45:03 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
local function set_index_miss(_, key, value)
|
2019-01-03 07:52:13 +01:00
|
|
|
if rawget(naughty, "set_"..key) then
|
|
|
|
return rawget(naughty, "set_"..key)(value)
|
|
|
|
elseif properties[key] ~= nil then
|
2017-07-02 04:43:26 +02:00
|
|
|
assert(type(value) == "boolean")
|
2019-01-03 07:52:13 +01:00
|
|
|
properties[key] = value
|
2019-07-14 06:03:12 +02:00
|
|
|
|
2020-01-13 08:32:28 +01:00
|
|
|
naughty.emit_signal("property::"..key, value)
|
2017-07-02 04:43:26 +02:00
|
|
|
else
|
|
|
|
rawset(naughty, key, value)
|
|
|
|
end
|
2015-02-27 21:45:03 +01:00
|
|
|
end
|
|
|
|
|
2014-05-26 21:43:39 +02:00
|
|
|
--- Create a notification.
|
2014-05-25 14:25:01 +02:00
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- This function is deprecated, create notification objects instead:
|
|
|
|
--
|
|
|
|
-- local notif = naughty.notification(args)
|
|
|
|
--
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam table args The argument table containing any of the arguments below.
|
2015-07-27 15:54:47 +02:00
|
|
|
-- @string[opt=""] args.text Text of the notification.
|
|
|
|
-- @string[opt] args.title Title of the notification.
|
|
|
|
-- @int[opt=5] args.timeout Time in seconds after which popup expires.
|
2014-05-25 14:25:01 +02:00
|
|
|
-- Set 0 for no timeout.
|
2015-07-27 15:54:47 +02:00
|
|
|
-- @int[opt] args.hover_timeout Delay in seconds after which hovered popup disappears.
|
2016-02-26 18:30:42 +01:00
|
|
|
-- @tparam[opt=focused] integer|screen args.screen Target screen for the notification.
|
2015-07-27 15:54:47 +02:00
|
|
|
-- @string[opt="top_right"] args.position Corner of the workarea displaying the popups.
|
|
|
|
-- Values: `"top_right"`, `"top_left"`, `"bottom_left"`,
|
2019-06-08 22:10:14 +02:00
|
|
|
-- `"bottom_right"`, `"top_middle"`, `"bottom_middle"`, `"middle"`.
|
2015-07-27 15:54:47 +02:00
|
|
|
-- @bool[opt=true] args.ontop Boolean forcing popups to display on top.
|
2016-10-06 21:22:32 +02:00
|
|
|
-- @int[opt=`beautiful.notification_height` or auto] args.height Popup height.
|
|
|
|
-- @int[opt=`beautiful.notification_width` or auto] args.width Popup width.
|
|
|
|
-- @string[opt=`beautiful.notification_font` or `beautiful.font` or `awesome.font`] args.font Notification font.
|
2015-07-27 15:54:47 +02:00
|
|
|
-- @string[opt] args.icon Path to icon.
|
|
|
|
-- @int[opt] args.icon_size Desired icon size in px.
|
2016-10-06 21:22:32 +02:00
|
|
|
-- @string[opt=`beautiful.notification_fg` or `beautiful.fg_focus` or `'#ffffff'`] args.fg Foreground color.
|
|
|
|
-- @string[opt=`beautiful.notification_fg` or `beautiful.bg_focus` or `'#535d6c'`] args.bg Background color.
|
|
|
|
-- @int[opt=`beautiful.notification_border_width` or 1] args.border_width Border width.
|
2019-11-11 02:47:43 +01:00
|
|
|
-- @string[opt=`beautiful.notification_border_color` or `beautiful.border_color_active` or `'#535d6c'`] args.border_color Border color.
|
2016-10-06 21:22:32 +02:00
|
|
|
-- @tparam[opt=`beautiful.notification_shape`] gears.shape args.shape Widget shape.
|
|
|
|
-- @tparam[opt=`beautiful.notification_opacity`] gears.opacity args.opacity Widget opacity.
|
|
|
|
-- @tparam[opt=`beautiful.notification_margin`] gears.margin args.margin Widget margin.
|
2015-09-23 10:37:02 +02:00
|
|
|
-- @tparam[opt] func args.run Function to run on left click. The notification
|
|
|
|
-- object will be passed to it as an argument.
|
|
|
|
-- You need to call e.g.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- `notification.die(naughty.notification_closed_reason.dismissedByUser)` from
|
2015-09-23 10:37:02 +02:00
|
|
|
-- there to dismiss the notification yourself.
|
2015-07-27 15:54:47 +02:00
|
|
|
-- @tparam[opt] func args.destroy Function to run when notification is destroyed.
|
|
|
|
-- @tparam[opt] table args.preset Table with any of the above parameters.
|
|
|
|
-- Note: Any parameters specified directly in args will override ones defined
|
|
|
|
-- in the preset.
|
|
|
|
-- @tparam[opt] int args.replaces_id Replace the notification with the given ID.
|
|
|
|
-- @tparam[opt] func args.callback Function that will be called with all arguments.
|
|
|
|
-- The notification will only be displayed if the function returns true.
|
|
|
|
-- Note: this function is only relevant to notifications sent via dbus.
|
2019-01-04 08:52:02 +01:00
|
|
|
-- @tparam[opt] table args.actions A list of `naughty.action`s.
|
2017-04-20 22:31:17 +02:00
|
|
|
-- @bool[opt=false] args.ignore_suspend If set to true this notification
|
|
|
|
-- will be shown even if notifications are suspended via `naughty.suspend`.
|
2019-01-04 10:39:07 +01:00
|
|
|
-- @usage naughty.notify({ title = "Achtung!", message = "You're idling", timeout = 0 })
|
2016-04-05 00:31:45 +02:00
|
|
|
-- @treturn ?table The notification object, or nil in case a notification was
|
|
|
|
-- not displayed.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @deprecated naughty.notify
|
2013-03-10 10:57:49 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
local nnotif = nil
|
2014-12-31 14:28:46 +01:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
function naughty.notify(args)
|
|
|
|
gdebug.deprecate(
|
|
|
|
"Use local notif = naughty.notification(args)",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--TODO v6 remove this hack
|
|
|
|
nnotif = nnotif or require("naughty.notification")
|
2010-02-16 17:54:45 +01:00
|
|
|
|
2019-03-02 18:53:25 +01:00
|
|
|
-- The existing notification object, if any.
|
|
|
|
local n = args and args.replaces_id and
|
|
|
|
naughty.get_by_id(args.replaces_id) or nil
|
|
|
|
|
|
|
|
-- It was possible to update the notification content using `replaces_id`.
|
|
|
|
-- This is a concept that come from the dbus API and leaked into the public
|
|
|
|
-- API. It has all kind of issues and brokenness, but it being used.
|
|
|
|
if n then
|
|
|
|
return gtable.crush(n, args)
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
return nnotif(args)
|
2008-11-25 09:45:28 +01:00
|
|
|
end
|
2008-11-20 17:51:29 +01:00
|
|
|
|
2020-03-15 11:04:42 +01:00
|
|
|
--- Request handler to get the icon using the clients icons.
|
|
|
|
-- @signalhandler naughty.client_icon_handler
|
|
|
|
function naughty.client_icon_handler(self, context)
|
|
|
|
if context ~= "clients" then return end
|
|
|
|
|
|
|
|
local clients = self:get_clients()
|
|
|
|
|
|
|
|
for _, t in ipairs { "normal", "dialog" } do
|
|
|
|
for _, c in ipairs(clients) do
|
|
|
|
if c.type == t then
|
|
|
|
self._private.icon = gsurface(c.icon) --TODO support other size
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Request handler to get the icon using the image or path.
|
|
|
|
-- @signalhandler naughty.icon_path_handler
|
|
|
|
function naughty.icon_path_handler(self, context, hints)
|
|
|
|
if context ~= "image" and context ~= "path" then return end
|
|
|
|
|
|
|
|
self._private.icon = gsurface.load_uncached_silently(
|
|
|
|
hints.path or hints.image
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-03-16 08:15:10 +01:00
|
|
|
--- Request handler for clearing the icon when asked by ie, DBus.
|
|
|
|
-- @signalhandler naughty.icon_clear_handler
|
|
|
|
function naughty.icon_clear_handler(self, context, hints) --luacheck: no unused args
|
|
|
|
if context ~= "dbus_clear" then return end
|
|
|
|
|
|
|
|
self._private.icon = nil
|
|
|
|
self:emit_signal("property::icon")
|
|
|
|
end
|
|
|
|
|
2019-07-09 07:29:33 +02:00
|
|
|
naughty.connect_signal("property::screen" , update_index)
|
|
|
|
naughty.connect_signal("property::position", update_index)
|
|
|
|
|
2020-03-15 11:04:42 +01:00
|
|
|
naughty.connect_signal("request::icon", naughty.client_icon_handler)
|
|
|
|
naughty.connect_signal("request::icon", naughty.icon_path_handler )
|
2020-03-16 08:15:10 +01:00
|
|
|
naughty.connect_signal("request::icon", naughty.icon_clear_handler )
|
2020-03-15 11:04:42 +01:00
|
|
|
|
2019-08-18 07:50:43 +02:00
|
|
|
--@DOC_signals_COMMON@
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
return setmetatable(naughty, {__index = index_miss, __newindex = set_index_miss})
|
2012-06-12 03:48:41 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|