From 4577e32a385f74bc333b434392b166601dc87d2c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 17 Oct 2015 18:52:41 +0200 Subject: [PATCH] naughty: Use :get_height_for_width() This changes the code in naughty so that it first decides on a width for the notification and then uses the new function :get_height_for_width() to find a suitable height. This makes a difference in the following example where before this change the text is cut off and afterwards it is shown completely: naughty.notify({ text = string.rep("abcdefghijklmnopqrstuvwxyz\n", 4), width = 75 }) Signed-off-by: Uli Schlachter --- lib/naughty/core.lua | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 9033957b2..ee41e72b7 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -598,18 +598,6 @@ function naughty.notify(args) if hover_timeout then notification.box:connect_signal("mouse::enter", hover_destroy) end - -- calculate the height - if not height then - local w, h = textbox:get_preferred_size(s) - if iconbox and icon_h + 2 * margin > h + 2 * margin then - height = icon_h + 2 * margin - else - height = h + 2 * margin - end - end - - height = height + actions_total_height - -- calculate the width if not width then local w, h = textbox:get_preferred_size(s) @@ -620,6 +608,19 @@ function naughty.notify(args) width = actions_max_width end + -- calculate the height + if not height then + local w = width - (iconbox and icon_w + 2 * margin or 0) - 2 * margin + local h = textbox:get_height_for_width(w, s) + if iconbox and icon_h + 2 * margin > h + 2 * margin then + height = icon_h + 2 * margin + else + height = h + 2 * margin + end + end + + height = height + actions_total_height + -- crop to workarea size if too big local workarea = capi.screen[screen].workarea if width > workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0) then