diff options
author | Andrea Cimitan <andrea.cimitan@canonical.com> | 2010-11-17 11:27:40 +0100 |
---|---|---|
committer | Andrea Cimitan <andrea.cimitan@canonical.com> | 2010-11-17 11:27:40 +0100 |
commit | f301b9c10c8e867acf076a3351060703d0049652 (patch) | |
tree | 166ad32c8fa113bf236d1b14ca576a1fe97bc056 /src | |
parent | 9c5e8107b0d034a422e3397858a91c51b695f3f2 (diff) | |
download | ayatana-indicator-sound-f301b9c10c8e867acf076a3351060703d0049652.tar.gz ayatana-indicator-sound-f301b9c10c8e867acf076a3351060703d0049652.tar.bz2 ayatana-indicator-sound-f301b9c10c8e867acf076a3351060703d0049652.zip |
implementing the focus/key_press thing
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-sound.c | 60 | ||||
-rw-r--r-- | src/transport-widget.c | 40 | ||||
-rw-r--r-- | src/transport-widget.h | 6 |
3 files changed, 89 insertions, 17 deletions
diff --git a/src/indicator-sound.c b/src/indicator-sound.c index b39d064..d4e5f3f 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -72,6 +72,7 @@ static void indicator_sound_scroll (IndicatorObject* io, gint delta, Indicato //Slider related static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); +static gboolean key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); static void style_changed_cb(GtkWidget *widget, gpointer user_data); //player widget realisation methods @@ -222,7 +223,8 @@ get_menu (IndicatorObject * io) 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), io); - + g_signal_connect(menu, "key-release-event", G_CALLBACK(key_release_cb), io); + return GTK_MENU(menu); } @@ -718,17 +720,63 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) else 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 ); + transport_widget_react_to_key_press_event ( TRANSPORT_WIDGET ( priv->transport_widget ), + TRANSPORT_NEXT ); + digested = TRUE; + break; + case GDK_Left: + transport_widget_react_to_key_press_event ( TRANSPORT_WIDGET ( priv->transport_widget ), + TRANSPORT_PREVIOUS ); + digested = TRUE; + break; + case GDK_KEY_space: + transport_widget_react_to_key_press_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; +} + + +/** +key_release_cb: +**/ +static gboolean +key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) +{ + gboolean digested = FALSE; + + g_return_val_if_fail(IS_INDICATOR_SOUND(data), FALSE); + + IndicatorSound *indicator = INDICATOR_SOUND (data); + + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + + GtkWidget *menuitem; + + menuitem = GTK_MENU_SHELL (widget)->active_menu_item; + if (IS_TRANSPORT_WIDGET(menuitem) == TRUE) { + switch (event->keyval) { + case GDK_Right: + transport_widget_react_to_key_release_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 ); + transport_widget_react_to_key_release_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_widget_react_to_key_release_event ( TRANSPORT_WIDGET ( priv->transport_widget ), TRANSPORT_PLAY_PAUSE ); digested = TRUE; break; diff --git a/src/transport-widget.c b/src/transport-widget.c index 88a352d..8c674a6 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -77,6 +77,7 @@ typedef struct _TransportWidgetPrivate TransportWidgetPrivate; struct _TransportWidgetPrivate { TransportWidgetEvent current_command; + TransportWidgetEvent key_event; TransportWidgetState current_state; GHashTable* command_coordinates; DbusmenuMenuitem* twin_item; @@ -146,6 +147,7 @@ transport_widget_init (TransportWidget *self) TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(self); priv->current_command = TRANSPORT_NADA; priv->current_state = PAUSE; + priv->key_event = TRANSPORT_NADA; priv->has_focus = FALSE; priv->command_coordinates = g_hash_table_new_full(g_direct_hash, g_direct_equal, @@ -267,6 +269,7 @@ transport_widget_button_press_event (GtkWidget *menuitem, TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE ( TRANSPORT_WIDGET(menuitem) ); TransportWidgetEvent result = transport_widget_determine_button_event ( TRANSPORT_WIDGET(menuitem), event); + if(result != TRANSPORT_NADA){ priv->current_command = result; cairo_t *cr; @@ -319,8 +322,24 @@ transport_widget_deselect (GtkItem* item, gpointer Userdata) } void -transport_widget_react_to_key_event ( TransportWidget* transport, - TransportWidgetEvent transport_event ) +transport_widget_react_to_key_press_event ( TransportWidget* transport, + TransportWidgetEvent transport_event ) +{ + if(transport_event != TRANSPORT_NADA){ + TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); + priv->current_command = transport_event; + priv->key_event = transport_event; + + cairo_t *cr; + cr = gdk_cairo_create ( GTK_WIDGET(transport)->window ); + draw ( GTK_WIDGET(transport), cr ); + cairo_destroy (cr); + } +} + +void +transport_widget_react_to_key_release_event ( TransportWidget* transport, + TransportWidgetEvent transport_event ) { if(transport_event != TRANSPORT_NADA){ TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); @@ -378,7 +397,9 @@ transport_widget_react_to_button_release ( TransportWidget* button, TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(button); if(priv->current_command == TRANSPORT_NADA){ //g_debug("returning from the playbutton release because my previous command was nada"); - return; + + /* Update the drawing in any case, should not hurt :) */ + // return; } else if(priv->current_command != TRANSPORT_NADA && command != TRANSPORT_NADA){ @@ -386,11 +407,12 @@ transport_widget_react_to_button_release ( TransportWidget* button, } cairo_t *cr; cr = gdk_cairo_create ( GTK_WIDGET(button)->window ); - priv->current_command = TRANSPORT_NADA; + priv->current_command = TRANSPORT_NADA; + priv->key_event = TRANSPORT_NADA; draw ( GTK_WIDGET(button), cr ); cairo_destroy (cr); -} +} /// internal helper functions ////////////////////////////////////////////////// @@ -1261,7 +1283,7 @@ draw (GtkWidget* button, cairo_t *cr) } // draw previous-button drop-shadow - if (priv->has_focus) + if (priv->has_focus && priv->key_event == TRANSPORT_PREVIOUS) { _setup (&cr_surf, &surf, PREV_WIDTH+6, PREV_HEIGHT+6); _mask_prev (cr_surf, @@ -1321,7 +1343,7 @@ draw (GtkWidget* button, cairo_t *cr) _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y); // draw next-button drop-shadow - if (priv->has_focus) + if (priv->has_focus && priv->key_event == TRANSPORT_NEXT) { _setup (&cr_surf, &surf, NEXT_WIDTH+6, NEXT_HEIGHT+6); _mask_next (cr_surf, @@ -1382,7 +1404,7 @@ draw (GtkWidget* button, cairo_t *cr) // draw pause-button drop-shadow if(priv->current_state == PLAY){ - if (priv->has_focus) + if (priv->has_focus && (priv->key_event == TRANSPORT_NADA || priv->key_event == TRANSPORT_PLAY_PAUSE)) { _setup (&cr_surf, &surf, PAUSE_WIDTH+6, PAUSE_HEIGHT+6); _mask_pause (cr_surf, @@ -1442,7 +1464,7 @@ draw (GtkWidget* button, cairo_t *cr) _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y); } else if(priv->current_state == PAUSE){ - if (priv->has_focus) + if (priv->has_focus && (priv->key_event == TRANSPORT_NADA || priv->key_event == TRANSPORT_PLAY_PAUSE)) { _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6); _mask_play (cr_surf, diff --git a/src/transport-widget.h b/src/transport-widget.h index 58a224c..7c087fb 100644 --- a/src/transport-widget.h +++ b/src/transport-widget.h @@ -66,8 +66,10 @@ 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 ); +void transport_widget_react_to_key_press_event ( TransportWidget* widget, + TransportWidgetEvent transport_event ); +void transport_widget_react_to_key_release_event ( TransportWidget* widget, + TransportWidgetEvent transport_event ); G_END_DECLS #endif |