diff options
-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 | ||||
-rw-r--r-- | vapi/common-defs.vapi | 1 |
5 files changed, 68 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. diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index c083e2a..98dbd94 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -36,6 +36,7 @@ namespace DbusmenuTransport{ namespace DbusmenuTitle{ public const string MENUITEM_TYPE; public const string MENUITEM_NAME; + public const string MENUITEM_RUNNING; } [CCode (cheader_filename = "common-defs.h")] |