diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in
index 31bc43d3..a766cff6 100644
--- a/lib/naughty.lua.in
+++ b/lib/naughty.lua.in
@@ -13,14 +13,12 @@ local pcall = pcall
local capi = { screen = screen,
awesome = awesome,
dbus = dbus,
- widget = widget,
- wibox = wibox,
- oocairo = oocairo,
- timer = timer }
+ timer = timer,
+ oocairo = oocairo }
local button = require("awful.button")
local util = require("awful.util")
local bt = require("beautiful")
-local layout = require("awful.widget.layout")
+local wibox = require("wibox")
--- Notification library
module("naughty")
@@ -352,13 +350,15 @@ function notify(args)
end
-- create textbox
- local textbox = capi.widget({ type = "textbox", align = "flex" })
- textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
- layout.margins[textbox] = { right = margin, left = margin, bottom = margin, top = margin }
+ local textbox = wibox.widget.textbox()
+ local marginbox = wibox.layout.margin()
+ marginbox:set_margins(margin)
+ marginbox:set_widget(textbox)
textbox.valign = "middle"
local function setText(pattern, replacements)
- textbox.text = string.format('%s%s', font, title, text:gsub(pattern, replacements))
+ textbox:set_markup(string.format('%s%s', font, title, text:gsub(pattern, replacements)))
+ textbox:check()
end
-- First try to set the text while only interpreting
.
@@ -366,12 +366,14 @@ function notify(args)
if not pcall(setText, "", "\n") then
-- That failed, escape everything which might cause an error from pango
if not pcall(setText, "[<>&]", { ['<'] = "<", ['>'] = ">", ['&'] = "&" }) then
- textbox.text = "<Invalid markup, cannot display message>"
+ textbox:set_markup("<Invalid markup, cannot display message>")
end
end
-- create iconbox
local iconbox = nil
+ local iconmargin = nil
+ local icon_w, icon_h = 0, 0
if icon then
-- try to guess icon if the provided one is non-existent/readable
if type(icon) == "string" and not util.file_readable(icon) then
@@ -380,44 +382,54 @@ function notify(args)
-- if we have an icon, use it
if icon then
- iconbox = capi.widget({ type = "imagebox", align = "left" })
- layout.margins[iconbox] = { right = margin, left = margin, bottom = margin, top = margin }
- iconbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
- local img
+ iconbox = wibox.widget.imagebox()
+ iconmargin = wibox.layout.margin()
+ iconmargin:set_widget(iconbox)
+ iconmargin:set_margins(margin)
+ local img = icon
if type(icon) == "string" then
img = capi.oocairo.image_surface_create_from_png(icon)
else
img = icon
end
if icon_size then
- img = img:crop_and_scale(0,0,img.height,img.width,icon_size,icon_size)
+ local scaled = capi.oocairo.image_surface_create("argb32", icon_size, icon_size)
+ local cr = capi.oocairo.context_create(scaled)
+ cr:scale(icon_size / img:get_height(), icon_size / img:get_width())
+ cr:set_source(img, 0, 0)
+ cr:paint()
+ img = scaled
end
- iconbox.resize = false
- iconbox.image = img
+ iconbox:set_resize(false)
+ iconbox:set_image(img)
+ icon_w = img:get_width()
+ icon_h = img:get_height()
end
end
-- create container wibox
- notification.box = capi.wibox({ fg = fg,
- bg = bg,
- border_color = border_color,
- border_width = border_width,
- type = "notification" })
+ notification.box = wibox({ fg = fg,
+ bg = bg,
+ border_color = border_color,
+ border_width = border_width,
+ type = "notification" })
if hover_timeout then notification.box:connect_signal("mouse::enter", hover_destroy) end
-- calculate the height
if not height then
- if iconbox and iconbox:extents().height + 2 * margin > textbox:extents().height + 2 * margin then
- height = iconbox:extents().height + 2 * margin
+ local w, h = textbox:fit(-1, -1)
+ if iconbox and icon_h + 2 * margin > h + 2 * margin then
+ height = icon_h + 2 * margin
else
- height = textbox:extents().height + 2 * margin
+ height = h + 2 * margin
end
end
-- calculate the width
if not width then
- width = textbox:extents().width + (iconbox and iconbox:extents().width + 2 * margin or 0) + 2 * margin
+ local w, h = textbox:fit(-1, -1)
+ width = w + (iconbox and icon_w + 2 * margin or 0) + 2 * margin
end
-- crop to workarea size if too big
@@ -445,11 +457,15 @@ function notify(args)
notification.idx = offset.idx
-- populate widgets
- if iconbox then
- notification.box.widgets = { iconbox, textbox, ["layout"] = layout.horizontal.leftright }
- else
- notification.box.widgets = { textbox, ["layout"] = layout.horizontal.leftright }
+ local layout = wibox.layout.fixed.horizontal()
+ if iconmargin then
+ layout:add(iconmargin)
end
+ layout:add(marginbox)
+ notification.box:set_widget(layout)
+
+ -- Setup the mouse events
+ layout:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
-- insert the notification to the table
table.insert(notifications[screen][notification.position], notification)