diff options
author | Andrea Cimitan <andrea.cimitan@canonical.com> | 2010-11-16 02:15:22 +0100 |
---|---|---|
committer | Andrea Cimitan <andrea.cimitan@canonical.com> | 2010-11-16 02:15:22 +0100 |
commit | 31bc33331673b761ba7d6e28bbb87da6b2e6e51a (patch) | |
tree | d5710ce890cc9bcb4e63c5157af53058f5f7ba3c /src | |
parent | 5fd2c5e12a059ab8c59306676d18dfc56c818077 (diff) | |
parent | 41284d027bd0c0eeff0e83e10b365f98a6977f59 (diff) | |
download | ayatana-indicator-sound-31bc33331673b761ba7d6e28bbb87da6b2e6e51a.tar.gz ayatana-indicator-sound-31bc33331673b761ba7d6e28bbb87da6b2e6e51a.tar.bz2 ayatana-indicator-sound-31bc33331673b761ba7d6e28bbb87da6b2e6e51a.zip |
Few changes, but cairo drawing should be redone
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-sound.c | 33 | ||||
-rw-r--r-- | src/sound-service.c | 4 | ||||
-rw-r--r-- | src/transport-widget.c | 204 | ||||
-rw-r--r-- | src/transport-widget.h | 2 |
4 files changed, 185 insertions, 58 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 13f1529..53a4876 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -47,6 +47,7 @@ typedef struct _IndicatorSoundPrivate IndicatorSoundPrivate; struct _IndicatorSoundPrivate { GtkWidget* volume_widget; + GtkWidget* transport_widget; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -241,11 +242,16 @@ new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbus //g_debug("indicator-sound: new_transport_bar() called "); GtkWidget* bar = NULL; + IndicatorObject *io = NULL; g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); bar = transport_widget_new(newitem); + io = g_object_get_data (G_OBJECT (client), "indicator"); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + priv->transport_widget = bar; + GtkMenuItem *menu_transport_bar = GTK_MENU_ITEM(bar); gtk_widget_show_all(bar); @@ -706,9 +712,34 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) new_value = CLAMP(new_value, 0, 100); if (new_value != current_value && current_state != STATE_MUTED) { //g_debug("Attempting to set the range from the key listener to %f", new_value); - volume_widget_update(VOLUME_WIDGET(priv->volume_widget), new_value); + volume_widget_update(VOLUME_WIDGET(priv->volume_widget), new_value); } } + if (IS_TRANSPORT_WIDGET(menuitem) == TRUE) { + switch (event->keyval) { + case GDK_Right: + transport_widget_react_to_key_event ( TRANSPORT_WIDGET ( priv->transport_widget ), + TRANSPORT_NEXT ); + digested = TRUE; + break; + case GDK_Left: + transport_widget_react_to_key_event ( TRANSPORT_WIDGET ( priv->transport_widget ), + TRANSPORT_PREVIOUS ); + digested = TRUE; + break; + case GDK_KEY_space: + transport_widget_react_to_key_event ( TRANSPORT_WIDGET ( priv->transport_widget ), + TRANSPORT_PLAY_PAUSE ); + digested = TRUE; + break; + case GDK_Up: + case GDK_Down: + digested = FALSE; + break; + default: + break; + } + } return digested; } diff --git a/src/sound-service.c b/src/sound-service.c index f19379d..51f5f37 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,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 26b7a98..cbe9154 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -33,7 +33,7 @@ Uses code from ctk #define Y 7.0f #define X 80.0f #define INNER_RADIUS 12.5 -#define MIDDLE_RADIUS 13.5f +#define MIDDLE_RADIUS 13.0f #define OUTER_RADIUS 14.5f #define CIRCLE_RADIUS 21.0f #define PREV_WIDTH 25.0f @@ -59,15 +59,18 @@ Uses code from ctk #define PLAY_PADDING 5.0f #define INNER_START_SHADE 0.98 #define INNER_END_SHADE 0.98 -#define MIDDLE_START_SHADE 0.7 -#define MIDDLE_END_SHADE 1.4 -#define OUTER_START_SHADE 0.96 -#define OUTER_END_SHADE 0.96 +#define MIDDLE_START_SHADE 1.0 +#define MIDDLE_END_SHADE 1.0 +#define OUTER_START_SHADE 0.75 +#define OUTER_END_SHADE 1.3 +#define SHADOW_BUTTON_SHADE 0.8 +#define OUTER_BUTTON_START_SHADE 0.7 +#define OUTER_BUTTON_END_SHADE 1.38 #define BUTTON_START_SHADE 1.1 #define BUTTON_END_SHADE 0.9 #define BUTTON_SHADOW_SHADE 0.8 -#define INNER_COMPRESSED_START_SHADE 0.95 -#define INNER_COMPRESSED_END_SHADE 1.05 +#define INNER_COMPRESSED_START_SHADE 1.0 +#define INNER_COMPRESSED_END_SHADE 1.0 typedef struct _TransportWidgetPrivate TransportWidgetPrivate; @@ -270,7 +273,6 @@ transport_widget_button_release_event (GtkWidget *menuitem, g_return_val_if_fail(IS_TRANSPORT_WIDGET(menuitem), FALSE); TransportWidget* transport = TRANSPORT_WIDGET(menuitem); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); - TransportWidgetEvent result = transport_widget_determine_button_event ( transport, event ); if(result != TRANSPORT_NADA){ @@ -289,6 +291,26 @@ transport_widget_button_release_event (GtkWidget *menuitem, return TRUE; } +void +transport_widget_react_to_key_event ( TransportWidget* transport, + TransportWidgetEvent transport_event ) +{ + if(transport_event != TRANSPORT_NADA){ + TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); + GValue value = {0}; + g_value_init(&value, G_TYPE_INT); + //g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); + g_value_set_int(&value, (int)transport_event); + dbusmenu_menuitem_handle_event ( priv->twin_item, + "Transport state change", + &value, + 0 ); + } + + transport_widget_react_to_button_release ( transport, + transport_event ); +} + static TransportWidgetEvent transport_widget_determine_button_event( TransportWidget* button, GdkEventButton* event ) @@ -348,6 +370,10 @@ draw_gradient (cairo_t* cr, { cairo_pattern_t* pattern = NULL; +/* cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);*/ +/* cairo_save (cr);*/ +/* cairo_rectangle (cr, x-2.0*r, y, w+2*r, r*2);*/ +/* cairo_clip (cr);*/ cairo_move_to (cr, x, y); cairo_line_to (cr, x + w - 2.0f * r, y); cairo_arc (cr, @@ -364,6 +390,12 @@ draw_gradient (cairo_t* cr, 90.0f * G_PI / 180.0f, 270.0f * G_PI / 180.0f); cairo_close_path (cr); + +/* cairo_arc (cr,*/ +/* x+(w-2*r)/2+1, y+(CIRCLE_RADIUS)/2+2,*/ +/* CIRCLE_RADIUS+1,*/ +/* 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, @@ -381,6 +413,7 @@ draw_gradient (cairo_t* cr, cairo_set_source (cr, pattern); cairo_fill (cr); cairo_pattern_destroy (pattern); +/* cairo_restore(cr);*/ } static void @@ -654,7 +687,7 @@ _color_rgb_to_hls (gdouble *r, static void _color_hls_to_rgb (gdouble *h, - gdouble *l, + gdouble *l, gdouble *s) { gdouble hue; @@ -995,35 +1028,42 @@ draw (GtkWidget* button, cairo_t *cr) GtkStyle *style; - CairoColorRGB bg_normal, fg_normal; - CairoColorRGB color_inner[2], color_middle[2], color_outer[2], color_button[3], color_inner_compressed[2]; + CairoColorRGB bg_color, fg_color; + CairoColorRGB color_inner[2], color_middle[2], color_outer[2], color_button[3], color_button_outer[2], color_button_shadow, color_inner_compressed[2]; style = gtk_widget_get_style (button); - bg_normal.r = style->bg[0].red/65535.0; - bg_normal.g = style->bg[0].green/65535.0; - bg_normal.b = style->bg[0].blue/65535.0; - - fg_normal.r = style->fg[0].red/65535.0; - fg_normal.g = style->fg[0].green/65535.0; - fg_normal.b = style->fg[0].blue/65535.0; - - _color_shade (&bg_normal, INNER_START_SHADE, &color_inner[0]); - _color_shade (&bg_normal, INNER_END_SHADE, &color_inner[1]); - _color_shade (&bg_normal, MIDDLE_START_SHADE, &color_middle[0]); - _color_shade (&bg_normal, MIDDLE_END_SHADE, &color_middle[1]); - _color_shade (&bg_normal, OUTER_START_SHADE, &color_outer[0]); - _color_shade (&bg_normal, OUTER_END_SHADE, &color_outer[1]); - _color_shade (&fg_normal, BUTTON_START_SHADE, &color_button[0]); - _color_shade (&fg_normal, BUTTON_END_SHADE, &color_button[1]); - _color_shade (&bg_normal, BUTTON_SHADOW_SHADE, &color_button[2]); - _color_shade (&bg_normal, INNER_COMPRESSED_START_SHADE, &color_inner_compressed[0]); - _color_shade (&bg_normal, INNER_COMPRESSED_END_SHADE, &color_inner_compressed[1]); + + bg_color.r = style->bg[0].red/65535.0; + bg_color.g = style->bg[0].green/65535.0; + bg_color.b = style->bg[0].blue/65535.0; + + fg_color.r = style->fg[0].red/65535.0; + fg_color.g = style->fg[0].green/65535.0; + fg_color.b = style->fg[0].blue/65535.0; + + _color_shade (&bg_color, INNER_START_SHADE, &color_inner[0]); + _color_shade (&bg_color, INNER_END_SHADE, &color_inner[1]); + _color_shade (&bg_color, MIDDLE_START_SHADE, &color_middle[0]); + _color_shade (&bg_color, MIDDLE_END_SHADE, &color_middle[1]); + _color_shade (&bg_color, OUTER_START_SHADE, &color_outer[0]); + _color_shade (&bg_color, OUTER_END_SHADE, &color_outer[1]); + _color_shade (&bg_color, OUTER_BUTTON_START_SHADE, &color_button_outer[0]); + _color_shade (&bg_color, OUTER_BUTTON_END_SHADE, &color_button_outer[1]); + _color_shade (&bg_color, SHADOW_BUTTON_SHADE, &color_button_shadow); + _color_shade (&fg_color, BUTTON_START_SHADE, &color_button[0]); + _color_shade (&fg_color, BUTTON_END_SHADE, &color_button[1]); + _color_shade (&bg_color, BUTTON_SHADOW_SHADE, &color_button[2]); + _color_shade (&bg_color, INNER_COMPRESSED_START_SHADE, &color_inner_compressed[0]); + _color_shade (&bg_color, INNER_COMPRESSED_END_SHADE, &color_inner_compressed[1]); double MIDDLE_END[] = {color_middle[0].r, color_middle[0].g, color_middle[0].b, 1.0f}; double MIDDLE_START[] = {color_middle[1].r, color_middle[1].g, color_middle[1].b, 1.0f}; + double SHADOW_BUTTON[] = {color_button_shadow.r, color_button_shadow.g, color_button_shadow.b, 0.16f}; double OUTER_END[] = {color_outer[0].r, color_outer[0].g, color_outer[0].b, 1.0f}; double OUTER_START[] = {color_outer[1].r, color_outer[1].g, color_outer[1].b, 1.0f}; + double OUTER_BUTTON_END[] = {color_button_outer[0].r, color_button_outer[0].g, color_button_outer[0].b, 1.0f}; + double OUTER_BUTTON_START[] = {color_button_outer[1].r, color_button_outer[1].g, color_button_outer[1].b, 1.0f}; double BUTTON_END[] = {color_button[0].r, color_button[0].g, color_button[0].b, 1.0f}; double BUTTON_START[] = {color_button[1].r, color_button[1].g, color_button[1].b, 1.0f}; double BUTTON_SHADOW[] = {color_button[2].r, color_button[2].g, color_button[2].b, 0.75f}; @@ -1031,6 +1071,15 @@ draw (GtkWidget* button, cairo_t *cr) double INNER_COMPRESSED_START[] = {color_inner_compressed[0].r, color_inner_compressed[0].g, color_inner_compressed[0].b, 1.0f}; // prev/next-background +/* if(priv->current_command != TRANSPORT_PREVIOUS && priv->current_command != TRANSPORT_NEXT){*/ +/* draw_gradient (cr,*/ +/* X-0.25,*/ +/* Y-1,*/ +/* RECT_WIDTH+2,*/ +/* OUTER_RADIUS+1,*/ +/* SHADOW_BUTTON,*/ +/* SHADOW_BUTTON);*/ +/* }*/ draw_gradient (cr, X, Y, @@ -1054,54 +1103,99 @@ draw (GtkWidget* button, cairo_t *cr) MIDDLE_END); if(priv->current_command == TRANSPORT_PREVIOUS){ + draw_gradient (cr, + X, + Y, + RECT_WIDTH/2, + OUTER_RADIUS, + OUTER_END, + OUTER_START); + + draw_gradient (cr, + X, + Y + 1, + RECT_WIDTH/2, + MIDDLE_RADIUS, + INNER_COMPRESSED_START, + INNER_COMPRESSED_END); draw_gradient (cr, X, Y + 2, RECT_WIDTH/2, - INNER_RADIUS, + MIDDLE_RADIUS, INNER_COMPRESSED_START, INNER_COMPRESSED_END); } else if(priv->current_command == TRANSPORT_NEXT){ draw_gradient (cr, + RECT_WIDTH / 2 + X, + Y, + RECT_WIDTH/2, + OUTER_RADIUS, + OUTER_END, + OUTER_START); + + draw_gradient (cr, + RECT_WIDTH / 2 + X, + Y + 1, + (RECT_WIDTH - 7)/2, + MIDDLE_RADIUS, + INNER_COMPRESSED_START, + INNER_COMPRESSED_END); + draw_gradient (cr, RECT_WIDTH / 2 + X, Y + 2, (RECT_WIDTH - 7)/2, - INNER_RADIUS, + MIDDLE_RADIUS, INNER_COMPRESSED_START, INNER_COMPRESSED_END); - } + } - // play/pause-background + // play/pause shadow + if(priv->current_command != TRANSPORT_PLAY_PAUSE){ draw_circle (cr, + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f - 1.0f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) - 1.0f, + CIRCLE_RADIUS + 1.0f, + SHADOW_BUTTON, + SHADOW_BUTTON); + } + // play/pause border + if(priv->current_command == TRANSPORT_PLAY_PAUSE){ + draw_circle (cr, + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) , + CIRCLE_RADIUS, + OUTER_BUTTON_END, + OUTER_BUTTON_START); + } + else { + draw_circle (cr, X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f, Y - ((CIRCLE_RADIUS - OUTER_RADIUS)), CIRCLE_RADIUS, - OUTER_START, - OUTER_END); - draw_circle (cr, - X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 0.5f, - Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 0.5f, - CIRCLE_RADIUS - 0.75f, - MIDDLE_START, - MIDDLE_END); + OUTER_BUTTON_START, + OUTER_BUTTON_END); + } + // play/pause-background if(priv->current_command == TRANSPORT_PLAY_PAUSE){ draw_circle (cr, - X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.5f, - Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.5f, - CIRCLE_RADIUS - 1.5f, + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.25f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.25f, + CIRCLE_RADIUS - 1.25, INNER_COMPRESSED_START, INNER_COMPRESSED_END); } - else{ + else { draw_circle (cr, - X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.5f, - Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.5f, - CIRCLE_RADIUS - 1.5f, - MIDDLE_START, - MIDDLE_END); - } + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.25f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.25f, + CIRCLE_RADIUS - 1.25, + MIDDLE_START, + MIDDLE_END); + } + // draw previous-button drop-shadow _setup (&cr_surf, &surf, PREV_WIDTH, PREV_HEIGHT); _mask_prev (cr_surf, @@ -1155,7 +1249,7 @@ draw (GtkWidget* button, cairo_t *cr) BUTTON_SHADOW, BUTTON_SHADOW, FALSE); - _surface_blur (surf, 1); + _surface_blur (surf, 1); _finalize (cr, &cr_surf, &surf, NEXT_X, NEXT_Y + 1.0f); // draw next-button @@ -1216,7 +1310,7 @@ draw (GtkWidget* button, cairo_t *cr) } else if(priv->current_state == PAUSE){ _setup (&cr_surf, &surf, PLAY_WIDTH, PLAY_HEIGHT); - _mask_play (cr_surf, + _mask_play (cr_surf, PLAY_PADDING, PLAY_PADDING, PLAY_WIDTH - (2*PLAY_PADDING), @@ -1271,7 +1365,7 @@ transport_widget_set_twin_item(TransportWidget* self, /** * transport_widget_update_state() * Callback for updates from the other side of dbus -**/ +**/ static void transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) diff --git a/src/transport-widget.h b/src/transport-widget.h index 6ccce05..470b1cd 100644 --- a/src/transport-widget.h +++ b/src/transport-widget.h @@ -66,6 +66,8 @@ typedef struct void _color_shade (const CairoColorRGB *a, float k, CairoColorRGB *b); GType transport_widget_get_type (void); GtkWidget* transport_widget_new ( DbusmenuMenuitem *item ); +void transport_widget_react_to_key_event ( TransportWidget* widget, + TransportWidgetEvent transport_event ); G_END_DECLS |