Merge lp:~cimi/indicator-messages/right-rounded-numbers into lp:indicator-messages/0.5

Proposed by Andrea Cimitan
Status: Merged
Approved by: David Barth
Approved revision: 194
Merged at revision: 190
Proposed branch: lp:~cimi/indicator-messages/right-rounded-numbers
Merge into: lp:indicator-messages/0.5
Diff against target: 124 lines (+83/-2)
1 file modified
src/indicator-messages.c (+83/-2)
To merge this branch: bzr merge lp:~cimi/indicator-messages/right-rounded-numbers
Reviewer Review Type Date Requested Status
David Barth Approve
Indicator Applet Developers Pending
Review via email: mp+31262@code.launchpad.net

Description of the change

Add rounded numbers on the right

To post a comment you must log in.
Revision history for this message
David Barth (dbarth) wrote :

THe patch compiles and runs, but the rendering omits the label. Re-add the gtk_label_new call you suppressed.

On a more general note, you should check all arguments passed to your functions, in particular callbacks. If they are NULL or not of the right type, exit early to avoid de-referencing a pointer (and crashing).

review: Needs Fixing
193. By Andrea Cimitan

Ops, readded the label :P

Revision history for this message
David Barth (dbarth) wrote :

Something like that:

=== modified file 'src/indicator-messages.c'
--- src/indicator-messages.c 2010-07-29 11:30:48 +0000
+++ src/indicator-messages.c 2010-07-29 11:36:44 +0000
@@ -314,6 +314,8 @@
  PangoLayout * layout;
  gint font_size = RIGHT_LABEL_FONT_SIZE;

+ if (! GTK_IS_WIDGET (widget)) return;
+
  /* get style */
  style = gtk_widget_get_style (widget);

194. By Andrea Cimitan

check if widget is really a widget before getting its style (from dbarth)

Revision history for this message
David Barth (dbarth) wrote :

+1 Congrats for your 1st DX merge proposal ;)

review: Approve
Revision history for this message
Andrea Cimitan (cimi) wrote :

> +1 Congrats for your 1st DX merge proposal ;)

ahaha ty ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator-messages.c'
2--- src/indicator-messages.c 2010-03-31 05:24:02 +0000
3+++ src/indicator-messages.c 2010-07-29 11:41:53 +0000
4@@ -44,6 +44,11 @@
5 #define IS_INDICATOR_MESSAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_MESSAGES_TYPE))
6 #define INDICATOR_MESSAGES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_MESSAGES_TYPE, IndicatorMessagesClass))
7
8+#define M_PI 3.1415926535897932384626433832795028841971693993751
9+
10+#define RIGHT_LABEL_FONT_SIZE 12
11+#define RIGHT_LABEL_RADIUS 20
12+
13 typedef struct _IndicatorMessages IndicatorMessages;
14 typedef struct _IndicatorMessagesClass IndicatorMessagesClass;
15
16@@ -285,6 +290,74 @@
17 return;
18 }
19
20+/* Custom function to draw rounded rectangle with max radius */
21+static void
22+custom_cairo_rounded_rectangle (cairo_t *cr,
23+ double x, double y, double w, double h)
24+{
25+ double radius = MIN (w/2.0, h/2.0);
26+
27+ cairo_move_to (cr, x+radius, y);
28+ cairo_arc (cr, x+w-radius, y+radius, radius, M_PI*1.5, M_PI*2);
29+ cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, M_PI*0.5);
30+ cairo_arc (cr, x+radius, y+h-radius, radius, M_PI*0.5, M_PI);
31+ cairo_arc (cr, x+radius, y+radius, radius, M_PI, M_PI*1.5);
32+}
33+
34+/* Draws a rounded rectangle with text inside. */
35+static gboolean
36+numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
37+{
38+ GtkStyle *style;
39+ cairo_t *cr;
40+ double x, y, w, h;
41+ PangoLayout * layout;
42+ gint font_size = RIGHT_LABEL_FONT_SIZE;
43+
44+ if (!GTK_IS_WIDGET (widget)) return;
45+
46+ /* get style */
47+ style = gtk_widget_get_style (widget);
48+
49+ /* set arrow position / dimensions */
50+ w = widget->allocation.width;
51+ h = widget->allocation.height;
52+ x = widget->allocation.x;
53+ y = widget->allocation.y;
54+
55+ layout = gtk_label_get_layout (GTK_LABEL(widget));
56+
57+ /* This does not work, don't ask me why but font_size is 0.
58+ * I wanted to use a dynamic font size to adjust the padding on left/right edges
59+ * of the rounded rectangle. Andrea Cimitan */
60+ /* const PangoFontDescription * font_description = pango_layout_get_font_description (layout);
61+ font_size = pango_font_description_get_size (font_description); */
62+
63+ /* initialize cairo drawing area */
64+ cr = (cairo_t*) gdk_cairo_create (widget->window);
65+
66+ /* set line width */
67+ cairo_set_line_width (cr, 1.0);
68+
69+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
70+
71+ /* cairo drawing code */
72+ custom_cairo_rounded_rectangle (cr, x - font_size/2.0, y, w + font_size, h);
73+
74+ cairo_set_source_rgba (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
75+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
76+ style->fg[gtk_widget_get_state(widget)].blue/65535.0, 0.5);
77+
78+ cairo_move_to (cr, x, y);
79+ pango_cairo_layout_path (cr, layout);
80+ cairo_fill (cr);
81+
82+ /* remember to destroy cairo context to avoid leaks */
83+ cairo_destroy (cr);
84+
85+ return TRUE;
86+}
87+
88 /* Builds a menu item representing a running application in the
89 messaging menu */
90 static gboolean
91@@ -335,7 +408,6 @@
92 return TRUE;
93 }
94
95-
96 typedef struct _indicator_item_t indicator_item_t;
97 struct _indicator_item_t {
98 GtkWidget * icon;
99@@ -405,6 +477,7 @@
100 GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new());
101
102 gint padding = 4;
103+ gint font_size = RIGHT_LABEL_FONT_SIZE;
104 gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL);
105
106 GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
107@@ -455,8 +528,16 @@
108 item. */
109 mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT));
110 gtk_size_group_add_widget(indicator_right_group, mi_data->right);
111+
112+ /* Doesn't work, look numbers_draw_cb. */
113+ /* PangoLayout * right_layout = gtk_label_get_layout (GTK_LABEL(mi_data->right));
114+ font_size = pango_font_description_get_size (pango_layout_get_font_description (right_layout)); */
115+
116+ g_signal_connect (G_OBJECT (mi_data->right), "expose_event",
117+ G_CALLBACK (numbers_draw_cb), NULL);
118+
119 gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5);
120- gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding);
121+ gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding + font_size/2.0);
122 gtk_widget_show(mi_data->right);
123
124 gtk_container_add(GTK_CONTAINER(gmi), hbox);

Subscribers

People subscribed via source and target branches