diff options
author | Stefano Karapetsas <[email protected]> | 2012-05-12 16:18:40 +0200 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2012-05-12 16:18:40 +0200 |
commit | ba4a0d842f8e9c5beffc25ca62b72bf7a86c83fb (patch) | |
tree | f8a83a7f6e54d9706694ea33fafaf600cb488093 /src/daemon/daemon.c | |
parent | b915b2e6dcc1ff03f8768bd8f28b877ec28ed372 (diff) | |
download | mate-notification-daemon-ba4a0d842f8e9c5beffc25ca62b72bf7a86c83fb.tar.bz2 mate-notification-daemon-ba4a0d842f8e9c5beffc25ca62b72bf7a86c83fb.tar.xz |
scale icon if size is greater than IMAGE_SIZE
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 75000a9..f8ab49d 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -1035,6 +1035,49 @@ static GdkPixbuf* _notify_daemon_pixbuf_from_path(const char* path) return pixbuf; } +static GdkPixbuf* _notify_daemon_scale_pixbuf(GdkPixbuf *pixbuf, gboolean no_stretch_hint) +{ + int pw; + int ph; + float scale_factor_x = 1.0; + float scale_factor_y = 1.0; + float scale_factor = 1.0; + + pw = gdk_pixbuf_get_width (pixbuf); + ph = gdk_pixbuf_get_height (pixbuf); + + /* Determine which dimension requires the smallest scale. */ + scale_factor_x = (float) IMAGE_SIZE / (float) pw; + scale_factor_y = (float) IMAGE_SIZE / (float) ph; + + if (scale_factor_x > scale_factor_y) + { + scale_factor = scale_factor_y; + } + else + { + scale_factor = scale_factor_x; + } + + /* always scale down, allow to disable scaling up */ + if (scale_factor < 1.0 || !no_stretch_hint) + { + int scale_x; + int scale_y; + + scale_x = (int) (pw * scale_factor); + scale_y = (int) (ph * scale_factor); + return gdk_pixbuf_scale_simple (pixbuf, + scale_x, + scale_y, + GDK_INTERP_BILINEAR); + } + else + { + return g_object_ref (pixbuf); + } +} + static void window_clicked_cb(GtkWindow* nw, GdkEventButton* button, NotifyDaemon* daemon) { if (daemon->priv->url_clicked_lock) @@ -1446,8 +1489,13 @@ gboolean notify_daemon_notify_handler(NotifyDaemon* daemon, const char* app_name if (pixbuf != NULL) { - theme_set_notification_icon (nw, pixbuf); + GdkPixbuf *scaled; + scaled = NULL; + scaled = _notify_daemon_scale_pixbuf (pixbuf, TRUE); + theme_set_notification_icon (nw, scaled); g_object_unref (G_OBJECT (pixbuf)); + if (scaled != NULL) + g_object_unref (scaled); } if (window_xid != None && !theme_get_always_stack (nw)) |