~ci-train-bot/ido/ido-ubuntu-xenial-2118

« back to all changes in this revision

Viewing changes to src/idoplaybackmenuitem.c

  • Committer: CI bot
  • Author(s): Lars Uebernickel
  • Date: 2014-03-28 11:27:23 UTC
  • mfrom: (175.1.2 trunk)
  • Revision ID: ps-jenkins@lists.canonical.com-20140328112723-hhrgewyhytao8gbe
Highlight back/forward buttons when hovering them with the pointer

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
  BUTTON_NONE,
40
40
  BUTTON_PREVIOUS,
41
41
  BUTTON_PLAYPAUSE,
42
 
  BUTTON_NEXT
 
42
  BUTTON_NEXT,
 
43
  N_BUTTONS
43
44
} Button;
44
45
 
45
46
typedef GtkMenuItemClass IdoPlaybackMenuItemClass;
55
56
  gboolean keyboard_activated; /* TRUE if the current button was activated with a key */
56
57
 
57
58
  GActionGroup *action_group;
58
 
  gchar *play_action;
59
 
  gchar *next_action;
60
 
  gchar *prev_action;
 
59
  gchar *button_actions[N_BUTTONS];
61
60
};
62
61
 
63
62
G_DEFINE_TYPE (IdoPlaybackMenuItem, ido_playback_menu_item, GTK_TYPE_MENU_ITEM);
82
81
ido_playback_menu_item_finalize (GObject *object)
83
82
{
84
83
  IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (object);
 
84
  gint i;
85
85
 
86
 
  g_free (item->play_action);
87
 
  g_free (item->next_action);
88
 
  g_free (item->prev_action);
 
86
  for (i = 0; i < N_BUTTONS; i++)
 
87
    g_free (item->button_actions[i]);
89
88
 
90
89
  G_OBJECT_CLASS (ido_playback_menu_item_parent_class)->finalize (object);
91
90
}
129
128
    {
130
129
    case GDK_KEY_Left:
131
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
131
      break;
135
132
 
136
133
    case GDK_KEY_Right:
137
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
135
      break;
141
136
 
142
137
    case GDK_KEY_space:
143
 
      self->cur_pushed_button = BUTTON_PLAYPAUSE;
144
 
      if (self->action_group && self->play_action)
145
 
        g_action_group_activate_action (self->action_group, self->play_action, NULL);
 
138
      if (self->cur_hover_button != BUTTON_NONE)
 
139
        self->cur_pushed_button = self->cur_hover_button;
 
140
      else
 
141
        self->cur_pushed_button = BUTTON_PLAYPAUSE;
146
142
      break;
147
143
 
148
144
    default:
151
147
 
152
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
155
      self->keyboard_activated = TRUE;
155
156
      gtk_widget_queue_draw (widget);
156
157
      return TRUE;
243
244
{
244
245
  IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (menuitem);
245
246
  Button button;
 
247
  const gchar *action = action;
246
248
 
247
249
  button = ido_playback_menu_item_get_button_at_pos (event->x, event->y);
248
250
  if (button != item->cur_pushed_button)
249
251
    button = BUTTON_NONE;
250
252
 
251
 
  switch (button)
252
 
    {
253
 
    case BUTTON_NONE:
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
 
    }
 
253
  action = item->button_actions[item->cur_pushed_button];
 
254
  if (item->action_group && action)
 
255
    g_action_group_activate_action (item->action_group, action, NULL);
271
256
 
272
257
  item->cur_pushed_button = BUTTON_NONE;
273
258
  gtk_widget_queue_draw (menuitem);
363
348
                                     gpointer      user_data)
364
349
{
365
350
  IdoPlaybackMenuItem *self = user_data;
 
351
  const gchar *action;
366
352
 
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
356
      GVariant *state;
370
357
 
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
359
      if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING))
373
360
        ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (state, NULL));
374
361
 
382
369
                                       gpointer      user_data)
383
370
{
384
371
  IdoPlaybackMenuItem *self = user_data;
 
372
  const gchar *action;
385
373
 
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
376
    ido_playback_menu_item_set_state (self, STATE_PAUSED);
388
377
}
389
378
 
394
383
                                             gpointer      user_data)
395
384
{
396
385
  IdoPlaybackMenuItem *self = user_data;
 
386
  const gchar *action;
397
387
 
398
388
  g_return_if_fail (action_name != NULL);
399
389
 
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
394
      if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
403
395
        ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (value, NULL));
409
401
                                       GActionGroup *actions)
410
402
{
411
403
  IdoPlaybackMenuItem *widget;
 
404
  gchar *play_action;
412
405
 
413
406
  widget = g_object_new (IDO_TYPE_PLAYBACK_MENU_ITEM, NULL);
414
407
 
417
410
  g_signal_connect (actions, "action-added", G_CALLBACK (ido_playback_menu_item_action_added), widget);
418
411
  g_signal_connect (actions, "action-removed", G_CALLBACK (ido_playback_menu_item_action_removed), widget);
419
412
 
420
 
  g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->play_action);
421
 
  g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->next_action);
422
 
  g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->prev_action);
 
413
  g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->button_actions[BUTTON_PLAYPAUSE]);
 
414
  g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->button_actions[BUTTON_NEXT]);
 
415
  g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->button_actions[BUTTON_PREVIOUS]);
423
416
 
424
 
  if (widget->play_action && g_action_group_has_action (actions, widget->play_action))
425
 
    ido_playback_menu_item_action_added (actions, widget->play_action, widget);
 
417
  play_action = widget->button_actions[BUTTON_PLAYPAUSE];
 
418
  if (play_action && g_action_group_has_action (actions, play_action))
 
419
    ido_playback_menu_item_action_added (actions, play_action, widget);
426
420
 
427
421
  return GTK_MENU_ITEM (widget);
428
422
}
1434
1428
  }
1435
1429
 
1436
1430
  // 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
1434
    _setup (&cr_surf, &surf, PREV_WIDTH+6, PREV_HEIGHT+6);
1440
1435
    _mask_prev (cr_surf,
1494
1489
  _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y);
1495
1490
 
1496
1491
  // 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
1495
    _setup (&cr_surf, &surf, NEXT_WIDTH+6, NEXT_HEIGHT+6);
1500
1496
    _mask_next (cr_surf,
1557
1553
  if (item->current_state == STATE_PLAYING)
1558
1554
  {
1559
1555
    if (item->has_focus &&
 
1556
        (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
1560
1557
        (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
1561
1558
    {
1562
1559
      _setup (&cr_surf, &surf, PAUSE_WIDTH+6, PAUSE_HEIGHT+6);
1619
1616
  else if (item->current_state == STATE_PAUSED)
1620
1617
  {
1621
1618
    if (item->has_focus &&
 
1619
        (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
1622
1620
        (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
1623
1621
    {
1624
1622
      _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6);