2017-07-02 04:43:26 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--- A notification object.
|
|
|
|
--
|
|
|
|
-- This class creates individual notification objects that can be manipulated
|
|
|
|
-- to extend the default behavior.
|
|
|
|
--
|
|
|
|
-- This class doesn't define the actual widget, but is rather intended as a data
|
|
|
|
-- object to hold the properties. All examples assume the default widgets, but
|
|
|
|
-- the whole implementation can be replaced.
|
|
|
|
--
|
|
|
|
--@DOC_naughty_actions_EXAMPLE@
|
|
|
|
--
|
|
|
|
-- @author Emmanuel Lepage Vallee
|
|
|
|
-- @copyright 2008 koniu
|
|
|
|
-- @copyright 2017 Emmanuel Lepage Vallee
|
2019-06-06 08:40:00 +02:00
|
|
|
-- @coreclassmod naughty.notification
|
2017-07-02 04:43:26 +02:00
|
|
|
---------------------------------------------------------------------------
|
2020-02-10 07:51:29 +01:00
|
|
|
local capi = { screen = screen }
|
2019-07-14 06:03:12 +02:00
|
|
|
local gobject = require("gears.object")
|
|
|
|
local gtable = require("gears.table")
|
|
|
|
local gsurface = require("gears.surface")
|
|
|
|
local timer = require("gears.timer")
|
|
|
|
local cst = require("naughty.constants")
|
|
|
|
local naughty = require("naughty.core")
|
|
|
|
local gdebug = require("gears.debug")
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
local notification = {}
|
|
|
|
|
|
|
|
--- Notifications font.
|
|
|
|
-- @beautiful beautiful.notification_font
|
|
|
|
-- @tparam string|lgi.Pango.FontDescription notification_font
|
|
|
|
|
|
|
|
--- Notifications background color.
|
|
|
|
-- @beautiful beautiful.notification_bg
|
|
|
|
-- @tparam color notification_bg
|
|
|
|
|
|
|
|
--- Notifications foreground color.
|
|
|
|
-- @beautiful beautiful.notification_fg
|
|
|
|
-- @tparam color notification_fg
|
|
|
|
|
|
|
|
--- Notifications border width.
|
|
|
|
-- @beautiful beautiful.notification_border_width
|
|
|
|
-- @tparam int notification_border_width
|
|
|
|
|
|
|
|
--- Notifications border color.
|
|
|
|
-- @beautiful beautiful.notification_border_color
|
|
|
|
-- @tparam color notification_border_color
|
|
|
|
|
|
|
|
--- Notifications shape.
|
|
|
|
-- @beautiful beautiful.notification_shape
|
|
|
|
-- @tparam[opt] gears.shape notification_shape
|
|
|
|
-- @see gears.shape
|
|
|
|
|
|
|
|
--- Notifications opacity.
|
|
|
|
-- @beautiful beautiful.notification_opacity
|
|
|
|
-- @tparam[opt] int notification_opacity
|
|
|
|
|
2019-03-12 19:30:15 +01:00
|
|
|
--- The margins inside of the notification widget (or popup).
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @beautiful beautiful.notification_margin
|
|
|
|
-- @tparam int notification_margin
|
|
|
|
|
|
|
|
--- Notifications width.
|
|
|
|
-- @beautiful beautiful.notification_width
|
|
|
|
-- @tparam int notification_width
|
|
|
|
|
|
|
|
--- Notifications height.
|
|
|
|
-- @beautiful beautiful.notification_height
|
|
|
|
-- @tparam int notification_height
|
|
|
|
|
2019-03-12 19:30:15 +01:00
|
|
|
--- The spacing between the notifications.
|
|
|
|
-- @beautiful beautiful.notification_spacing
|
|
|
|
-- @param[opt=2] number
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2019-02-17 18:36:02 +01:00
|
|
|
-- Unique identifier of the notification.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- This is the equivalent to a PID as allows external applications to select
|
|
|
|
-- notifications.
|
2019-02-17 18:36:02 +01:00
|
|
|
-- @property id
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @tparam number id
|
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-03-12 19:30:15 +01:00
|
|
|
--- Text of the notification.
|
|
|
|
--
|
|
|
|
-- This exists only for the pre-AwesomeWM v4.4 new notification implementation.
|
|
|
|
-- Please always use `title`.
|
|
|
|
--
|
|
|
|
-- @deprecatedproperty text
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @param string
|
|
|
|
-- @see title
|
|
|
|
|
|
|
|
--- Title of the notification.
|
|
|
|
--@DOC_naughty_helloworld_EXAMPLE@
|
|
|
|
-- @property title
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @tparam string title
|
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Time in seconds after which popup expires.
|
|
|
|
-- Set 0 for no timeout.
|
|
|
|
-- @property timeout
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @tparam number timeout
|
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
--- The notification urgency level.
|
|
|
|
--
|
|
|
|
-- The default urgency levels are:
|
|
|
|
--
|
|
|
|
-- * low
|
|
|
|
-- * normal
|
|
|
|
-- * critical
|
|
|
|
--
|
|
|
|
-- @property urgency
|
|
|
|
-- @param string
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
|
|
|
--- The notification category.
|
|
|
|
--
|
|
|
|
-- The category should be named using the `x-vendor.class.name` naming scheme or
|
|
|
|
-- use one of the default categories:
|
|
|
|
--
|
|
|
|
-- <table class='widget_list' border=1>
|
|
|
|
-- <tr style='font-weight: bold;'>
|
|
|
|
-- <th align='center'>Name</th>
|
|
|
|
-- <th align='center'>Description</th>
|
|
|
|
-- </tr>
|
|
|
|
-- <tr><td><b>device</b></td><td>A generic device-related notification that
|
|
|
|
-- doesn't fit into any other category.</td></tr>
|
|
|
|
-- <tr><td><b>device.added</b></td><td>A device, such as a USB device, was added to the system.</td></tr>
|
|
|
|
-- <tr><td><b>device.error</b></td><td>A device had some kind of error.</td></tr>
|
|
|
|
-- <tr><td><b>device.removed</b></td><td>A device, such as a USB device, was removed from the system.</td></tr>
|
|
|
|
-- <tr><td><b>email</b></td><td>A generic e-mail-related notification that doesn't fit into
|
|
|
|
-- any other category.</td></tr>
|
|
|
|
-- <tr><td><b>email.arrived</b></td><td>A new e-mail notification.</td></tr>
|
|
|
|
-- <tr><td><b>email.bounced</b></td><td>A notification stating that an e-mail has bounced.</td></tr>
|
|
|
|
-- <tr><td><b>im</b></td><td>A generic instant message-related notification that doesn't fit into
|
|
|
|
-- any other category.</td></tr>
|
|
|
|
-- <tr><td><b>im.error</b></td><td>An instant message error notification.</td></tr>
|
|
|
|
-- <tr><td><b>im.received</b></td><td>A received instant message notification.</td></tr>
|
|
|
|
-- <tr><td><b>network</b></td><td>A generic network notification that doesn't fit into any other
|
|
|
|
-- category.</td></tr>
|
|
|
|
-- <tr><td><b>network.connected</b></td><td>A network connection notification, such as successful
|
|
|
|
-- sign-on to a network service. <br />
|
|
|
|
-- This should not be confused with device.added for new network devices.</td></tr>
|
|
|
|
-- <tr><td><b>network.disconnected</b></td><td>A network disconnected notification. This should not
|
|
|
|
-- be confused with <br />
|
|
|
|
-- device.removed for disconnected network devices.</td></tr>
|
|
|
|
-- <tr><td><b>network.error</b></td><td>A network-related or connection-related error.</td></tr>
|
|
|
|
-- <tr><td><b>presence</b></td><td>A generic presence change notification that doesn't fit into any
|
|
|
|
-- other category, <br />
|
|
|
|
-- such as going away or idle.</td></tr>
|
|
|
|
-- <tr><td><b>presence.offline</b></td><td>An offline presence change notification.</td></tr>
|
|
|
|
-- <tr><td><b>presence.online</b></td><td>An online presence change notification.</td></tr>
|
|
|
|
-- <tr><td><b>transfer</b></td><td>A generic file transfer or download notification that doesn't
|
|
|
|
-- fit into any other category.</td></tr>
|
|
|
|
-- <tr><td><b>transfer.complete</b></td><td>A file transfer or download complete notification.</td></tr>
|
|
|
|
-- <tr><td><b>transfer.error</b></td><td>A file transfer or download error.</td></tr>
|
|
|
|
-- </table>
|
|
|
|
--
|
|
|
|
-- @property category
|
|
|
|
-- @tparam string|nil category
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
|
|
|
--- True if the notification should be kept when an action is pressed.
|
|
|
|
--
|
|
|
|
-- By default, invoking an action will destroy the notification. Some actions,
|
|
|
|
-- like the "Snooze" action of alarm clock, will cause the notification to
|
|
|
|
-- be updated with a date further in the future.
|
|
|
|
--
|
|
|
|
-- @property resident
|
|
|
|
-- @param[opt=false] boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Delay in seconds after which hovered popup disappears.
|
|
|
|
-- @property hover_timeout
|
|
|
|
-- @param number
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Target screen for the notification.
|
|
|
|
-- @property screen
|
|
|
|
-- @param screen
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Corner of the workarea displaying the popups.
|
|
|
|
--
|
|
|
|
-- The possible values are:
|
|
|
|
--
|
|
|
|
-- * *top_right*
|
|
|
|
-- * *top_left*
|
|
|
|
-- * *bottom_left*
|
|
|
|
-- * *bottom_right*
|
|
|
|
-- * *top_middle*
|
|
|
|
-- * *bottom_middle*
|
2019-06-08 22:10:14 +02:00
|
|
|
-- * *middle*
|
2017-07-02 04:43:26 +02:00
|
|
|
--
|
2019-03-12 19:30:15 +01:00
|
|
|
--@DOC_awful_notification_box_corner_EXAMPLE@
|
2017-07-02 04:43:26 +02:00
|
|
|
--
|
|
|
|
-- @property position
|
|
|
|
-- @param string
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-03-12 19:30:15 +01:00
|
|
|
-- @see awful.placement.next_to
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Boolean forcing popups to display on top.
|
|
|
|
-- @property ontop
|
|
|
|
-- @param boolean
|
|
|
|
|
|
|
|
--- Popup height.
|
2019-03-12 19:30:15 +01:00
|
|
|
--
|
|
|
|
--@DOC_awful_notification_geometry_EXAMPLE@
|
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @property height
|
|
|
|
-- @param number
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-03-12 19:30:15 +01:00
|
|
|
-- @see width
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Popup width.
|
|
|
|
-- @property width
|
|
|
|
-- @param number
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-03-12 19:30:15 +01:00
|
|
|
-- @see height
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Notification font.
|
|
|
|
--@DOC_naughty_colors_EXAMPLE@
|
|
|
|
-- @property font
|
|
|
|
-- @param string
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
--- "All in one" way to access the default image or icon.
|
|
|
|
--
|
|
|
|
-- A notification can provide a combination of an icon, a static image, or if
|
|
|
|
-- enabled, a looping animation. Add to that the ability to import the icon
|
|
|
|
-- information from the client or from a `.desktop` file, there is multiple
|
|
|
|
-- conflicting sources of "icons".
|
|
|
|
--
|
|
|
|
-- On the other hand, the vast majority of notifications don't multiple or
|
|
|
|
-- ambiguous sources of icons. This property will pick the first of the
|
|
|
|
-- following.
|
|
|
|
--
|
|
|
|
-- * The `image`.
|
|
|
|
-- * The `app_icon`.
|
|
|
|
-- * The `icon` from a client with `normal` type.
|
|
|
|
-- * The `icon` of a client with `dialog` type.
|
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @property icon
|
|
|
|
-- @tparam string|surface icon
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
-- @see app_icon
|
|
|
|
-- @see image
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Desired icon size in px.
|
|
|
|
-- @property icon_size
|
|
|
|
-- @param number
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
--- The icon provided in the `app_icon` field of the DBus notification.
|
|
|
|
--
|
|
|
|
-- This should always be either the URI (path) to an icon or a valid XDG
|
|
|
|
-- icon name to be fetched from the theme.
|
|
|
|
--
|
|
|
|
-- @property app_icon
|
|
|
|
-- @param string
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
|
|
|
--- The notification image.
|
|
|
|
--
|
|
|
|
-- This is usually provided as a `gears.surface` object. The image is used
|
|
|
|
-- instead of the `app_icon` by notification assets which are auto-generated
|
|
|
|
-- or stored elsewhere than the filesystem (databases, web, Android phones, etc).
|
|
|
|
--
|
|
|
|
-- @property image
|
|
|
|
-- @tparam string|surface image
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
|
|
|
--- The notification (animated) images.
|
|
|
|
--
|
|
|
|
-- Note that calling this without first setting
|
|
|
|
-- `naughty.image_animations_enabled` to true will throw an exception.
|
|
|
|
--
|
|
|
|
-- Also note that there is *zero* support for this anywhere else in `naughty`
|
|
|
|
-- and very, very few applications support this.
|
|
|
|
--
|
|
|
|
-- @property images
|
|
|
|
-- @tparam nil|table images
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-14 06:03:12 +02:00
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Foreground color.
|
2019-03-12 19:30:15 +01:00
|
|
|
--
|
|
|
|
--@DOC_awful_notification_fg_EXAMPLE@
|
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @property fg
|
|
|
|
-- @tparam string|color|pattern fg
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @see title
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- Background color.
|
2019-03-12 19:30:15 +01:00
|
|
|
--
|
|
|
|
--@DOC_awful_notification_bg_EXAMPLE@
|
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @property bg
|
|
|
|
-- @tparam string|color|pattern bg
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @see title
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- Border width.
|
|
|
|
-- @property border_width
|
|
|
|
-- @param number
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Border color.
|
2019-03-12 19:30:15 +01:00
|
|
|
--
|
|
|
|
--@DOC_awful_notification_border_color_EXAMPLE@
|
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @property border_color
|
|
|
|
-- @param string
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- Widget shape.
|
2019-03-04 23:06:42 +01:00
|
|
|
--
|
|
|
|
-- Note that when using a custom `request::display` handler or `naughty.rules`,
|
|
|
|
-- choosing between multiple shapes depending on the content can be done using
|
|
|
|
-- expressions like:
|
|
|
|
--
|
|
|
|
-- -- The notification object is called `n`
|
|
|
|
-- shape = #n.actions > 0 and
|
|
|
|
-- gears.shape.rounded_rect or gears.shape.rounded_bar,
|
|
|
|
--
|
2019-03-12 19:30:15 +01:00
|
|
|
--@DOC_awful_notification_shape_EXAMPLE@
|
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
--@DOC_naughty_shape_EXAMPLE@
|
2019-03-04 23:06:42 +01:00
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @property shape
|
2019-06-09 00:55:04 +02:00
|
|
|
-- @tparam gears.shape shape
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Widget opacity.
|
|
|
|
-- @property opacity
|
2019-06-09 00:55:04 +02:00
|
|
|
-- @tparam number opacity Between 0 to 1.
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Widget margin.
|
2019-03-12 19:30:15 +01:00
|
|
|
--
|
|
|
|
--@DOC_awful_notification_margin_EXAMPLE@
|
|
|
|
--
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @property margin
|
|
|
|
-- @tparam number|table margin
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @see shape
|
|
|
|
|
|
|
|
--- Function to run on left click.
|
2019-06-09 00:28:39 +02:00
|
|
|
--
|
|
|
|
-- Use the signals rather than this.
|
|
|
|
--
|
|
|
|
-- @deprecatedproperty run
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @param function
|
2019-06-09 00:28:39 +02:00
|
|
|
-- @see destroyed
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Function to run when notification is destroyed.
|
2019-06-09 00:28:39 +02:00
|
|
|
--
|
|
|
|
-- Use the signals rather than this.
|
|
|
|
--
|
|
|
|
-- @deprecatedproperty destroy
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @param function
|
2019-06-09 00:28:39 +02:00
|
|
|
-- @see destroyed
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Table with any of the above parameters.
|
|
|
|
-- args will override ones defined
|
|
|
|
-- in the preset.
|
|
|
|
-- @property preset
|
|
|
|
-- @param table
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- 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.
|
|
|
|
-- @property callback
|
|
|
|
-- @param function
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- A table containing strings that represents actions to buttons.
|
|
|
|
--
|
|
|
|
-- The table key (a number) is used by DBus to set map the action.
|
|
|
|
--
|
|
|
|
-- @property actions
|
|
|
|
-- @param table
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Ignore this notification, do not display.
|
|
|
|
--
|
|
|
|
-- Note that this property has to be set in a `preset` or in a `request::preset`
|
|
|
|
-- handler.
|
|
|
|
--
|
|
|
|
-- @property ignore
|
|
|
|
-- @param boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
--- Tell if the notification is currently suspended (read only).
|
|
|
|
--
|
|
|
|
-- This is always equal to `naughty.suspended`
|
|
|
|
--@property suspended
|
|
|
|
--@param boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
--- If the notification is expired.
|
|
|
|
-- @property is_expired
|
|
|
|
-- @param boolean
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-01-03 07:52:13 +01:00
|
|
|
-- @see naughty.expiration_paused
|
|
|
|
|
2019-07-11 06:45:55 +02:00
|
|
|
--- If the timeout needs to be reset when a property changes.
|
|
|
|
--
|
|
|
|
-- By default it fallsback to `naughty.auto_reset_timeout`, which itself is
|
|
|
|
-- true by default.
|
|
|
|
--
|
|
|
|
-- @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
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Emitted when the notification is destroyed.
|
|
|
|
-- @signal destroyed
|
2019-01-03 09:09:42 +01:00
|
|
|
-- @tparam number reason Why it was destroyed
|
|
|
|
-- @tparam boolean keep_visible If it was kept visible.
|
|
|
|
-- @see naughty.notification_closed_reason
|
2017-07-02 04:43:26 +02:00
|
|
|
|
|
|
|
-- . --FIXME needs a description
|
|
|
|
-- @property ignore_suspend If set to true this notification
|
|
|
|
-- will be shown even if notifications are suspended via `naughty.suspend`.
|
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
--- A list of clients associated with this notification.
|
|
|
|
--
|
|
|
|
-- When used with DBus notifications, this returns all clients sharing the PID
|
|
|
|
-- of the notification sender. Note that this is highly unreliable.
|
|
|
|
-- Applications that use a different process to send the notification or
|
|
|
|
-- applications (and scripts) calling the `notify-send` command wont have any
|
|
|
|
-- client.
|
|
|
|
--
|
|
|
|
-- @property clients
|
|
|
|
-- @param table
|
|
|
|
|
2019-07-15 23:44:58 +02:00
|
|
|
--- The maximum popup width.
|
|
|
|
--
|
|
|
|
-- Some notifications have overlong message, cap them to this width. Note that
|
|
|
|
-- this is ignored by `naughty.list.notifications` because it delegate this
|
|
|
|
-- decision to the layout.
|
|
|
|
--
|
|
|
|
-- @property[opt=500] max_width
|
|
|
|
-- @param number
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-15 23:44:58 +02:00
|
|
|
|
|
|
|
--- The application name specified by the notification.
|
|
|
|
--
|
|
|
|
-- This can be anything. It is usually less relevant than the `clients`
|
2019-09-23 18:39:12 +02:00
|
|
|
-- property, but can sometime be specified for remote or headless notifications.
|
2019-07-15 23:44:58 +02:00
|
|
|
-- In these case, it helps to triage and detect the notification from the rules.
|
|
|
|
-- @property app_name
|
|
|
|
-- @param string
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-15 23:44:58 +02:00
|
|
|
|
|
|
|
--- The widget template used to represent the notification.
|
|
|
|
--
|
|
|
|
-- Some notifications, such as chat messages or music applications are better
|
|
|
|
-- off with a specialized notification widget.
|
|
|
|
--
|
|
|
|
-- @property widget_template
|
|
|
|
-- @param table
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @propemits true false
|
2019-07-15 23:44:58 +02:00
|
|
|
|
2019-02-17 18:36:02 +01:00
|
|
|
--- Destroy notification by notification object.
|
2017-07-02 04:43:26 +02:00
|
|
|
--
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method destroy
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @tparam string reason One of the reasons from `notification_closed_reason`
|
|
|
|
-- @tparam[opt=false] boolean keep_visible If true, keep the notification visible
|
2020-01-13 08:32:28 +01:00
|
|
|
-- @treturn boolean True if the popup was successfully destroyed, false otherwise.
|
|
|
|
-- @emits destroyed
|
|
|
|
-- @emitstparam destroyed integer reason The reason.
|
|
|
|
-- @emitstparam destroyed boolean keep_visible If the notification should be kept.
|
|
|
|
-- @see naughty.notification_closed_reason
|
2017-07-02 04:43:26 +02:00
|
|
|
function notification:destroy(reason, keep_visible)
|
2019-02-17 18:36:02 +01:00
|
|
|
if self._private.is_destroyed then
|
|
|
|
gdebug.print_warning("Trying to destroy the same notification twice. It"..
|
|
|
|
" was destroyed because: "..self._private.destroy_reason)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2019-03-02 18:59:24 +01:00
|
|
|
reason = reason or cst.notification_closed_reason.dismissed_by_user
|
|
|
|
|
2019-01-03 09:09:42 +01:00
|
|
|
self:emit_signal("destroyed", reason, keep_visible)
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-02-17 18:36:02 +01:00
|
|
|
self._private.is_destroyed = true
|
|
|
|
self._private.destroy_reason = reason
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Set new notification timeout.
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method reset_timeout
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @tparam number new_timeout Time in seconds after which notification disappears.
|
|
|
|
function notification:reset_timeout(new_timeout)
|
|
|
|
if self.timer then self.timer:stop() end
|
|
|
|
|
2019-07-15 08:12:20 +02:00
|
|
|
-- Do not set `self.timeout` to `self.timeout` since that would create the
|
|
|
|
-- timer before the constructor ends.
|
|
|
|
if new_timeout and self.timer then
|
2019-09-21 13:43:35 +02:00
|
|
|
self.timeout = new_timeout
|
2019-07-15 08:12:20 +02:00
|
|
|
end
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-03-11 19:45:31 +01:00
|
|
|
if self.timer and not self.timer.started then
|
2019-01-03 07:17:22 +01:00
|
|
|
self.timer:start()
|
|
|
|
end
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function notification:set_id(new_id)
|
|
|
|
assert(self._private.id == nil, "Notification identifier can only be set once")
|
|
|
|
self._private.id = new_id
|
|
|
|
self:emit_signal("property::id", new_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
function notification:set_timeout(timeout)
|
2019-07-15 22:25:49 +02:00
|
|
|
timeout = timeout or 0
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
local die = function (reason)
|
2019-01-03 07:52:13 +01:00
|
|
|
if reason == cst.notification_closed_reason.expired then
|
|
|
|
self.is_expired = true
|
|
|
|
if naughty.expiration_paused then
|
|
|
|
table.insert(naughty.notifications._expired[1], self)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
self:destroy(reason)
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.timer and self._private.timeout == timeout then return end
|
|
|
|
|
2019-01-03 07:17:22 +01:00
|
|
|
-- 0 == never
|
2017-07-02 04:43:26 +02:00
|
|
|
if timeout > 0 then
|
|
|
|
local timer_die = timer { timeout = timeout }
|
2019-01-03 07:17:22 +01:00
|
|
|
|
|
|
|
timer_die:connect_signal("timeout", function()
|
|
|
|
pcall(die, cst.notification_closed_reason.expired)
|
|
|
|
|
|
|
|
-- Prevent infinite timers events on errors.
|
|
|
|
if timer_die.started then
|
|
|
|
timer_die:stop()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
--FIXME there's still a dependency loop to fix before it works
|
|
|
|
if not self.suspended then
|
2017-07-02 04:43:26 +02:00
|
|
|
timer_die:start()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Prevent a memory leak and the accumulation of active timers
|
|
|
|
if self.timer and self.timer.started then
|
|
|
|
self.timer:stop()
|
|
|
|
end
|
|
|
|
|
|
|
|
self.timer = timer_die
|
|
|
|
end
|
|
|
|
self.die = die
|
|
|
|
self._private.timeout = timeout
|
2020-01-13 08:32:28 +01:00
|
|
|
self:emit_signal("property::timeout", timeout)
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
2019-01-04 10:39:07 +01:00
|
|
|
function notification:set_text(txt)
|
|
|
|
gdebug.deprecate(
|
|
|
|
"The `text` attribute is deprecated, use `message`",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
|
|
|
self:set_message(txt)
|
|
|
|
end
|
|
|
|
|
|
|
|
function notification:get_text()
|
|
|
|
gdebug.deprecate(
|
|
|
|
"The `text` attribute is deprecated, use `message`",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
|
|
|
return self:get_message()
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
local properties = {
|
2019-01-04 10:39:07 +01:00
|
|
|
"message" , "title" , "timeout" , "hover_timeout" ,
|
2020-02-10 07:51:29 +01:00
|
|
|
"app_name", "position", "ontop" , "border_width" ,
|
2017-07-02 04:43:26 +02:00
|
|
|
"width" , "font" , "icon" , "icon_size" ,
|
|
|
|
"fg" , "bg" , "height" , "border_color" ,
|
|
|
|
"shape" , "opacity" , "margin" , "ignore_suspend",
|
2019-07-11 06:06:24 +02:00
|
|
|
"destroy" , "preset" , "callback", "actions" ,
|
2019-07-14 06:03:12 +02:00
|
|
|
"run" , "id" , "ignore" , "auto_reset_timeout",
|
2019-07-15 23:44:58 +02:00
|
|
|
"urgency" , "image" , "images" , "widget_template",
|
2020-02-10 07:51:29 +01:00
|
|
|
"max_width",
|
2017-07-02 04:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, prop in ipairs(properties) do
|
|
|
|
notification["get_"..prop] = notification["get_"..prop] or function(self)
|
|
|
|
-- It's possible this could be called from the `request::preset` handler.
|
|
|
|
-- `rawget()` is necessary to avoid a stack overflow.
|
|
|
|
local preset = rawget(self, "preset")
|
|
|
|
|
|
|
|
return self._private[prop]
|
|
|
|
or (preset and preset[prop])
|
|
|
|
or cst.config.defaults[prop]
|
|
|
|
end
|
|
|
|
|
|
|
|
notification["set_"..prop] = notification["set_"..prop] or function(self, value)
|
|
|
|
self._private[prop] = value
|
|
|
|
self:emit_signal("property::"..prop, value)
|
2019-07-11 06:45:55 +02:00
|
|
|
|
|
|
|
-- When a notification is updated over dbus or by setting a property,
|
|
|
|
-- it is usually convenient to reset the timeout.
|
|
|
|
local reset = ((not self.suspended)
|
|
|
|
and self.auto_reset_timeout ~= false
|
|
|
|
and naughty.auto_reset_timeout)
|
|
|
|
|
|
|
|
if reset then
|
|
|
|
self:reset_timeout()
|
|
|
|
end
|
2019-07-14 06:03:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-03-08 02:35:33 +01:00
|
|
|
-- Changing the image will change the icon, make sure property::icon is emitted.
|
|
|
|
for _, prop in ipairs {"image", "images" } do
|
|
|
|
local cur = notification["set_"..prop]
|
|
|
|
|
|
|
|
notification["set_"..prop] = function(self, value)
|
|
|
|
cur(self, value)
|
|
|
|
self._private.icon = nil
|
|
|
|
self:emit_signal("property::icon")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
local hints_default = {
|
|
|
|
urgency = "normal",
|
|
|
|
resident = false,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, prop in ipairs { "category", "resident" } do
|
|
|
|
notification["get_"..prop] = notification["get_"..prop] or function(self)
|
|
|
|
return self._private[prop] or (
|
|
|
|
self._private.freedesktop_hints and self._private.freedesktop_hints[prop]
|
|
|
|
) or hints_default[prop]
|
|
|
|
end
|
|
|
|
|
|
|
|
notification["set_"..prop] = notification["set_"..prop] or function(self, value)
|
|
|
|
self._private[prop] = value
|
|
|
|
self:emit_signal("property::"..prop, value)
|
|
|
|
end
|
|
|
|
end
|
2019-07-11 06:45:55 +02:00
|
|
|
|
2019-07-14 06:03:12 +02:00
|
|
|
function notification.get_icon(self)
|
2020-03-15 08:35:40 +01:00
|
|
|
-- Honor all overrides.
|
2019-07-14 06:03:12 +02:00
|
|
|
if self._private.icon then
|
|
|
|
return self._private.icon == "" and nil or self._private.icon
|
2020-03-15 08:35:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local ret = nil
|
|
|
|
|
|
|
|
-- First, check if the image is passed as a surface or a path.
|
|
|
|
if self.image and self.image ~= "" then
|
|
|
|
ret = self.image
|
2019-07-14 06:03:12 +02:00
|
|
|
elseif self._private.app_icon and self._private.app_icon ~= "" then
|
2020-03-15 08:35:40 +01:00
|
|
|
ret = self._private.app_icon
|
|
|
|
end
|
|
|
|
|
|
|
|
local s, err = nil, nil
|
|
|
|
|
|
|
|
-- See if this is a valid path.
|
|
|
|
if ret and ret ~= "" then
|
|
|
|
s, err = gsurface.load_silently(ret)
|
|
|
|
end
|
|
|
|
|
|
|
|
if s and not err then
|
|
|
|
return s
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
2020-03-15 08:35:40 +01:00
|
|
|
-- The second fallback are the client(s) icon(s).
|
2019-07-14 06:03:12 +02:00
|
|
|
local clients = notification.get_clients(self)
|
|
|
|
|
2020-03-15 08:35:40 +01:00
|
|
|
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 self._private.icon
|
|
|
|
end
|
2019-07-14 06:03:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-15 08:35:40 +01:00
|
|
|
-- Now, it might be an XDG icon name or something a request handler can
|
|
|
|
-- understand.
|
|
|
|
if err then
|
|
|
|
local ctx = self._private.app_icon and "app_icon" or "image"
|
|
|
|
naughty.emit_signal("request::icon", self, ctx, {
|
|
|
|
app_icon = self._private.app_icon,
|
|
|
|
image = self.image
|
|
|
|
})
|
2019-07-14 06:03:12 +02:00
|
|
|
end
|
|
|
|
|
2020-03-15 08:35:40 +01:00
|
|
|
return self._private.icon == "" and nil or self._private.icon
|
2019-07-14 06:03:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function notification.get_clients(self)
|
|
|
|
-- Clients from the future don't send notification, it's useless to reload
|
|
|
|
-- the list over and over.
|
|
|
|
if self._private.clients then return self._private.clients end
|
|
|
|
|
|
|
|
if not self._private._unique_sender then return {} end
|
|
|
|
|
|
|
|
self._private.clients = require("naughty.dbus").get_clients(self)
|
|
|
|
|
|
|
|
return self._private.clients
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
2019-07-17 06:26:44 +02:00
|
|
|
function notification.set_actions(self, new_actions)
|
|
|
|
for _, a in ipairs(self._private.actions or {}) do
|
|
|
|
a:disconnect_signal("_changed", self._private.action_cb )
|
|
|
|
a:disconnect_signal("invoked" , self._private.invoked_cb)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Clone so `append_actions` doesn't add unwanted actions to other
|
|
|
|
-- notifications.
|
|
|
|
self._private.actions = gtable.clone(new_actions, false)
|
|
|
|
|
|
|
|
for _, a in ipairs(self._private.actions or {}) do
|
|
|
|
a:connect_signal("_changed", self._private.action_cb )
|
|
|
|
a:connect_signal("invoked" , self._private.invoked_cb)
|
|
|
|
end
|
|
|
|
|
|
|
|
self:emit_signal("property::actions", new_actions)
|
|
|
|
|
|
|
|
-- When a notification is updated over dbus or by setting a property,
|
|
|
|
-- it is usually convenient to reset the timeout.
|
|
|
|
local reset = ((not self.suspended)
|
|
|
|
and self.auto_reset_timeout ~= false
|
|
|
|
and naughty.auto_reset_timeout)
|
|
|
|
|
|
|
|
if reset then
|
|
|
|
self:reset_timeout()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-17 06:40:40 +02:00
|
|
|
--- Add more actions to the notification.
|
|
|
|
-- @method append_actions
|
|
|
|
-- @tparam table new_actions
|
|
|
|
|
|
|
|
function notification:append_actions(new_actions)
|
|
|
|
self._private.actions = self._private.actions or {}
|
|
|
|
|
|
|
|
for _, a in ipairs(new_actions or {}) do
|
|
|
|
a:connect_signal("_changed", self._private.action_cb )
|
|
|
|
a:connect_signal("invoked" , self._private.invoked_cb)
|
|
|
|
table.insert(self._private.actions, a)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-02-10 07:51:29 +01:00
|
|
|
function notification:set_screen(s)
|
|
|
|
assert(not self._private.screen)
|
|
|
|
|
|
|
|
s = s and capi.screen[s] or nil
|
|
|
|
|
|
|
|
-- Avoid an infinite loop in the management code.
|
|
|
|
if s == self._private.weak_screen[1] then return end
|
|
|
|
|
|
|
|
self._private.weak_screen = setmetatable({s}, {__mode="v"})
|
|
|
|
|
|
|
|
self:emit_signal("property::screen", s)
|
|
|
|
end
|
|
|
|
|
|
|
|
function notification:get_screen()
|
|
|
|
return self._private.weak_screen[1]
|
|
|
|
end
|
|
|
|
|
2019-01-04 08:52:02 +01:00
|
|
|
--TODO v6: remove this
|
|
|
|
local function convert_actions(actions)
|
|
|
|
gdebug.deprecate(
|
|
|
|
"The notification actions should now be of type `naughty.action`, "..
|
|
|
|
"not strings or callback functions",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
|
|
|
|
|
|
|
local naction = require("naughty.action")
|
|
|
|
|
2019-03-04 22:56:15 +01:00
|
|
|
local new_actions = {}
|
|
|
|
|
2019-01-04 08:52:02 +01:00
|
|
|
-- Does not attempt to handle when there is a mix of strings and objects
|
|
|
|
for idx, name in pairs(actions) do
|
2019-03-04 22:56:15 +01:00
|
|
|
local cb, old_idx = nil, idx
|
2019-01-04 08:52:02 +01:00
|
|
|
|
|
|
|
if type(name) == "function" then
|
|
|
|
cb = name
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(idx) == "string" then
|
2019-03-04 22:56:15 +01:00
|
|
|
name, idx = idx, #actions+1
|
2019-01-04 08:52:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local a = naction {
|
|
|
|
position = idx,
|
|
|
|
name = name,
|
|
|
|
}
|
|
|
|
|
|
|
|
if cb then
|
|
|
|
a:connect_signal("invoked", cb)
|
|
|
|
end
|
|
|
|
|
2019-03-04 22:56:15 +01:00
|
|
|
new_actions[old_idx] = a
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Yes, it modifies `args`, this is legacy code, cloning the args
|
|
|
|
-- just for this isn't worth it.
|
|
|
|
for old_idx, a in pairs(new_actions) do
|
|
|
|
actions[a.position] = a
|
|
|
|
actions[ old_idx ] = nil
|
2019-01-04 08:52:02 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-15 06:55:34 +02:00
|
|
|
-- The old API used monkey-patched variable presets.
|
|
|
|
--
|
|
|
|
-- Monkey-patched anything is always an issue and prevent module from safely
|
|
|
|
-- doing anything without stepping on each other foot. In the background,
|
|
|
|
-- presets were selected with a rule-like API anyway.
|
|
|
|
local function select_legacy_preset(n, args)
|
|
|
|
for _, obj in pairs(cst.config.mapping) do
|
|
|
|
local filter, preset = obj[1], obj[2]
|
|
|
|
if (not filter.urgency or filter.urgency == args.urgency) and
|
|
|
|
(not filter.category or filter.category == args.category) and
|
|
|
|
(not filter.appname or filter.appname == args.appname) then
|
|
|
|
args.preset = gtable.join(args.preset or {}, preset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- gather variables together
|
|
|
|
rawset(n, "preset", gtable.join(
|
|
|
|
cst.config.defaults or {},
|
|
|
|
args.preset or cst.config.presets.normal or {},
|
|
|
|
rawget(n, "preset") or {}
|
|
|
|
))
|
|
|
|
|
|
|
|
for k, v in pairs(n.preset) do
|
|
|
|
n._private[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
--- Create a notification.
|
|
|
|
--
|
2019-12-31 07:09:39 +01:00
|
|
|
-- @tparam table args The argument table containing any of the arguments below.
|
2017-07-02 04:43:26 +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.
|
|
|
|
-- Set 0 for no timeout.
|
|
|
|
-- @int[opt] args.hover_timeout Delay in seconds after which hovered popup disappears.
|
|
|
|
-- @tparam[opt=focused] integer|screen args.screen Target screen for the notification.
|
|
|
|
-- @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"`.
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @bool[opt=true] args.ontop Boolean forcing popups to display on top.
|
|
|
|
-- @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.
|
|
|
|
-- @string[opt] args.icon Path to icon.
|
|
|
|
-- @int[opt] args.icon_size Desired icon size in px.
|
|
|
|
-- @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
|
2019-11-11 02:47:43 +01:00
|
|
|
-- `beautiful.border_color_active` or `'#535d6c'`] args.border_color Border color.
|
2017-07-02 04:43:26 +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.
|
|
|
|
-- @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.
|
|
|
|
-- `notification.die(naughty.notification_closed_reason.dismissedByUser)` from
|
|
|
|
-- there to dismiss the notification yourself.
|
|
|
|
-- @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] 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-07-02 04:43:26 +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 })
|
2017-07-02 04:43:26 +02:00
|
|
|
-- @treturn ?table The notification object, or nil in case a notification was
|
|
|
|
-- not displayed.
|
2019-06-07 20:59:34 +02:00
|
|
|
-- @constructorfct naughty.notification
|
2017-07-02 04:43:26 +02:00
|
|
|
local function create(args)
|
|
|
|
if cst.config.notify_callback then
|
|
|
|
args = cst.config.notify_callback(args)
|
|
|
|
if not args then return end
|
|
|
|
end
|
|
|
|
|
2019-02-22 17:14:50 +01:00
|
|
|
assert(not args.id, "Identifiers cannot be specified externally")
|
|
|
|
|
2019-01-04 08:52:02 +01:00
|
|
|
args = args or {}
|
|
|
|
|
|
|
|
-- Old actions usually have callbacks and names. But this isn't non
|
|
|
|
-- compliant with the spec. The spec has explicit ordering and optional
|
|
|
|
-- icons. The old format doesn't allow these metadata to be stored.
|
|
|
|
local is_old_action = args.actions and (
|
|
|
|
(args.actions[1] and type(args.actions[1]) == "string") or
|
|
|
|
(type(next(args.actions)) == "string")
|
|
|
|
)
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
local n = gobject {
|
|
|
|
enable_properties = true,
|
|
|
|
}
|
|
|
|
|
2019-01-04 10:39:07 +01:00
|
|
|
if args.text then
|
|
|
|
gdebug.deprecate(
|
|
|
|
"The `text` attribute is deprecated, use `message`",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
|
|
|
args.message = args.text
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
assert(naughty.emit_signal)
|
|
|
|
-- Make sure all signals bubble up
|
|
|
|
n:_connect_everything(naughty.emit_signal)
|
|
|
|
|
|
|
|
-- Avoid modifying the original table
|
2020-02-10 07:51:29 +01:00
|
|
|
local private = {weak_screen = setmetatable({}, {__mode="v"})}
|
2019-07-15 06:55:34 +02:00
|
|
|
rawset(n, "_private", private)
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-07-15 06:55:34 +02:00
|
|
|
-- Allow extensions to create override the preset with custom data
|
|
|
|
if not naughty._has_preset_handler then
|
|
|
|
select_legacy_preset(n, args)
|
|
|
|
end
|
2017-07-02 04:43:26 +02:00
|
|
|
|
2019-03-04 22:56:15 +01:00
|
|
|
if is_old_action then
|
2019-01-04 08:52:02 +01:00
|
|
|
convert_actions(args.actions)
|
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
for k, v in pairs(args) do
|
2020-02-10 07:51:29 +01:00
|
|
|
-- Don't keep a strong reference to the screen, Lua 5.1 GC wont be
|
|
|
|
-- smart enough to unwind the mess of circular weak references.
|
|
|
|
if k ~= "screen" then
|
|
|
|
private[k] = v
|
|
|
|
end
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
2019-01-03 07:52:13 +01:00
|
|
|
-- It's an automatic property
|
|
|
|
n.is_expired = false
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
gtable.crush(n, notification, true)
|
|
|
|
|
2019-07-17 06:26:44 +02:00
|
|
|
-- Always emit property::actions when any of the action change to allow
|
|
|
|
-- some widgets to be updated without over complicated built-in tracking
|
|
|
|
-- of all options.
|
|
|
|
function n._private.action_cb() n:emit_signal("property::actions") end
|
|
|
|
|
|
|
|
-- Listen to action press and destroy non-resident notifications.
|
|
|
|
function n._private.invoked_cb(a, notif)
|
|
|
|
if (not notif) or notif == n then
|
|
|
|
n:emit_signal("invoked", a)
|
|
|
|
|
|
|
|
if not n.resident then
|
|
|
|
n:destroy(cst.notification_closed_reason.dismissed_by_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- notif.actions should not be nil to allow checking if there is actions
|
|
|
|
-- using the shorthand `if #notif.actions > 0 then`
|
|
|
|
private.actions = {}
|
|
|
|
if args.actions then
|
|
|
|
notification.set_actions(n, args.actions)
|
|
|
|
end
|
|
|
|
|
2019-07-09 07:25:00 +02:00
|
|
|
n.id = n.id or notification._gen_next_id()
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Register the notification before requesting a widget
|
|
|
|
n:emit_signal("new", args)
|
|
|
|
|
2019-07-15 06:55:34 +02:00
|
|
|
-- The rules are attached to this.
|
|
|
|
if naughty._has_preset_handler then
|
2020-02-16 08:22:34 +01:00
|
|
|
naughty.emit_signal("request::preset", n, "new", args)
|
2019-07-15 06:55:34 +02:00
|
|
|
end
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
-- Let all listeners handle the actual visual aspects
|
2019-07-15 06:55:34 +02:00
|
|
|
if (not n.ignore) and ((not n.preset) or n.preset.ignore ~= true) then
|
2020-02-16 08:22:34 +01:00
|
|
|
naughty.emit_signal("request::display" , n, "new", args)
|
|
|
|
naughty.emit_signal("request::fallback", n, "new", args)
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Because otherwise the setter logic would not be executed
|
|
|
|
if n._private.timeout then
|
2019-07-15 06:55:34 +02:00
|
|
|
n:set_timeout(n._private.timeout
|
|
|
|
or (n.preset and n.preset.timeout)
|
|
|
|
or cst.config.timeout
|
|
|
|
)
|
2017-07-02 04:43:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return n
|
|
|
|
end
|
|
|
|
|
2019-02-22 17:14:50 +01:00
|
|
|
-- This allows notification to be updated later.
|
|
|
|
local counter = 1
|
|
|
|
|
|
|
|
-- Identifier support.
|
|
|
|
function notification._gen_next_id()
|
|
|
|
counter = counter+1
|
|
|
|
return counter
|
|
|
|
end
|
|
|
|
|
2019-06-06 22:32:53 +02:00
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
2017-07-02 04:43:26 +02:00
|
|
|
return setmetatable(notification, {__call = function(_, ...) return create(...) end})
|