Add support for resizing notification icon with respect to aspect (#2176)
* Add support for resizing notification icon with respect to aspect Previously, if an icon was not exactly square, an icon size set in configuration would cause the notification to pad the icon with empty space so dimensions are equal. Now behaviour is different: the bigger dimension of the icon is scaled to fit the icon_size value, while smaller is scaled same amount to preserve aspect. Also, ImageSurface is now not created as fixed size square, but it's dimensions are computed in similar way. * Round the computed dimensions of ImageSurface Even one pixel off is still off.
This commit is contained in:
parent
b0b5a1c1ab
commit
584c5cedb1
|
@ -22,6 +22,7 @@ local screen = require("awful.screen")
|
|||
local util = require("awful.util")
|
||||
local gtable = require("gears.table")
|
||||
local gfs = require("gears.filesystem")
|
||||
local gmath = require("gears.math")
|
||||
local beautiful = require("beautiful")
|
||||
local wibox = require("wibox")
|
||||
local surface = require("gears.surface")
|
||||
|
@ -759,9 +760,14 @@ function naughty.notify(args)
|
|||
iconbox = wibox.widget.imagebox()
|
||||
iconmargin = wibox.container.margin(iconbox, margin, margin, margin, margin)
|
||||
if icon_size then
|
||||
local scaled = cairo.ImageSurface(cairo.Format.ARGB32, icon_size, icon_size)
|
||||
local scale_factor = icon_size / math.max(icon:get_height(),
|
||||
icon:get_width())
|
||||
local scaled =
|
||||
cairo.ImageSurface(cairo.Format.ARGB32,
|
||||
gmath.round(icon:get_width() * scale_factor),
|
||||
gmath.round(icon:get_height() * scale_factor))
|
||||
local cr = cairo.Context(scaled)
|
||||
cr:scale(icon_size / icon:get_height(), icon_size / icon:get_width())
|
||||
cr:scale(scale_factor, scale_factor)
|
||||
cr:set_source_surface(icon, 0, 0)
|
||||
cr:paint()
|
||||
icon = scaled
|
||||
|
|
Loading…
Reference in New Issue