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")
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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*
|
|
|
|
-- support for this and enabled it will cause bugs.
|
|
|
|
--
|
|
|
|
-- @property image_animations_enabled
|
|
|
|
-- @param[opt=false] boolean
|
|
|
|
|
|
|
|
--- 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
|
|
|
|
|
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 = {}
|
|
|
|
|
2016-04-05 06:01:31 +02:00
|
|
|
screen.connect_for_each_screen(function(s)
|
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
|
|
|
}
|
2016-03-26 18:36:04 +01:00
|
|
|
end)
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2016-05-05 16:46:40 +02:00
|
|
|
capi.screen.connect_signal("removed", function(scr)
|
|
|
|
-- 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 get_screen(s)
|
|
|
|
return s and capi.screen[s]
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
-- 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
|
|
|
|
local s = get_screen(n.screen or n.preset.screen or screen.focused())
|
|
|
|
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
|
|
|
|
|
2019-05-06 05:00:58 +02:00
|
|
|
local conns = gobject._setup_class_signals(naughty)
|
2017-07-16 04:54:41 +02:00
|
|
|
|
|
|
|
--- Connect a global signal on the notification engine.
|
|
|
|
--
|
|
|
|
-- Functions connected to this signal source will be executed when any
|
|
|
|
-- notification object emits the signal.
|
|
|
|
--
|
|
|
|
-- It is also used for some generic notification signals such as
|
|
|
|
-- `request::display`.
|
|
|
|
--
|
|
|
|
-- @tparam string name The name of the signal
|
|
|
|
-- @tparam function func The function to attach
|
2019-05-06 05:00:58 +02:00
|
|
|
-- @staticfct naughty.connect_signal
|
2017-07-16 04:54:41 +02:00
|
|
|
-- @usage naughty.connect_signal("added", function(notif)
|
|
|
|
-- -- do something
|
|
|
|
-- end)
|
|
|
|
|
|
|
|
--- Emit a notification signal.
|
|
|
|
-- @tparam string name The signal name.
|
|
|
|
-- @param ... The signal callback arguments
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct naughty.emit_signal
|
2017-07-16 04:54:41 +02:00
|
|
|
|
|
|
|
--- Disconnect a signal from a source.
|
|
|
|
-- @tparam string name The name of the signal
|
|
|
|
-- @tparam function func The attached function
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct naughty.disconnect_signal
|
2019-05-06 05:00:58 +02:00
|
|
|
-- @treturn boolean If the disconnection was successful
|
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
|
2016-02-07 14:19:42 +01:00
|
|
|
for _, v in pairs(naughty.notifications.suspended) do
|
2019-01-03 07:52:13 +01:00
|
|
|
local args = v._private.args
|
|
|
|
assert(args)
|
|
|
|
v._private.args = nil
|
|
|
|
|
|
|
|
naughty.emit_signal("added", v, args)
|
|
|
|
naughty.emit_signal("request::display", v, args)
|
2010-02-16 17:54:45 +01:00
|
|
|
if v.timer then v.timer:start() end
|
|
|
|
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
|
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
|
2016-03-06 13:31:30 +01:00
|
|
|
for s in pairs(naughty.notifications) do
|
2016-02-07 14:19:42 +01:00
|
|
|
for p in pairs(naughty.notifications[s]) do
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
for k, v in pairs(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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
-- @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.
|
|
|
|
-- @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`.
|
|
|
|
--
|
|
|
|
-- @signal request::icon
|
|
|
|
-- @tparam naughty.action action The action.
|
|
|
|
-- @tparam string icon_name The icon name.
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Register a new notification object.
|
|
|
|
local function register(notification, args)
|
|
|
|
-- Add the some more properties
|
|
|
|
rawset(notification, "get_suspended", get_suspended)
|
|
|
|
|
|
|
|
--TODO v5 uncouple the notifications and the screen
|
|
|
|
local s = get_screen(args.screen or notification.preset.screen or screen.focused())
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
if properties.suspended and not args.ignore_suspend then
|
|
|
|
notification._private.args = args
|
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
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
assert(rawget(notification, "preset"))
|
|
|
|
|
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
|
|
|
|
if not value then
|
2017-07-02 04:43:26 +02:00
|
|
|
resume()
|
|
|
|
end
|
2019-07-14 06:03:12 +02:00
|
|
|
|
|
|
|
naughty.emit_signal("property::"..key)
|
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)
|
|
|
|
--
|
2014-05-26 21:43:39 +02:00
|
|
|
-- @tab 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.
|
|
|
|
-- @string[opt=`beautiful.notification_border_color` or `beautiful.border_focus` or `'#535d6c'`] args.border_color Border color.
|
|
|
|
-- @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
|
|
|
|
2019-07-09 07:29:33 +02:00
|
|
|
naughty.connect_signal("property::screen" , update_index)
|
|
|
|
naughty.connect_signal("property::position", update_index)
|
|
|
|
|
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
|