From 33395ee8bff3e3d4b42bc40823eb9efe88f1611d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 28 Jun 2010 17:54:39 +0100 Subject: new playbutton for cairo drawing --- src/play-button.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ src/play-button.h | 48 ++++++++++++++++++++++++ src/transport-widget.c | 4 +- 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 src/play-button.c create mode 100644 src/play-button.h diff --git a/src/play-button.c b/src/play-button.c new file mode 100644 index 0000000..ab441ea --- /dev/null +++ b/src/play-button.c @@ -0,0 +1,100 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "play-button.h" +#include "common-defs.h" +#include + + +typedef struct _PlayButtonPrivate PlayButtonPrivate; + +struct _PlayButtonPrivate +{ + +}; + +#define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate)) + +/* Gobject boiler plate */ +static void play_button_class_init (PlayButtonClass *klass); +static void play_button_init (PlayButton *self); +static void play_button_dispose (GObject *object); +static void play_button_finalize (GObject *object); + +static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); + +G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); + + +static void +play_button_class_init (PlayButtonClass *klass) +{ + g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); + GtkWidgetClass* widget_class; + + widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->expose_event = play_button_expose; + + gobject_class->dispose = play_button_dispose; + gobject_class->finalize = play_button_finalize; + +} + +static void +play_button_init (PlayButton *self) +{ + g_debug("PlayButton::play_button_init"); +} + +static void +play_button_dispose (GObject *object) +{ + G_OBJECT_CLASS (play_button_parent_class)->dispose (object); +} + +static void +play_button_finalize (GObject *object) +{ + G_OBJECT_CLASS (play_button_parent_class)->finalize (object); +} + +static gboolean +play_button_expose (GtkWidget *button, GdkEventExpose *event) +{ +return FALSE; +} + + + +/** +* play_button_new: +* @returns: a new #PlayButton. +**/ +GtkWidget* +play_button_new() +{ + return g_object_new(PLAY_BUTTON_TYPE, NULL); +} + diff --git a/src/play-button.h b/src/play-button.h new file mode 100644 index 0000000..a1e18f7 --- /dev/null +++ b/src/play-button.h @@ -0,0 +1,48 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ +#ifndef __PLAY_BUTTON_H__ +#define __PLAY_BUTTON_H__ + +G_BEGIN_DECLS + +#define PLAY_BUTTON_TYPE (play_button_get_type ()) +#define PLAY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLAY_BUTTON_TYPE, PlayButton)) +#define PLAY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLAY_BUTTON_TYPE, PlayButtonClass)) +#define IS_PLAY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLAY_BUTTON_TYPE)) +#define IS_PLAY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLAY_BUTTON_TYPE)) +#define PLAY_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLAY_BUTTON_TYPE, PlayButtonClass)) + +typedef struct _PlayButton PlayButton; +typedef struct _PlayButtonClass PlayButtonClass; + +struct _PlayButtonClass { + GtkDrawingAreaClass parent_class; +}; + +struct _PlayButton { + GtkDrawingArea parent; +}; + +GType play_button_get_type (void); +GtkWidget* play_button_new(); + +G_END_DECLS + +#endif + diff --git a/src/transport-widget.c b/src/transport-widget.c index bc9df53..a86e37b 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -34,8 +34,8 @@ typedef struct _TransportWidgetPrivate TransportWidgetPrivate; struct _TransportWidgetPrivate { - GtkWidget* hbox; - GtkWidget* play_button; + //GtkWidget* hbox; + //GtkWidget* play_button; }; enum { -- cgit v1.2.3 From 0e616c323a678732dbd593d0d430507e099fda9f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 28 Jun 2010 21:12:07 +0100 Subject: moving in the right direction --- src/Makefile.am | 2 + src/play-button.c | 82 +++++++++++++++++++++++++++++---- src/play-button.h | 2 + src/sound-service.c | 4 +- src/transport-widget.c | 123 +++++++++---------------------------------------- 5 files changed, 102 insertions(+), 111 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b33107d..21212d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,8 @@ libsoundmenu_la_SOURCES = \ transport-widget.h \ metadata-widget.c \ metadata-widget.h \ + play-button.c \ + play-button.h \ indicator-sound.c \ dbus-shared-names.h \ sound-service-client.h diff --git a/src/play-button.c b/src/play-button.c index ab441ea..774b1e6 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -21,10 +21,8 @@ with this program. If not, see . #include "config.h" #endif -#include +#include #include "play-button.h" -#include "common-defs.h" -#include typedef struct _PlayButtonPrivate PlayButtonPrivate; @@ -43,6 +41,7 @@ static void play_button_dispose (GObject *object); static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); +static void draw (GtkWidget* button, cairo_t *cr); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -50,22 +49,32 @@ G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); static void play_button_class_init (PlayButtonClass *klass) { - g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); - GtkWidgetClass* widget_class; + + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); + g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); widget_class->expose_event = play_button_expose; gobject_class->dispose = play_button_dispose; gobject_class->finalize = play_button_finalize; - } static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); + GtkAllocation alloc; + + alloc.width = 100; + alloc.height = 100; + alloc.x = 0; + alloc.y = 0; + + gtk_widget_set_allocation(GTK_WIDGET(self), + &alloc); + //g_free(alloc); } static void @@ -83,11 +92,66 @@ play_button_finalize (GObject *object) static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event) { -return FALSE; + cairo_t *cr; + cr = gdk_cairo_create (button->window); + cairo_rectangle (cr, + event->area.x, event->area.y, + event->area.width, event->area.height); + + cairo_clip(cr); + draw (button, cr); + cairo_destroy (cr); + return FALSE; } +static void +draw (GtkWidget* button, cairo_t *cr) +{ + double x, y; + double radius; + int i; + + x = button->allocation.x + button->allocation.width / 2; + y = button->allocation.y + button->allocation.height / 2; + radius = MIN (button->allocation.width / 2, + button->allocation.height / 2) - 5; + + /* button back */ + cairo_arc (cr, x, y, radius, 0, 2 * M_PI); + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_fill_preserve (cr); + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_stroke (cr); + + /* button ticks */ + for (i = 0; i < 12; i++) + { + int inset; + + cairo_save (cr); /* stack-pen-size */ + + if (i % 3 == 0) + { + inset = 0.2 * radius; + } + else + { + inset = 0.1 * radius; + cairo_set_line_width (cr, 0.5 * + cairo_get_line_width (cr)); + } + + cairo_move_to (cr, + x + (radius - inset) * cos (i * M_PI / 6), + y + (radius - inset) * sin (i * M_PI / 6)); + cairo_line_to (cr, + x + radius * cos (i * M_PI / 6), + y + radius * sin (i * M_PI / 6)); + cairo_stroke (cr); + cairo_restore (cr); /* stack-pen-size */ + } +} - /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/play-button.h b/src/play-button.h index a1e18f7..4f7cdd0 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -19,6 +19,8 @@ with this program. If not, see . #ifndef __PLAY_BUTTON_H__ #define __PLAY_BUTTON_H__ +#include + G_BEGIN_DECLS #define PLAY_BUTTON_TYPE (play_button_get_type ()) diff --git a/src/sound-service.c b/src/sound-service.c index bcdac07..ea04e4b 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -45,8 +45,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-widget.c b/src/transport-widget.c index a86e37b..07e7402 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -25,8 +25,8 @@ with this program. If not, see . #include "transport-widget.h" #include "common-defs.h" #include +#include "play-button.h" -// TODO: think about leakage: ted ! static DbusmenuMenuitem* twin_item; @@ -34,20 +34,10 @@ typedef struct _TransportWidgetPrivate TransportWidgetPrivate; struct _TransportWidgetPrivate { - //GtkWidget* hbox; - //GtkWidget* play_button; + GtkWidget* hbox; + GtkWidget* play_button; }; -enum { - PLAY, - PAUSE, - NEXT, - PREVIOUS, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - #define TRANSPORT_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRANSPORT_WIDGET_TYPE, TransportWidgetPrivate)) /* Gobject boiler plate */ @@ -60,21 +50,14 @@ static void transport_widget_finalize (GObject *object); static gboolean transport_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); static gboolean transport_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event); -static void transport_widget_play_clicked (GtkWidget* button, - TransportWidget* self); - + GdkEventButton *event); static void transport_widget_property_update(DbusmenuMenuitem* item, - gchar * property, - GValue * value, - gpointer userdata); -// utility methods -static gchar* transport_widget_toggle_play_label(gint state); + gchar * property, + GValue * value, + gpointer userdata); G_DEFINE_TYPE (TransportWidget, transport_widget, GTK_TYPE_MENU_ITEM); - - static void transport_widget_class_init (TransportWidgetClass *klass) { @@ -84,45 +67,12 @@ transport_widget_class_init (TransportWidgetClass *klass) menu_item_class->hide_on_activate = FALSE; widget_class->button_press_event = transport_widget_button_press_event; - widget_class->button_release_event = transport_widget_button_release_event; - + widget_class->button_release_event = transport_widget_button_release_event; g_type_class_add_private (klass, sizeof (TransportWidgetPrivate)); gobject_class->dispose = transport_widget_dispose; gobject_class->finalize = transport_widget_finalize; - signals[PLAY] = g_signal_new ("play", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[PAUSE] = g_signal_new ("pause", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - - signals[NEXT] = g_signal_new ("next", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[PREVIOUS] = g_signal_new ("previous", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); } static void @@ -131,19 +81,17 @@ transport_widget_init (TransportWidget *self) g_debug("TransportWidget::transport_widget_init"); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(self); - GtkWidget *hbox; + GtkWidget* hbox; hbox = gtk_hbox_new(TRUE, 2); - gchar* symbol = transport_widget_toggle_play_label(dbusmenu_menuitem_property_get_int(twin_item, DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE)); - priv->play_button = gtk_button_new_with_label(symbol); - //g_free(symbol); - gtk_box_pack_start (GTK_BOX (hbox), priv->play_button, FALSE, TRUE, 0); priv->hbox = hbox; + + priv->play_button = play_button_new(); + + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); - - g_signal_connect(priv->play_button, "clicked", G_CALLBACK(transport_widget_play_clicked), self); gtk_container_add (GTK_CONTAINER (self), priv->hbox); @@ -172,28 +120,17 @@ transport_widget_button_press_event (GtkWidget *menuitem, return FALSE; } - TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - - gtk_widget_event (priv->hbox, (GdkEvent*)event); - gboolean state = g_ascii_strcasecmp(gtk_button_get_label(GTK_BUTTON(priv->play_button)), ">") == 0; + //TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label((gint)state)); - GValue value = {0}; - g_value_init(&value, G_TYPE_BOOLEAN); - g_debug("TransportWidget::menu_press_event - going to send value %i", state); - - g_value_set_boolean(&value, state); - dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); + //GValue value = {0}; + //g_value_init(&value, G_TYPE_BOOLEAN); + //g_debug("TransportWidget::menu_press_event - going to send value %i", state); + //g_value_set_boolean(&value, state); + //dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); return TRUE; } -static void -transport_widget_play_clicked(GtkWidget* button, - TransportWidget* self) -{ - g_debug("Transport_widget_play_clicked"); -} static gboolean transport_widget_button_release_event (GtkWidget *menuitem, @@ -203,9 +140,6 @@ transport_widget_button_release_event (GtkWidget *menuitem, if(IS_TRANSPORT_WIDGET(menuitem) == FALSE){ return FALSE; } - - TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - gtk_widget_event (priv->hbox, (GdkEvent*)event); return TRUE; } @@ -219,23 +153,12 @@ transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) { g_debug("transport_widget_update_state - with property %s", property); - int update_value = g_value_get_int(value); - g_debug("transport_widget_update_state - with value %i", update_value); + //int update_value = g_value_get_int(value); + //g_debug("transport_widget_update_state - with value %i", update_value); - TransportWidget* bar = (TransportWidget*)userdata; - TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar); + //TransportWidget* bar = (TransportWidget*)userdata; + //TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar); - gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label(update_value)); -} - -// will be needed for image swapping -static gchar* transport_widget_toggle_play_label(int play_state) -{ - gchar* label = ">"; - if(play_state == 1){ - label = "||"; - } - return label; } /** -- cgit v1.2.3 From a9186ea33c957a90cb4bfea464244602f4637b37 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 10:16:45 +0100 Subject: more debug --- src/play-button.c | 27 ++++++++++++++++----------- src/transport-widget.c | 10 ++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 774b1e6..8962377 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -65,16 +65,6 @@ static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); - GtkAllocation alloc; - - alloc.width = 100; - alloc.height = 100; - alloc.x = 0; - alloc.y = 0; - - gtk_widget_set_allocation(GTK_WIDGET(self), - &alloc); - //g_free(alloc); } static void @@ -92,9 +82,24 @@ play_button_finalize (GObject *object) static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event) { + GtkAllocation alloc; + + alloc.width = 200; + alloc.height = 600; + alloc.x = 100; + alloc.y = 100; + + gtk_widget_set_allocation(GTK_WIDGET(button), + &alloc); + cairo_t *cr; cr = gdk_cairo_create (button->window); - cairo_rectangle (cr, + + g_debug("PlayButton::Draw - width = %i", button->allocation.width); + g_debug("PlayButton::Draw - event->area.width = %i", event->area.width); + g_debug("PlayButton::Draw - event->area.x = %i", event->area.x); + + cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height); diff --git a/src/transport-widget.c b/src/transport-widget.c index 07e7402..6ff3c04 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -89,6 +89,16 @@ transport_widget_init (TransportWidget *self) priv->play_button = play_button_new(); + GtkAllocation alloc; + + alloc.width = 200; + alloc.height = 600; + alloc.x = 100; + alloc.y = 0; + + gtk_widget_set_allocation(GTK_WIDGET(priv->play_button), + &alloc); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); -- cgit v1.2.3 From 914519bfe7983f250db3bd83a3f4545aa7071d66 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 11:31:22 +0100 Subject: updates --- src/play-button.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 8962377..6b67042 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -51,11 +51,11 @@ play_button_class_init (PlayButtonClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); + //GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); - widget_class->expose_event = play_button_expose; + //widget_class->expose_event = play_button_expose; gobject_class->dispose = play_button_dispose; gobject_class->finalize = play_button_finalize; @@ -64,7 +64,8 @@ play_button_class_init (PlayButtonClass *klass) static void play_button_init (PlayButton *self) { - g_debug("PlayButton::play_button_init"); + g_debug("PlayButton::play_button_init"); + g_signal_connect(GTK_WIDGET(self), "expose-event", G_CALLBACK (play_button_expose), NULL); } static void @@ -86,8 +87,8 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) alloc.width = 200; alloc.height = 600; - alloc.x = 100; - alloc.y = 100; + alloc.x = 10; + alloc.y = 10; gtk_widget_set_allocation(GTK_WIDGET(button), &alloc); @@ -103,7 +104,7 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) event->area.x, event->area.y, event->area.width, event->area.height); - cairo_clip(cr); + //cairo_clip(cr); draw (button, cr); cairo_destroy (cr); return FALSE; @@ -155,6 +156,7 @@ draw (GtkWidget* button, cairo_t *cr) cairo_stroke (cr); cairo_restore (cr); /* stack-pen-size */ } + cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } /** @@ -164,6 +166,8 @@ draw (GtkWidget* button, cairo_t *cr) GtkWidget* play_button_new() { - return g_object_new(PLAY_BUTTON_TYPE, NULL); + GtkWidget* widget = g_object_new(PLAY_BUTTON_TYPE, NULL); + gtk_widget_set_app_paintable (widget, TRUE); + return widget; } -- cgit v1.2.3 From 8dc783c9943dbb1a80579d6f7e70492769b67717 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 14:42:14 +0100 Subject: updates --- src/play-button.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 6b67042..e798668 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -40,7 +40,7 @@ static void play_button_init (PlayButton *self); static void play_button_dispose (GObject *object); static void play_button_finalize (GObject *object); -static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); +static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata); static void draw (GtkWidget* button, cairo_t *cr); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -81,7 +81,7 @@ play_button_finalize (GObject *object) } static gboolean -play_button_expose (GtkWidget *button, GdkEventExpose *event) +play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata) { GtkAllocation alloc; @@ -123,7 +123,7 @@ draw (GtkWidget* button, cairo_t *cr) button->allocation.height / 2) - 5; /* button back */ - cairo_arc (cr, x, y, radius, 0, 2 * M_PI); + cairo_arc (cr, x, y, radius, 0, 2 * G_PI); cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); @@ -148,11 +148,11 @@ draw (GtkWidget* button, cairo_t *cr) } cairo_move_to (cr, - x + (radius - inset) * cos (i * M_PI / 6), - y + (radius - inset) * sin (i * M_PI / 6)); + x + (radius - inset) * cos (i * G_PI / 6), + y + (radius - inset) * sin (i * G_PI / 6)); cairo_line_to (cr, - x + radius * cos (i * M_PI / 6), - y + radius * sin (i * M_PI / 6)); + x + radius * cos (i * G_PI / 6), + y + radius * sin (i * G_PI / 6)); cairo_stroke (cr); cairo_restore (cr); /* stack-pen-size */ } -- cgit v1.2.3 From 2d1c2058a7384a6dc0d4c1b900e223b6905df4c6 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 21:52:56 +0100 Subject: launching apps now working --- src/music-player-bridge.vala | 35 ++++++++++++++++++++++++++--------- src/sound-service.c | 4 ++-- src/transport-menu-item.vala | 1 - 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 6fc9032..07eef2a 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -42,15 +42,22 @@ public class MusicPlayerBridge : GLib.Object listener.server_removed.connect(on_server_removed); listener.server_count_changed.connect(on_server_count_changed); } - // Alpha 2 not in use ... yet. + private void try_to_add_inactive_familiar_clients(){ // for now just use one of the entries. int count = 0; foreach(string app in this.playersDB.records()){ if(count == 0){ debug("we have found %s", app); + if(app == null){ + debug("moving on to next player"); + continue; + } string[] bits = app.split("/"); - + if(bits.length < 2){ + continue; + } + debug("trying to dig deeper %s", app); try{ string app_name = bits[bits.length -1].split(".")[0]; debug("we have found %s", app_name); @@ -58,9 +65,11 @@ public class MusicPlayerBridge : GLib.Object app_name, false); this.registered_clients.set(app_name, ctrl); - DesktopAppInfo info = new DesktopAppInfo.from_filename(app_name); - string desc = info.get_display_name(); - debug("description from app %s", desc); + DesktopAppInfo info = new DesktopAppInfo.from_filename(app); + GLib.AppInfo app_info = info as GLib.AppInfo; + + debug("Display name = %s", app_info.get_display_name()); + app_info.launch(null, null); count += 1; } catch(Error er){ @@ -93,7 +102,8 @@ public class MusicPlayerBridge : GLib.Object if (root_menu != null && client_name != null){ registered_clients[client_name].vanish(); registered_clients.remove(client_name); - debug("Successively removed menu_item for client %s from registered_clients", client_name); + debug("Successively removed menu_item for client %s from registered_clients", + client_name); } } @@ -109,15 +119,22 @@ public class MusicPlayerBridge : GLib.Object private void desktop_info_callback(Indicate.ListenerServer server, owned string path, void* data) { - debug("we got a desktop file path hopefully: %s", path); MusicPlayerBridge bridge = data as MusicPlayerBridge; - bridge.playersDB.insert(path); + // Not the most secure validation + // TODO revisit validation mechanism + if(path.contains("/")){ + debug("About to store desktop file path: %s", path); + bridge.playersDB.insert(path); + } + else{ + debug("Ignoring desktop file path: %s", path); + } } public void set_root_menu_item(Dbusmenu.Menuitem menu) { this.root_menu = menu; - //try_to_add_inactive_familiar_clients(); + try_to_add_inactive_familiar_clients(); } public void on_server_count_changed(Indicate.ListenerServer object, uint i) diff --git a/src/sound-service.c b/src/sound-service.c index 8f4e941..a5f3941 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -43,8 +43,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 264e153..e0d241e 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -27,7 +27,6 @@ public class TransportMenuitem : PlayerItem public TransportMenuitem() { this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE); - debug("transport on the vala side"); } public void change_play_state(int state) -- cgit v1.2.3 From edac78eadc5ddceb17b93bffa101eeffbab4437c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 30 Jun 2010 18:02:53 +0100 Subject: correct startup behaviour in place --- src/familiar-players-db.vala | 3 +- src/music-player-bridge.vala | 74 ++++++++++++++++++++++++++++---------------- src/player-controller.vala | 25 ++++++++++----- 3 files changed, 67 insertions(+), 35 deletions(-) diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala index 88bc01f..b83caa3 100644 --- a/src/familiar-players-db.vala +++ b/src/familiar-players-db.vala @@ -143,7 +143,8 @@ public class FamiliarPlayersDB : GLib.Object public bool already_familiar(string desktop) { - return this.players_DB.get(desktop); + debug("playerDB->already_familiar - result %s", this.players_DB.keys.contains(desktop).to_string()); + return this.players_DB.keys.contains(desktop); } public Gee.Set records() diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 07eef2a..84bf3df 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -44,32 +44,26 @@ public class MusicPlayerBridge : GLib.Object } private void try_to_add_inactive_familiar_clients(){ - // for now just use one of the entries. int count = 0; foreach(string app in this.playersDB.records()){ if(count == 0){ - debug("we have found %s", app); if(app == null){ - debug("moving on to next player"); + warning("App string in keyfile is null therefore moving on to next player"); continue; } - string[] bits = app.split("/"); - if(bits.length < 2){ - continue; - } - debug("trying to dig deeper %s", app); try{ - string app_name = bits[bits.length -1].split(".")[0]; - debug("we have found %s", app_name); - PlayerController ctrl = new PlayerController(this.root_menu, - app_name, - false); - this.registered_clients.set(app_name, ctrl); DesktopAppInfo info = new DesktopAppInfo.from_filename(app); + if(info == null){ + warning("Could not create a desktopappinfo instance from app: %s", app); + continue; + } GLib.AppInfo app_info = info as GLib.AppInfo; - - debug("Display name = %s", app_info.get_display_name()); - app_info.launch(null, null); + PlayerController ctrl = new PlayerController(this.root_menu, + app_info.get_name(), + app_info); + ctrl.set("active", false); + this.registered_clients.set(app_info.get_name().down().strip(), ctrl); + debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip()); count += 1; } catch(Error er){ @@ -84,13 +78,24 @@ public class MusicPlayerBridge : GLib.Object { debug("MusicPlayerBridge -> on_server_added with value %s", type); if(server_is_not_of_interest(type)) return; - string client_name = type.split(".")[1]; + string client_name = type.split(".")[1]; if (root_menu != null && client_name != null){ - listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; - this.listener.server_get_desktop(object, cb, this); - PlayerController ctrl = new PlayerController(root_menu, client_name, true); - registered_clients.set(client_name, ctrl); - debug("client of name %s has successfully registered with us", client_name); + // If we have an instance already for this player, ensure it is switched to active + if(this.registered_clients.keys.contains(client_name)){ + debug("It figured out that it already has an instance for this player already"); + this.registered_clients[client_name].set("active", true); + } + //else init a new one + else{ + PlayerController ctrl = new PlayerController(root_menu, client_name); + registered_clients.set(client_name, ctrl); + debug("New Client of name %s has successfully registered with us", client_name); + } + // irregardless check that it has a desktop file if not kick off a request for it + if(this.registered_clients[client_name].app_info == null){ + listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; + this.listener.server_get_desktop(object, cb, this); + } } } @@ -122,12 +127,18 @@ public class MusicPlayerBridge : GLib.Object MusicPlayerBridge bridge = data as MusicPlayerBridge; // Not the most secure validation // TODO revisit validation mechanism - if(path.contains("/")){ - debug("About to store desktop file path: %s", path); + if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ + debug("About to store desktop file path: %s", path); bridge.playersDB.insert(path); + AppInfo? app_info = create_app_info(path); + if(app_info != null){ + PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; + ctrl.set("app_info", app_info); + debug("successfully created appinfo from path and set it on the respective instance"); + } } else{ - debug("Ignoring desktop file path: %s", path); + debug("Ignoring desktop file path because its either invalid of the db cache file has it already: %s", path); } } @@ -156,6 +167,17 @@ public class MusicPlayerBridge : GLib.Object debug("MusicPlayerBridge -> indicator_modified with vale %s", s ); } + public static AppInfo? create_app_info(string path) + { + DesktopAppInfo info = new DesktopAppInfo.from_filename(path); + if(path == null){ + warning("Could not create a desktopappinfo instance from app: %s", path); + return null; + } + GLib.AppInfo app_info = info as GLib.AppInfo; + return app_info; + } + } diff --git a/src/player-controller.vala b/src/player-controller.vala index 0d8dc01..dfc2659 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -27,19 +27,20 @@ public class PlayerController : GLib.Object private const int TRANSPORT = 3; private Dbusmenu.Menuitem root_menu; - private string name; - private bool is_active; + public string name { get; set;} + public bool active { get; set;} public ArrayList custom_items; private MprisController mpris_adaptor; - private string desktop_path; - - public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active) + public AppInfo app_info { get; set;} + + public PlayerController(Dbusmenu.Menuitem root, string client_name, AppInfo? info = null) { this.root_menu = root; this.name = format_client_name(client_name.strip()); - this.is_active = active; this.custom_items = new ArrayList(); + this.app_info = info; self_construct(); + //app_info.launch(null, null); // Temporary scenario to handle both v1 and v2 of MPRIS. if(this.name == "Vlc"){ @@ -61,6 +62,14 @@ public class PlayerController : GLib.Object root_menu.child_delete(item); } } + + //public void switch_active(bool active){ + // this.is_active = active; + //} + + //public bool has_app_info(){ + // return (this.app_info != null); + //} private bool self_construct() { @@ -84,7 +93,7 @@ public class PlayerController : GLib.Object } return true; } - + private static string format_client_name(string client_name) { string formatted = client_name; @@ -94,5 +103,5 @@ public class PlayerController : GLib.Object } return formatted; } - + } \ No newline at end of file -- cgit v1.2.3 From f3fc28d63254fe90de5472352256e7df415ab886 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 30 Jun 2010 18:20:45 +0100 Subject: highlighting sorted and a start towards the cairo stuff --- src/metadata-widget.c | 13 ++++++++++++- src/play-button.c | 37 +++++++++++++++++++------------------ src/transport-widget.c | 21 +++++++++++---------- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/metadata-widget.c b/src/metadata-widget.c index ce3bcd1..28a3839 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -47,6 +47,8 @@ static void metadata_widget_class_init (MetadataWidgetClass *klass); static void metadata_widget_init (MetadataWidget *self); static void metadata_widget_dispose (GObject *object); static void metadata_widget_finalize (GObject *object); +static gboolean metadata_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); + // keyevent consumers static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); @@ -74,7 +76,7 @@ metadata_widget_class_init (MetadataWidgetClass *klass) widget_class->button_press_event = metadata_widget_button_press_event; widget_class->button_release_event = metadata_widget_button_release_event; - + widget_class->expose_event = metadata_widget_expose_event; g_type_class_add_private (klass, sizeof (MetadataWidgetPrivate)); gobject_class->dispose = metadata_widget_dispose; @@ -152,6 +154,15 @@ metadata_widget_init (MetadataWidget *self) } +static gboolean +metadata_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) +{ + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); + + gtk_container_propagate_expose(GTK_CONTAINER(widget), priv->hbox, event); + return TRUE; +} + static void metadata_widget_dispose (GObject *object) { diff --git a/src/play-button.c b/src/play-button.c index e798668..d79161b 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -40,7 +40,7 @@ static void play_button_init (PlayButton *self); static void play_button_dispose (GObject *object); static void play_button_finalize (GObject *object); -static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata); +static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -51,11 +51,11 @@ play_button_class_init (PlayButtonClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - //GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); + GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); - //widget_class->expose_event = play_button_expose; + widget_class->expose_event = play_button_expose; gobject_class->dispose = play_button_dispose; gobject_class->finalize = play_button_finalize; @@ -65,7 +65,7 @@ static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); - g_signal_connect(GTK_WIDGET(self), "expose-event", G_CALLBACK (play_button_expose), NULL); + gtk_widget_set_size_request(GTK_WIDGET(self), 50, 50); } static void @@ -81,18 +81,8 @@ play_button_finalize (GObject *object) } static gboolean -play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata) +play_button_expose (GtkWidget *button, GdkEventExpose *event) { - GtkAllocation alloc; - - alloc.width = 200; - alloc.height = 600; - alloc.x = 10; - alloc.y = 10; - - gtk_widget_set_allocation(GTK_WIDGET(button), - &alloc); - cairo_t *cr; cr = gdk_cairo_create (button->window); @@ -110,14 +100,23 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata) return FALSE; } + static void draw (GtkWidget* button, cairo_t *cr) { - double x, y; + double x=50; + double y=30; double radius; - int i; - x = button->allocation.x + button->allocation.width / 2; + int rect_width = 100; + int rect_height = 50; + + cairo_move_to(cr, x+radius, y); + cairo_line_to(cr, x+rect_width-radius, y); + cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); + cairo_line_to(x+w,y+h-r) + cairo_curve_to(cr, + x = button->allocation.x - button->allocation.width / 2; y = button->allocation.y + button->allocation.height / 2; radius = MIN (button->allocation.width / 2, button->allocation.height / 2) - 5; @@ -159,6 +158,8 @@ draw (GtkWidget* button, cairo_t *cr) cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } + + /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/transport-widget.c b/src/transport-widget.c index 6ff3c04..10c564b 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -45,6 +45,7 @@ static void transport_widget_class_init (TransportWidgetClass *klass); static void transport_widget_init (TransportWidget *self); static void transport_widget_dispose (GObject *object); static void transport_widget_finalize (GObject *object); +static gboolean transport_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); /* UI and dbusmenu callbacks */ static gboolean transport_widget_button_press_event (GtkWidget *menuitem, @@ -68,6 +69,7 @@ transport_widget_class_init (TransportWidgetClass *klass) menu_item_class->hide_on_activate = FALSE; widget_class->button_press_event = transport_widget_button_press_event; widget_class->button_release_event = transport_widget_button_release_event; + widget_class->expose_event = transport_widget_expose_event; g_type_class_add_private (klass, sizeof (TransportWidgetPrivate)); gobject_class->dispose = transport_widget_dispose; @@ -89,16 +91,6 @@ transport_widget_init (TransportWidget *self) priv->play_button = play_button_new(); - GtkAllocation alloc; - - alloc.width = 200; - alloc.height = 600; - alloc.x = 100; - alloc.y = 0; - - gtk_widget_set_allocation(GTK_WIDGET(priv->play_button), - &alloc); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); @@ -120,6 +112,15 @@ transport_widget_finalize (GObject *object) G_OBJECT_CLASS (transport_widget_parent_class)->finalize (object); } +static gboolean +transport_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) +{ + //TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(widget); + //gtk_container_propagate_expose(GTK_CONTAINER(widget),priv->play_button, event); + return TRUE; +} + + /* keyevents */ static gboolean transport_widget_button_press_event (GtkWidget *menuitem, -- cgit v1.2.3 From 40a1f7e531f1a8d841fc855f2ba16b9370a272be Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 1 Jul 2010 13:29:06 +0100 Subject: outline drawn --- src/play-button.c | 71 ++++++++++++++++++-------------------------------- src/transport-widget.c | 4 ++- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index d79161b..7db2a38 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -65,7 +65,7 @@ static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); - gtk_widget_set_size_request(GTK_WIDGET(self), 50, 50); + gtk_widget_set_size_request(GTK_WIDGET(self), 200, 80); } static void @@ -94,7 +94,7 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) event->area.x, event->area.y, event->area.width, event->area.height); - //cairo_clip(cr); + cairo_clip(cr); draw (button, cr); cairo_destroy (cr); return FALSE; @@ -104,58 +104,37 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) static void draw (GtkWidget* button, cairo_t *cr) { - double x=50; - double y=30; - double radius; + int rect_width = 150; + int rect_height = 30; + + double x= button->allocation.width/2 - rect_width/2; + double y= button->allocation.height/2 -rect_height/2; + double radius=60; - int rect_width = 100; - int rect_height = 50; cairo_move_to(cr, x+radius, y); cairo_line_to(cr, x+rect_width-radius, y); cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); - cairo_line_to(x+w,y+h-r) - cairo_curve_to(cr, - x = button->allocation.x - button->allocation.width / 2; - y = button->allocation.y + button->allocation.height / 2; - radius = MIN (button->allocation.width / 2, - button->allocation.height / 2) - 5; - - /* button back */ - cairo_arc (cr, x, y, radius, 0, 2 * G_PI); + + cairo_line_to(cr, x + rect_width, y + rect_height - radius); + cairo_curve_to(cr, x + rect_width, y + rect_height, x + rect_width, + y + rect_height, x + rect_width - radius, y + rect_height); + + cairo_line_to(cr, x + radius, y + rect_height); + cairo_curve_to(cr, x, y + rect_height, x, y+rect_height, x, y+rect_height-radius); + cairo_line_to(cr, x, y + radius); + cairo_curve_to(cr, x, y, x, y, x + radius, y); + + cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/2, 0, 2 * M_PI); + cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill_preserve (cr); - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_stroke (cr); - /* button ticks */ - for (i = 0; i < 12; i++) - { - int inset; - - cairo_save (cr); /* stack-pen-size */ - - if (i % 3 == 0) - { - inset = 0.2 * radius; - } - else - { - inset = 0.1 * radius; - cairo_set_line_width (cr, 0.5 * - cairo_get_line_width (cr)); - } - - cairo_move_to (cr, - x + (radius - inset) * cos (i * G_PI / 6), - y + (radius - inset) * sin (i * G_PI / 6)); - cairo_line_to (cr, - x + radius * cos (i * G_PI / 6), - y + radius * sin (i * G_PI / 6)); - cairo_stroke (cr); - cairo_restore (cr); /* stack-pen-size */ - } - cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); + // cr.fill() + // cr.stroke() + //cairo_set_source_rgb (cr, 1, 1, 1); + //cairo_stroke (cr); + //cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } diff --git a/src/transport-widget.c b/src/transport-widget.c index 10c564b..ae01c0f 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -74,7 +74,6 @@ transport_widget_class_init (TransportWidgetClass *klass) gobject_class->dispose = transport_widget_dispose; gobject_class->finalize = transport_widget_finalize; - } static void @@ -87,6 +86,9 @@ transport_widget_init (TransportWidget *self) hbox = gtk_hbox_new(TRUE, 2); + //GtkAllocation alloc; + //gtk_widget_get_allocation(GTK_WIDGET(self), &alloc); + //g_debug("allocation width for the transport widget %i", alloc.width); priv->hbox = hbox; priv->play_button = play_button_new(); -- cgit v1.2.3 From b1d159ec617f067753cd3a012697e94c592e2b88 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 1 Jul 2010 18:30:00 +0100 Subject: background working correctly --- src/metadata-widget.c | 6 +++--- src/play-button.c | 52 +++++++++++++++++++++++++++++++++++++------------- src/transport-widget.c | 1 - 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 28a3839..bb9c8a8 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -113,7 +113,7 @@ metadata_widget_init (MetadataWidget *self) gtk_misc_set_alignment(GTK_MISC(artist), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(artist), 20); - gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_END); + gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_MIDDLE); priv->artist_label = artist; // Style it up. style_artist_text(self); @@ -124,7 +124,7 @@ metadata_widget_init (MetadataWidget *self) DBUSMENU_METADATA_MENUITEM_TEXT_TITLE)); gtk_misc_set_alignment(GTK_MISC(piece), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(piece), 16); - gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_END); + gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_MIDDLE); priv->piece_label = piece; // Style it up. style_title_text(self); @@ -135,7 +135,7 @@ metadata_widget_init (MetadataWidget *self) DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM)); gtk_misc_set_alignment(GTK_MISC(container), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(container), 20); - gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_END); + gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_MIDDLE); priv->container_label = container; // Style it up. style_album_text(self); diff --git a/src/play-button.c b/src/play-button.c index 7db2a38..24eea0d 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -42,6 +42,8 @@ static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); +static void play_button_draw_background(cairo_t* cr, double x, double y, int width, int height, double radius); + G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -104,14 +106,47 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) static void draw (GtkWidget* button, cairo_t *cr) { + int rect_width = 150; int rect_height = 30; - + double radius=40; double x= button->allocation.width/2 - rect_width/2; double y= button->allocation.height/2 -rect_height/2; - double radius=60; + + //cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + //cairo_paint(cr); + + play_button_draw_background(cr, x, y, rect_width, rect_height, radius); + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0); + cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 256.0); + cairo_pattern_add_color_stop_rgba (pat, 0.4, 256, 256, 256, 160.0); + cairo_pattern_add_color_stop_rgba (pat, 0.6, 256, 256, 256, 256.0); + + cairo_set_source (cr, pat); + cairo_fill (cr); + + //int factor = 10; + //cairo_reset_clip(cr); + play_button_draw_background(cr, x+2.5, y+2.5, rect_width-5, rect_height-5, radius-5); + //cairo_translate(cr, 50, 50); + cairo_set_source_rgba (cr, 256,256,256, 15); + cairo_fill(cr); + //cairo_reset_clip(cr); + cairo_pattern_destroy (pat); + + // cr.fill() + // cr.stroke() + //cairo_set_source_rgb (cr, 1, 1, 1); + //cairo_stroke (cr); + cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); +} + +static void +play_button_draw_background(cairo_t* cr, double x, double y, int rect_width, int rect_height, double radius) +{ cairo_move_to(cr, x+radius, y); cairo_line_to(cr, x+rect_width-radius, y); cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); @@ -125,20 +160,11 @@ draw (GtkWidget* button, cairo_t *cr) cairo_line_to(cr, x, y + radius); cairo_curve_to(cr, x, y, x, y, x + radius, y); - cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/2, 0, 2 * M_PI); - - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_fill_preserve (cr); - - // cr.fill() - // cr.stroke() - //cairo_set_source_rgb (cr, 1, 1, 1); - //cairo_stroke (cr); - //cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); + cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/1.7, 0, 2 * M_PI); + cairo_close_path(cr); } - /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/transport-widget.c b/src/transport-widget.c index ae01c0f..648370f 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -92,7 +92,6 @@ transport_widget_init (TransportWidget *self) priv->hbox = hbox; priv->play_button = play_button_new(); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); -- cgit v1.2.3 From 1954771a97e724e53754100c0eef84ae0efeec3f Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 2 Jul 2010 10:01:31 +0200 Subject: If gnome-volume-control is not available, try xfce4-mixer --- src/dbus-menu-manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index d19bfbb..a68976a 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -172,7 +172,8 @@ Bring up the gnome volume preferences dialog static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data) { GError * error = NULL; - if (!g_spawn_command_line_async("gnome-volume-control", &error)) { + if (!g_spawn_command_line_async("gnome-volume-control", &error) && + !g_spawn_command_line_async("xfce4-mixer", &error)) g_warning("Unable to show dialog: %s", error->message); g_error_free(error); } -- cgit v1.2.3 From d79472daaf580062397ef688766cbe48b2cbd992 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 2 Jul 2010 20:04:15 +0100 Subject: cairo is taking some time --- src/play-button.c | 201 ++++++++++++++++++++++++++++++++++++++----------- src/play-button.h | 1 + src/transport-widget.c | 8 +- 3 files changed, 162 insertions(+), 48 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 24eea0d..84b29cc 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -29,7 +29,11 @@ typedef struct _PlayButtonPrivate PlayButtonPrivate; struct _PlayButtonPrivate { - + GdkColor background_colour_fg; + GdkColor background_colour_bg_dark; + GdkColor background_colour_bg_light; + GdkColor foreground_colour_fg; + GdkColor foreground_colour_bg; }; #define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate)) @@ -42,9 +46,15 @@ static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); -static void play_button_draw_background(cairo_t* cr, double x, double y, int width, int height, double radius); +static void play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double width, double height, double p_radius); +static void play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); +static void play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); + + +//static void play_button_draw_play_symbol(cairo_t* cr, double x, double y); +static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y); + - G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -103,68 +113,170 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) } +void +play_button_set_style(GtkWidget* button, GtkStyle* style) +{ + PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); + priv->background_colour_fg = style->fg[GTK_STATE_NORMAL]; + priv->background_colour_bg_dark = style->bg[GTK_STATE_NORMAL]; + priv->background_colour_bg_light = style->base[GTK_STATE_NORMAL]; + priv->foreground_colour_fg = style->fg[GTK_STATE_PRELIGHT]; + priv->foreground_colour_bg = style->bg[GTK_STATE_NORMAL]; +} + static void draw (GtkWidget* button, cairo_t *cr) { - int rect_width = 150; - int rect_height = 30; - double radius=40; - double x= button->allocation.width/2 - rect_width/2; - double y= button->allocation.height/2 -rect_height/2; + //PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); + double rect_width = 115; + double rect_height = 28; + double p_radius = 21; + double y = 15; + double x = 22; + //double radius=35; + //double x= button->allocation.width/2 - rect_width/2; + //double y= button->allocation.height/2 -rect_height/2; + + // Draw the outside drop shadow background + play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); + + // Draw the inside drop shadow background + gint offset = 1.5; + play_button_draw_background_shadow_2(button, cr, x+ offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); - //cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); - //cairo_paint(cr); + offset = 3; + // Draw the inside actual background + play_button_draw_background(button, cr, x+offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); + + play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x, rect_height/5 +y ); + cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); +} + +static void +play_button_draw_pause_symbol(cairo_t* cr, double x, double y) +{ + cairo_set_line_width (cr, 6.0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to (cr, x, y); + cairo_rel_line_to (cr, 0, 16); + //cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - play_button_draw_background(cr, x, y, rect_width, rect_height, radius); - cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (x, y, x, y+16); + cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); + cairo_pattern_add_color_stop_rgb(pat, .1, 94/255.0, 93/255.0, 90/255.0); + cairo_set_source (cr, pat); + cairo_stroke(cr); + cairo_close_path(cr); + + cairo_set_line_width (cr, 5.0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to (cr, x+1, y+1); + cairo_rel_line_to (cr, 0, 15); + + pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); + cairo_pattern_add_color_stop_rgb(pat, .7, 252/255.0, 252/255.0, 251/255.0); + cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); + cairo_set_source (cr, pat); + cairo_stroke(cr); + cairo_close_path(cr); - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0); - cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 256.0); - cairo_pattern_add_color_stop_rgba (pat, 0.4, 256, 256, 256, 160.0); - cairo_pattern_add_color_stop_rgba (pat, 0.6, 256, 256, 256, 256.0); + cairo_pattern_destroy (pat); +} + +static void +play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) +{ + double radius=rect_height/2; + cairo_set_line_width (cr, rect_height); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to(cr, x+radius, y+radius); + cairo_line_to(cr, x+rect_width, y+radius); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (x, y, x, y+rect_height); + cairo_pattern_add_color_stop_rgb(pat, .7, 227/255.0, 222/255.0, 214/255.0); + cairo_pattern_add_color_stop_rgb(pat, .9, 183/255.0, 178/255.0, 172/255.0); + cairo_set_source (cr, pat); + cairo_stroke (cr); + + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_set_source (cr, pat); + cairo_fill(cr); + + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); + cairo_set_line_width (cr, 2); + cairo_stroke(cr); + cairo_close_path(cr); + cairo_pattern_destroy (pat); +} + +static void +play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) +{ + double radius=rect_height/2; + cairo_set_line_width (cr, rect_height); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to(cr, x+radius, y+radius); + cairo_line_to(cr, x+rect_width, y+radius); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (0, 0, 0, rect_height); + cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); - cairo_fill (cr); + cairo_stroke (cr); - //int factor = 10; - //cairo_reset_clip(cr); - play_button_draw_background(cr, x+2.5, y+2.5, rect_width-5, rect_height-5, radius-5); - //cairo_translate(cr, 50, 50); - cairo_set_source_rgba (cr, 256,256,256, 15); + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); + cairo_set_source (cr, pat); cairo_fill(cr); - //cairo_reset_clip(cr); + cairo_close_path(cr); cairo_pattern_destroy (pat); - // cr.fill() - // cr.stroke() - //cairo_set_source_rgb (cr, 1, 1, 1); - //cairo_stroke (cr); - cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } static void -play_button_draw_background(cairo_t* cr, double x, double y, int rect_width, int rect_height, double radius) -{ - cairo_move_to(cr, x+radius, y); - cairo_line_to(cr, x+rect_width-radius, y); - cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); - - cairo_line_to(cr, x + rect_width, y + rect_height - radius); - cairo_curve_to(cr, x + rect_width, y + rect_height, x + rect_width, - y + rect_height, x + rect_width - radius, y + rect_height); - - cairo_line_to(cr, x + radius, y + rect_height); - cairo_curve_to(cr, x, y + rect_height, x, y+rect_height, x, y+rect_height-radius); - cairo_line_to(cr, x, y + radius); - cairo_curve_to(cr, x, y, x, y, x + radius, y); - - cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/1.7, 0, 2 * M_PI); +play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) +{ + double radius=rect_height/2; + + cairo_set_line_width (cr, rect_height); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to(cr, x+radius, y+radius); + cairo_line_to(cr, x+rect_width, y+radius); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (0, 0, 0, rect_height); + cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); + cairo_set_source (cr, pat); + cairo_stroke (cr); + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); + + cairo_set_source (cr, pat); + cairo_fill(cr); + cairo_close_path(cr); + cairo_pattern_destroy (pat); + } + + /** * play_button_new: * @returns: a new #PlayButton. @@ -172,6 +284,7 @@ play_button_draw_background(cairo_t* cr, double x, double y, int rect_width, int GtkWidget* play_button_new() { + GtkWidget* widget = g_object_new(PLAY_BUTTON_TYPE, NULL); gtk_widget_set_app_paintable (widget, TRUE); return widget; diff --git a/src/play-button.h b/src/play-button.h index 4f7cdd0..6c6aee3 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -42,6 +42,7 @@ struct _PlayButton { }; GType play_button_get_type (void); +void play_button_set_style(GtkWidget* button, GtkStyle* style); GtkWidget* play_button_new(); G_END_DECLS diff --git a/src/transport-widget.c b/src/transport-widget.c index 648370f..6d39a03 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -86,12 +86,12 @@ transport_widget_init (TransportWidget *self) hbox = gtk_hbox_new(TRUE, 2); - //GtkAllocation alloc; - //gtk_widget_get_allocation(GTK_WIDGET(self), &alloc); - //g_debug("allocation width for the transport widget %i", alloc.width); + GtkStyle* style = gtk_rc_get_style(GTK_WIDGET(self)); + priv->hbox = hbox; - priv->play_button = play_button_new(); + play_button_set_style(priv->play_button, style); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); -- cgit v1.2.3 From fedd8fab03ebb4ab9e96090f30eb02dd2a112860 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 5 Jul 2010 13:30:36 +0100 Subject: getting closer to the mock up --- src/Makefile.am | 2 +- src/play-button.c | 90 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 21212d1..71a3068 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ libsoundmenu_la_SOURCES = \ dbus-shared-names.h \ sound-service-client.h -libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror -DG_LOG_DOMAIN=\"Indicator-Sound\" +libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -DG_LOG_DOMAIN=\"Indicator-Sound\" libsoundmenu_la_LIBADD = $(APPLET_LIBS) libsoundmenu_la_LDFLAGS = -module -avoid-version diff --git a/src/play-button.c b/src/play-button.c index 84b29cc..775ab53 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -53,6 +53,7 @@ static void play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, //static void play_button_draw_play_symbol(cairo_t* cr, double x, double y); static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y); +static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -142,42 +143,74 @@ draw (GtkWidget* button, cairo_t *cr) play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); // Draw the inside drop shadow background - gint offset = 1.5; - play_button_draw_background_shadow_2(button, cr, x+ offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); + gint offset = 4; + play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2)); - offset = 3; + offset = 5; // Draw the inside actual background - play_button_draw_background(button, cr, x+offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); + play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); - play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x, rect_height/5 +y ); + play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); + + play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); + play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset); cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } +static void +play_button_draw_previous_symbol(cairo_t* cr, double x, double y) +{ + cairo_set_line_width (cr, 3); + cairo_move_to (cr, x, y); + gint shape_height = 17; + gint shape_width = 22; + cairo_move_to(x, y); + cairo_rel_line_to (cr, 0, shape_height); + cairo_move_to (cr, x, y+shape_height/2); + cairo_rel_line_to (cr, 15, -shape_height/2); + //cairo_move_to (cr, x, y+shape_height/2); + //cairo_rel_line_to (cr, 15, +shape_height/2); + //cairo_rel_line_to (cr, 15, shape_height/2); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (x, y, x, y+16); + + cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); + cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); + cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); + cairo_set_source (cr, pat); + cairo_fill(cr); + cairo_close_path(cr); + +} + static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y) { - cairo_set_line_width (cr, 6.0); + cairo_set_line_width (cr, 7); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_move_to (cr, x, y); - cairo_rel_line_to (cr, 0, 16); + cairo_rel_line_to (cr, 0, 18); //cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); cairo_pattern_t *pat; pat = cairo_pattern_create_linear (x, y, x, y+16); cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .1, 94/255.0, 93/255.0, 90/255.0); + cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); + cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); cairo_stroke(cr); cairo_close_path(cr); - cairo_set_line_width (cr, 5.0); + cairo_set_line_width (cr, 5.5); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to (cr, x+1, y+1); - cairo_rel_line_to (cr, 0, 15); + cairo_move_to (cr, x, y+0.75); + cairo_rel_line_to (cr, 0, 16.5); pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); - cairo_pattern_add_color_stop_rgb(pat, .7, 252/255.0, 252/255.0, 251/255.0); - cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); + cairo_pattern_add_color_stop_rgb(pat, .3, 252/255.0, 252/255.0, 251/255.0); + cairo_pattern_add_color_stop_rgb(pat, .8, 227/255.0, 222/255.0, 214/255.0); + //1cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); cairo_set_source (cr, pat); cairo_stroke(cr); cairo_close_path(cr); @@ -196,20 +229,21 @@ play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, cairo_pattern_t *pat; pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .7, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .9, 183/255.0, 178/255.0, 172/255.0); + cairo_pattern_add_color_stop_rgb(pat, .5, 225/255.0, 218/255.0, 211/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 197/255.0, 192/255.0, 185/255.0); + cairo_pattern_add_color_stop_rgb(pat, .9, 185/255.0, 179/255.0, 173/255.0); cairo_set_source (cr, pat); cairo_stroke (cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); cairo_set_source (cr, pat); cairo_fill(cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - cairo_set_line_width (cr, 2); + cairo_set_line_width (cr, 0.75); cairo_stroke(cr); cairo_close_path(cr); cairo_pattern_destroy (pat); @@ -226,16 +260,16 @@ play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, d cairo_line_to(cr, x+rect_width, y+radius); cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (0, 0, 0, rect_height); - cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + pat = cairo_pattern_create_linear (x, y, x, y+rect_height); + cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); cairo_stroke (cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); cairo_fill(cr); @@ -255,16 +289,16 @@ play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, d cairo_line_to(cr, x+rect_width, y+radius); cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (0, 0, 0, rect_height); - cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + pat = cairo_pattern_create_linear (x, y, x, y+rect_height); + cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); cairo_set_source (cr, pat); cairo_stroke (cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); cairo_set_source (cr, pat); -- cgit v1.2.3 From e830c3a70e7feaa761c006c9fcbce9183686dac7 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 5 Jul 2010 15:06:56 +0100 Subject: previous button coming along --- src/play-button.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 775ab53..76a8109 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -153,35 +153,39 @@ draw (GtkWidget* button, cairo_t *cr) play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); - play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset); + play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2); cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y) { - cairo_set_line_width (cr, 3); - cairo_move_to (cr, x, y); - gint shape_height = 17; + gint line_width = 2; + cairo_set_line_width (cr, line_width); + gint shape_height = 15; gint shape_width = 22; - cairo_move_to(x, y); - cairo_rel_line_to (cr, 0, shape_height); - cairo_move_to (cr, x, y+shape_height/2); - cairo_rel_line_to (cr, 15, -shape_height/2); - //cairo_move_to (cr, x, y+shape_height/2); - //cairo_rel_line_to (cr, 15, +shape_height/2); - //cairo_rel_line_to (cr, 15, shape_height/2); + gint single_arrow_width=16; cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+16); + pat = cairo_pattern_create_linear (x, y, x, y+shape_height); cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); - cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); + cairo_pattern_add_color_stop_rgb(pat, .4, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); + + cairo_move_to(cr, x, y); + cairo_rel_line_to (cr, 0, shape_height); + cairo_stroke(cr); + + cairo_move_to (cr, x+line_width, y+shape_height/2); + cairo_line_to (cr, x+single_arrow_width, y); + cairo_line_to (cr, x+single_arrow_width, y+shape_height); + cairo_line_to (cr, x+line_width, y+shape_height/2); cairo_fill(cr); - cairo_close_path(cr); - + + cairo_pattern_destroy (pat); + cairo_close_path(cr); } static void @@ -210,7 +214,7 @@ play_button_draw_pause_symbol(cairo_t* cr, double x, double y) pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); cairo_pattern_add_color_stop_rgb(pat, .3, 252/255.0, 252/255.0, 251/255.0); cairo_pattern_add_color_stop_rgb(pat, .8, 227/255.0, 222/255.0, 214/255.0); - //1cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); + //cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); cairo_set_source (cr, pat); cairo_stroke(cr); cairo_close_path(cr); -- cgit v1.2.3 From f015c04d1e44c59ab650fe9f118bcf633833a150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirco=20M=C3=BCller?= Date: Tue, 6 Jul 2010 13:47:31 +0200 Subject: added some internal helpers for blurring, added more precise button-background rendering --- src/play-button.c | 402 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 390 insertions(+), 12 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 76a8109..347a0bc 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -15,6 +15,8 @@ PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . + +Uses code from ctk */ #ifdef HAVE_CONFIG_H @@ -58,6 +60,227 @@ static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); +/// internal helper functions ////////////////////////////////////////////////// + +static double +_align (double val) +{ + double fract = val - (int) val; + + if (fract != 0.5f) + return (double) ((int) val + 0.5f); + else + return val; +} + +static inline void +_blurinner (guchar* pixel, + gint* zR, + gint* zG, + gint* zB, + gint* zA, + gint alpha, + gint aprec, + gint zprec) +{ + gint R; + gint G; + gint B; + guchar A; + + R = *pixel; + G = *(pixel + 1); + B = *(pixel + 2); + A = *(pixel + 3); + + *zR += (alpha * ((R << zprec) - *zR)) >> aprec; + *zG += (alpha * ((G << zprec) - *zG)) >> aprec; + *zB += (alpha * ((B << zprec) - *zB)) >> aprec; + *zA += (alpha * ((A << zprec) - *zA)) >> aprec; + + *pixel = *zR >> zprec; + *(pixel + 1) = *zG >> zprec; + *(pixel + 2) = *zB >> zprec; + *(pixel + 3) = *zA >> zprec; +} + +static inline void +_blurrow (guchar* pixels, + gint width, + gint height, + gint channels, + gint line, + gint alpha, + gint aprec, + gint zprec) +{ + gint zR; + gint zG; + gint zB; + gint zA; + gint index; + guchar* scanline; + + scanline = &(pixels[line * width * channels]); + + zR = *scanline << zprec; + zG = *(scanline + 1) << zprec; + zB = *(scanline + 2) << zprec; + zA = *(scanline + 3) << zprec; + + for (index = 0; index < width; index ++) + _blurinner (&scanline[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); + + for (index = width - 2; index >= 0; index--) + _blurinner (&scanline[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); +} + +static inline void +_blurcol (guchar* pixels, + gint width, + gint height, + gint channels, + gint x, + gint alpha, + gint aprec, + gint zprec) +{ + gint zR; + gint zG; + gint zB; + gint zA; + gint index; + guchar* ptr; + + ptr = pixels; + + ptr += x * channels; + + zR = *((guchar*) ptr ) << zprec; + zG = *((guchar*) ptr + 1) << zprec; + zB = *((guchar*) ptr + 2) << zprec; + zA = *((guchar*) ptr + 3) << zprec; + + for (index = width; index < (height - 1) * width; index += width) + _blurinner ((guchar*) &ptr[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); + + for (index = (height - 2) * width; index >= 0; index -= width) + _blurinner ((guchar*) &ptr[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); +} + +void +_expblur (guchar* pixels, + gint width, + gint height, + gint channels, + gint radius, + gint aprec, + gint zprec) +{ + gint alpha; + gint row = 0; + gint col = 0; + + if (radius < 1) + return; + + // calculate the alpha such that 90% of + // the kernel is within the radius. + // (Kernel extends to infinity) + alpha = (gint) ((1 << aprec) * (1.0f - expf (-2.3f / (radius + 1.f)))); + + for (; row < height; row++) + _blurrow (pixels, + width, + height, + channels, + row, + alpha, + aprec, + zprec); + + for(; col < width; col++) + _blurcol (pixels, + width, + height, + channels, + col, + alpha, + aprec, + zprec); + + return; +} + +void +_surface_blur (cairo_surface_t* surface, + guint radius) +{ + guchar* pixels; + guint width; + guint height; + cairo_format_t format; + + // before we mess with the surface execute any pending drawing + cairo_surface_flush (surface); + + pixels = cairo_image_surface_get_data (surface); + width = cairo_image_surface_get_width (surface); + height = cairo_image_surface_get_height (surface); + format = cairo_image_surface_get_format (surface); + + switch (format) + { + case CAIRO_FORMAT_ARGB32: + _expblur (pixels, width, height, 4, radius, 16, 7); + break; + + case CAIRO_FORMAT_RGB24: + _expblur (pixels, width, height, 3, radius, 16, 7); + break; + + case CAIRO_FORMAT_A8: + _expblur (pixels, width, height, 1, radius, 16, 7); + break; + + default : + // do nothing + break; + } + + // inform cairo we altered the surfaces contents + cairo_surface_mark_dirty (surface); +} + +/// GObject functions ////////////////////////////////////////////////////////// static void play_button_class_init (PlayButtonClass *klass) @@ -97,7 +320,7 @@ static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event) { cairo_t *cr; - cr = gdk_cairo_create (button->window); + cr = gdk_cairo_create (button->window); g_debug("PlayButton::Draw - width = %i", button->allocation.width); g_debug("PlayButton::Draw - event->area.width = %i", event->area.width); @@ -109,7 +332,7 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) cairo_clip(cr); draw (button, cr); - cairo_destroy (cr); + cairo_destroy (cr); return FALSE; } @@ -126,34 +349,189 @@ play_button_set_style(GtkWidget* button, GtkStyle* style) } static void -draw (GtkWidget* button, cairo_t *cr) +draw_gradient (cairo_t* cr, + double x, + double y, + double w, + double r, + double* rgba_start, + double* rgba_end) { + cairo_pattern_t* pattern = NULL; + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + w - 2.0f * r, y); + cairo_arc (cr, + x + w - 2.0f * r, + y + r, + r, + -90.0f * G_PI / 180.0f, + 90.0f * G_PI / 180.0f); + cairo_line_to (cr, x, y + 2.0f * r); + cairo_arc (cr, + x, + y + r, + r, + 90.0f * G_PI / 180.0f, + 270.0f * G_PI / 180.0f); + cairo_close_path (cr); + + pattern = cairo_pattern_create_linear (x, y, x, y + 2.0f * r); + cairo_pattern_add_color_stop_rgba (pattern, + 0.0f, + rgba_start[0], + rgba_start[1], + rgba_start[2], + rgba_start[3]); + cairo_pattern_add_color_stop_rgba (pattern, + 1.0f, + rgba_end[0], + rgba_end[1], + rgba_end[2], + rgba_end[3]); + cairo_set_source (cr, pattern); + cairo_fill (cr); + cairo_pattern_destroy (pattern); +} + +static void +draw_circle (cairo_t* cr, + double x, + double y, + double r, + double* rgba_start, + double* rgba_end) +{ + cairo_pattern_t* pattern = NULL; + + cairo_move_to (cr, x, y); + cairo_arc (cr, + x + r, + y + r, + r, + 0.0f * G_PI / 180.0f, + 360.0f * G_PI / 180.0f); + + pattern = cairo_pattern_create_linear (x, y, x, y + 2.0f * r); + cairo_pattern_add_color_stop_rgba (pattern, + 0.0f, + rgba_start[0], + rgba_start[1], + rgba_start[2], + rgba_start[3]); + cairo_pattern_add_color_stop_rgba (pattern, + 1.0f, + rgba_end[0], + rgba_end[1], + rgba_end[2], + rgba_end[3]); + cairo_set_source (cr, pattern); + cairo_fill (cr); + cairo_pattern_destroy (pattern); +} + +static void +draw (GtkWidget* button, cairo_t *cr) +{ //PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); - double rect_width = 115; - double rect_height = 28; - double p_radius = 21; + double rect_width = 130; double y = 15; double x = 22; + double inner_height = 25.0f; + double inner_radius = 12.5f; + double inner_start[] = {229.0f / 255.0f, + 223.0f / 255.0f, + 215.0f / 255.0f, + 1.0f}; + double inner_end[] = {183.0f / 255.0f, + 178.0f / 255.0f, + 172.0f / 255.0f, + 1.0f}; + double middle_height = 27.0f; + double middle_radius = 13.5f; + double middle_start[] = {61.0f / 255.0f, + 60.0f / 255.0f, + 57.0f / 255.0f, + 1.0f}; + double middle_end[] = {94.0f / 255.0f, + 93.0f / 255.0f, + 90.0f / 255.0f, + 1.0f}; + double outter_height = 29.0f; + double outter_radius = 14.5f; + double outter_start[] = {36.0f / 255.0f, + 35.0f / 255.0f, + 33.0f / 255.0f, + 1.0f}; + double outter_end[] = {123.0f / 255.0f, + 123.0f / 255.0f, + 120.0f / 255.0f, + 1.0f}; + + double circle_radius = 19.0f; + //double radius=35; //double x= button->allocation.width/2 - rect_width/2; //double y= button->allocation.height/2 -rect_height/2; + // ffwd/back-background + draw_gradient (cr, + x, + y, + rect_width, + outter_radius, + outter_start, + outter_end); + draw_gradient (cr, + x, + y + 1, + rect_width - 2, + middle_radius, + middle_start, + middle_end); + draw_gradient (cr, + x, + y + 2, + rect_width - 4, + inner_radius, + inner_start, + inner_end); + + // play/pause-background + draw_circle (cr, + x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f, + y - ((circle_radius - outter_radius)), + circle_radius, + outter_start, + outter_end); + draw_circle (cr, + x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 1.0f, + y - ((circle_radius - outter_radius)) + 1.0f, + circle_radius - 1, + middle_start, + middle_end); + draw_circle (cr, + x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 2.0f, + y - ((circle_radius - outter_radius)) + 2.0f, + circle_radius - 2.0f, + inner_start, + inner_end); + // Draw the outside drop shadow background - play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); + //play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); // Draw the inside drop shadow background - gint offset = 4; - play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2)); + /*gint offset = 4; + play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2));*/ - offset = 5; + //offset = 5; // Draw the inside actual background - play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); + /*play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); - play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2); + play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2);*/ cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } -- cgit v1.2.3 From 7555ea6755750dd64a6c4652b852a0bdc0d0bfeb Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 6 Jul 2010 18:55:05 +0100 Subject: whole new widget to house the customised title item --- src/Makefile.am | 3 + src/common-defs.h | 3 + src/metadata-menu-item.vala | 2 +- src/mpris-controller.vala | 5 ++ src/music-player-bridge.vala | 17 +++-- src/player-controller.vala | 97 +++++++++++++++++++-------- src/player-item.vala | 30 ++++++--- src/title-menu-item.vala | 37 +++++++++++ src/title-widget.c | 155 +++++++++++++++++++++++++++++++++++++++++++ src/title-widget.h | 51 ++++++++++++++ src/transport-menu-item.vala | 4 +- src/transport-widget.c | 2 - vapi/common-defs.vapi | 6 ++ 13 files changed, 361 insertions(+), 51 deletions(-) create mode 100644 src/title-menu-item.vala create mode 100644 src/title-widget.c create mode 100644 src/title-widget.h diff --git a/src/Makefile.am b/src/Makefile.am index b33107d..327fcbb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,8 @@ libsoundmenu_la_SOURCES = \ metadata-widget.c \ metadata-widget.h \ indicator-sound.c \ + title-widget.c \ + title-widget.h \ dbus-shared-names.h \ sound-service-client.h @@ -54,6 +56,7 @@ music_bridge_VALASOURCES = \ music-player-bridge.vala \ transport-menu-item.vala \ metadata-menu-item.vala \ + title-menu-item.vala \ player-controller.vala \ mpris-controller-v2.vala \ mpris-controller.vala \ diff --git a/src/common-defs.h b/src/common-defs.h index dca21cc..9c1fbab 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -34,3 +34,6 @@ with this program. If not, see . #define DBUSMENU_METADATA_MENUITEM_TEXT_TITLE "x-canonical-metadata-text-title" #define DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM "x-canonical-metadata-text-album" #define DBUSMENU_METADATA_MENUITEM_ARTURL "x-canonical-metadata-arturl" + +#define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-menu-item" +#define DBUSMENU_TITLE_MENUITEM_TEXT_NAME "x-canonical-sound-menu-player-title-name" diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 541fbf4..7eb112a 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -25,7 +25,7 @@ public class MetadataMenuitem : PlayerItem { public MetadataMenuitem() { - this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE); } public static HashSet attributes_format() diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index beaf02c..b1e66f3 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -76,6 +76,11 @@ public class MprisController : GLib.Object this.mpris_player.Pause(); } } + + public bool connected() + { + return (this.mpris_player != null); + } private void onStatusChange(dynamic DBus.Object mpris_client, status st) { diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 84bf3df..77341a4 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -44,6 +44,7 @@ public class MusicPlayerBridge : GLib.Object } private void try_to_add_inactive_familiar_clients(){ + // TODO handle multple players - just working with one right now int count = 0; foreach(string app in this.playersDB.records()){ if(count == 0){ @@ -59,9 +60,9 @@ public class MusicPlayerBridge : GLib.Object } GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, - app_info.get_name(), - app_info); - ctrl.set("active", false); + app_info.get_name(), + PlayerController.OFFLINE); + ctrl.set("app_info", app_info); this.registered_clients.set(app_info.get_name().down().strip(), ctrl); debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip()); count += 1; @@ -83,11 +84,11 @@ public class MusicPlayerBridge : GLib.Object // If we have an instance already for this player, ensure it is switched to active if(this.registered_clients.keys.contains(client_name)){ debug("It figured out that it already has an instance for this player already"); - this.registered_clients[client_name].set("active", true); + this.registered_clients[client_name].activate(); } //else init a new one else{ - PlayerController ctrl = new PlayerController(root_menu, client_name); + PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.READY); registered_clients.set(client_name, ctrl); debug("New Client of name %s has successfully registered with us", client_name); } @@ -125,14 +126,12 @@ public class MusicPlayerBridge : GLib.Object owned string path, void* data) { MusicPlayerBridge bridge = data as MusicPlayerBridge; - // Not the most secure validation - // TODO revisit validation mechanism if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ debug("About to store desktop file path: %s", path); bridge.playersDB.insert(path); AppInfo? app_info = create_app_info(path); if(app_info != null){ - PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; + PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; ctrl.set("app_info", app_info); debug("successfully created appinfo from path and set it on the respective instance"); } @@ -169,7 +168,7 @@ public class MusicPlayerBridge : GLib.Object public static AppInfo? create_app_info(string path) { - DesktopAppInfo info = new DesktopAppInfo.from_filename(path); + DesktopAppInfo info = new DesktopAppInfo.from_filename(path); if(path == null){ warning("Could not create a desktopappinfo instance from app: %s", path); return null; diff --git a/src/player-controller.vala b/src/player-controller.vala index dfc2659..dd55f3d 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -25,37 +25,79 @@ public class PlayerController : GLib.Object { public const int METADATA = 2; private const int TRANSPORT = 3; + + public static const int OFFLINE = 0; + public static const int INSTANTIATING = 1; + public static const int READY = 2; + public static const int CONNECTED = 3; + public static const int DISCONNECTED = 4; + + public int current_state = OFFLINE; + private Dbusmenu.Menuitem root_menu; public string name { get; set;} - public bool active { get; set;} public ArrayList custom_items; private MprisController mpris_adaptor; - public AppInfo app_info { get; set;} + public AppInfo? app_info { get; set;} - public PlayerController(Dbusmenu.Menuitem root, string client_name, AppInfo? info = null) + public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) { this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList(); - this.app_info = info; - self_construct(); - //app_info.launch(null, null); - - // Temporary scenario to handle both v1 and v2 of MPRIS. + this.update_state(state); + construct_widgets(); + establish_mpris_connection(); + update_layout(); + } + + public void update_state(int new_state) + { + debug("update_state : new state %i", new_state); + this.current_state = new_state; + } + + public void activate() + { + debug("about to try to establish an mpris connection"); + this.establish_mpris_connection(); + this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); + } + + /* + instantiate() + The user should be able to start the app from the transport bar when in an offline state + There is a need to wait before the application is on DBus before attempting to access its mpris address + Hence only when the it has registered with us via libindicate do we attempt to kick off mpris communication + */ + public void instantiate() + { + this.app_info.launch(null, null); + this.update_state(INSTANTIATING); + } + + private void establish_mpris_connection() + { + if(this.current_state != READY){ + debug("establish_mpris_connection - Not ready to connect"); + return; + } if(this.name == "Vlc"){ this.mpris_adaptor = new MprisControllerV2(this.name, this); } else{ this.mpris_adaptor = new MprisController(this.name, this); - } - this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); - - // At start up if there is no metadata then hide the item. - // TODO: NOT working -> dbus menu bug ? - //((MetadataMenuitem)this.custom_items[METADATA]).check_layout(); + } + if(this.mpris_adaptor.connected() == true){ + this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); + this.update_state(CONNECTED); + } + else{ + this.update_state(DISCONNECTED); + } } - + public void vanish() { foreach(Dbusmenu.Menuitem item in this.custom_items){ @@ -63,21 +105,25 @@ public class PlayerController : GLib.Object } } - //public void switch_active(bool active){ - // this.is_active = active; - //} - - //public bool has_app_info(){ - // return (this.app_info != null); - //} + private void update_layout() + { + bool visibility = true; + if(this.current_state != CONNECTED){ + visibility = false; + } + this.custom_items[TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); + this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); + } + - private bool self_construct() + private void construct_widgets() { // Separator item - this.custom_items.add(PlayerItem.new_separator_item()); + this.custom_items.add(new PlayerItem(CLIENT_TYPES_SEPARATOR)); // Title item - this.custom_items.add(PlayerItem.new_title_item(this.name)); + TitleMenuitem title_menu_item = new TitleMenuitem(); + this.custom_items.add(title_menu_item); // Metadata item MetadataMenuitem metadata_item = new MetadataMenuitem(); @@ -91,7 +137,6 @@ public class PlayerController : GLib.Object foreach(PlayerItem item in this.custom_items){ root_menu.child_add_position(item, offset + this.custom_items.index_of(item)); } - return true; } private static string format_client_name(string client_name) diff --git a/src/player-item.vala b/src/player-item.vala index a5c5512..88e1dd3 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -22,10 +22,18 @@ using Gee; public class PlayerItem : Dbusmenu.Menuitem { + public MprisController mpris_adaptor; - - public PlayerItem() + public string item_type { get; construct; } + + public PlayerItem(string type) { + Object(item_type: type); + } + + construct { + debug("in the base constructor for %s", item_type); + this.property_set(MENUITEM_PROP_TYPE, item_type); } public void reset(HashSet attrs){ @@ -94,19 +102,19 @@ public class PlayerItem : Dbusmenu.Menuitem //----- Custom constructors for player items ----------------// // Title item - public static PlayerItem new_title_item(dynamic string name) - { - PlayerItem item = new PlayerItem(); - item.property_set(MENUITEM_PROP_LABEL, name); - item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia"); - return item; - } + //public static PlayerItem new_title_item(dynamic string name) + //{ + // PlayerItem item = new PlayerItem(); + // item.property_set(MENUITEM_PROP_LABEL, name); + // item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia"); + // return item; + //} // Separator item public static PlayerItem new_separator_item() { - PlayerItem separator = new PlayerItem(); - separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); + PlayerItem separator = new PlayerItem(CLIENT_TYPES_SEPARATOR); + //separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); return separator; } diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala new file mode 100644 index 0000000..f29d970 --- /dev/null +++ b/src/title-menu-item.vala @@ -0,0 +1,37 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +using Dbusmenu; +using DbusmenuTitle; +using Gee; + +public class TitleMenuitem : PlayerItem +{ + public TitleMenuitem() + { + Object(item_type: MENUITEM_TYPE); + } + + public static HashSet attributes_format() + { + HashSet attrs = new HashSet(); + attrs.add(MENUITEM_TEXT_NAME); + return attrs; + } +} \ No newline at end of file diff --git a/src/title-widget.c b/src/title-widget.c new file mode 100644 index 0000000..f5af09e --- /dev/null +++ b/src/title-widget.c @@ -0,0 +1,155 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "title-widget.h" +#include "common-defs.h" +#include + +static DbusmenuMenuitem* twin_item; + +typedef struct _TitleWidgetPrivate TitleWidgetPrivate; + +struct _TitleWidgetPrivate +{ + GtkWidget* hbox; +}; + +#define TITLE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TITLE_WIDGET_TYPE, TitleWidgetPrivate)) + +/* Prototypes */ +static void title_widget_class_init (TitleWidgetClass *klass); +static void title_widget_init (TitleWidget *self); +static void title_widget_dispose (GObject *object); +static void title_widget_finalize (GObject *object); +// keyevent consumers +static gboolean title_widget_button_press_event (GtkWidget *menuitem, + GdkEventButton *event); +static gboolean title_widget_button_release_event (GtkWidget *menuitem, + GdkEventButton *event); +static gboolean title_widget_expose_event(GtkWidget* widget, + GdkEventExpose* event); + +// Dbusmenuitem properties update callback +static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata); + + +G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_MENU_ITEM); + + + +static void +title_widget_class_init (TitleWidgetClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->button_press_event = title_widget_button_press_event; + widget_class->button_release_event = title_widget_button_release_event; + widget_class->expose_event = title_widget_expose_event; + + g_type_class_add_private (klass, sizeof (TitleWidgetPrivate)); + + gobject_class->dispose = title_widget_dispose; + gobject_class->finalize = title_widget_finalize; + +} + +static void +title_widget_init (TitleWidget *self) +{ + g_debug("TitleWidget::title_widget_init"); + + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); + + GtkWidget *hbox; + + hbox = gtk_hbox_new(FALSE, 0); + priv->hbox = hbox; + + g_signal_connect(G_OBJECT(twin_item), "property-changed", + G_CALLBACK(title_widget_property_update), self); + gtk_widget_show_all (priv->hbox); + gtk_container_add (GTK_CONTAINER (self), hbox); + +} + +static void +title_widget_dispose (GObject *object) +{ + G_OBJECT_CLASS (title_widget_parent_class)->dispose (object); +} + +static void +title_widget_finalize (GObject *object) +{ + G_OBJECT_CLASS (title_widget_parent_class)->finalize (object); +} + +/* Suppress/consume keyevents */ +static gboolean +title_widget_button_press_event (GtkWidget *menuitem, + GdkEventButton *event) +{ + g_debug("TitleWidget::menu_press_event"); + return TRUE; +} + +static gboolean +title_widget_button_release_event (GtkWidget *menuitem, + GdkEventButton *event) +{ + g_debug("TitleWidget::menu_release_event"); + return TRUE; +} + +static gboolean +title_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) +{ + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(widget); + + gtk_container_propagate_expose(GTK_CONTAINER(widget), priv->hbox, event); + return TRUE; +} + +static void +title_widget_property_update(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata) +{ + g_return_if_fail (IS_TITLE_WIDGET (userdata)); + +} + + + /** + * transport_new: + * @returns: a new #TitleWidget. + **/ +GtkWidget* +title_widget_new(DbusmenuMenuitem *item) +{ + twin_item = item; + return g_object_new(TITLE_WIDGET_TYPE, NULL); +} + diff --git a/src/title-widget.h b/src/title-widget.h new file mode 100644 index 0000000..efc0c78 --- /dev/null +++ b/src/title-widget.h @@ -0,0 +1,51 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ +#ifndef __TITLE_WIDGET_H__ +#define __TITLE_WIDGET_H__ + +#include +#include + +G_BEGIN_DECLS + +#define TITLE_WIDGET_TYPE (title_widget_get_type ()) +#define TITLE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TITLE_WIDGET_TYPE, TitleWidget)) +#define TITLE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TITLE_WIDGET_TYPE, TitleWidgetClass)) +#define IS_TITLE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TITLE_WIDGET_TYPE)) +#define IS_TITLE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TITLE_WIDGET_TYPE)) +#define TITLE_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TITLE_WIDGET_TYPE, TitleWidgetClass)) + +typedef struct _TitleWidget TitleWidget; +typedef struct _TitleWidgetClass TitleWidgetClass; + +struct _TitleWidgetClass { + GtkMenuItemClass parent_class; +}; + +struct _TitleWidget { + GtkMenuItem parent; +}; + +GType title_widget_get_type (void); +GtkWidget* title_widget_new(DbusmenuMenuitem *twin_item); + +G_END_DECLS + +#endif + diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index e0d241e..af71df4 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -26,7 +26,7 @@ public class TransportMenuitem : PlayerItem public TransportMenuitem() { - this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE); } public void change_play_state(int state) @@ -37,7 +37,7 @@ public class TransportMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { debug("handle_event with bool value %s", input_value.get_boolean().to_string()); - this.mpris_adaptor.toggle_playback(input_value.get_boolean()); + this.mpris_adaptor.toggle_playback(input_value.get_boolean()); } public override void check_layout(){ diff --git a/src/transport-widget.c b/src/transport-widget.c index bc9df53..a05bda2 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -26,8 +26,6 @@ with this program. If not, see . #include "common-defs.h" #include -// TODO: think about leakage: ted ! - static DbusmenuMenuitem* twin_item; typedef struct _TransportWidgetPrivate TransportWidgetPrivate; diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index 222fb67..6649b26 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -30,4 +30,10 @@ namespace DbusmenuMetadata{ namespace DbusmenuTransport{ public const string MENUITEM_TYPE; public const string MENUITEM_PLAY_STATE; +} + +[CCode (cheader_filename = "common-defs.h")] +namespace DbusmenuTitle{ + public const string MENUITEM_TYPE; + public const string MENUITEM_TEXT_NAME; } \ No newline at end of file -- cgit v1.2.3 From 9ec9e3fa570d0208c6409b13103bcd558f2b61a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirco=20M=C3=BCller?= Date: Wed, 7 Jul 2010 03:46:29 +0200 Subject: finished the rendering of the custom widget --- src/play-button.c | 467 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 288 insertions(+), 179 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 347a0bc..3c5b120 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -3,6 +3,7 @@ Copyright 2010 Canonical Ltd. Authors: Conor Curran + Mirco Müller This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published @@ -430,6 +431,147 @@ draw_circle (cairo_t* cr, cairo_pattern_destroy (pattern); } +static void +_setup (cairo_t** cr, + cairo_surface_t** surf, + gint width, + gint height) +{ + if (!cr || !surf) + return; + + *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + *cr = cairo_create (*surf); + cairo_scale (*cr, 1.0f, 1.0f); + cairo_set_operator (*cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (*cr); + cairo_set_operator (*cr, CAIRO_OPERATOR_OVER); +} + +static void +_mask_prev (cairo_t* cr, + double x, + double y, + double tri_width, + double tri_height, + double tri_offset) +{ + if (!cr) + return; + + cairo_move_to (cr, x, y + tri_height / 2.0f); + cairo_line_to (cr, x + tri_width, y); + cairo_line_to (cr, x + tri_width, y + tri_height); + x += tri_offset; + cairo_move_to (cr, x, y + tri_height / 2.0f); + cairo_line_to (cr, x + tri_width, y); + cairo_line_to (cr, x + tri_width, y + tri_height); + x -= tri_offset; + cairo_rectangle (cr, x, y, 2.5f, tri_height); + cairo_close_path (cr); +} + +static void +_mask_next (cairo_t* cr, + double x, + double y, + double tri_width, + double tri_height, + double tri_offset) +{ + if (!cr) + return; + + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + tri_width, y + tri_height / 2.0f); + cairo_line_to (cr, x, y + tri_height); + x += tri_offset; + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + tri_width, y + tri_height / 2.0f); + cairo_line_to (cr, x, y + tri_height); + x -= tri_offset; + x += 2.0f * tri_width - tri_offset - 1.0f; + cairo_rectangle (cr, x, y, 2.5f, tri_height); + + cairo_close_path (cr); +} + +static void +_mask_pause (cairo_t* cr, + double x, + double y, + double bar_width, + double bar_height, + double bar_offset) +{ + if (!cr) + return; + + cairo_set_line_width (cr, bar_width); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + + x += bar_width; + y += bar_width; + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + bar_height); + cairo_move_to (cr, x + bar_offset, y); + cairo_line_to (cr, x + bar_offset, y + bar_height); + + //cairo_close_path (cr); +} + +static void +_fill (cairo_t* cr, + double x_start, + double y_start, + double x_end, + double y_end, + double* rgba_start, + double* rgba_end, + gboolean stroke) +{ + cairo_pattern_t* pattern = NULL; + + if (!cr || !rgba_start || !rgba_end) + return; + + pattern = cairo_pattern_create_linear (x_start, y_start, x_end, y_end); + cairo_pattern_add_color_stop_rgba (pattern, + 0.0f, + rgba_start[0], + rgba_start[1], + rgba_start[2], + rgba_start[3]); + cairo_pattern_add_color_stop_rgba (pattern, + 1.0f, + rgba_end[0], + rgba_end[1], + rgba_end[2], + rgba_end[3]); + cairo_set_source (cr, pattern); + if (stroke) + cairo_stroke (cr); + else + cairo_fill (cr); + cairo_pattern_destroy (pattern); +} + +static void +_finalize (cairo_t* cr, + cairo_t** cr_surf, + cairo_surface_t** surf, + double x, + double y) +{ + if (!cr || !cr_surf || !surf) + return; + + cairo_set_source_surface (cr, *surf, x, y); + cairo_paint (cr); + cairo_surface_destroy (*surf); + cairo_destroy (*cr_surf); +} + static void draw (GtkWidget* button, cairo_t *cr) { @@ -470,11 +612,40 @@ draw (GtkWidget* button, cairo_t *cr) double circle_radius = 19.0f; - //double radius=35; - //double x= button->allocation.width/2 - rect_width/2; - //double y= button->allocation.height/2 -rect_height/2; - - // ffwd/back-background + double button_start[] = {252.0f / 255.0f, + 251.0f / 255.0f, + 251.0f / 255.0f, + 1.0f}; + double button_end[] = {186.0f / 255.0f, + 180.0f / 255.0f, + 170.0f / 255.0f, + 1.0f}; + double button_shadow[] = {0.0f / 255.0f, + 0.0f / 255.0f, + 0.0f / 255.0f, + 0.75f}; + double prev_width = 25.0f; + double prev_height = 17.0f; + double next_width = prev_width; + double next_height = prev_height; + cairo_surface_t* surf = NULL; + cairo_t* cr_surf = NULL; + double tri_width = 11.0f; + double tri_height = 13.0f; + double tri_offset = 6.0f; + double prev_x = 20.0f; + double prev_y = 21.0f; + double next_x = 98.0f; + double next_y = prev_y; + double pause_width = 21.0f; + double pause_height = 27.0f; + double bar_width = 4.5f; + double bar_height = 24.0f; + double bar_offset = 10.0f; + double pause_x = 62.0f; + double pause_y = 15.0f; + + // prev/next-background draw_gradient (cr, x, y, @@ -517,182 +688,120 @@ draw (GtkWidget* button, cairo_t *cr) inner_start, inner_end); - // Draw the outside drop shadow background - //play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); - - // Draw the inside drop shadow background - /*gint offset = 4; - play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2));*/ - - //offset = 5; - // Draw the inside actual background - /*play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); - - play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); - - play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); - play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2);*/ - cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); -} - -static void -play_button_draw_previous_symbol(cairo_t* cr, double x, double y) -{ - gint line_width = 2; - cairo_set_line_width (cr, line_width); - gint shape_height = 15; - gint shape_width = 22; - gint single_arrow_width=16; - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+shape_height); - - cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); - cairo_pattern_add_color_stop_rgb(pat, .4, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - - cairo_move_to(cr, x, y); - cairo_rel_line_to (cr, 0, shape_height); - cairo_stroke(cr); - - cairo_move_to (cr, x+line_width, y+shape_height/2); - cairo_line_to (cr, x+single_arrow_width, y); - cairo_line_to (cr, x+single_arrow_width, y+shape_height); - cairo_line_to (cr, x+line_width, y+shape_height/2); - cairo_fill(cr); - - cairo_pattern_destroy (pat); - cairo_close_path(cr); -} - -static void -play_button_draw_pause_symbol(cairo_t* cr, double x, double y) -{ - cairo_set_line_width (cr, 7); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to (cr, x, y); - cairo_rel_line_to (cr, 0, 18); - //cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+16); - cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); - cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - cairo_stroke(cr); - cairo_close_path(cr); - - cairo_set_line_width (cr, 5.5); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to (cr, x, y+0.75); - cairo_rel_line_to (cr, 0, 16.5); - - pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); - cairo_pattern_add_color_stop_rgb(pat, .3, 252/255.0, 252/255.0, 251/255.0); - cairo_pattern_add_color_stop_rgb(pat, .8, 227/255.0, 222/255.0, 214/255.0); - //cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); - cairo_set_source (cr, pat); - cairo_stroke(cr); - cairo_close_path(cr); - - cairo_pattern_destroy (pat); -} - -static void -play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) -{ - double radius=rect_height/2; - cairo_set_line_width (cr, rect_height); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to(cr, x+radius, y+radius); - cairo_line_to(cr, x+rect_width, y+radius); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .5, 225/255.0, 218/255.0, 211/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 197/255.0, 192/255.0, 185/255.0); - cairo_pattern_add_color_stop_rgb(pat, .9, 185/255.0, 179/255.0, 173/255.0); - cairo_set_source (cr, pat); - cairo_stroke (cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - cairo_set_source (cr, pat); - cairo_fill(cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - cairo_set_line_width (cr, 0.75); - cairo_stroke(cr); - cairo_close_path(cr); - cairo_pattern_destroy (pat); -} - -static void -play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) -{ - double radius=rect_height/2; - - cairo_set_line_width (cr, rect_height); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to(cr, x+radius, y+radius); - cairo_line_to(cr, x+rect_width, y+radius); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - cairo_stroke (cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - cairo_fill(cr); - cairo_close_path(cr); - cairo_pattern_destroy (pat); - -} - -static void -play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) -{ - double radius=rect_height/2; - - cairo_set_line_width (cr, rect_height); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to(cr, x+radius, y+radius); - cairo_line_to(cr, x+rect_width, y+radius); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); - cairo_set_source (cr, pat); - cairo_stroke (cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); - - cairo_set_source (cr, pat); - cairo_fill(cr); - cairo_close_path(cr); - cairo_pattern_destroy (pat); - + // draw previous-button drop-shadow + _setup (&cr_surf, &surf, prev_width, prev_height); + _mask_prev (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_shadow, + button_shadow, + FALSE); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, prev_x, prev_y + 1.0f); + + // draw previous-button + _setup (&cr_surf, &surf, prev_width, prev_height); + _mask_prev (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_start, + button_end, + FALSE); + _finalize (cr, &cr_surf, &surf, prev_x, prev_y); + + // draw next-button drop-shadow + _setup (&cr_surf, &surf, next_width, next_height); + _mask_next (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_shadow, + button_shadow, + FALSE); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, next_x, next_y + 1.0f); + + // draw next-button + _setup (&cr_surf, &surf, next_width, next_height); + _mask_next (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_start, + button_end, + FALSE); + _finalize (cr, &cr_surf, &surf, next_x, next_y); + + // draw pause-button drop-shadow + _setup (&cr_surf, &surf, pause_width, pause_height); + _mask_pause (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + bar_width, + bar_height - 2.0f * bar_width, + bar_offset); + _fill (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (double) bar_height, + button_shadow, + button_shadow, + TRUE); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, pause_x, pause_y + 1.0f); + + // draw pause-button + _setup (&cr_surf, &surf, pause_width, pause_height); + _mask_pause (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + bar_width, + bar_height - 2.0f * bar_width, + bar_offset); + _fill (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (double) bar_height, + button_start, + button_end, + TRUE); + _finalize (cr, &cr_surf, &surf, pause_x, pause_y); + + cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/foobar.png"); } - - - /** * play_button_new: * @returns: a new #PlayButton. -- cgit v1.2.3 From 6eef19e54ead5184d2cb136d3e6fdacc6eef37bf Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 11:51:47 +0100 Subject: typo in merge --- src/dbus-menu-manager.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index a68976a..4cd4a6b 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -174,6 +174,7 @@ static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data GError * error = NULL; if (!g_spawn_command_line_async("gnome-volume-control", &error) && !g_spawn_command_line_async("xfce4-mixer", &error)) + { g_warning("Unable to show dialog: %s", error->message); g_error_free(error); } -- cgit v1.2.3 From 410965575fa1039cbcc6c6ef7f7ef316438118ed Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 13:22:18 +0100 Subject: alot of work around the title menu stuff --- data/album_artwork.png | Bin 0 -> 552 bytes data/sound_icon.png | Bin 0 -> 467 bytes src/indicator-sound.c | 24 +++++++++++++++++++--- src/metadata-menu-item.vala | 5 ----- src/player-controller.vala | 7 +++---- src/player-item.vala | 33 +---------------------------- src/title-menu-item.vala | 15 ++++++++++++-- src/title-widget.c | 48 +++++++++++++++++++++++++++++++++++++------ src/transport-menu-item.vala | 13 ++++-------- 9 files changed, 84 insertions(+), 61 deletions(-) create mode 100644 data/album_artwork.png create mode 100644 data/sound_icon.png diff --git a/data/album_artwork.png b/data/album_artwork.png new file mode 100644 index 0000000..940a69b Binary files /dev/null and b/data/album_artwork.png differ diff --git a/data/sound_icon.png b/data/sound_icon.png new file mode 100644 index 0000000..b52d6c4 Binary files /dev/null and b/data/sound_icon.png differ diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3f0d2d3..10333fe 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -40,6 +40,7 @@ with this program. If not, see . #include "indicator-sound.h" #include "transport-widget.h" #include "metadata-widget.h" +#include "title-widget.h" #include "dbus-shared-names.h" #include "sound-service-client.h" #include "common-defs.h" @@ -96,6 +97,7 @@ static void style_changed_cb(GtkWidget *widget, gpointer user_data); //player widgets related static gboolean new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -243,7 +245,7 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TRANSPORT_MENUITEM_TYPE, new_transport_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); - + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget); // register Key-press listening on the menu widget as the slider does not allow this. g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); return GTK_MENU(menu); @@ -353,9 +355,25 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm return TRUE; } -//const gchar* path = dbusmenu_menuitem_property_get(new_item, DBUSMENU_METADATA_MENUITEM_IMAGE_PATH); +static gboolean +new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + g_debug("indicator-sound: new_title_widget"); + + GtkWidget* title = NULL; + + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + + title = title_widget_new (newitem); + GtkMenuItem *menu_title_widget = GTK_MENU_ITEM(title); + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_title_widget, parent); -//g_debug("New transport bar path = %s", path); + gtk_widget_show_all(title); + + return TRUE; +} static void diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 7eb112a..cfcb3bc 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -37,11 +37,6 @@ public class MetadataMenuitem : PlayerItem attrs.add(MENUITEM_ARTURL); return attrs; } - - public override void check_layout(){ - this.property_set_bool(MENUITEM_PROP_VISIBLE, this.populated()); - debug("check layout for the metadata = %s", this.populated().to_string()); - } public bool populated() { diff --git a/src/player-controller.vala b/src/player-controller.vala index dd55f3d..75c251c 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -38,7 +38,7 @@ public class PlayerController : GLib.Object private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList custom_items; - private MprisController mpris_adaptor; + public MprisController mpris_adaptor; public AppInfo? app_info { get; set;} public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) @@ -90,7 +90,6 @@ public class PlayerController : GLib.Object this.mpris_adaptor = new MprisController(this.name, this); } if(this.mpris_adaptor.connected() == true){ - this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); this.update_state(CONNECTED); } else{ @@ -122,7 +121,7 @@ public class PlayerController : GLib.Object this.custom_items.add(new PlayerItem(CLIENT_TYPES_SEPARATOR)); // Title item - TitleMenuitem title_menu_item = new TitleMenuitem(); + TitleMenuitem title_menu_item = new TitleMenuitem(this, this.name); this.custom_items.add(title_menu_item); // Metadata item @@ -130,7 +129,7 @@ public class PlayerController : GLib.Object this.custom_items.add(metadata_item); // Transport item - TransportMenuitem transport_item = new TransportMenuitem(); + TransportMenuitem transport_item = new TransportMenuitem(this); this.custom_items.add(transport_item); int offset = 2; diff --git a/src/player-item.vala b/src/player-item.vala index 88e1dd3..171c140 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -22,8 +22,7 @@ using Gee; public class PlayerItem : Dbusmenu.Menuitem { - - public MprisController mpris_adaptor; + public PlayerController owner {get; construct;} public string item_type { get; construct; } public PlayerItem(string type) @@ -32,7 +31,6 @@ public class PlayerItem : Dbusmenu.Menuitem } construct { - debug("in the base constructor for %s", item_type); this.property_set(MENUITEM_PROP_TYPE, item_type); } @@ -68,15 +66,8 @@ public class PlayerItem : Dbusmenu.Menuitem this.property_set_bool(property, v.get_boolean()); } } - // TODO: not working - //this.check_layout(); } - public void set_adaptor(MprisController adaptor) - { - this.mpris_adaptor = adaptor; - } - private static bool ensure_valid_updates(HashTable data, HashSet attributes) { if(data == null){ @@ -99,27 +90,5 @@ public class PlayerItem : Dbusmenu.Menuitem return result; } - - //----- Custom constructors for player items ----------------// - // Title item - //public static PlayerItem new_title_item(dynamic string name) - //{ - // PlayerItem item = new PlayerItem(); - // item.property_set(MENUITEM_PROP_LABEL, name); - // item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia"); - // return item; - //} - - // Separator item - public static PlayerItem new_separator_item() - { - PlayerItem separator = new PlayerItem(CLIENT_TYPES_SEPARATOR); - //separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); - return separator; - } - - public virtual void check_layout(){ - warning("this should not be hit"); - } } diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index f29d970..0acd97f 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -23,11 +23,22 @@ using Gee; public class TitleMenuitem : PlayerItem { - public TitleMenuitem() + public TitleMenuitem(PlayerController parent, string name) { - Object(item_type: MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE, owner: parent); + this.property_set(MENUITEM_TEXT_NAME, name); } + public override void handle_event(string name, GLib.Value input_value, uint timestamp) + { + debug("handle_event with bool value %s", input_value.get_boolean().to_string()); + if(this.owner.current_state == PlayerController.OFFLINE) + { + this.owner.instantiate(); + } + } + + public static HashSet attributes_format() { HashSet attrs = new HashSet(); diff --git a/src/title-widget.c b/src/title-widget.c index f5af09e..45f918f 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -33,6 +33,8 @@ typedef struct _TitleWidgetPrivate TitleWidgetPrivate; struct _TitleWidgetPrivate { GtkWidget* hbox; + GtkWidget* name; + GtkWidget* player_icon; }; #define TITLE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TITLE_WIDGET_TYPE, TitleWidgetPrivate)) @@ -42,19 +44,19 @@ static void title_widget_class_init (TitleWidgetClass *klass); static void title_widget_init (TitleWidget *self); static void title_widget_dispose (GObject *object); static void title_widget_finalize (GObject *object); + // keyevent consumers static gboolean title_widget_button_press_event (GtkWidget *menuitem, - GdkEventButton *event); + GdkEventButton *event); static gboolean title_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event); + GdkEventButton *event); static gboolean title_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); // Dbusmenuitem properties update callback static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); - - +static void style_name_text(TitleWidget* self); G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_MENU_ITEM); @@ -87,9 +89,19 @@ title_widget_init (TitleWidget *self) hbox = gtk_hbox_new(FALSE, 0); priv->hbox = hbox; - g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); + + priv->player_icon = gtk_image_new_from_file("/home/ronoc/branches/sound-menu-v2/finish-indicate/indicator-sound/data/sound_icon.png"); + gtk_box_pack_start(GTK_BOX (priv->hbox), priv->player_icon, FALSE, FALSE, 0); + + priv->name = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, + DBUSMENU_TITLE_MENUITEM_TEXT_NAME)); + gtk_misc_set_padding(GTK_MISC(priv->name), 10, 0); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0); + + style_name_text(self); + gtk_widget_show_all (priv->hbox); gtk_container_add (GTK_CONTAINER (self), hbox); @@ -113,6 +125,13 @@ title_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { g_debug("TitleWidget::menu_press_event"); + + GValue value = {0}; + g_value_init(&value, G_TYPE_BOOLEAN); + + g_value_set_boolean(&value, TRUE); + dbusmenu_menuitem_handle_event (twin_item, "Title menu event", &value, 0); + return TRUE; } @@ -138,9 +157,26 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) { g_return_if_fail (IS_TITLE_WIDGET (userdata)); - + TitleWidget* mitem = TITLE_WIDGET(userdata); + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(mitem); + + if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_TEXT_NAME, property) == 0){ + gtk_label_set_text(GTK_LABEL(priv->name), g_value_get_string(value)); + style_name_text(mitem); + } } +static void +style_name_text(TitleWidget* self) +{ + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); + + char* markup; + markup = g_markup_printf_escaped ("%s", + gtk_label_get_text(GTK_LABEL(priv->name))); + gtk_label_set_markup (GTK_LABEL (priv->name), markup); + g_free(markup); +} /** * transport_new: diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index af71df4..7a1bb4a 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -24,9 +24,9 @@ using DbusmenuTransport; public class TransportMenuitem : PlayerItem { - public TransportMenuitem() + public TransportMenuitem(PlayerController parent) { - Object(item_type: MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE, owner: parent); } public void change_play_state(int state) @@ -37,13 +37,8 @@ public class TransportMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { debug("handle_event with bool value %s", input_value.get_boolean().to_string()); - this.mpris_adaptor.toggle_playback(input_value.get_boolean()); - } - - public override void check_layout(){ - // nothing to be done for this item - always active - } - + this.owner.mpris_adaptor.toggle_playback(input_value.get_boolean()); + } public static HashSet attributes_format() { -- cgit v1.2.3 From caf13b4dccb20aff410ffc0da63c298cabbcca5f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 13:36:56 +0100 Subject: fixed the mpris connection problems --- src/music-player-bridge.vala | 1 + src/player-controller.vala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 77341a4..46723cb 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -84,6 +84,7 @@ public class MusicPlayerBridge : GLib.Object // If we have an instance already for this player, ensure it is switched to active if(this.registered_clients.keys.contains(client_name)){ debug("It figured out that it already has an instance for this player already"); + this.registered_clients[client_name].update_state(PlayerController.READY); this.registered_clients[client_name].activate(); } //else init a new one diff --git a/src/player-controller.vala b/src/player-controller.vala index 75c251c..88dc3a7 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -60,7 +60,6 @@ public class PlayerController : GLib.Object public void activate() { - debug("about to try to establish an mpris connection"); this.establish_mpris_connection(); this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -95,6 +94,7 @@ public class PlayerController : GLib.Object else{ this.update_state(DISCONNECTED); } + this.update_layout(); } public void vanish() -- cgit v1.2.3 From b41d94677b3471742fa957cc4f60381d8f67ea5d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 15:08:34 +0100 Subject: updated for merge --- data/Makefile.am | 1 - src/sound-service.c | 4 ++-- src/title-widget.c | 2 +- src/transport-widget.c | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/data/Makefile.am b/data/Makefile.am index 0389576..9fa0c9b 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,4 +1,3 @@ - dbus_servicesdir = $(DBUSSERVICEDIR) service_in_files = indicator-sound.service.in dbus_services_DATA = $(service_in_files:.service.in=.service) diff --git a/src/sound-service.c b/src/sound-service.c index a5f3941..8f4e941 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -43,8 +43,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } diff --git a/src/title-widget.c b/src/title-widget.c index 45f918f..9951754 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -91,7 +91,7 @@ title_widget_init (TitleWidget *self) priv->hbox = hbox; g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); - + // TODO - waiting theme icon name for correct usage priv->player_icon = gtk_image_new_from_file("/home/ronoc/branches/sound-menu-v2/finish-indicate/indicator-sound/data/sound_icon.png"); gtk_box_pack_start(GTK_BOX (priv->hbox), priv->player_icon, FALSE, FALSE, 0); diff --git a/src/transport-widget.c b/src/transport-widget.c index a05bda2..e7b8e4f 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -134,7 +134,7 @@ transport_widget_init (TransportWidget *self) hbox = gtk_hbox_new(TRUE, 2); gchar* symbol = transport_widget_toggle_play_label(dbusmenu_menuitem_property_get_int(twin_item, DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE)); priv->play_button = gtk_button_new_with_label(symbol); - //g_free(symbol); + gtk_box_pack_start (GTK_BOX (hbox), priv->play_button, FALSE, TRUE, 0); priv->hbox = hbox; -- cgit v1.2.3 From 5d8d12718e518a8bc695e57c071760720de4329e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 17:42:38 +0100 Subject: moved what I could to a #define and removed unused --- src/play-button.c | 349 +++++++++++++++++++++++------------------------------- 1 file changed, 151 insertions(+), 198 deletions(-) diff --git a/src/play-button.c b/src/play-button.c index 3c5b120..136f25d 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -27,6 +27,31 @@ Uses code from ctk #include #include "play-button.h" +#define RECT_WIDTH 130.0f +#define Y 15.0f +#define X 22.0f +#define INNER_RADIUS 12.5 +#define MIDDLE_RADIUS 13.5f +#define OUTER_RADIUS 14.5f +#define CIRCLE_RADIUS 19.0f +#define PREV_WIDTH 25.0f +#define PREV_HEIGHT 17.0f +#define NEXT_WIDTH 25.0f //PREV_WIDTH +#define NEXT_HEIGHT 17.0f //PREV_HEIGHT +#define TRI_WIDTH 11.0f +#define TRI_HEIGHT 13.0f +#define TRI_OFFSET 6.0f +#define PREV_X 20.0f +#define PREV_Y 21.0f +#define NEXT_X 98.0f +#define NEXT_Y 21.0f //prev_y +#define PAUSE_WIDTH 21.0f +#define PAUSE_HEIGHT 27.0f +#define BAR_WIDTH 4.5f +#define BAR_HEIGHT 24.0f +#define BAR_OFFSET 10.0f +#define PAUSE_X 62.0f +#define PAUSE_Y 15.0f typedef struct _PlayButtonPrivate PlayButtonPrivate; @@ -49,15 +74,6 @@ static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); -static void play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double width, double height, double p_radius); -static void play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); -static void play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); - - -//static void play_button_draw_play_symbol(cairo_t* cr, double x, double y); -static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y); -static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y); - G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -301,7 +317,6 @@ play_button_class_init (PlayButtonClass *klass) static void play_button_init (PlayButton *self) { - g_debug("PlayButton::play_button_init"); gtk_widget_set_size_request(GTK_WIDGET(self), 200, 80); } @@ -323,10 +338,6 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) cairo_t *cr; cr = gdk_cairo_create (button->window); - g_debug("PlayButton::Draw - width = %i", button->allocation.width); - g_debug("PlayButton::Draw - event->area.width = %i", event->area.width); - g_debug("PlayButton::Draw - event->area.x = %i", event->area.x); - cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height); @@ -517,7 +528,6 @@ _mask_pause (cairo_t* cr, cairo_move_to (cr, x + bar_offset, y); cairo_line_to (cr, x + bar_offset, y + bar_height); - //cairo_close_path (cr); } static void @@ -575,233 +585,176 @@ _finalize (cairo_t* cr, static void draw (GtkWidget* button, cairo_t *cr) { - //PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); - double rect_width = 130; - double y = 15; - double x = 22; - double inner_height = 25.0f; - double inner_radius = 12.5f; - double inner_start[] = {229.0f / 255.0f, - 223.0f / 255.0f, - 215.0f / 255.0f, - 1.0f}; - double inner_end[] = {183.0f / 255.0f, - 178.0f / 255.0f, - 172.0f / 255.0f, - 1.0f}; - double middle_height = 27.0f; - double middle_radius = 13.5f; - double middle_start[] = {61.0f / 255.0f, - 60.0f / 255.0f, - 57.0f / 255.0f, - 1.0f}; - double middle_end[] = {94.0f / 255.0f, - 93.0f / 255.0f, - 90.0f / 255.0f, - 1.0f}; - double outter_height = 29.0f; - double outter_radius = 14.5f; - double outter_start[] = {36.0f / 255.0f, - 35.0f / 255.0f, - 33.0f / 255.0f, - 1.0f}; - double outter_end[] = {123.0f / 255.0f, - 123.0f / 255.0f, - 120.0f / 255.0f, - 1.0f}; - - double circle_radius = 19.0f; - - double button_start[] = {252.0f / 255.0f, - 251.0f / 255.0f, - 251.0f / 255.0f, - 1.0f}; - double button_end[] = {186.0f / 255.0f, - 180.0f / 255.0f, - 170.0f / 255.0f, - 1.0f}; - double button_shadow[] = {0.0f / 255.0f, - 0.0f / 255.0f, - 0.0f / 255.0f, - 0.75f}; - double prev_width = 25.0f; - double prev_height = 17.0f; - double next_width = prev_width; - double next_height = prev_height; cairo_surface_t* surf = NULL; cairo_t* cr_surf = NULL; - double tri_width = 11.0f; - double tri_height = 13.0f; - double tri_offset = 6.0f; - double prev_x = 20.0f; - double prev_y = 21.0f; - double next_x = 98.0f; - double next_y = prev_y; - double pause_width = 21.0f; - double pause_height = 27.0f; - double bar_width = 4.5f; - double bar_height = 24.0f; - double bar_offset = 10.0f; - double pause_x = 62.0f; - double pause_y = 15.0f; + double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f}; + double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f}; + double MIDDLE_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; + double MIDDLE_END[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f}; + double OUTER_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; + double OUTER_END[] = {123.0f / 255.0f, 123.0f / 255.0f, 120.0f / 255.0f, 1.0f}; + double BUTTON_START[] = {252.0f / 255.0f, 251.0f / 255.0f, 251.0f / 255.0f,1.0f}; + double BUTTON_END[] = {186.0f / 255.0f,180.0f / 255.0f, 170.0f / 255.0f, 1.0f}; + double BUTTON_SHADOW[] = {0.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f, 0.75f}; + + // prev/next-background - draw_gradient (cr, - x, - y, - rect_width, - outter_radius, - outter_start, - outter_end); - draw_gradient (cr, - x, - y + 1, - rect_width - 2, - middle_radius, - middle_start, - middle_end); - draw_gradient (cr, - x, - y + 2, - rect_width - 4, - inner_radius, - inner_start, - inner_end); + draw_gradient (cr, + X, + Y, + RECT_WIDTH, + OUTER_RADIUS, + OUTER_START, + OUTER_END); + draw_gradient (cr, + X, + Y + 1, + RECT_WIDTH - 2, + MIDDLE_RADIUS, + MIDDLE_START, + MIDDLE_END); + draw_gradient (cr, + X, + Y + 2, + RECT_WIDTH - 4, + INNER_RADIUS, + INNER_START, + INNER_END); // play/pause-background draw_circle (cr, - x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f, - y - ((circle_radius - outter_radius)), - circle_radius, - outter_start, - outter_end); + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 4.5f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)), + CIRCLE_RADIUS, + OUTER_START, + OUTER_END); draw_circle (cr, - x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 1.0f, - y - ((circle_radius - outter_radius)) + 1.0f, - circle_radius - 1, - middle_start, - middle_end); + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 4.5f + 1.0f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.0f, + CIRCLE_RADIUS - 1, + MIDDLE_START, + MIDDLE_END); draw_circle (cr, - x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 2.0f, - y - ((circle_radius - outter_radius)) + 2.0f, - circle_radius - 2.0f, - inner_start, - inner_end); + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 4.5f + 2.0f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 2.0f, + CIRCLE_RADIUS - 2.0f, + INNER_START, + INNER_END); // draw previous-button drop-shadow - _setup (&cr_surf, &surf, prev_width, prev_height); + _setup (&cr_surf, &surf, PREV_WIDTH, PREV_HEIGHT); _mask_prev (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_shadow, - button_shadow, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_SHADOW, + BUTTON_SHADOW, FALSE); _surface_blur (surf, 1); - _finalize (cr, &cr_surf, &surf, prev_x, prev_y + 1.0f); + _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y + 1.0f); // draw previous-button - _setup (&cr_surf, &surf, prev_width, prev_height); + _setup (&cr_surf, &surf, PREV_WIDTH, PREV_HEIGHT); _mask_prev (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_start, - button_end, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_START, + BUTTON_END, FALSE); - _finalize (cr, &cr_surf, &surf, prev_x, prev_y); + _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y); // draw next-button drop-shadow - _setup (&cr_surf, &surf, next_width, next_height); + _setup (&cr_surf, &surf, NEXT_WIDTH, NEXT_HEIGHT); _mask_next (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_shadow, - button_shadow, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_SHADOW, + BUTTON_SHADOW, FALSE); _surface_blur (surf, 1); - _finalize (cr, &cr_surf, &surf, next_x, next_y + 1.0f); + _finalize (cr, &cr_surf, &surf, NEXT_X, NEXT_Y + 1.0f); // draw next-button - _setup (&cr_surf, &surf, next_width, next_height); + _setup (&cr_surf, &surf, NEXT_WIDTH, NEXT_HEIGHT); _mask_next (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_start, - button_end, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_START, + BUTTON_END, FALSE); - _finalize (cr, &cr_surf, &surf, next_x, next_y); + _finalize (cr, &cr_surf, &surf, NEXT_X, NEXT_Y); // draw pause-button drop-shadow - _setup (&cr_surf, &surf, pause_width, pause_height); + _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); _mask_pause (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - bar_width, - bar_height - 2.0f * bar_width, - bar_offset); + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + BAR_WIDTH, + BAR_HEIGHT - 2.0f * BAR_WIDTH, + BAR_OFFSET); _fill (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (double) bar_height, - button_shadow, - button_shadow, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (double) BAR_HEIGHT, + BUTTON_SHADOW, + BUTTON_SHADOW, TRUE); _surface_blur (surf, 1); - _finalize (cr, &cr_surf, &surf, pause_x, pause_y + 1.0f); + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y + 1.0f); // draw pause-button - _setup (&cr_surf, &surf, pause_width, pause_height); + _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); _mask_pause (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - bar_width, - bar_height - 2.0f * bar_width, - bar_offset); + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + BAR_WIDTH, + BAR_HEIGHT - 2.0f * BAR_WIDTH, + BAR_OFFSET); _fill (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (double) bar_height, - button_start, - button_end, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (double) BAR_HEIGHT, + BUTTON_START, + BUTTON_END, TRUE); - _finalize (cr, &cr_surf, &surf, pause_x, pause_y); - - cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/foobar.png"); + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y); } + /** * play_button_new: * @returns: a new #PlayButton. -- cgit v1.2.3 From e4f900efd1e48814a70e4351cc3d878312daef37 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 8 Jul 2010 16:12:59 +0100 Subject: event handling now plugged in crudely --- src/indicator-sound.c | 6 ++---- src/metadata-widget.c | 6 +++--- src/mpris-controller.vala | 29 +++++++++++++++++++++-------- src/play-button.c | 23 +++++++++++++++++++++++ src/play-button.h | 2 ++ src/player-controller.vala | 1 + src/transport-menu-item.vala | 10 ++++++++-- src/transport-widget.c | 23 +++++++++++++++++------ 8 files changed, 77 insertions(+), 23 deletions(-) diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 10333fe..8be97b4 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -328,10 +328,9 @@ new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbus bar = transport_widget_new(newitem); GtkMenuItem *menu_transport_bar = GTK_MENU_ITEM(bar); + gtk_widget_show_all(bar); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_transport_bar, parent); - gtk_widget_show_all(bar); - return TRUE; } @@ -348,10 +347,9 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm metadata = metadata_widget_new (newitem); GtkMenuItem *menu_metadata_widget = GTK_MENU_ITEM(metadata); + gtk_widget_show_all(metadata); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_metadata_widget, parent); - gtk_widget_show_all(metadata); - return TRUE; } diff --git a/src/metadata-widget.c b/src/metadata-widget.c index bb9c8a8..8235725 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -112,7 +112,7 @@ metadata_widget_init (MetadataWidget *self) DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST)); gtk_misc_set_alignment(GTK_MISC(artist), (gfloat)0, (gfloat)0); - gtk_label_set_width_chars(GTK_LABEL(artist), 20); + gtk_label_set_width_chars(GTK_LABEL(artist), 15); gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_MIDDLE); priv->artist_label = artist; // Style it up. @@ -123,7 +123,7 @@ metadata_widget_init (MetadataWidget *self) piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_TITLE)); gtk_misc_set_alignment(GTK_MISC(piece), (gfloat)0, (gfloat)0); - gtk_label_set_width_chars(GTK_LABEL(piece), 16); + gtk_label_set_width_chars(GTK_LABEL(piece), 12); gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_MIDDLE); priv->piece_label = piece; // Style it up. @@ -134,7 +134,7 @@ metadata_widget_init (MetadataWidget *self) container = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM)); gtk_misc_set_alignment(GTK_MISC(container), (gfloat)0, (gfloat)0); - gtk_label_set_width_chars(GTK_LABEL(container), 20); + gtk_label_set_width_chars(GTK_LABEL(container), 15); gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_MIDDLE); priv->container_label = container; // Style it up. diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index b1e66f3..61c96e7 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -65,16 +65,29 @@ public class MprisController : GLib.Object * TRUE => Playing * FALSE => Paused **/ - public void toggle_playback(bool state) + public void transport_event(int command) { - if(state == true){ - debug("about to play"); - this.mpris_player.Play(); + if(command == 2){ + status st = this.mpris_player.GetStatus(); + bool play_state = st.playback == 1; + debug("toggle_playback - initial play state %i", (int)play_state); + bool new_play_state = !play_state; + debug("toggle_playback - new play state %i", (int)new_play_state); + if(new_play_state == true){ + debug("about to play"); + this.mpris_player.Play(); + } + else{ + debug("about to pause"); + this.mpris_player.Pause(); + } + } + else if(command == 1){ + this.mpris_player.previous(); + } + else if(command == 3){ + this.mpris_player.next(); } - else{ - debug("about to pause"); - this.mpris_player.Pause(); - } } public bool connected() diff --git a/src/play-button.c b/src/play-button.c index 136f25d..afb46d8 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -349,6 +349,29 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) } +gint +determine_button_event(GtkWidget* button, GdkEventButton* event) +{ + g_debug("event x coordinate = %f", event->x); + g_debug("event y coordinate = %f", event->y); + gint result = 0; + // For now very simple rectangular collision detection + if(event->x > 40 && event->x < 80 + && event->y > 22 && event->y < 46){ + result = 1; + } + else if(event->x > 86 && event->x < 118 + && event->y > 20 && event->y < 47){ + result = 2; + } + else if(event->x > 122 && event->x < 164 + && event->y > 22 && event->y < 46){ + result = 3; + } + + return result; +} + void play_button_set_style(GtkWidget* button, GtkStyle* style) { diff --git a/src/play-button.h b/src/play-button.h index 6c6aee3..3eaabcc 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -43,6 +43,8 @@ struct _PlayButton { GType play_button_get_type (void); void play_button_set_style(GtkWidget* button, GtkStyle* style); +gint determine_button_event(GtkWidget* button, GdkEventButton* event); + GtkWidget* play_button_new(); G_END_DECLS diff --git a/src/player-controller.vala b/src/player-controller.vala index 88dc3a7..dfbf6d3 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -110,6 +110,7 @@ public class PlayerController : GLib.Object if(this.current_state != CONNECTED){ visibility = false; } + debug("about the set the visibility on both the transport and metadata widget to %s", visibility.to_string()); this.custom_items[TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); } diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 7a1bb4a..7e7bedc 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -36,8 +36,14 @@ public class TransportMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { - debug("handle_event with bool value %s", input_value.get_boolean().to_string()); - this.owner.mpris_adaptor.toggle_playback(input_value.get_boolean()); + int input = input_value.get_int(); + debug("handle_event with value %s", input.to_string()); + if(input > 0){ + this.owner.mpris_adaptor.transport_event(input); + } + else{ + debug("A mouse event I'm not interested in"); + } } public static HashSet attributes_format() diff --git a/src/transport-widget.c b/src/transport-widget.c index 6d39a03..9852b50 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -132,13 +132,24 @@ transport_widget_button_press_event (GtkWidget *menuitem, return FALSE; } - //TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); + TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - //GValue value = {0}; - //g_value_init(&value, G_TYPE_BOOLEAN); - //g_debug("TransportWidget::menu_press_event - going to send value %i", state); - //g_value_set_boolean(&value, state); - //dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); + GtkWidget *parent; + + // can we block emissions of "grab-notify" on parent?? + parent = gtk_widget_get_parent (GTK_WIDGET (menuitem)); + gint result = determine_button_event(priv->play_button, event); + + //GTK_OBJECT_FLAGS (scale) |= GTK_HAS_GRAB; + //gtk_widget_event (scale, + //((GdkEvent *)(void*)(event))); + //GTK_OBJECT_FLAGS (scale) &= ~(GTK_HAS_GRAB); + + GValue value = {0}; + g_value_init(&value, G_TYPE_INT); + g_debug("TransportWidget::menu_press_event - going to send value %i", result); + g_value_set_int(&value, result); + dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); return TRUE; } -- cgit v1.2.3 From 0f2a6b2736713951fb4b88848e79849a8f1dc72a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 8 Jul 2010 17:47:28 +0100 Subject: constants replaced and enums and title image now fetched from the mono theme --- src/mpris-controller.vala | 15 ++++++++------- src/music-player-bridge.vala | 6 +++--- src/play-button.c | 13 ++++++++++--- src/player-controller.vala | 37 ++++++++++++++++++++++--------------- src/title-menu-item.vala | 2 +- src/title-widget.c | 5 +++-- src/transport-menu-item.vala | 13 +++++++------ 7 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index 61c96e7..2194d44 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -27,9 +27,9 @@ public class MprisController : GLib.Object private PlayerController controller; struct status { public int32 playback; - public int32 shuffle; - public int32 repeat; - public int32 endless; + //public int32 shuffle; // Not used just yet + //public int32 repeat; + //public int32 endless; } public MprisController(string name, PlayerController controller, string mpris_interface="org.freedesktop.MediaPlayer"){ @@ -65,9 +65,10 @@ public class MprisController : GLib.Object * TRUE => Playing * FALSE => Paused **/ - public void transport_event(int command) + public void transport_event(TransportMenuitem.action command) { - if(command == 2){ + debug("transport_event input = %i", (int)command); + if(command == TransportMenuitem.action.PLAY_PAUSE){ status st = this.mpris_player.GetStatus(); bool play_state = st.playback == 1; debug("toggle_playback - initial play state %i", (int)play_state); @@ -82,10 +83,10 @@ public class MprisController : GLib.Object this.mpris_player.Pause(); } } - else if(command == 1){ + else if(command == TransportMenuitem.action.PREVIOUS){ this.mpris_player.previous(); } - else if(command == 3){ + else if(command == TransportMenuitem.action.NEXT){ this.mpris_player.next(); } } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 46723cb..d771192 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -61,7 +61,7 @@ public class MusicPlayerBridge : GLib.Object GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, app_info.get_name(), - PlayerController.OFFLINE); + PlayerController.state.OFFLINE); ctrl.set("app_info", app_info); this.registered_clients.set(app_info.get_name().down().strip(), ctrl); debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip()); @@ -84,12 +84,12 @@ public class MusicPlayerBridge : GLib.Object // If we have an instance already for this player, ensure it is switched to active if(this.registered_clients.keys.contains(client_name)){ debug("It figured out that it already has an instance for this player already"); - this.registered_clients[client_name].update_state(PlayerController.READY); + this.registered_clients[client_name].update_state(PlayerController.state.READY); this.registered_clients[client_name].activate(); } //else init a new one else{ - PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.READY); + PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.state.READY); registered_clients.set(client_name, ctrl); debug("New Client of name %s has successfully registered with us", client_name); } diff --git a/src/play-button.c b/src/play-button.c index afb46d8..2fddbcf 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -53,6 +53,13 @@ Uses code from ctk #define PAUSE_X 62.0f #define PAUSE_Y 15.0f +// Transport events +enum { + PREVIOUS, + PLAY_PAUSE, + NEXT +}; + typedef struct _PlayButtonPrivate PlayButtonPrivate; struct _PlayButtonPrivate @@ -358,15 +365,15 @@ determine_button_event(GtkWidget* button, GdkEventButton* event) // For now very simple rectangular collision detection if(event->x > 40 && event->x < 80 && event->y > 22 && event->y < 46){ - result = 1; + result = PREVIOUS; } else if(event->x > 86 && event->x < 118 && event->y > 20 && event->y < 47){ - result = 2; + result = PLAY_PAUSE; } else if(event->x > 122 && event->x < 164 && event->y > 22 && event->y < 46){ - result = 3; + result = NEXT; } return result; diff --git a/src/player-controller.vala b/src/player-controller.vala index dfbf6d3..3fb4750 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -26,13 +26,15 @@ public class PlayerController : GLib.Object public const int METADATA = 2; private const int TRANSPORT = 3; - public static const int OFFLINE = 0; - public static const int INSTANTIATING = 1; - public static const int READY = 2; - public static const int CONNECTED = 3; - public static const int DISCONNECTED = 4; + public enum state{ + OFFLINE, + INSTANTIATING, + READY, + CONNECTED, + DISCONNECTED + } - public int current_state = OFFLINE; + public int current_state = state.OFFLINE; private Dbusmenu.Menuitem root_menu; @@ -41,18 +43,18 @@ public class PlayerController : GLib.Object public MprisController mpris_adaptor; public AppInfo? app_info { get; set;} - public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) + public PlayerController(Dbusmenu.Menuitem root, string client_name, state initial_state) { this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList(); - this.update_state(state); + this.update_state(initial_state); construct_widgets(); establish_mpris_connection(); update_layout(); } - public void update_state(int new_state) + public void update_state(state new_state) { debug("update_state : new state %i", new_state); this.current_state = new_state; @@ -72,13 +74,18 @@ public class PlayerController : GLib.Object */ public void instantiate() { - this.app_info.launch(null, null); - this.update_state(INSTANTIATING); + try{ + this.app_info.launch(null, null); + this.update_state(state.INSTANTIATING); + } + catch(GLib.Error error){ + warning("Failed to launch app %s with error message: %s", this.name, error.message); + } } private void establish_mpris_connection() { - if(this.current_state != READY){ + if(this.current_state != state.READY){ debug("establish_mpris_connection - Not ready to connect"); return; } @@ -89,10 +96,10 @@ public class PlayerController : GLib.Object this.mpris_adaptor = new MprisController(this.name, this); } if(this.mpris_adaptor.connected() == true){ - this.update_state(CONNECTED); + this.update_state(state.CONNECTED); } else{ - this.update_state(DISCONNECTED); + this.update_state(state.DISCONNECTED); } this.update_layout(); } @@ -107,7 +114,7 @@ public class PlayerController : GLib.Object private void update_layout() { bool visibility = true; - if(this.current_state != CONNECTED){ + if(this.current_state != state.CONNECTED){ visibility = false; } debug("about the set the visibility on both the transport and metadata widget to %s", visibility.to_string()); diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index 0acd97f..612d279 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -32,7 +32,7 @@ public class TitleMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { debug("handle_event with bool value %s", input_value.get_boolean().to_string()); - if(this.owner.current_state == PlayerController.OFFLINE) + if(this.owner.current_state == PlayerController.state.OFFLINE) { this.owner.instantiate(); } diff --git a/src/title-widget.c b/src/title-widget.c index 9951754..1b57fe9 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -25,6 +25,7 @@ with this program. If not, see . #include "title-widget.h" #include "common-defs.h" #include +#include static DbusmenuMenuitem* twin_item; @@ -91,8 +92,8 @@ title_widget_init (TitleWidget *self) priv->hbox = hbox; g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); - // TODO - waiting theme icon name for correct usage - priv->player_icon = gtk_image_new_from_file("/home/ronoc/branches/sound-menu-v2/finish-indicate/indicator-sound/data/sound_icon.png"); + + priv->player_icon = indicator_image_helper("sound_icon"); gtk_box_pack_start(GTK_BOX (priv->hbox), priv->player_icon, FALSE, FALSE, 0); priv->name = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 7e7bedc..e0710a8 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -23,6 +23,11 @@ using DbusmenuTransport; public class TransportMenuitem : PlayerItem { + public enum action{ + PREVIOUS, + PLAY_PAUSE, + NEXT + } public TransportMenuitem(PlayerController parent) { @@ -38,12 +43,8 @@ public class TransportMenuitem : PlayerItem { int input = input_value.get_int(); debug("handle_event with value %s", input.to_string()); - if(input > 0){ - this.owner.mpris_adaptor.transport_event(input); - } - else{ - debug("A mouse event I'm not interested in"); - } + // Fire and forgot - the widget would not have sent it over it didn't think it was relevant. + this.owner.mpris_adaptor.transport_event((action)input); } public static HashSet attributes_format() -- cgit v1.2.3 From b0a09afe59a904ce4b4e90e58d933ad1f0b036d9 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 8 Jul 2010 17:54:11 +0100 Subject: bumped version number is prep for 0.3.5 release --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index b6c4fe3..5a6abc4 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ -AC_INIT(indicator-sound, 0.3.4, conor.curran@canonical.com) +AC_INIT(indicator-sound, 0.3.5, conor.curran@canonical.com) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-sound, 0.3.4) +AM_INIT_AUTOMAKE(indicator-sound, 0.3.5) AM_MAINTAINER_MODE -- cgit v1.2.3