2008-10-17 22:38:01 +02:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
-- @author koniu <gkusnierz@gmail.com>
|
|
|
|
-- @copyright 2008 koniu
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Package environment
|
|
|
|
local pairs = pairs
|
|
|
|
local table = table
|
|
|
|
local wibox = wibox
|
|
|
|
local image = image
|
2008-12-17 17:47:23 +01:00
|
|
|
local type = type
|
2008-12-11 13:55:25 +01:00
|
|
|
local tostring = tostring
|
2008-10-17 22:38:01 +02:00
|
|
|
local hooks = require("awful.hooks")
|
|
|
|
local string = string
|
|
|
|
local widget = widget
|
2009-04-17 18:08:52 +02:00
|
|
|
local button = require("awful.button")
|
|
|
|
local util = require("awful.util")
|
2009-04-28 16:21:50 +02:00
|
|
|
local capi = { screen = screen, awesome = awesome }
|
2008-11-13 11:53:41 +01:00
|
|
|
local bt = require("beautiful")
|
2008-11-20 17:13:23 +01:00
|
|
|
local screen = screen
|
2008-11-20 17:51:29 +01:00
|
|
|
local awful = awful
|
|
|
|
local dbus = dbus
|
2008-10-17 22:38:01 +02:00
|
|
|
|
|
|
|
--- Notification library
|
|
|
|
module("naughty")
|
|
|
|
|
|
|
|
--- Naughty configuration - a table containing common/default popup settings.
|
|
|
|
-- You can override some of these for individual popups using args to notify().
|
|
|
|
-- @name config
|
|
|
|
-- @field screen Screen on which the popups will appear number. Default: 1
|
|
|
|
-- @field position Corner of the workarea the popups will appear.
|
|
|
|
-- Valid values: 'top_right', 'top_left', 'bottom_right', 'bottom_left'.
|
|
|
|
-- Default: 'top_right'
|
2008-11-15 21:08:17 +01:00
|
|
|
-- @field padding Space between popups and edge of the workarea. Default: 4
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @field width Width of a popup. Default: 300
|
2008-11-15 21:08:17 +01:00
|
|
|
-- @field spacing Spacing between popups. Default: 1
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @field ontop Boolean forcing popups to display on top. Default: true
|
2008-11-15 21:08:17 +01:00
|
|
|
-- @field margin Space between popup edge and content. Default: 10
|
2008-11-22 18:24:33 +01:00
|
|
|
-- @field icon_dirs List of directories that will be checked by getIcon()
|
|
|
|
-- Default: { "/usr/share/pixmaps/", }
|
|
|
|
-- @field icon_formats List of formats that will be checked by getIcon()
|
|
|
|
-- Default: { "png", "gif" }
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @field border_width Border width. Default: 1
|
|
|
|
-- @class table
|
|
|
|
|
|
|
|
config = {}
|
2008-11-15 21:08:17 +01:00
|
|
|
config.padding = 4
|
|
|
|
config.spacing = 1
|
|
|
|
config.margin = 10
|
2008-11-27 10:07:07 +01:00
|
|
|
config.ontop = true
|
2008-11-22 18:24:33 +01:00
|
|
|
config.icon_dirs = { "/usr/share/pixmaps/", }
|
|
|
|
config.icon_formats = { "png", "gif" }
|
2008-11-27 10:07:07 +01:00
|
|
|
|
2008-10-17 22:38:01 +02:00
|
|
|
config.border_width = 1
|
2008-11-27 10:07:07 +01:00
|
|
|
|
|
|
|
--- Notification Presets - a table containing presets for different purposes
|
|
|
|
-- You have to pass a reference of a preset in your notify() call to use the preset
|
|
|
|
-- At least the default preset named "normal" has to be defined
|
|
|
|
-- The presets "low", "normal" and "critical" are used for notifications over DBUS
|
|
|
|
-- @name config.presets
|
|
|
|
-- @field low The preset for notifications with low urgency level
|
|
|
|
-- @field normal The default preset for every notification without a preset that will also be used for normal urgency level
|
|
|
|
-- @field critical The preset for notifications with a critical urgency level
|
|
|
|
-- @class table
|
|
|
|
|
|
|
|
--- Default preset for notifications
|
|
|
|
-- @name config.presets.normal
|
|
|
|
-- @field timeout Number of seconds after which popups disappear.
|
|
|
|
-- Set to 0 for no timeout. Default: 5
|
|
|
|
-- @field hover_timeout Delay in seconds after which hovered popup disappears.
|
|
|
|
-- Default: nil
|
|
|
|
-- @field border_color Border color.
|
|
|
|
-- Default: beautiful.border_focus or '#535d6c'
|
|
|
|
-- @field fg Foreground color. Default: beautiful.fg_focus or '#ffffff'
|
|
|
|
-- @field bg Background color. Default: beautiful.bg_focus or '#535d6c'
|
|
|
|
-- @field font Popup font. Default: beautiful.font or "Verdana 8"
|
|
|
|
-- @field height Height of a single line of text. Default: 16
|
|
|
|
-- @field icon Popup icon. Default: nil
|
|
|
|
-- @field icon_size Size of the icon in pixels. Default: nil
|
2008-12-17 17:47:23 +01:00
|
|
|
-- @field 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
|
2008-11-27 10:07:07 +01:00
|
|
|
|
|
|
|
config.presets = {
|
|
|
|
low = {
|
|
|
|
timeout = 5
|
|
|
|
},
|
|
|
|
normal = {
|
|
|
|
timeout = 8,
|
|
|
|
hover_timeout = nil,
|
|
|
|
position = "top_right",
|
|
|
|
screen = 1,
|
|
|
|
width = 300,
|
|
|
|
height = 16,
|
|
|
|
icon = nil,
|
|
|
|
icon_size = nil
|
|
|
|
},
|
|
|
|
critical = {
|
|
|
|
bg = "#ff0000",
|
|
|
|
fg = "#ffffff",
|
|
|
|
timeout = 0,
|
|
|
|
height = 25
|
|
|
|
}
|
|
|
|
}
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2008-11-27 10:07:07 +01:00
|
|
|
-- DBUS Notification constants
|
2008-12-11 13:53:24 +01:00
|
|
|
urgency = {
|
2008-11-27 10:07:07 +01:00
|
|
|
low = "\0",
|
|
|
|
normal = "\1",
|
|
|
|
critical = "\2"
|
|
|
|
}
|
|
|
|
|
2008-12-11 13:53:24 +01:00
|
|
|
--- DBUS notification to preset mapping
|
|
|
|
-- @name config.mapping
|
|
|
|
-- The first element is an object containing the filter
|
|
|
|
-- If the rules in the filter matches the associated preset will be applied
|
|
|
|
-- The rules object can contain: urgency, category, appname
|
|
|
|
-- The second element is the preset
|
|
|
|
|
|
|
|
config.mapping = {
|
|
|
|
{{urgency = urgency.low}, config.presets.low},
|
|
|
|
{{urgency = urgency.normal}, config.presets.normal},
|
|
|
|
{{urgency = urgency.critical}, config.presets.critical}
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Counter for the notifications
|
|
|
|
-- Required for later access via DBUS
|
|
|
|
local counter = 1
|
|
|
|
|
2008-10-17 22:38:01 +02:00
|
|
|
--- Index of notifications. See config table for valid 'position' values.
|
|
|
|
-- Each element is a table consisting of:
|
|
|
|
-- @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
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @name notifications[position]
|
|
|
|
-- @class table
|
|
|
|
|
2008-11-20 17:13:23 +01:00
|
|
|
notifications = {}
|
|
|
|
for s = 1, screen.count() do
|
|
|
|
notifications[s] = {
|
|
|
|
top_left = {},
|
|
|
|
top_right = {},
|
|
|
|
bottom_left = {},
|
|
|
|
bottom_right = {},
|
|
|
|
}
|
|
|
|
end
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2009-01-08 12:26:00 +01:00
|
|
|
-- Evaluate desired position of the notification by index - internal
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @param idx Index of the notification
|
|
|
|
-- @param position top_right | top_left | bottom_right | bottom_left
|
2008-11-15 17:55:38 +01:00
|
|
|
-- @param height Popup height
|
2008-11-19 03:16:44 +01:00
|
|
|
-- @param width Popup width (optional)
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @return Absolute position in {x, y} dictionary
|
2008-11-20 17:13:23 +01:00
|
|
|
local function get_offset(screen, position, idx, width, height)
|
|
|
|
local ws = capi.screen[screen].workarea
|
2008-10-17 22:38:01 +02:00
|
|
|
local v = {}
|
2008-11-20 17:13:23 +01:00
|
|
|
width = width or notifications[screen][position][idx].width or config.width
|
2008-10-17 22:38:01 +02:00
|
|
|
|
|
|
|
-- calculate x
|
|
|
|
if position:match("left") then
|
2008-11-15 21:08:17 +01:00
|
|
|
v.x = ws.x + config.padding
|
2008-10-17 22:38:01 +02:00
|
|
|
else
|
2008-12-12 00:01:43 +01:00
|
|
|
v.x = ws.x + ws.width - (width + config.padding)
|
2008-10-17 22:38:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- calculate existing popups' height
|
|
|
|
local existing = 0
|
|
|
|
for i = 1, idx-1, 1 do
|
2008-12-12 00:01:43 +01:00
|
|
|
existing = existing + notifications[screen][position][i].height + config.spacing
|
2008-10-17 22:38:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- calculate y
|
|
|
|
if position:match("top") then
|
2008-11-15 21:08:17 +01:00
|
|
|
v.y = ws.y + config.padding + existing
|
2008-10-17 22:38:01 +02:00
|
|
|
else
|
2008-12-12 00:01:43 +01:00
|
|
|
v.y = ws.y + ws.height - (config.padding + height + existing)
|
2008-10-17 22:38:01 +02:00
|
|
|
end
|
|
|
|
|
2008-10-23 18:47:43 +02:00
|
|
|
-- if positioned outside workarea, destroy oldest popup and recalculate
|
2008-11-15 17:55:38 +01:00
|
|
|
if v.y + height > ws.y + ws.height or v.y < ws.y then
|
2008-10-23 18:47:43 +02:00
|
|
|
idx = idx - 1
|
2008-11-20 17:13:23 +01:00
|
|
|
destroy(notifications[screen][position][1])
|
|
|
|
v = get_offset(screen, position, idx, width, height)
|
2008-10-23 18:47:43 +02:00
|
|
|
end
|
|
|
|
|
2008-10-17 22:38:01 +02:00
|
|
|
return v
|
|
|
|
end
|
|
|
|
|
2009-01-08 12:26:00 +01:00
|
|
|
-- Re-arrange notifications according to their position and index - internal
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @return None
|
2008-11-20 17:13:23 +01:00
|
|
|
local function arrange(screen)
|
|
|
|
for p,pos in pairs(notifications[screen]) do
|
|
|
|
for i,notification in pairs(notifications[screen][p]) do
|
|
|
|
local offset = get_offset(screen, p, i, notification.width, notification.height)
|
2008-11-21 01:44:55 +01:00
|
|
|
notification.box:geometry({ x = offset.x, y = offset.y, width = notification.width, height = notification.height })
|
2008-10-19 20:58:50 +02:00
|
|
|
notification.idx = i
|
2008-10-17 22:38:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Destroy notification by index
|
2008-11-25 09:45:28 +01:00
|
|
|
-- @param notification Notification object to be destroyed
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @return True if the popup was successfully destroyed, nil otherwise
|
2008-10-19 20:58:50 +02:00
|
|
|
function destroy(notification)
|
2008-11-22 18:49:27 +01:00
|
|
|
if notification and notification.box.screen then
|
2008-11-20 17:13:23 +01:00
|
|
|
local scr = notification.box.screen
|
|
|
|
table.remove(notifications[notification.box.screen][notification.position], notification.idx)
|
2008-11-15 16:25:22 +01:00
|
|
|
hooks.timer.unregister(notification.die)
|
2008-11-20 17:13:23 +01:00
|
|
|
notification.box.screen = nil
|
|
|
|
arrange(scr)
|
2008-10-17 22:38:01 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-08 12:26:00 +01:00
|
|
|
-- Get notification by ID
|
2008-11-20 17:51:29 +01:00
|
|
|
-- @param id ID of the notification
|
|
|
|
-- @return notification object if it was found, nil otherwise
|
|
|
|
local function getById(id)
|
|
|
|
-- iterate the notifications to get the notfications with the correct ID
|
|
|
|
for s = 1, screen.count() do
|
|
|
|
for p,pos in pairs(notifications[s]) do
|
|
|
|
for i,notification in pairs(notifications[s][p]) do
|
|
|
|
if notification.id == id then
|
|
|
|
return notification
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-08 12:26:00 +01:00
|
|
|
-- Search for an icon in specified directories with a specified format
|
2008-11-22 18:24:33 +01:00
|
|
|
-- @param icon Name of the icon
|
|
|
|
-- @return full path of the icon, or nil of no icon was found
|
|
|
|
local function getIcon(name)
|
|
|
|
for d, dir in pairs(config.icon_dirs) do
|
|
|
|
for f, format in pairs(config.icon_formats) do
|
|
|
|
local icon = dir .. name .. "." .. format
|
|
|
|
if awful.util.file_readable(icon) then
|
|
|
|
return icon
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-17 22:38:01 +02:00
|
|
|
--- Create notification. args is a dictionary of optional arguments. For more information and defaults see respective fields in config table.
|
|
|
|
-- @param text Text of the notification
|
|
|
|
-- @param timeout Time in seconds after which popup expires
|
|
|
|
-- @param title Title of the notification
|
|
|
|
-- @param position Corner of the workarea the popups will appear
|
|
|
|
-- @param icon Path to icon
|
2008-10-20 22:02:22 +02:00
|
|
|
-- @param icon_size Desired icon size in px
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @param fg Foreground color
|
|
|
|
-- @param bg Background color
|
|
|
|
-- @param screen Target screen for the notification
|
|
|
|
-- @param ontop Target screen for the notification
|
2008-11-05 03:03:28 +01:00
|
|
|
-- @param run Function to run on left click
|
2008-11-19 03:16:44 +01:00
|
|
|
-- @param width The popup width
|
2008-11-25 01:14:29 +01:00
|
|
|
-- @field hover_timeout Delay in seconds after which hovered popup disappears.
|
2008-11-20 17:51:29 +01:00
|
|
|
-- @param replaces_id Replace the notification with the given ID
|
2008-10-17 22:38:01 +02:00
|
|
|
-- @usage naughty.notify({ title = 'Achtung!', text = 'You\'re idling', timeout = 0 })
|
2008-11-25 09:45:28 +01:00
|
|
|
-- @return The notification object
|
2008-10-17 22:38:01 +02:00
|
|
|
function notify(args)
|
2008-11-15 17:55:38 +01:00
|
|
|
-- gather variables together
|
2008-11-27 10:07:07 +01:00
|
|
|
local timeout = args.timeout or (args.preset and args.preset.timeout) or config.presets.normal.timeout
|
|
|
|
local icon = args.icon or (args.preset and args.preset.icon) or config.icon
|
|
|
|
local icon_size = args.icon_size or (args.preset and args.preset.icon_size) or config.icon_size
|
2008-12-11 13:55:25 +01:00
|
|
|
local text = tostring(args.text) or ""
|
2008-11-27 10:07:07 +01:00
|
|
|
local screen = args.screen or (args.preset and args.preset.screen) or config.presets.normal.screen
|
2008-10-17 22:38:01 +02:00
|
|
|
local ontop = args.ontop or config.ontop
|
2008-11-27 10:07:07 +01:00
|
|
|
local width = args.width or (args.preset and args.preset.width) or config.presets.normal.width
|
|
|
|
local hover_timeout = args.hover_timeout or (args.preset and args.preset.hover_timeout) or config.presets.normal.hover_timeout
|
2009-04-10 23:18:51 +02:00
|
|
|
local opacity = args.opacity or (args.preset and args.preset.opacity) or config.presets.normal.opacity
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2008-11-21 01:43:18 +01:00
|
|
|
-- beautiful
|
|
|
|
local beautiful = bt.get()
|
2008-11-27 10:07:07 +01:00
|
|
|
local font = args.font or config.font or (args.preset and args.preset.font) or config.presets.normal.font or beautiful.font or "Verdana 8"
|
|
|
|
local fg = args.fg or config.fg or (args.preset and args.preset.fg) or config.presets.normal.fg or beautiful.fg_normal or '#ffffff'
|
|
|
|
local bg = args.bg or config.bg or (args.preset and args.preset.bg) or config.presets.normal.bg or beautiful.bg_normal or '#535d6c'
|
|
|
|
local border_color = (args.preset and args.preset.border_color) or config.presets.normal.border_color or beautiful.bg_focus or '#535d6c'
|
2008-11-15 17:55:38 +01:00
|
|
|
local notification = {}
|
2008-11-20 17:51:29 +01:00
|
|
|
|
|
|
|
-- replace notification if needed
|
|
|
|
if args.replaces_id then
|
|
|
|
obj = getById(args.replaces_id)
|
|
|
|
if obj then
|
|
|
|
-- destroy this and ...
|
|
|
|
destroy(obj)
|
|
|
|
end
|
|
|
|
-- ... may use its ID
|
|
|
|
if args.replaces_id < counter then
|
|
|
|
notification.id = args.replaces_id
|
|
|
|
else
|
|
|
|
counter = counter + 1
|
|
|
|
notification.id = counter
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- get a brand new ID
|
|
|
|
counter = counter + 1
|
|
|
|
notification.id = counter
|
|
|
|
end
|
|
|
|
|
2008-11-27 10:07:07 +01:00
|
|
|
notification.position = args.position or (args.preset and args.preset.position) or config.presets.normal.position
|
2008-11-20 17:13:23 +01:00
|
|
|
notification.idx = #notifications[screen][notification.position] + 1
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2008-11-15 17:55:38 +01:00
|
|
|
local title = ""
|
2008-12-11 13:55:25 +01:00
|
|
|
if args.title then title = tostring(args.title) .. "\n" end
|
2008-10-19 20:58:50 +02:00
|
|
|
|
2008-11-15 17:55:38 +01:00
|
|
|
-- hook destroy
|
2008-11-05 03:18:01 +01:00
|
|
|
local die = function () destroy(notification) end
|
|
|
|
hooks.timer.register(timeout, die)
|
|
|
|
notification.die = die
|
2008-11-04 20:35:18 +01:00
|
|
|
|
2008-11-25 06:45:40 +01:00
|
|
|
local run = function ()
|
2008-12-03 23:52:59 +01:00
|
|
|
if args.run then
|
|
|
|
args.run(notification)
|
|
|
|
else
|
|
|
|
die()
|
|
|
|
end
|
2008-11-25 06:45:40 +01:00
|
|
|
end
|
2008-11-05 03:03:28 +01:00
|
|
|
|
2008-11-04 20:35:18 +01:00
|
|
|
local hover_destroy = function ()
|
2008-11-25 01:14:29 +01:00
|
|
|
if hover_timeout == 0 then die()
|
|
|
|
else hooks.timer.register(hover_timeout, die) end
|
2008-11-04 20:35:18 +01:00
|
|
|
end
|
|
|
|
|
2008-11-15 17:55:38 +01:00
|
|
|
-- create textbox
|
2008-11-12 11:48:51 +01:00
|
|
|
local textbox = widget({ type = "textbox", align = "flex" })
|
2009-04-17 18:08:52 +02:00
|
|
|
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
2008-12-02 18:14:51 +01:00
|
|
|
textbox:margin({ right = config.margin, left = config.margin })
|
|
|
|
textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text)
|
2008-11-25 01:14:29 +01:00
|
|
|
if hover_timeout then textbox.mouse_enter = hover_destroy end
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2008-11-15 17:55:38 +01:00
|
|
|
-- create iconbox
|
2008-10-17 22:38:01 +02:00
|
|
|
local iconbox = nil
|
|
|
|
if icon then
|
2008-11-22 18:24:33 +01:00
|
|
|
-- try to guess icon if the provided one is non-existent/readable
|
2009-03-11 17:11:06 +01:00
|
|
|
if type(icon) == "string" and not awful.util.file_readable(icon) then
|
|
|
|
icon = getIcon(icon)
|
|
|
|
end
|
2008-11-22 18:24:33 +01:00
|
|
|
|
|
|
|
-- if we have an icon, use it
|
|
|
|
if icon then
|
|
|
|
iconbox = widget({ type = "imagebox", align = "left" })
|
2009-04-18 10:34:39 +02:00
|
|
|
iconbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
2009-03-11 17:11:06 +01:00
|
|
|
local img
|
|
|
|
if type(icon) == "string" then
|
|
|
|
img = image(icon)
|
|
|
|
else
|
|
|
|
img = icon
|
|
|
|
end
|
2008-11-22 18:24:33 +01:00
|
|
|
if icon_size then
|
|
|
|
img = img:crop_and_scale(0,0,img.height,img.width,icon_size,icon_size)
|
|
|
|
end
|
|
|
|
iconbox.resize = false
|
|
|
|
iconbox.image = img
|
2009-02-05 18:10:19 +01:00
|
|
|
iconbox.valign = "center"
|
2008-11-25 01:14:29 +01:00
|
|
|
if hover_timeout then iconbox.mouse_enter = hover_destroy end
|
2008-11-04 21:09:28 +01:00
|
|
|
end
|
2008-10-17 22:38:01 +02:00
|
|
|
end
|
|
|
|
|
2008-11-15 17:55:38 +01:00
|
|
|
-- create container wibox
|
2008-11-12 11:48:51 +01:00
|
|
|
notification.box = wibox({ position = "floating",
|
2008-11-21 01:43:18 +01:00
|
|
|
fg = fg,
|
|
|
|
bg = bg,
|
2008-11-27 10:07:07 +01:00
|
|
|
border_color = args.preset and args.preset.border_color or config.presets.normal.border_color,
|
2008-11-15 17:55:38 +01:00
|
|
|
border_width = config.border_width })
|
|
|
|
|
|
|
|
-- position the wibox
|
|
|
|
local lines = 1; for i in string.gmatch(title..text, "\n") do lines = lines + 1 end
|
2008-11-27 10:07:07 +01:00
|
|
|
local height = args.preset and args.preset.height or config.presets.normal.height
|
|
|
|
if iconbox and iconbox.image.height > lines * height then
|
2008-11-15 17:55:38 +01:00
|
|
|
notification.height = iconbox.image.height
|
|
|
|
else
|
2008-11-27 10:07:07 +01:00
|
|
|
notification.height = lines * height end
|
2008-11-19 03:16:44 +01:00
|
|
|
notification.width = width
|
2008-11-20 17:13:23 +01:00
|
|
|
local offset = get_offset(screen, notification.position, notification.idx, notification.width, notification.height)
|
|
|
|
notification.box:geometry({ width = notification.width,
|
2008-11-15 17:55:38 +01:00
|
|
|
height = notification.height,
|
|
|
|
x = offset.x,
|
|
|
|
y = offset.y })
|
|
|
|
notification.box.ontop = ontop
|
2009-04-10 23:18:51 +02:00
|
|
|
notification.box.opacity = opacity
|
2008-11-15 17:55:38 +01:00
|
|
|
notification.box.screen = screen
|
|
|
|
|
|
|
|
-- populate widgets
|
|
|
|
notification.box.widgets = { iconbox, textbox }
|
2008-10-17 22:38:01 +02:00
|
|
|
|
|
|
|
-- insert the notification to the table
|
2008-11-25 09:45:28 +01:00
|
|
|
table.insert(notifications[screen][notification.position], notification)
|
2008-10-17 22:38:01 +02:00
|
|
|
|
2008-11-25 09:45:28 +01:00
|
|
|
-- return the notification
|
|
|
|
return notification
|
|
|
|
end
|
2008-11-20 17:51:29 +01:00
|
|
|
|
|
|
|
-- DBUS/Notification support
|
|
|
|
-- Notify
|
2009-01-08 11:39:53 +01:00
|
|
|
if awful.hooks.dbus then
|
|
|
|
awful.hooks.dbus.register("org.freedesktop.Notifications", function (data, appname, replaces_id, icon, title, text, actions, hints, expire)
|
2009-02-23 15:25:21 +01:00
|
|
|
args = { preset = { } }
|
2009-01-08 11:39:53 +01:00
|
|
|
if data.member == "Notify" then
|
|
|
|
if text ~= "" then
|
|
|
|
args.text = text
|
|
|
|
if title ~= "" then
|
|
|
|
args.title = title
|
|
|
|
end
|
2008-11-20 17:51:29 +01:00
|
|
|
else
|
2009-01-08 11:39:53 +01:00
|
|
|
if title ~= "" then
|
|
|
|
args.text = title
|
|
|
|
else
|
|
|
|
return nil
|
2008-12-11 13:53:24 +01:00
|
|
|
end
|
|
|
|
end
|
2009-01-08 11:39:53 +01:00
|
|
|
local score = 0
|
|
|
|
for i, obj in pairs(config.mapping) do
|
|
|
|
local filter, preset, s = obj[1], obj[2], 0
|
|
|
|
if (not filter.urgency or filter.urgency == hints.urgency) and
|
|
|
|
(not filter.category or filter.category == hints.category) and
|
|
|
|
(not filter.appname or filter.appname == appname) then
|
|
|
|
for j, el in pairs(filter) do s = s + 1 end
|
|
|
|
if s > score then
|
|
|
|
score = s
|
|
|
|
args.preset = preset
|
|
|
|
end
|
|
|
|
end
|
2008-12-17 17:47:23 +01:00
|
|
|
end
|
2009-01-08 11:39:53 +01:00
|
|
|
if not args.preset.callback or (type(args.preset.callback) == "function" and
|
|
|
|
args.preset.callback(data, appname, replaces_id, icon, title, text, actions, hints, expire)) then
|
|
|
|
if icon ~= "" then
|
|
|
|
args.icon = icon
|
2009-03-11 19:04:12 +01:00
|
|
|
elseif hints.icon_data then
|
|
|
|
-- icon_data is an array:
|
|
|
|
-- 1 -> width, 2 -> height, 3 -> rowstride, 4 -> has alpha
|
|
|
|
-- 5 -> bits per sample, 6 -> channels, 7 -> data
|
|
|
|
|
|
|
|
local imgdata
|
|
|
|
-- If has alpha (ARGB32)
|
|
|
|
if hints.icon_data[6] == 4 then
|
|
|
|
imgdata = hints.icon_data[7]
|
|
|
|
-- If has not alpha (RGB24)
|
|
|
|
elseif hints.icon_data[6] == 3 then
|
|
|
|
imgdata = ""
|
|
|
|
for i = 1, #hints.icon_data[7], 3 do
|
|
|
|
imgdata = imgdata .. hints.icon_data[7]:sub(i , i + 2):reverse()
|
|
|
|
imgdata = imgdata .. string.format("%c", 255) -- alpha is 255
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if imgdata then
|
|
|
|
args.icon = image.argb32(hints.icon_data[1], hints.icon_data[2], imgdata)
|
|
|
|
end
|
2009-01-08 11:39:53 +01:00
|
|
|
end
|
|
|
|
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
|
|
|
|
args.replaces_id = replaces_id
|
|
|
|
end
|
|
|
|
if expire and expire > -1 then
|
|
|
|
args.timeout = expire / 1000
|
|
|
|
end
|
|
|
|
local id = notify(args).id
|
2009-02-23 15:32:24 +01:00
|
|
|
return "u", id
|
2008-12-17 17:47:23 +01:00
|
|
|
end
|
2009-02-23 15:32:24 +01:00
|
|
|
return "u", "0"
|
2009-01-08 11:39:53 +01:00
|
|
|
elseif data.member == "CloseNotification" then
|
|
|
|
local obj = getById(arg1)
|
|
|
|
if obj then
|
|
|
|
destroy(obj)
|
2008-12-17 17:47:23 +01:00
|
|
|
end
|
2009-01-08 11:39:53 +01:00
|
|
|
elseif data.member == "GetServerInfo" or data.member == "GetServerInformation" then
|
|
|
|
-- name of notification app, name of vender, version
|
2009-04-28 16:21:50 +02:00
|
|
|
return "s", "naughty", "s", "awesome", "s", capi.awesome.version:match("%d.%d")
|
2008-11-27 10:07:07 +01:00
|
|
|
end
|
2009-01-08 11:39:53 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
awful.hooks.dbus.register("org.freedesktop.DBus.Introspectable",
|
|
|
|
function (data, text)
|
|
|
|
if data.member == "Introspect" then
|
|
|
|
local xml = [=[<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object
|
|
|
|
Introspection 1.0//EN"
|
|
|
|
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
|
|
|
<node>
|
|
|
|
<interface name="org.freedesktop.DBus.Introspectable">
|
|
|
|
<method name="Introspect">
|
|
|
|
<arg name="data" direction="out" type="s"/>
|
|
|
|
</method>
|
|
|
|
</interface>
|
|
|
|
<interface name="org.freedesktop.Notifications">
|
|
|
|
<method name="CloseNotification">
|
|
|
|
<arg name="id" type="u" direction="in"/>
|
|
|
|
</method>
|
|
|
|
<method name="Notify">
|
|
|
|
<arg name="app_name" type="s" direction="in"/>
|
|
|
|
<arg name="id" type="u" direction="in"/>
|
|
|
|
<arg name="icon" type="s" direction="in"/>
|
|
|
|
<arg name="summary" type="s" direction="in"/>
|
|
|
|
<arg name="body" type="s" direction="in"/>
|
|
|
|
<arg name="actions" type="as" direction="in"/>
|
|
|
|
<arg name="hints" type="a{sv}" direction="in"/>
|
|
|
|
<arg name="timeout" type="i" direction="in"/>
|
|
|
|
<arg name="return_id" type="u" direction="out"/>
|
|
|
|
</method>
|
|
|
|
<method name="GetServerInformation">
|
|
|
|
<arg name="return_name" type="s" direction="out"/>
|
|
|
|
<arg name="return_vendor" type="s" direction="out"/>
|
|
|
|
<arg name="return_version" type="s" direction="out"/>
|
|
|
|
</method>
|
|
|
|
<method name="GetServerInfo">
|
|
|
|
<arg name="return_name" type="s" direction="out"/>
|
|
|
|
<arg name="return_vendor" type="s" direction="out"/>
|
|
|
|
<arg name="return_version" type="s" direction="out"/>
|
|
|
|
</method>
|
|
|
|
</interface>
|
|
|
|
</node>]=]
|
|
|
|
return "s", xml
|
2008-11-20 17:51:29 +01:00
|
|
|
end
|
2009-01-08 11:39:53 +01:00
|
|
|
end)
|
2008-11-20 17:51:29 +01:00
|
|
|
|
2009-01-08 11:39:53 +01:00
|
|
|
-- listen for dbus notification requests
|
2009-04-18 16:07:31 +02:00
|
|
|
dbus.request_name("session", "org.freedesktop.Notifications")
|
2009-01-08 11:39:53 +01:00
|
|
|
end
|
2008-11-20 17:51:29 +01:00
|
|
|
|
2008-10-17 22:38:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|