naughty: resize naughtifications to the minimum needed space
This commits adds support for :extents() to naughty. It changes the behaviour of naughty.config.presets.*.width so that if it's set to nil, the notification gets resized automagically. Else the value of width is used for the notification's width. The meaning of naughty.config.presets.*.height changed similarly, now, if set, it means the literal height of the notifications. If unset, the notification gets resized automagically as well. Signed-off-by: Gregor Best <farhaven@googlemail.com> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
0f2da4b9bf
commit
a4de60b23f
|
@ -91,8 +91,8 @@ config.presets = {
|
||||||
hover_timeout = nil,
|
hover_timeout = nil,
|
||||||
position = "top_right",
|
position = "top_right",
|
||||||
screen = 1,
|
screen = 1,
|
||||||
width = 300,
|
width = nil,
|
||||||
height = 16,
|
height = nil,
|
||||||
icon = nil,
|
icon = nil,
|
||||||
icon_size = nil
|
icon_size = nil
|
||||||
},
|
},
|
||||||
|
@ -273,6 +273,7 @@ function notify(args)
|
||||||
local screen = args.screen or (args.preset and args.preset.screen) or config.presets.normal.screen
|
local screen = args.screen or (args.preset and args.preset.screen) or config.presets.normal.screen
|
||||||
local ontop = args.ontop or config.ontop
|
local ontop = args.ontop or config.ontop
|
||||||
local width = args.width or (args.preset and args.preset.width) or config.presets.normal.width
|
local width = args.width or (args.preset and args.preset.width) or config.presets.normal.width
|
||||||
|
local height = args.preset and args.preset.height or config.presets.normal.height
|
||||||
local hover_timeout = args.hover_timeout or (args.preset and args.preset.hover_timeout) or config.presets.normal.hover_timeout
|
local hover_timeout = args.hover_timeout or (args.preset and args.preset.hover_timeout) or config.presets.normal.hover_timeout
|
||||||
local opacity = args.opacity or (args.preset and args.preset.opacity) or config.presets.normal.opacity
|
local opacity = args.opacity or (args.preset and args.preset.opacity) or config.presets.normal.opacity
|
||||||
|
|
||||||
|
@ -370,13 +371,31 @@ function notify(args)
|
||||||
border_width = config.border_width })
|
border_width = config.border_width })
|
||||||
|
|
||||||
-- position the wibox
|
-- position the wibox
|
||||||
local lines = 1; for i in string.gmatch(title..text, "\n") do lines = lines + 1 end
|
if height then
|
||||||
local height = args.preset and args.preset.height or config.presets.normal.height
|
if iconbox and iconbox.image.height > height then
|
||||||
if iconbox and iconbox.image.height > lines * height then
|
|
||||||
notification.height = iconbox.image.height
|
notification.height = iconbox.image.height
|
||||||
else
|
else
|
||||||
notification.height = lines * height end
|
notification.height = height
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if iconbox and iconbox:extents().height > textbox:extents().height then
|
||||||
|
notification.height = iconbox:extents().height
|
||||||
|
else
|
||||||
|
notification.height = textbox:extents().height
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if width then
|
||||||
notification.width = width
|
notification.width = width
|
||||||
|
else
|
||||||
|
notification.width = textbox:extents().width + (iconbox and iconbox:extents().width or 0) + (2 * (config.border_width or 0))
|
||||||
|
end
|
||||||
|
if notification.width > capi.screen[screen].workarea.width - 2 * (config.border_width or 0) then
|
||||||
|
notification.width = capi.screen[screen].workarea.width - 2 * (config.border_width or 0)
|
||||||
|
end
|
||||||
|
if notification.height > capi.screen[screen].workarea.height - 2 * (config.border_width or 0) - 2 * (config.padding or 0) then
|
||||||
|
notification.height = capi.screen[screen].workarea.height - 2 * (config.border_width or 0) - 2 * (config.padding or 0)
|
||||||
|
end
|
||||||
|
|
||||||
local offset = get_offset(screen, notification.position, nil, notification.width, notification.height)
|
local offset = get_offset(screen, notification.position, nil, notification.width, notification.height)
|
||||||
notification.box:geometry({ width = notification.width,
|
notification.box:geometry({ width = notification.width,
|
||||||
height = notification.height,
|
height = notification.height,
|
||||||
|
|
Loading…
Reference in New Issue