diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-09-02 18:04:41 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-09-02 18:04:41 +0100 |
commit | 0125f59bd6229cc8c98314b86795814ca5df6c42 (patch) | |
tree | 12d4f35061b5b9cd820ab7b8846c7fdf7070d008 /src | |
parent | 966137c8c0547f1c749fa7b13955c6f536539129 (diff) | |
download | ayatana-indicator-sound-0125f59bd6229cc8c98314b86795814ca5df6c42.tar.gz ayatana-indicator-sound-0125f59bd6229cc8c98314b86795814ca5df6c42.tar.bz2 ayatana-indicator-sound-0125f59bd6229cc8c98314b86795814ca5df6c42.zip |
active triangle now in place
Diffstat (limited to 'src')
-rw-r--r-- | src/common-defs.h | 1 | ||||
-rw-r--r-- | src/player-controller.vala | 4 | ||||
-rw-r--r-- | src/title-menu-item.vala | 7 | ||||
-rw-r--r-- | src/title-widget.c | 58 |
4 files changed, 67 insertions, 3 deletions
diff --git a/src/common-defs.h b/src/common-defs.h index e554c11..e268aaa 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -41,6 +41,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-type" #define DBUSMENU_TITLE_MENUITEM_NAME "x-canonical-sound-menu-player-title-name" +#define DBUSMENU_TITLE_MENUITEM_RUNNING "x-canonical-sound-menu-player-title-running" #define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-type" #define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-mpris:length" diff --git a/src/player-controller.vala b/src/player-controller.vala index 4d9f054..2ea9331 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -116,6 +116,8 @@ public class PlayerController : GLib.Object update_state(PlayerController.state.OFFLINE); this.custom_items[widget_order.TRANSPORT].reset(TransportMenuitem.attributes_format()); this.custom_items[widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem; + title.toggle_active_triangle(false); } public void update_layout() @@ -172,6 +174,8 @@ public class PlayerController : GLib.Object { if(this.mpris_bridge.connected() == true){ this.update_state(state.CONNECTED); + TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem; + title.toggle_active_triangle(true); } else{ this.update_state(state.DISCONNECTED); diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index ec1cc62..bb3d103 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -27,6 +27,7 @@ public class TitleMenuitem : PlayerItem { Object(item_type: MENUITEM_TYPE, owner: parent); this.property_set(MENUITEM_NAME, parent.name); + this.property_set_bool(MENUITEM_RUNNING, false); } public override void handle_event(string name, GLib.Value input_value, uint timestamp) @@ -39,7 +40,11 @@ public class TitleMenuitem : PlayerItem this.owner.mpris_bridge.expose(); } } - + + public void toggle_active_triangle(bool update) + { + this.property_set_bool(MENUITEM_RUNNING, update); + } public static HashSet<string> attributes_format() { diff --git a/src/title-widget.c b/src/title-widget.c index 04471c0..4b77cb2 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -57,6 +57,10 @@ static void title_widget_set_twin_item( TitleWidget* self, DbusmenuMenuitem* twin_item); static void title_widget_style_name_text(TitleWidget* self); +static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, + GdkEventExpose *event, + gpointer data); + G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_IMAGE_MENU_ITEM); @@ -104,9 +108,9 @@ title_widget_init (TitleWidget *self) height); gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), icon); - gtk_widget_show(icon); - gtk_widget_show(GTK_WIDGET(self)); + gtk_widget_show_all(icon); + // DEBUG GtkImageType type = gtk_image_get_storage_type(GTK_IMAGE(icon)); g_debug("gtk_image_storage_type = %i", type); @@ -163,6 +167,9 @@ title_widget_set_twin_item(TitleWidget* self, priv->twin_item = twin_item; g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); + g_signal_connect_after(G_OBJECT (self), + "expose_event", G_CALLBACK (title_widget_triangle_draw_cb), twin_item); + // Add the application name priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item, DBUSMENU_TITLE_MENUITEM_NAME)); @@ -187,6 +194,53 @@ title_widget_style_name_text(TitleWidget* self) g_free(markup); } +static gboolean +title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + GtkStyle *style; + cairo_t *cr; + int x, y, arrow_width, arrow_height; + + if (!GTK_IS_WIDGET (widget)) return FALSE; + if (!DBUSMENU_IS_MENUITEM (data)) return FALSE; + + /* render the triangle indicator only if the application is running */ + if (! dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM(data), + DBUSMENU_TITLE_MENUITEM_RUNNING)){ + return FALSE; + } + + /* get style */ + style = gtk_widget_get_style (widget); + + /* set arrow position / dimensions */ + arrow_width = 5; /* the pixel-based reference triangle is 5x9 */ + arrow_height = 9; + x = widget->allocation.x; + y = widget->allocation.y + widget->allocation.height/2.0 - (double)arrow_height/2.0; + + /* initialize cairo drawing area */ + cr = (cairo_t*) gdk_cairo_create (widget->window); + + /* set line width */ + cairo_set_line_width (cr, 1.0); + + /* cairo drawing code */ + 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); + + /* remember to destroy cairo context to avoid leaks */ + cairo_destroy (cr); + + return FALSE; +} + /** * transport_new: * @returns: a new #TitleWidget. |