aboutsummaryrefslogtreecommitdiff
path: root/src/metadata-widget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/metadata-widget.c')
-rw-r--r--src/metadata-widget.c166
1 files changed, 70 insertions, 96 deletions
diff --git a/src/metadata-widget.c b/src/metadata-widget.c
index 7c7e750..4d7763f 100644
--- a/src/metadata-widget.c
+++ b/src/metadata-widget.c
@@ -44,7 +44,7 @@ struct _MetadataWidgetPrivate
GtkWidget* piece_label;
GtkWidget* container_label;
GtkWidget* player_label;
- GdkPixbuf* icon_buf;
+ GtkWidget* player_icon;
DbusmenuMenuitem* twin_item;
gint current_height;
};
@@ -126,7 +126,6 @@ metadata_widget_init (MetadataWidget *self)
MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self);
GtkWidget *hbox;
GtkWidget *outer_v_box;
- priv->icon_buf = NULL;
#if GTK_CHECK_VERSION(3, 0, 0)
outer_v_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -178,7 +177,6 @@ metadata_widget_init (MetadataWidget *self)
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
#endif
-
// artist
GtkWidget* artist;
artist = gtk_label_new("");
@@ -224,16 +222,35 @@ metadata_widget_init (MetadataWidget *self)
G_CALLBACK(metadata_widget_selection_received_event_callback),
GTK_WIDGET(self));
+ gint padding = 4;
+ gtk_widget_style_get(GTK_WIDGET(self), "toggle-spacing", &padding, NULL);
+
+#if GTK_CHECK_VERSION(3, 0, 0)
+ GtkWidget * tophbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, padding);
+#else
+ GtkWidget * tophbox = gtk_hbox_new(FALSE, padding);
+#endif
+
+ GtkWidget *player_icon;
+ player_icon = gtk_image_new();
+ priv->player_icon = player_icon;
+
+ gtk_misc_set_alignment (GTK_MISC(priv->player_icon), 1.0 /* right aligned */, 0.5);
+ gtk_box_pack_start (GTK_BOX (tophbox), priv->player_icon, FALSE, FALSE, 0);
+ GtkWidget* spacer;
+ spacer = gtk_alignment_new (0,0,0,0);
+ gtk_container_add (GTK_CONTAINER (spacer), priv->meta_data_h_box);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (spacer),5,0,0,0);
+
// player label
GtkWidget* player_label;
player_label = gtk_label_new ("");
- gtk_misc_set_alignment(GTK_MISC(player_label), (gfloat)0, (gfloat)0);
- gtk_misc_set_padding (GTK_MISC(player_label), (gfloat)1, (gfloat)3);
- gtk_widget_set_size_request (player_label, 150, 24);
+ gtk_misc_set_alignment(GTK_MISC(player_label), (gfloat)0, 0.5);
priv->player_label = player_label;
+ gtk_box_pack_start (GTK_BOX (tophbox), priv->player_label, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX(outer_v_box), priv->player_label, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX(outer_v_box), priv->meta_data_h_box, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(outer_v_box), tophbox, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(outer_v_box), spacer, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (self), outer_v_box);
@@ -246,16 +263,6 @@ metadata_widget_init (MetadataWidget *self)
static void
metadata_widget_dispose (GObject *object)
{
- MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(METADATA_WIDGET(object));
-
- if (priv->icon_buf != NULL){
- #if GTK_CHECK_VERSION(3, 0, 0)
- g_object_unref(priv->icon_buf);
- #else
- gdk_pixbuf_unref(priv->icon_buf);
- #endif
- priv->icon_buf = NULL;
- }
G_OBJECT_CLASS (metadata_widget_parent_class)->dispose (object);
}
@@ -349,13 +356,19 @@ metadata_image_expose_gtk_3 (GtkWidget *metadata,
// Draw the triangle if the player is running ...
static gboolean
metadata_widget_icon_triangle_draw_cb_gtk_3 (GtkWidget *widget,
- cairo_t* cr,
- gpointer user_data)
+ cairo_t* cr,
+ gpointer user_data)
{
- g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE);
- MetadataWidget* meta = METADATA_WIDGET(user_data);
+ g_return_val_if_fail (IS_METADATA_WIDGET (user_data), FALSE);
+ MetadataWidget* meta = METADATA_WIDGET (user_data);
MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(meta);
+ gboolean running = dbusmenu_menuitem_property_get_bool (priv->twin_item,
+ DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING);
+
+ if (!running)
+ return FALSE;
+
GtkStyle *style;
int x, y, arrow_width, arrow_height;
@@ -369,32 +382,18 @@ metadata_widget_icon_triangle_draw_cb_gtk_3 (GtkWidget *widget,
x = allocation.x;
y = 0;
- gint offset = gdk_pixbuf_get_height (priv->icon_buf) / 3;
-
- // Draw player icon
- if (priv->icon_buf != NULL){
- gdk_cairo_set_source_pixbuf (cr,
- priv->icon_buf,
- x + arrow_width + 1,
- y + offset);
- cairo_paint (cr);
- }
-
// Draw triangle but only if the player is running.
- if (dbusmenu_menuitem_property_get_bool (priv->twin_item,
- DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING)){
- y += gdk_pixbuf_get_height (priv->icon_buf) / 3 + 3;
- cairo_set_line_width (cr, 1.0);
-
- cairo_move_to (cr, x, y);
- cairo_line_to (cr, x, y + arrow_height);
- cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0);
- cairo_close_path (cr);
- cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
- style->fg[gtk_widget_get_state(widget)].green/65535.0,
- style->fg[gtk_widget_get_state(widget)].blue/65535.0);
- cairo_fill (cr);
- }
+ y += gtk_image_get_pixel_size (GTK_IMAGE (priv->player_icon)) / 3 + 5;
+ cairo_set_line_width (cr, 1.0);
+
+ cairo_move_to (cr, x, y);
+ cairo_line_to (cr, x, y + arrow_height);
+ cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0);
+ cairo_close_path (cr);
+ cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
+ style->fg[gtk_widget_get_state(widget)].blue/65535.0);
+ cairo_fill (cr);
return FALSE;
}
@@ -445,7 +444,7 @@ metadata_image_expose (GtkWidget *metadata,
return FALSE;
}
clear_album_art (GTK_IMAGE(priv->album_art));
- g_string_erase (priv->old_image_path, 0, -1);
+ g_string_erase (priv->old_image_path, 0, -1);
gtk_widget_set_size_request(GTK_WIDGET(priv->album_art), 60, 60);
draw_album_art_placeholder(metadata);
return FALSE;
@@ -459,9 +458,16 @@ metadata_widget_icon_triangle_draw_cb (GtkWidget *widget,
gpointer user_data)
{
g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE);
+
MetadataWidget* meta = METADATA_WIDGET(user_data);
MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(meta);
+ gboolean running = dbusmenu_menuitem_property_get_bool (priv->twin_item,
+ DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING);
+
+ if (!running)
+ return FALSE;
+
GtkStyle *style;
cairo_t *cr;
int x, y, arrow_width, arrow_height;
@@ -478,32 +484,18 @@ metadata_widget_icon_triangle_draw_cb (GtkWidget *widget,
x = allocation.x;
y = allocation.y;
- gint offset = (allocation.height - gdk_pixbuf_get_height (priv->icon_buf)) / 2;
-
- // Draw player icon
- if (priv->icon_buf != NULL){
- gdk_cairo_set_source_pixbuf (cr,
- priv->icon_buf,
- x + arrow_width + 1,
- y + offset);
- cairo_paint (cr);
- }
-
// Draw triangle but only if the player is running.
- if (dbusmenu_menuitem_property_get_bool (priv->twin_item,
- DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING)){
- y += allocation.height/2.0 - (double)arrow_height/2.0;
- cairo_set_line_width (cr, 1.0);
-
- cairo_move_to (cr, x, y);
- cairo_line_to (cr, x, y + arrow_height);
- cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0);
- cairo_close_path (cr);
- cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
- style->fg[gtk_widget_get_state(widget)].green/65535.0,
- style->fg[gtk_widget_get_state(widget)].blue/65535.0);
- cairo_fill (cr);
- }
+ y += allocation.height/2.0 - (double)arrow_height/2.0;
+ cairo_set_line_width (cr, 1.0);
+
+ cairo_move_to (cr, x, y);
+ cairo_line_to (cr, x, y + arrow_height);
+ cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0);
+ cairo_close_path (cr);
+ cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
+ style->fg[gtk_widget_get_state(widget)].blue/65535.0);
+ cairo_fill (cr);
cairo_destroy (cr);
return FALSE;
@@ -790,27 +782,12 @@ metadata_widget_set_style(GtkWidget* metadata, GtkStyle* style)
static void
metadata_widget_set_icon (MetadataWidget *self)
{
- MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self);
-
- if (priv->icon_buf != NULL){
- #if GTK_CHECK_VERSION(3, 0, 0)
- g_object_unref(priv->icon_buf);
- #else
- gdk_pixbuf_unref(priv->icon_buf);
- #endif
- priv->icon_buf = NULL;
- }
-
- gint padding = 0;
- gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL);
- gint width, height;
- gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
-
+ MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self);
+
GString* banshee_string = g_string_new ( "banshee" );
gchar * tmp = g_utf8_strdown (dbusmenu_menuitem_property_get(priv->twin_item, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME), -1);
GString* app_panel = g_string_new (tmp);
g_free (tmp);
- GdkPixbuf* icon_buf;
// Banshee Special case!
// Not ideal but apparently we want the banshee icon to be the greyscale one
@@ -827,12 +804,9 @@ metadata_widget_set_icon (MetadataWidget *self)
dbusmenu_menuitem_property_get ( priv->twin_item,
DBUSMENU_METADATA_MENUITEM_PLAYER_ICON ));
}
- icon_buf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default(),
- app_panel->str,
- (width > height) ? width : height,
- GTK_ICON_LOOKUP_GENERIC_FALLBACK,
- NULL );
- priv->icon_buf = icon_buf;
+
+ gtk_image_set_from_icon_name(GTK_IMAGE (priv->player_icon), app_panel->str, GTK_ICON_SIZE_MENU);
+
g_string_free ( app_panel, TRUE);
g_string_free ( banshee_string, TRUE);
}