diff options
author | Ted Gould <ted@gould.cx> | 2011-08-17 14:20:01 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2011-08-17 14:20:01 -0500 |
commit | 7e62cf98a12ec3580b4506a1cd61b24f303005a3 (patch) | |
tree | 7c1152de3ca10570e5ff1292c63c0296b2ca4168 | |
parent | 3e347a0dba56074bcd4023450afb1982e16e1684 (diff) | |
parent | a97707f5ea06bace3bc77f589b052293549e054b (diff) | |
download | ayatana-indicator-messages-7e62cf98a12ec3580b4506a1cd61b24f303005a3.tar.gz ayatana-indicator-messages-7e62cf98a12ec3580b4506a1cd61b24f303005a3.tar.bz2 ayatana-indicator-messages-7e62cf98a12ec3580b4506a1cd61b24f303005a3.zip |
Fix drawing on GTK3
-rw-r--r-- | src/indicator-messages.c | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 82a9315..f2baf83 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -416,12 +416,18 @@ application_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * valu } /* Draws a triangle on the left, using fg[STATE_TYPE] color. */ +#if GTK_CHECK_VERSION(3, 0, 0) +static gboolean +application_triangle_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data) +{ +#else static gboolean application_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) { + cairo_t *cr; +#endif GtkAllocation allocation; GtkStyle *style; - cairo_t *cr; int x, y, arrow_width, arrow_height; if (!GTK_IS_WIDGET (widget)) return FALSE; @@ -438,13 +444,22 @@ application_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer arrow_width = 5; /* the pixel-based reference triangle is 5x9 */ arrow_height = 9; gtk_widget_get_allocation (widget, &allocation); +#if GTK_CHECK_VERSION(3, 0, 0) + x = 0; + y = allocation.height/2.0 - (double)arrow_height/2.0; +#else x = allocation.x; y = allocation.y + allocation.height/2.0 - (double)arrow_height/2.0; +#endif +#if GTK_CHECK_VERSION(3, 0, 0) + cairo_save (cr); +#else /* initialize cairo drawing area */ cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget)); +#endif - /* set line width */ + /* set line width */ cairo_set_line_width (cr, 1.0); /* cairo drawing code */ @@ -457,8 +472,12 @@ application_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer style->fg[gtk_widget_get_state(widget)].blue/65535.0); cairo_fill (cr); +#if GTK_CHECK_VERSION(3, 0, 0) + cairo_restore (cr); +#else /* remember to destroy cairo context to avoid leaks */ cairo_destroy (cr); +#endif return FALSE; } @@ -478,12 +497,18 @@ custom_cairo_rounded_rectangle (cairo_t *cr, } /* Draws a rounded rectangle with text inside. */ +#if GTK_CHECK_VERSION(3, 0, 0) +static gboolean +numbers_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data) +{ +#else static gboolean numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) { + cairo_t *cr; +#endif GtkAllocation allocation; GtkStyle *style; - cairo_t *cr; double x, y, w, h; PangoLayout * layout; gint font_size = RIGHT_LABEL_FONT_SIZE; @@ -495,10 +520,15 @@ numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) /* set arrow position / dimensions */ gtk_widget_get_allocation (widget, &allocation); - w = allocation.width; - h = allocation.height; +#if GTK_CHECK_VERSION(3, 0, 0) + x = 0; + y = 0; +#else x = allocation.x; y = allocation.y; +#endif + w = allocation.width; + h = allocation.height; layout = gtk_label_get_layout (GTK_LABEL(widget)); @@ -508,10 +538,14 @@ numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) /* const PangoFontDescription * font_description = pango_layout_get_font_description (layout); font_size = pango_font_description_get_size (font_description); */ +#if GTK_CHECK_VERSION(3, 0, 0) + cairo_save (cr); +#else /* initialize cairo drawing area */ cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget)); +#endif - /* set line width */ + /* set line width */ cairo_set_line_width (cr, 1.0); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); @@ -527,8 +561,12 @@ numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) pango_cairo_layout_path (cr, layout); cairo_fill (cr); +#if GTK_CHECK_VERSION(3, 0, 0) + cairo_restore (cr); +#else /* remember to destroy cairo context to avoid leaks */ - cairo_destroy (cr); + cairo_destroy (cr); +#endif return TRUE; } @@ -577,7 +615,11 @@ new_application_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu /* Make sure we can handle the label changing */ g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_prop_change_cb), label); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_icon_change_cb), icon); +#if GTK_CHECK_VERSION(3, 0, 0) + g_signal_connect_after(G_OBJECT (gmi), "draw", G_CALLBACK (application_triangle_draw_cb), newitem); +#else g_signal_connect_after(G_OBJECT (gmi), "expose_event", G_CALLBACK (application_triangle_draw_cb), newitem); +#endif return TRUE; } @@ -710,8 +752,13 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT)); gtk_size_group_add_widget(indicator_right_group, mi_data->right); /* install extra decoration overlay */ +#if GTK_CHECK_VERSION(3, 0, 0) + g_signal_connect (G_OBJECT (mi_data->right), "draw", + G_CALLBACK (numbers_draw_cb), NULL); +#else g_signal_connect (G_OBJECT (mi_data->right), "expose_event", G_CALLBACK (numbers_draw_cb), NULL); +#endif gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding + font_size/2.0); |