From 584c5cedb1f2f970612e245db3f30d026eff8e8d Mon Sep 17 00:00:00 2001 From: Alexander Melnyk Date: Tue, 6 Feb 2018 18:01:40 +0200 Subject: [PATCH] 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. --- lib/naughty/core.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 2d58d2e0..b418bbc4 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -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