aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkarl-qdh <karl@qdh.org.uk>2011-03-03 14:45:37 +0000
committerkarl-qdh <karl@qdh.org.uk>2011-03-03 14:45:37 +0000
commit76825a8ee0227c18fd02a30ab74ecc5a95382b6d (patch)
treeb5b3dc03304bb2d9b1e7bbdca4ceb93a9c77149d
parent27e4da12f64cf3fbb3ae581a70503865c64e76b2 (diff)
downloadayatana-indicator-datetime-76825a8ee0227c18fd02a30ab74ecc5a95382b6d.tar.gz
ayatana-indicator-datetime-76825a8ee0227c18fd02a30ab74ecc5a95382b6d.tar.bz2
ayatana-indicator-datetime-76825a8ee0227c18fd02a30ab74ecc5a95382b6d.zip
Added some small fixes to make sure the pixbuf redraws everytime. There may be some memory leaks corrupting data somewhere.
-rw-r--r--src/datetime-service.c77
1 files changed, 41 insertions, 36 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 45546a0..fd14af9 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -82,6 +82,7 @@ static DbusmenuMenuitem * add_appointment = NULL;
static GList * appointments = NULL;
static GList * dconflocations = NULL;
static GList * comp_instances = NULL;
+static gboolean updating_appointments = FALSE;
GSettings *conf;
@@ -567,6 +568,8 @@ update_appointment_menu_items (gpointer user_data)
// tea timers, pomodoro timers etc... that people may add, this is hinted to in the spec.
if (calendar == NULL) return FALSE;
if (!g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) return FALSE;
+ if (updating_appointments) return TRUE;
+ updating_appointments = TRUE;
time_t t1, t2;
gchar *ad;
@@ -640,10 +643,6 @@ update_appointment_menu_items (gpointer user_data)
comp_instances = NULL;
i = 0;
- gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
- if (width == 0) width = 12;
- if (height == 0) height = 12;
-
for (l = sorted_comp_instances; l; l = l->next) {
struct comp_instance *ci = l->data;
ECalComponent *ecalcomp = ci->comp;
@@ -743,7 +742,12 @@ update_appointment_menu_items (gpointer user_data)
if (color_spec != NULL) {
// Fixme causes segfault, but we have colours now yay!
GdkColor color;
- gdk_color_parse (color_spec, &color);
+ gdk_color_parse (color_spec, &color);
+
+ gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
+ if (width == 0) width = 12;
+ if (height == 0) height = 12;
+
cairo_surface_t *surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, height );
cairo_t *cr = cairo_create(surface);
@@ -758,39 +762,39 @@ update_appointment_menu_items (gpointer user_data)
GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
!!(content & CAIRO_CONTENT_ALPHA),
8, width, height);
-
- gint sstride = cairo_image_surface_get_stride( surface );
- gint dstride = gdk_pixbuf_get_rowstride (pixbuf);
- guchar *spixels = cairo_image_surface_get_data( surface );
- guchar *dpixels = gdk_pixbuf_get_pixels (pixbuf);
-
-
- int x, y;
- for (y = 0; y < height; y++) {
- guint32 *src = (guint32 *) spixels;
-
- for (x = 0; x < width; x++) {
- guint alpha = src[x] >> 24;
-
- if (alpha == 0) {
- dpixels[x * 4 + 0] = 0;
- dpixels[x * 4 + 1] = 0;
- dpixels[x * 4 + 2] = 0;
- } else {
- dpixels[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
- dpixels[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
- dpixels[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
+ if (pixbuf != NULL) {
+ gint sstride = cairo_image_surface_get_stride( surface );
+ gint dstride = gdk_pixbuf_get_rowstride (pixbuf);
+ guchar *spixels = cairo_image_surface_get_data( surface );
+ guchar *dpixels = gdk_pixbuf_get_pixels (pixbuf);
+
+ int x, y;
+ for (y = 0; y < height; y++) {
+ guint32 *src = (guint32 *) spixels;
+
+ for (x = 0; x < width; x++) {
+ guint alpha = src[x] >> 24;
+
+ if (alpha == 0) {
+ dpixels[x * 4 + 0] = 0;
+ dpixels[x * 4 + 1] = 0;
+ dpixels[x * 4 + 2] = 0;
+ } else {
+ dpixels[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
+ dpixels[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
+ dpixels[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
+ }
+ dpixels[x * 4 + 3] = alpha;
}
- dpixels[x * 4 + 3] = alpha;
- }
- spixels += sstride;
- dpixels += dstride;
- }
-
- cairo_surface_destroy (surface);
- cairo_destroy(cr);
+ spixels += sstride;
+ dpixels += dstride;
+ }
+
+ cairo_surface_destroy (surface);
+ cairo_destroy(cr);
- dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);
+ dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);
+ }
}
dbusmenu_menuitem_child_add_position (root, item, 2+i);
appointments = g_list_append (appointments, item); // Keep track of the items here to make them east to remove
@@ -804,6 +808,7 @@ update_appointment_menu_items (gpointer user_data)
g_list_free(sorted_comp_instances);
}
+ updating_appointments = FALSE;
g_debug("End of objects");
return TRUE;
}