diff options
Diffstat (limited to 'applets/notification_area/status-notifier/sn-item-v0.c')
-rw-r--r-- | applets/notification_area/status-notifier/sn-item-v0.c | 95 |
1 files changed, 71 insertions, 24 deletions
diff --git a/applets/notification_area/status-notifier/sn-item-v0.c b/applets/notification_area/status-notifier/sn-item-v0.c index d218abad..9e66f361 100644 --- a/applets/notification_area/status-notifier/sn-item-v0.c +++ b/applets/notification_area/status-notifier/sn-item-v0.c @@ -59,6 +59,7 @@ struct _SnItemV0 gchar *title; gint32 window_id; gchar *icon_name; + gchar *label; SnIconPixmap **icon_pixmap; gchar *overlay_icon_name; SnIconPixmap **overlay_icon_pixmap; @@ -83,7 +84,7 @@ enum LAST_PROP }; -static GParamSpec *properties[LAST_PROP] = { NULL }; +static GParamSpec *obj_properties[LAST_PROP] = { NULL }; G_DEFINE_TYPE (SnItemV0, sn_item_v0, SN_TYPE_ITEM) @@ -155,7 +156,7 @@ compare_size (gconstpointer a, } static cairo_surface_t * -get_surface (SnItemV0 *v0, +get_surface (SnIconPixmap **icon_pixmap, GtkOrientation orientation, gint size) { @@ -164,10 +165,10 @@ get_surface (SnItemV0 *v0, SnIconPixmap *pixmap = NULL; GList *l; - g_assert (v0->icon_pixmap != NULL && v0->icon_pixmap[0] != NULL); + g_assert (icon_pixmap != NULL && icon_pixmap[0] != NULL); - for (i = 0; v0->icon_pixmap[i] != NULL; i++) - pixmaps = g_list_prepend (pixmaps, v0->icon_pixmap[i]); + for (i = 0; icon_pixmap[i] != NULL; i++) + pixmaps = g_list_prepend (pixmaps, icon_pixmap[i]); pixmaps = g_list_sort_with_data (pixmaps, compare_size, GUINT_TO_POINTER (orientation)); @@ -233,6 +234,9 @@ get_icon_by_name (const gchar *icon_name, NULL, GTK_ICON_LOOKUP_FORCE_SIZE, NULL); } +#define ICON_NAME_VALID(icon_name) (icon_name && icon_name[0] != '\0') +#define ICON_PIXMAP_VALID(icon_pixmap) (icon_pixmap && icon_pixmap[0] != NULL) + static void update (SnItemV0 *v0) { @@ -240,7 +244,9 @@ update (SnItemV0 *v0) GtkImage *image; SnTooltip *tip; gint icon_size; - gboolean visible; + const gchar *icon_name; + SnIconPixmap **icon_pixmap; + g_return_if_fail (SN_IS_ITEM_V0 (v0)); image = GTK_IMAGE (v0->image); @@ -250,23 +256,43 @@ update (SnItemV0 *v0) else icon_size = MAX (1, v0->effective_icon_size); - if (v0->icon_name != NULL && v0->icon_name[0] != '\0') + /* If the item requests attention and has a specific icon for it, use that + * instead of the default icon. */ + if (g_strcmp0 (v0->status, "NeedsAttention") == 0 && + (ICON_NAME_VALID (v0->attention_icon_name) || + ICON_PIXMAP_VALID (v0->attention_icon_pixmap))) + { + icon_name = v0->attention_icon_name; + icon_pixmap = v0->attention_icon_pixmap; + } + else + { + icon_name = v0->icon_name; + icon_pixmap = v0->icon_pixmap; + } + + if (ICON_NAME_VALID (icon_name)) { cairo_surface_t *surface; gint scale; scale = gtk_widget_get_scale_factor (GTK_WIDGET (image)); - surface = get_icon_by_name (v0->icon_name, icon_size, scale); + surface = get_icon_by_name (icon_name, icon_size, scale); if (!surface) { GdkPixbuf *pixbuf; /*try to find icons specified by path and filename*/ - pixbuf = gdk_pixbuf_new_from_file (v0->icon_name, NULL); + pixbuf = gdk_pixbuf_new_from_file (icon_name, NULL); if (pixbuf && icon_size > 1) { /*An icon specified by path and filename may be the wrong size for the tray */ - pixbuf = gdk_pixbuf_scale_simple (pixbuf, icon_size-2, icon_size-2, GDK_INTERP_BILINEAR); + GdkPixbuf *scaled_pixbuf; + + scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, icon_size-2, icon_size-2, GDK_INTERP_BILINEAR); + g_object_unref (pixbuf); + pixbuf = scaled_pixbuf; + surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL); } if (pixbuf) @@ -280,11 +306,11 @@ update (SnItemV0 *v0) gtk_image_set_from_surface (image, surface); cairo_surface_destroy (surface); } - else if (v0->icon_pixmap != NULL && v0->icon_pixmap[0] != NULL) + else if (ICON_PIXMAP_VALID (icon_pixmap)) { cairo_surface_t *surface; - surface = get_surface (v0, + surface = get_surface (icon_pixmap, gtk_orientable_get_orientation (GTK_ORIENTABLE (v0)), icon_size); if (surface != NULL) @@ -329,6 +355,7 @@ update (SnItemV0 *v0) gtk_widget_set_tooltip_markup (GTK_WIDGET (v0), NULL); } + gtk_button_set_label (GTK_BUTTON (v0), v0->label); accessible = gtk_widget_get_accessible (GTK_WIDGET (v0)); if (v0->title != NULL && *v0->title != '\0') @@ -339,7 +366,7 @@ update (SnItemV0 *v0) /* TODO: hide "Passive" items with a setting? */ /*Special case mate-polkit*/ if (g_strcmp0 (v0->status, "password-dialog") != 0){ - visible = g_strcmp0 (v0->status, "Passive") != 0; + gboolean visible = g_strcmp0 (v0->status, "Passive") != 0; gtk_widget_set_visible (GTK_WIDGET (v0), visible); } else @@ -638,7 +665,7 @@ update_title (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->title, g_free); + g_free (v0->title); v0->title = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -666,7 +693,7 @@ update_icon_name (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->icon_name, g_free); + g_free (v0->icon_name); v0->icon_name = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -717,7 +744,7 @@ update_overlay_icon_name (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->overlay_icon_name, g_free); + g_free (v0->overlay_icon_name); v0->overlay_icon_name = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -768,7 +795,7 @@ update_attention_icon_name (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->attention_icon_name, g_free); + g_free (v0->attention_icon_name); v0->attention_icon_name = g_variant_dup_string (variant, NULL); g_clear_pointer (&variant, g_variant_unref); @@ -790,7 +817,7 @@ update_attention_icon_pixmap (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->attention_icon_pixmap, icon_pixmap_free); + icon_pixmap_free (v0->attention_icon_pixmap); v0->attention_icon_pixmap = icon_pixmap_new (variant); g_clear_pointer (&variant, g_variant_unref); @@ -819,7 +846,7 @@ update_tooltip (GObject *source_object, v0 = SN_ITEM_V0 (user_data); - g_clear_pointer (&v0->tooltip, sn_tooltip_free); + sn_tooltip_free (v0->tooltip); v0->tooltip = sn_tooltip_new (variant); g_clear_pointer (&variant, g_variant_unref); @@ -848,6 +875,21 @@ new_status_cb (SnItemV0 *v0, } static void +new_label_cb (SnItemV0 *v0, + GVariant *parameters) +{ + GVariant *variant; + + variant = g_variant_get_child_value (parameters, 0); + + g_free (v0->label); + v0->label = g_variant_dup_string (variant, NULL); + g_variant_unref (variant); + + queue_update (v0); +} + +static void new_icon_theme_path_cb (SnItemV0 *v0, GVariant *parameters) { @@ -905,6 +947,8 @@ g_signal_cb (GDBusProxy *proxy, new_status_cb (v0, parameters); else if (g_strcmp0 (signal_name, "NewIconThemePath") == 0) new_icon_theme_path_cb (v0, parameters); + else if (g_strcmp0 (signal_name, "XAyatanaNewLabel") == 0) + new_label_cb (v0, parameters); else g_debug ("signal '%s' not handled!", signal_name); } @@ -975,6 +1019,8 @@ get_all_cb (GObject *source_object, v0->menu = g_variant_dup_string (value, NULL); else if (g_strcmp0 (key, "ItemIsMenu") == 0) v0->item_is_menu = g_variant_get_boolean (value); + else if (g_strcmp0 (key, "XAyatanaLabel") == 0) + v0->label = g_variant_dup_string (value, NULL); else g_debug ("property '%s' not handled!", key); @@ -1111,6 +1157,7 @@ sn_item_v0_finalize (GObject *object) g_clear_pointer (&v0->title, g_free); g_clear_pointer (&v0->icon_name, g_free); + g_clear_pointer (&v0->label, g_free); g_clear_pointer (&v0->icon_pixmap, icon_pixmap_free); g_clear_pointer (&v0->overlay_icon_name, g_free); g_clear_pointer (&v0->overlay_icon_pixmap, icon_pixmap_free); @@ -1345,15 +1392,15 @@ sn_item_v0_set_property (GObject *object, static void install_properties (GObjectClass *object_class) { - properties[PROP_ICON_SIZE] = + obj_properties[PROP_ICON_SIZE] = g_param_spec_int ("icon-size", "Icon size", "Icon size", 0, G_MAXINT, 16, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - properties[PROP_ICON_PADDING] = + obj_properties[PROP_ICON_PADDING] = g_param_spec_int ("icon-padding", "Icon padding", "Icon padding", 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, LAST_PROP, properties); + g_object_class_install_properties (object_class, LAST_PROP, obj_properties); } static void @@ -1395,7 +1442,7 @@ sn_item_v0_init (SnItemV0 *v0) v0->icon_size = 16; v0->effective_icon_size = 0; v0->image = gtk_image_new (); - gtk_container_add (GTK_CONTAINER (v0), v0->image); + gtk_button_set_image (GTK_BUTTON (v0), v0->image); gtk_widget_show (v0->image); } @@ -1465,7 +1512,7 @@ sn_item_v0_set_icon_size (SnItemV0 *v0, if (v0->icon_size != size) { v0->icon_size = size; - g_object_notify_by_pspec (G_OBJECT (v0), properties[PROP_ICON_SIZE]); + g_object_notify_by_pspec (G_OBJECT (v0), obj_properties[PROP_ICON_SIZE]); if (v0->id != NULL) queue_update (v0); |