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
1=== modified file 'src/idoplaybackmenuitem.c'
2--- src/idoplaybackmenuitem.c 2014-03-24 15:09:02 +0000
3+++ src/idoplaybackmenuitem.c 2014-03-25 18:04:35 +0000
4@@ -39,7 +39,8 @@
5 BUTTON_NONE,
6 BUTTON_PREVIOUS,
7 BUTTON_PLAYPAUSE,
8- BUTTON_NEXT
9+ BUTTON_NEXT,
10+ N_BUTTONS
11 } Button;
12
13 typedef GtkMenuItemClass IdoPlaybackMenuItemClass;
14@@ -55,9 +56,7 @@
15 gboolean keyboard_activated; /* TRUE if the current button was activated with a key */
16
17 GActionGroup *action_group;
18- gchar *play_action;
19- gchar *next_action;
20- gchar *prev_action;
21+ gchar *button_actions[N_BUTTONS];
22 };
23
24 G_DEFINE_TYPE (IdoPlaybackMenuItem, ido_playback_menu_item, GTK_TYPE_MENU_ITEM);
25@@ -82,10 +81,10 @@
26 ido_playback_menu_item_finalize (GObject *object)
27 {
28 IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (object);
29+ gint i;
30
31- g_free (item->play_action);
32- g_free (item->next_action);
33- g_free (item->prev_action);
34+ for (i = 0; i < N_BUTTONS; i++)
35+ g_free (item->button_actions[i]);
36
37 G_OBJECT_CLASS (ido_playback_menu_item_parent_class)->finalize (object);
38 }
39@@ -129,20 +128,17 @@
40 {
41 case GDK_KEY_Left:
42 self->cur_pushed_button = BUTTON_PREVIOUS;
43- if (self->action_group && self->prev_action)
44- g_action_group_activate_action (self->action_group, self->prev_action, NULL);
45 break;
46
47 case GDK_KEY_Right:
48 self->cur_pushed_button = BUTTON_NEXT;
49- if (self->action_group && self->next_action)
50- g_action_group_activate_action (self->action_group, self->next_action, NULL);
51 break;
52
53 case GDK_KEY_space:
54- self->cur_pushed_button = BUTTON_PLAYPAUSE;
55- if (self->action_group && self->play_action)
56- g_action_group_activate_action (self->action_group, self->play_action, NULL);
57+ if (self->cur_hover_button != BUTTON_NONE)
58+ self->cur_pushed_button = self->cur_hover_button;
59+ else
60+ self->cur_pushed_button = BUTTON_PLAYPAUSE;
61 break;
62
63 default:
64@@ -151,6 +147,11 @@
65
66 if (self->cur_pushed_button != BUTTON_NONE)
67 {
68+ const gchar *action = self->button_actions[self->cur_pushed_button];
69+
70+ if (self->action_group && action)
71+ g_action_group_activate_action (self->action_group, action, NULL);
72+
73 self->keyboard_activated = TRUE;
74 gtk_widget_queue_draw (widget);
75 return TRUE;
76@@ -243,31 +244,15 @@
77 {
78 IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (menuitem);
79 Button button;
80+ const gchar *action = action;
81
82 button = ido_playback_menu_item_get_button_at_pos (event->x, event->y);
83 if (button != item->cur_pushed_button)
84 button = BUTTON_NONE;
85
86- switch (button)
87- {
88- case BUTTON_NONE:
89- break;
90-
91- case BUTTON_PREVIOUS:
92- if (item->action_group && item->prev_action)
93- g_action_group_activate_action (item->action_group, item->prev_action, NULL);
94- break;
95-
96- case BUTTON_NEXT:
97- if (item->action_group && item->next_action)
98- g_action_group_activate_action (item->action_group, item->next_action, NULL);
99- break;
100-
101- case BUTTON_PLAYPAUSE:
102- if (item->action_group && item->play_action)
103- g_action_group_activate_action (item->action_group, item->play_action, NULL);
104- break;
105- }
106+ action = item->button_actions[item->cur_pushed_button];
107+ if (item->action_group && action)
108+ g_action_group_activate_action (item->action_group, action, NULL);
109
110 item->cur_pushed_button = BUTTON_NONE;
111 gtk_widget_queue_draw (menuitem);
112@@ -363,12 +348,14 @@
113 gpointer user_data)
114 {
115 IdoPlaybackMenuItem *self = user_data;
116+ const gchar *action;
117
118- if (self->play_action && g_str_equal (action_name, self->play_action))
119+ action = self->button_actions[BUTTON_PLAYPAUSE];
120+ if (action && g_str_equal (action_name, action))
121 {
122 GVariant *state;
123
124- state = g_action_group_get_action_state (action_group, self->play_action);
125+ state = g_action_group_get_action_state (action_group, action);
126 if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING))
127 ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (state, NULL));
128
129@@ -382,8 +369,10 @@
130 gpointer user_data)
131 {
132 IdoPlaybackMenuItem *self = user_data;
133+ const gchar *action;
134
135- if (self->play_action && g_str_equal (action_name, self->play_action))
136+ action = self->button_actions[BUTTON_PLAYPAUSE];
137+ if (action && g_str_equal (action_name, action))
138 ido_playback_menu_item_set_state (self, STATE_PAUSED);
139 }
140
141@@ -394,10 +383,13 @@
142 gpointer user_data)
143 {
144 IdoPlaybackMenuItem *self = user_data;
145+ const gchar *action;
146
147 g_return_if_fail (action_name != NULL);
148
149- if (self->play_action && g_str_equal (action_name, self->play_action))
150+ action = self->button_actions[BUTTON_PLAYPAUSE];
151+
152+ if (action && g_str_equal (action_name, action))
153 {
154 if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
155 ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (value, NULL));
156@@ -409,6 +401,7 @@
157 GActionGroup *actions)
158 {
159 IdoPlaybackMenuItem *widget;
160+ gchar *play_action;
161
162 widget = g_object_new (IDO_TYPE_PLAYBACK_MENU_ITEM, NULL);
163
164@@ -417,12 +410,13 @@
165 g_signal_connect (actions, "action-added", G_CALLBACK (ido_playback_menu_item_action_added), widget);
166 g_signal_connect (actions, "action-removed", G_CALLBACK (ido_playback_menu_item_action_removed), widget);
167
168- g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->play_action);
169- g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->next_action);
170- g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->prev_action);
171+ g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->button_actions[BUTTON_PLAYPAUSE]);
172+ g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->button_actions[BUTTON_NEXT]);
173+ g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->button_actions[BUTTON_PREVIOUS]);
174
175- if (widget->play_action && g_action_group_has_action (actions, widget->play_action))
176- ido_playback_menu_item_action_added (actions, widget->play_action, widget);
177+ play_action = widget->button_actions[BUTTON_PLAYPAUSE];
178+ if (play_action && g_action_group_has_action (actions, play_action))
179+ ido_playback_menu_item_action_added (actions, play_action, widget);
180
181 return GTK_MENU_ITEM (widget);
182 }
183@@ -1434,7 +1428,8 @@
184 }
185
186 // draw previous-button drop-shadow
187- if (item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated )
188+ if ((item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated) ||
189+ item->cur_hover_button == BUTTON_PREVIOUS)
190 {
191 _setup (&cr_surf, &surf, PREV_WIDTH+6, PREV_HEIGHT+6);
192 _mask_prev (cr_surf,
193@@ -1494,7 +1489,8 @@
194 _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y);
195
196 // draw next-button drop-shadow
197- if (item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated)
198+ if ((item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated) ||
199+ item->cur_hover_button == BUTTON_NEXT)
200 {
201 _setup (&cr_surf, &surf, NEXT_WIDTH+6, NEXT_HEIGHT+6);
202 _mask_next (cr_surf,
203@@ -1557,6 +1553,7 @@
204 if (item->current_state == STATE_PLAYING)
205 {
206 if (item->has_focus &&
207+ (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
208 (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
209 {
210 _setup (&cr_surf, &surf, PAUSE_WIDTH+6, PAUSE_HEIGHT+6);
211@@ -1619,6 +1616,7 @@
212 else if (item->current_state == STATE_PAUSED)
213 {
214 if (item->has_focus &&
215+ (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
216 (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
217 {
218 _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6);

Subscribers

People subscribed via source and target branches