diff options
author | James Henstridge <james@jamesh.id.au> | 2004-09-30 11:25:37 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 2004-09-30 11:25:37 +0000 |
commit | 17cd55e682d5b78738f03255b2638bb9da937962 (patch) | |
tree | f22cd656edc45bbc3f8b414a23fe412a64107200 /src | |
parent | 64dcfbcb2c7a1a36355f45cd81d5dcf4a7a51702 (diff) |
function to set a GtkImage to a scaled pixbuf.
2004-09-30 James Henstridge <james@jamesh.id.au>
* src/notification.c (set_scaled_pixbuf): function to set a
GtkImage to a scaled pixbuf.
(zenity_notification_handle_stdin): set the image to a
GTK_ICON_SIZE_BUTTON sized image.
(zenity_notification): same here.
Diffstat (limited to 'src')
-rw-r--r-- | src/notification.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/notification.c b/src/notification.c index f3b3b1f..a67b730 100644 --- a/src/notification.c +++ b/src/notification.c @@ -33,6 +33,39 @@ static GtkWidget *icon_event_box; static GtkTooltips *tooltips; +static void +set_scaled_pixbuf (GtkImage *image, GdkPixbuf *pixbuf, GtkIconSize icon_size) +{ + GdkScreen *screen; + GtkSettings *settings; + int width, height, desired_width, desired_height; + GdkPixbuf *new_pixbuf; + + screen = gtk_widget_get_screen (GTK_WIDGET (image)); + settings = gtk_settings_get_for_screen (screen); + if (!gtk_icon_size_lookup_for_settings (settings, icon_size, + &desired_width, &desired_height)) + return; + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + if (height > desired_height || width > desired_width) { + if (width * desired_height / height > desired_width) + desired_height = height * desired_width / width; + else + desired_width = width * desired_height / height; + + new_pixbuf = gdk_pixbuf_scale_simple (pixbuf, + desired_width, + desired_height, + GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf (image, new_pixbuf); + g_object_unref (new_pixbuf); + } else { + gtk_image_set_from_pixbuf (image, pixbuf); + } +} + static gboolean zenity_notification_icon_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer data) { @@ -138,7 +171,8 @@ zenity_notification_handle_stdin (GIOChannel *channel, pixbuf = zenity_util_pixbuf_new_from_file (GTK_WIDGET (tray_icon), value); if (pixbuf != NULL) { - gtk_image_set_from_pixbuf (GTK_IMAGE (icon_image), pixbuf); + set_scaled_pixbuf (GTK_IMAGE (icon_image), pixbuf, + GTK_ICON_SIZE_BUTTON); gdk_pixbuf_unref (pixbuf); } else { g_warning ("Could not load notification icon : %s", value); @@ -198,9 +232,11 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data pixbuf = gdk_pixbuf_new_from_file (ZENITY_IMAGE_FULLPATH ("zenity-notification.png"), NULL); icon_event_box = gtk_event_box_new (); + icon_image = gtk_image_new (); if (pixbuf) { - icon_image = gtk_image_new_from_pixbuf (pixbuf); + set_scaled_pixbuf (GTK_IMAGE (icon_image), pixbuf, + GTK_ICON_SIZE_BUTTON); gdk_pixbuf_unref (pixbuf); } else { g_warning ("Could not load notification icon : %s", ZENITY_IMAGE_FULLPATH ("zenity-notification.png")); |