Merge lp:~cjcurran/indicator-sound/icon-placement into lp:indicator-sound/sound-menu-v2

Proposed by Conor Curran
Status: Merged
Merged at revision: 129
Proposed branch: lp:~cjcurran/indicator-sound/icon-placement
Merge into: lp:indicator-sound/sound-menu-v2
Diff against target: 502 lines (+152/-80)
10 files modified
src/common-defs.h (+1/-0)
src/indicator-sound.c (+17/-12)
src/mpris2-controller.vala (+11/-11)
src/play-button.c (+6/-5)
src/player-controller.vala (+6/-0)
src/title-menu-item.vala (+6/-1)
src/title-widget.c (+92/-46)
src/title-widget.h (+3/-3)
src/transport-menu-item.vala (+9/-2)
vapi/common-defs.vapi (+1/-0)
To merge this branch: bzr merge lp:~cjcurran/indicator-sound/icon-placement
Reviewer Review Type Date Requested Status
Cody Russell (community) Approve
Review via email: mp+34864@code.launchpad.net

Description of the change

Icon now displayed in the gutter. Triangle now drawn when the application is running.

To post a comment you must log in.
Revision history for this message
Cody Russell (bratsche) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/common-defs.h'
2--- src/common-defs.h 2010-09-03 13:06:00 +0000
3+++ src/common-defs.h 2010-09-08 14:53:39 +0000
4@@ -41,6 +41,7 @@
5
6 #define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-type"
7 #define DBUSMENU_TITLE_MENUITEM_NAME "x-canonical-sound-menu-player-title-name"
8+#define DBUSMENU_TITLE_MENUITEM_RUNNING "x-canonical-sound-menu-player-title-running"
9
10 #define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-type"
11 #define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-mpris:length"
12
13=== modified file 'src/indicator-sound.c'
14--- src/indicator-sound.c 2010-09-06 17:07:15 +0000
15+++ src/indicator-sound.c 2010-09-08 14:53:39 +0000
16@@ -196,8 +196,10 @@
17 static GtkImage *
18 get_icon (IndicatorObject * io)
19 {
20- gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));
21- g_debug("At start-up attempting to set the image to %s", current_name);
22+ gchar* current_name = g_hash_table_lookup(volume_states,
23+ GINT_TO_POINTER(current_state));
24+ g_debug("At start-up attempting to set the image to %s",
25+ current_name);
26 speaker_image = indicator_image_helper(current_name);
27 gtk_widget_show(GTK_WIDGET(speaker_image));
28 return speaker_image;
29@@ -209,7 +211,8 @@
30 static GtkMenu *
31 get_menu (IndicatorObject * io)
32 {
33- DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT);
34+ DbusmenuGtkMenu* menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT);
35+
36 DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu);
37 g_object_set_data (G_OBJECT (client), "indicator", io);
38 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_VOLUME_MENUITEM_TYPE, new_volume_slider_widget);
39@@ -217,10 +220,10 @@
40 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget);
41 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget);
42 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SCRUB_MENUITEM_TYPE, new_scrub_bar_widget);
43-
44 // register Key-press listening on the menu widget as the slider does not allow this.
45 g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io);
46- return GTK_MENU(menu);
47+
48+ return GTK_MENU(menu);
49 }
50
51 static void
52@@ -274,20 +277,22 @@
53 static gboolean
54 new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
55 {
56- g_debug("indicator-sound: new_title_widget");
57-
58- GtkWidget* title = NULL;
59-
60+ g_debug("indicator-sound: new_title_widget");
61 g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
62 g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);
63
64+ g_debug ("%s (\"%s\")", __func__, dbusmenu_menuitem_property_get(newitem, DBUSMENU_TITLE_MENUITEM_NAME));
65+
66+ GtkWidget* title = NULL;
67+
68 title = title_widget_new (newitem);
69 GtkMenuItem *menu_title_widget = GTK_MENU_ITEM(title);
70-
71+
72 gtk_widget_show_all(title);
73
74- dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_title_widget, parent);
75-
76+ dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
77+ newitem,
78+ menu_title_widget, parent);
79 return TRUE;
80 }
81
82
83=== modified file 'src/mpris2-controller.vala'
84--- src/mpris2-controller.vala 2010-09-06 20:14:15 +0000
85+++ src/mpris2-controller.vala 2010-09-08 14:53:39 +0000
86@@ -105,7 +105,7 @@
87 if(play_v != null){
88 string state = play_v.get_string();
89 debug("new playback state = %s", state);
90- int p = this.determine_play_state(state);
91+ TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state);
92 (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p);
93 }
94
95@@ -143,29 +143,29 @@
96 }
97
98
99- private int determine_play_state(string status){
100+ private TransportMenuitem.state determine_play_state(string status){
101 if(status == null)
102- return 1;
103+ return TransportMenuitem.state.PAUSED;
104
105 if(status != null && status == "Playing"){
106 debug("determine play state - state = %s", status);
107- return 0;
108+ return TransportMenuitem.state.PLAYING;
109 }
110- return 1;
111+ return TransportMenuitem.state.PAUSED;
112 }
113
114 public void initial_update()
115 {
116- int32 status;
117+ TransportMenuitem.state update;
118 if(this.player.PlaybackStatus == null){
119- status = 1;
120+ update = TransportMenuitem.state.PAUSED;
121 }
122 else{
123- status = determine_play_state(this.player.PlaybackStatus);
124+ update = determine_play_state(this.player.PlaybackStatus);
125 }
126- debug("initial update - play state %i", status);
127+ debug("initial update - play state %i", (int)update);
128
129- (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status);
130+ (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(update);
131 GLib.HashTable<string, Value?> cleaned_metadata = this.clean_metadata();
132 this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata,
133 MetadataMenuitem.attributes_format());
134@@ -260,7 +260,7 @@
135 this.mpris2_root.Raise();
136 }
137 catch(DBus.Error e){
138- error("Exception thrown while calling root function Raise - %s", e.message);
139+ error("Exception thrown while calling function Raise - %s", e.message);
140 }
141 }
142 }
143
144=== modified file 'src/play-button.c'
145--- src/play-button.c 2010-09-07 09:52:23 +0000
146+++ src/play-button.c 2010-09-08 14:53:39 +0000
147@@ -388,19 +388,20 @@
148 g_debug("event y coordinate = %f", event->y);
149 PlayButtonEvent button_event = TRANSPORT_NADA;
150 // For now very simple rectangular collision detection
151- if(event->x > 55 && event->x < 95
152+ if(event->x > 67 && event->x < 112
153 && event->y > 12 && event->y < 40){
154 button_event = TRANSPORT_PREVIOUS;
155 }
156- else if(event->x > 99 && event->x < 136
157+ else if(event->x > 111 && event->x < 153
158 && event->y > 5 && event->y < 47){
159 button_event = TRANSPORT_PLAY_PAUSE;
160 }
161- else if(event->x > 137 && event->x < 179
162+ else if(event->x > 152 && event->x < 197
163 && event->y > 12 && event->y < 40){
164 button_event = TRANSPORT_NEXT;
165 }
166 return button_event;
167+
168 }
169
170 void
171@@ -730,8 +731,8 @@
172 cairo_surface_t* surf = NULL;
173 cairo_t* cr_surf = NULL;
174
175- double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f};
176- double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f};
177+ //double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f};
178+ //double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f};
179 double MIDDLE_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f};
180 double MIDDLE_END[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f};
181 double OUTER_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f};
182
183=== modified file 'src/player-controller.vala'
184--- src/player-controller.vala 2010-08-27 11:25:47 +0000
185+++ src/player-controller.vala 2010-09-08 14:53:39 +0000
186@@ -116,6 +116,8 @@
187 update_state(PlayerController.state.OFFLINE);
188 this.custom_items[widget_order.TRANSPORT].reset(TransportMenuitem.attributes_format());
189 this.custom_items[widget_order.METADATA].reset(MetadataMenuitem.attributes_format());
190+ TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem;
191+ title.toggle_active_triangle(false);
192 }
193
194 public void update_layout()
195@@ -172,6 +174,10 @@
196 {
197 if(this.mpris_bridge.connected() == true){
198 this.update_state(state.CONNECTED);
199+ TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem;
200+ title.toggle_active_triangle(true);
201+ TransportMenuitem transport = this.custom_items[widget_order.TRANSPORT] as TransportMenuitem;
202+ transport.change_play_state(TransportMenuitem.state.PAUSED);
203 }
204 else{
205 this.update_state(state.DISCONNECTED);
206
207=== modified file 'src/title-menu-item.vala'
208--- src/title-menu-item.vala 2010-08-17 16:26:47 +0000
209+++ src/title-menu-item.vala 2010-09-08 14:53:39 +0000
210@@ -27,6 +27,7 @@
211 {
212 Object(item_type: MENUITEM_TYPE, owner: parent);
213 this.property_set(MENUITEM_NAME, parent.name);
214+ this.property_set_bool(MENUITEM_RUNNING, false);
215 }
216
217 public override void handle_event(string name, GLib.Value input_value, uint timestamp)
218@@ -39,7 +40,11 @@
219 this.owner.mpris_bridge.expose();
220 }
221 }
222-
223+
224+ public void toggle_active_triangle(bool update)
225+ {
226+ this.property_set_bool(MENUITEM_RUNNING, update);
227+ }
228
229 public static HashSet<string> attributes_format()
230 {
231
232=== modified file 'src/title-widget.c'
233--- src/title-widget.c 2010-08-25 17:15:56 +0000
234+++ src/title-widget.c 2010-09-08 14:53:39 +0000
235@@ -32,10 +32,7 @@
236
237 struct _TitleWidgetPrivate
238 {
239- GtkWidget* hbox;
240- GtkWidget* name;
241- GtkWidget* player_icon;
242- DbusmenuMenuitem* twin_item;
243+ DbusmenuMenuitem* twin_item;
244 };
245
246 #define TITLE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TITLE_WIDGET_TYPE, TitleWidgetPrivate))
247@@ -54,10 +51,12 @@
248 static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property,
249 GValue* value, gpointer userdata);
250 static void title_widget_set_twin_item( TitleWidget* self,
251- DbusmenuMenuitem* twin_item);
252-static void title_widget_style_name_text(TitleWidget* self);
253+ DbusmenuMenuitem* twin_item);
254+static gboolean title_widget_triangle_draw_cb (GtkWidget *widget,
255+ GdkEventExpose *event,
256+ gpointer data);
257
258-G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_MENU_ITEM);
259+G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_IMAGE_MENU_ITEM);
260
261
262
263@@ -73,7 +72,6 @@
264
265 gobject_class->dispose = title_widget_dispose;
266 gobject_class->finalize = title_widget_finalize;
267-
268 }
269
270 static void
271@@ -81,15 +79,22 @@
272 {
273 g_debug("TitleWidget::title_widget_init");
274
275- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self);
276-
277- GtkWidget *hbox;
278-
279- hbox = gtk_hbox_new(FALSE, 0);
280- priv->hbox = hbox;
281-
282- priv->player_icon = indicator_image_helper("sound_icon");
283- gtk_box_pack_start(GTK_BOX (priv->hbox), priv->player_icon, FALSE, FALSE, 0);
284+ gint padding = 0;
285+ gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL);
286+
287+ gint width, height;
288+ gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
289+
290+ GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU);
291+
292+ gtk_widget_set_size_request(icon, width
293+ + 5 /* ref triangle is 5x9 pixels */
294+ + 1 /* padding */,
295+ height);
296+ gtk_misc_set_alignment(GTK_MISC(icon), 0.5 /* right aligned */, 0);
297+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon));
298+ gtk_widget_show(icon);
299+
300 }
301
302 static void
303@@ -127,11 +132,10 @@
304 {
305 g_return_if_fail (IS_TITLE_WIDGET (userdata));
306 TitleWidget* mitem = TITLE_WIDGET(userdata);
307- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(mitem);
308-
309- if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){
310- gtk_label_set_text(GTK_LABEL(priv->name), g_value_get_string(value));
311- title_widget_style_name_text(mitem);
312+
313+ if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){
314+ gtk_menu_item_set_label (GTK_MENU_ITEM(mitem),
315+ g_value_get_string(value));
316 }
317 }
318
319@@ -139,33 +143,72 @@
320 title_widget_set_twin_item(TitleWidget* self,
321 DbusmenuMenuitem* twin_item)
322 {
323- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self);
324- priv->twin_item = twin_item;
325- g_signal_connect(G_OBJECT(twin_item), "property-changed",
326- G_CALLBACK(title_widget_property_update), self);
327- priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item,
328- DBUSMENU_TITLE_MENUITEM_NAME));
329- gtk_misc_set_padding(GTK_MISC(priv->name), 10, 0);
330- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0);
331-
332- title_widget_style_name_text(self);
333-
334- gtk_widget_show_all (priv->hbox);
335- gtk_container_add (GTK_CONTAINER (self), priv->hbox);
336+ TitleWidgetPrivate *priv = TITLE_WIDGET_GET_PRIVATE(self);
337+
338+ priv->twin_item = twin_item;
339+
340+ g_signal_connect (G_OBJECT (twin_item),
341+ "property-changed",
342+ G_CALLBACK (title_widget_property_update),
343+ self);
344+ g_signal_connect_after (G_OBJECT (self),
345+ "expose_event",
346+ G_CALLBACK (title_widget_triangle_draw_cb),
347+ twin_item);
348+
349+ gtk_menu_item_set_label (GTK_MENU_ITEM(self),
350+ dbusmenu_menuitem_property_get(priv->twin_item,
351+ DBUSMENU_TITLE_MENUITEM_NAME));
352+
353 }
354
355-static void
356-title_widget_style_name_text(TitleWidget* self)
357+static gboolean
358+title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
359 {
360- TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self);
361-
362- char* markup;
363- markup = g_markup_printf_escaped ("<span size=\"medium\">%s</span>",
364- gtk_label_get_text(GTK_LABEL(priv->name)));
365- gtk_label_set_markup (GTK_LABEL (priv->name), markup);
366- g_free(markup);
367+ GtkStyle *style;
368+ cairo_t *cr;
369+ int x, y, arrow_width, arrow_height;
370+
371+ if (!GTK_IS_WIDGET (widget)) return FALSE;
372+ if (!DBUSMENU_IS_MENUITEM (data)) return FALSE;
373+
374+ /* render the triangle indicator only if the application is running */
375+ if (! dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM(data),
376+ DBUSMENU_TITLE_MENUITEM_RUNNING)){
377+ return FALSE;
378+ }
379+
380+ /* get style */
381+ style = gtk_widget_get_style (widget);
382+
383+ /* set arrow position / dimensions */
384+ arrow_width = 5; /* the pixel-based reference triangle is 5x9 */
385+ arrow_height = 9;
386+ x = widget->allocation.x;
387+ y = widget->allocation.y + widget->allocation.height/2.0 - (double)arrow_height/2.0;
388+
389+ /* initialize cairo drawing area */
390+ cr = (cairo_t*) gdk_cairo_create (widget->window);
391+
392+ /* set line width */
393+ cairo_set_line_width (cr, 1.0);
394+
395+ /* cairo drawing code */
396+ cairo_move_to (cr, x, y);
397+ cairo_line_to (cr, x, y + arrow_height);
398+ cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0);
399+ cairo_close_path (cr);
400+ cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
401+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
402+ style->fg[gtk_widget_get_state(widget)].blue/65535.0);
403+ cairo_fill (cr);
404+
405+ /* remember to destroy cairo context to avoid leaks */
406+ cairo_destroy (cr);
407+
408+ return FALSE;
409 }
410-
411+
412 /**
413 * transport_new:
414 * @returns: a new #TitleWidget.
415@@ -173,8 +216,11 @@
416 GtkWidget*
417 title_widget_new(DbusmenuMenuitem *item)
418 {
419- GtkWidget* widget = g_object_new(TITLE_WIDGET_TYPE, NULL);
420+ GtkWidget* widget = g_object_new (TITLE_WIDGET_TYPE,
421+ NULL);
422+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (widget), TRUE);
423 title_widget_set_twin_item((TitleWidget*)widget, item);
424+
425 return widget;
426 }
427
428
429=== modified file 'src/title-widget.h'
430--- src/title-widget.h 2010-08-06 12:20:03 +0000
431+++ src/title-widget.h 2010-09-08 14:53:39 +0000
432@@ -19,7 +19,7 @@
433 #ifndef __TITLE_WIDGET_H__
434 #define __TITLE_WIDGET_H__
435
436-#include <gtk/gtkmenuitem.h>
437+#include <gtk/gtkimagemenuitem.h>
438 #include <libdbusmenu-gtk/menuitem.h>
439
440 G_BEGIN_DECLS
441@@ -35,11 +35,11 @@
442 typedef struct _TitleWidgetClass TitleWidgetClass;
443
444 struct _TitleWidgetClass {
445- GtkMenuItemClass parent_class;
446+ GtkImageMenuItemClass parent_class;
447 };
448
449 struct _TitleWidget {
450- GtkMenuItem parent;
451+ GtkImageMenuItem parent;
452 };
453
454 GType title_widget_get_type (void);
455
456=== modified file 'src/transport-menu-item.vala'
457--- src/transport-menu-item.vala 2010-08-12 12:21:57 +0000
458+++ src/transport-menu-item.vala 2010-09-08 14:53:39 +0000
459@@ -28,6 +28,11 @@
460 PLAY_PAUSE,
461 NEXT
462 }
463+
464+ public enum state{
465+ PLAYING,
466+ PAUSED
467+ }
468
469 public TransportMenuitem(PlayerController parent)
470 {
471@@ -35,9 +40,9 @@
472 this.property_set_int(MENUITEM_PLAY_STATE, 1);
473 }
474
475- public void change_play_state(int state)
476+ public void change_play_state(state update)
477 {
478- this.property_set_int(MENUITEM_PLAY_STATE, state);
479+ this.property_set_int(MENUITEM_PLAY_STATE, update);
480 }
481
482 public override void handle_event(string name, GLib.Value input_value, uint timestamp)
483@@ -54,4 +59,6 @@
484 attrs.add(MENUITEM_PLAY_STATE);
485 return attrs;
486 }
487+
488+
489 }
490\ No newline at end of file
491
492=== modified file 'vapi/common-defs.vapi'
493--- vapi/common-defs.vapi 2010-09-03 13:06:00 +0000
494+++ vapi/common-defs.vapi 2010-09-08 14:53:39 +0000
495@@ -36,6 +36,7 @@
496 namespace DbusmenuTitle{
497 public const string MENUITEM_TYPE;
498 public const string MENUITEM_NAME;
499+ public const string MENUITEM_RUNNING;
500 }
501
502 [CCode (cheader_filename = "common-defs.h")]

Subscribers

People subscribed via source and target branches

to all changes: