Merge lp:~larsu/ido/lp733285 into lp:ido/14.04

Proposed by Lars Karlitski
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 177
Merged at revision: 176
Proposed branch: lp:~larsu/ido/lp733285
Merge into: lp:ido/14.04
Diff against target: 218 lines (+43/-45)
1 file modified
src/idoplaybackmenuitem.c (+43/-45)
To merge this branch: bzr merge lp:~larsu/ido/lp733285
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Sebastien Bacher user runtime testing Approve
Review via email: mp+212691@code.launchpad.net

Commit message

Highlight back/forward buttons when hovering them with the pointer

Space bar still activates play/pause, unless the mouse pointer hovers another button.

Description of the change

Highlight back/forward buttons when hovering them with the pointer

Space bar still activates play/pause, unless the mouse pointer hovers another button.

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

I didn't review the code but the changes works fine from an user perspective ;-)

review: Approve (user runtime testing)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/idoplaybackmenuitem.c'
--- src/idoplaybackmenuitem.c 2014-03-24 15:09:02 +0000
+++ src/idoplaybackmenuitem.c 2014-03-25 18:04:35 +0000
@@ -39,7 +39,8 @@
39 BUTTON_NONE,39 BUTTON_NONE,
40 BUTTON_PREVIOUS,40 BUTTON_PREVIOUS,
41 BUTTON_PLAYPAUSE,41 BUTTON_PLAYPAUSE,
42 BUTTON_NEXT42 BUTTON_NEXT,
43 N_BUTTONS
43} Button;44} Button;
4445
45typedef GtkMenuItemClass IdoPlaybackMenuItemClass;46typedef GtkMenuItemClass IdoPlaybackMenuItemClass;
@@ -55,9 +56,7 @@
55 gboolean keyboard_activated; /* TRUE if the current button was activated with a key */56 gboolean keyboard_activated; /* TRUE if the current button was activated with a key */
5657
57 GActionGroup *action_group;58 GActionGroup *action_group;
58 gchar *play_action;59 gchar *button_actions[N_BUTTONS];
59 gchar *next_action;
60 gchar *prev_action;
61};60};
6261
63G_DEFINE_TYPE (IdoPlaybackMenuItem, ido_playback_menu_item, GTK_TYPE_MENU_ITEM);62G_DEFINE_TYPE (IdoPlaybackMenuItem, ido_playback_menu_item, GTK_TYPE_MENU_ITEM);
@@ -82,10 +81,10 @@
82ido_playback_menu_item_finalize (GObject *object)81ido_playback_menu_item_finalize (GObject *object)
83{82{
84 IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (object);83 IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (object);
84 gint i;
8585
86 g_free (item->play_action);86 for (i = 0; i < N_BUTTONS; i++)
87 g_free (item->next_action);87 g_free (item->button_actions[i]);
88 g_free (item->prev_action);
8988
90 G_OBJECT_CLASS (ido_playback_menu_item_parent_class)->finalize (object);89 G_OBJECT_CLASS (ido_playback_menu_item_parent_class)->finalize (object);
91}90}
@@ -129,20 +128,17 @@
129 {128 {
130 case GDK_KEY_Left:129 case GDK_KEY_Left:
131 self->cur_pushed_button = BUTTON_PREVIOUS;130 self->cur_pushed_button = BUTTON_PREVIOUS;
132 if (self->action_group && self->prev_action)
133 g_action_group_activate_action (self->action_group, self->prev_action, NULL);
134 break;131 break;
135132
136 case GDK_KEY_Right:133 case GDK_KEY_Right:
137 self->cur_pushed_button = BUTTON_NEXT;134 self->cur_pushed_button = BUTTON_NEXT;
138 if (self->action_group && self->next_action)
139 g_action_group_activate_action (self->action_group, self->next_action, NULL);
140 break;135 break;
141136
142 case GDK_KEY_space:137 case GDK_KEY_space:
143 self->cur_pushed_button = BUTTON_PLAYPAUSE;138 if (self->cur_hover_button != BUTTON_NONE)
144 if (self->action_group && self->play_action)139 self->cur_pushed_button = self->cur_hover_button;
145 g_action_group_activate_action (self->action_group, self->play_action, NULL);140 else
141 self->cur_pushed_button = BUTTON_PLAYPAUSE;
146 break;142 break;
147143
148 default:144 default:
@@ -151,6 +147,11 @@
151147
152 if (self->cur_pushed_button != BUTTON_NONE)148 if (self->cur_pushed_button != BUTTON_NONE)
153 {149 {
150 const gchar *action = self->button_actions[self->cur_pushed_button];
151
152 if (self->action_group && action)
153 g_action_group_activate_action (self->action_group, action, NULL);
154
154 self->keyboard_activated = TRUE;155 self->keyboard_activated = TRUE;
155 gtk_widget_queue_draw (widget);156 gtk_widget_queue_draw (widget);
156 return TRUE;157 return TRUE;
@@ -243,31 +244,15 @@
243{244{
244 IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (menuitem);245 IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (menuitem);
245 Button button;246 Button button;
247 const gchar *action = action;
246248
247 button = ido_playback_menu_item_get_button_at_pos (event->x, event->y);249 button = ido_playback_menu_item_get_button_at_pos (event->x, event->y);
248 if (button != item->cur_pushed_button)250 if (button != item->cur_pushed_button)
249 button = BUTTON_NONE;251 button = BUTTON_NONE;
250252
251 switch (button)253 action = item->button_actions[item->cur_pushed_button];
252 {254 if (item->action_group && action)
253 case BUTTON_NONE:255 g_action_group_activate_action (item->action_group, action, NULL);
254 break;
255
256 case BUTTON_PREVIOUS:
257 if (item->action_group && item->prev_action)
258 g_action_group_activate_action (item->action_group, item->prev_action, NULL);
259 break;
260
261 case BUTTON_NEXT:
262 if (item->action_group && item->next_action)
263 g_action_group_activate_action (item->action_group, item->next_action, NULL);
264 break;
265
266 case BUTTON_PLAYPAUSE:
267 if (item->action_group && item->play_action)
268 g_action_group_activate_action (item->action_group, item->play_action, NULL);
269 break;
270 }
271256
272 item->cur_pushed_button = BUTTON_NONE;257 item->cur_pushed_button = BUTTON_NONE;
273 gtk_widget_queue_draw (menuitem);258 gtk_widget_queue_draw (menuitem);
@@ -363,12 +348,14 @@
363 gpointer user_data)348 gpointer user_data)
364{349{
365 IdoPlaybackMenuItem *self = user_data;350 IdoPlaybackMenuItem *self = user_data;
351 const gchar *action;
366352
367 if (self->play_action && g_str_equal (action_name, self->play_action))353 action = self->button_actions[BUTTON_PLAYPAUSE];
354 if (action && g_str_equal (action_name, action))
368 {355 {
369 GVariant *state;356 GVariant *state;
370357
371 state = g_action_group_get_action_state (action_group, self->play_action);358 state = g_action_group_get_action_state (action_group, action);
372 if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING))359 if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING))
373 ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (state, NULL));360 ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (state, NULL));
374361
@@ -382,8 +369,10 @@
382 gpointer user_data)369 gpointer user_data)
383{370{
384 IdoPlaybackMenuItem *self = user_data;371 IdoPlaybackMenuItem *self = user_data;
372 const gchar *action;
385373
386 if (self->play_action && g_str_equal (action_name, self->play_action))374 action = self->button_actions[BUTTON_PLAYPAUSE];
375 if (action && g_str_equal (action_name, action))
387 ido_playback_menu_item_set_state (self, STATE_PAUSED);376 ido_playback_menu_item_set_state (self, STATE_PAUSED);
388}377}
389378
@@ -394,10 +383,13 @@
394 gpointer user_data)383 gpointer user_data)
395{384{
396 IdoPlaybackMenuItem *self = user_data;385 IdoPlaybackMenuItem *self = user_data;
386 const gchar *action;
397387
398 g_return_if_fail (action_name != NULL);388 g_return_if_fail (action_name != NULL);
399389
400 if (self->play_action && g_str_equal (action_name, self->play_action))390 action = self->button_actions[BUTTON_PLAYPAUSE];
391
392 if (action && g_str_equal (action_name, action))
401 {393 {
402 if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))394 if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
403 ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (value, NULL));395 ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (value, NULL));
@@ -409,6 +401,7 @@
409 GActionGroup *actions)401 GActionGroup *actions)
410{402{
411 IdoPlaybackMenuItem *widget;403 IdoPlaybackMenuItem *widget;
404 gchar *play_action;
412405
413 widget = g_object_new (IDO_TYPE_PLAYBACK_MENU_ITEM, NULL);406 widget = g_object_new (IDO_TYPE_PLAYBACK_MENU_ITEM, NULL);
414407
@@ -417,12 +410,13 @@
417 g_signal_connect (actions, "action-added", G_CALLBACK (ido_playback_menu_item_action_added), widget);410 g_signal_connect (actions, "action-added", G_CALLBACK (ido_playback_menu_item_action_added), widget);
418 g_signal_connect (actions, "action-removed", G_CALLBACK (ido_playback_menu_item_action_removed), widget);411 g_signal_connect (actions, "action-removed", G_CALLBACK (ido_playback_menu_item_action_removed), widget);
419412
420 g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->play_action);413 g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->button_actions[BUTTON_PLAYPAUSE]);
421 g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->next_action);414 g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->button_actions[BUTTON_NEXT]);
422 g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->prev_action);415 g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->button_actions[BUTTON_PREVIOUS]);
423416
424 if (widget->play_action && g_action_group_has_action (actions, widget->play_action))417 play_action = widget->button_actions[BUTTON_PLAYPAUSE];
425 ido_playback_menu_item_action_added (actions, widget->play_action, widget);418 if (play_action && g_action_group_has_action (actions, play_action))
419 ido_playback_menu_item_action_added (actions, play_action, widget);
426420
427 return GTK_MENU_ITEM (widget);421 return GTK_MENU_ITEM (widget);
428}422}
@@ -1434,7 +1428,8 @@
1434 }1428 }
14351429
1436 // draw previous-button drop-shadow1430 // draw previous-button drop-shadow
1437 if (item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated )1431 if ((item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated) ||
1432 item->cur_hover_button == BUTTON_PREVIOUS)
1438 {1433 {
1439 _setup (&cr_surf, &surf, PREV_WIDTH+6, PREV_HEIGHT+6);1434 _setup (&cr_surf, &surf, PREV_WIDTH+6, PREV_HEIGHT+6);
1440 _mask_prev (cr_surf,1435 _mask_prev (cr_surf,
@@ -1494,7 +1489,8 @@
1494 _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y);1489 _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y);
14951490
1496 // draw next-button drop-shadow1491 // draw next-button drop-shadow
1497 if (item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated)1492 if ((item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated) ||
1493 item->cur_hover_button == BUTTON_NEXT)
1498 {1494 {
1499 _setup (&cr_surf, &surf, NEXT_WIDTH+6, NEXT_HEIGHT+6);1495 _setup (&cr_surf, &surf, NEXT_WIDTH+6, NEXT_HEIGHT+6);
1500 _mask_next (cr_surf,1496 _mask_next (cr_surf,
@@ -1557,6 +1553,7 @@
1557 if (item->current_state == STATE_PLAYING)1553 if (item->current_state == STATE_PLAYING)
1558 {1554 {
1559 if (item->has_focus &&1555 if (item->has_focus &&
1556 (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
1560 (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))1557 (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
1561 {1558 {
1562 _setup (&cr_surf, &surf, PAUSE_WIDTH+6, PAUSE_HEIGHT+6);1559 _setup (&cr_surf, &surf, PAUSE_WIDTH+6, PAUSE_HEIGHT+6);
@@ -1619,6 +1616,7 @@
1619 else if (item->current_state == STATE_PAUSED)1616 else if (item->current_state == STATE_PAUSED)
1620 {1617 {
1621 if (item->has_focus &&1618 if (item->has_focus &&
1619 (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
1622 (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))1620 (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
1623 {1621 {
1624 _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6);1622 _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6);

Subscribers

People subscribed via source and target branches