comparison gtk3/dw.c @ 1353:f4ad4ba39b61

Apparently it is unsafe to set properties in the GTK3 size allocate callback. Start an idle timer and set the splitbar position at an idle time later.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 16 Nov 2011 20:31:35 +0000
parents 08de3c1f4ae4
children 1f22addc2722
comparison
equal deleted inserted replaced
1352:08de3c1f4ae4 1353:f4ad4ba39b61
9498 } 9498 }
9499 } 9499 }
9500 DW_MUTEX_UNLOCK; 9500 DW_MUTEX_UNLOCK;
9501 } 9501 }
9502 9502
9503 /* Function to do delayed positioning */
9504 gboolean _splitbar_set_percent(gpointer data)
9505 {
9506 GtkWidget *widget = data;
9507 float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent");
9508
9509 if(percent)
9510 {
9511 GtkAllocation alloc;
9512
9513 gtk_widget_get_allocation(widget, &alloc);
9514
9515 if(GTK_IS_HPANED(widget))
9516 gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.width * (*percent / 100.0)));
9517 if(GTK_IS_VPANED(widget))
9518 gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.height * (*percent / 100.0)));
9519 g_object_set_data(G_OBJECT(widget), "_dw_percent", NULL);
9520 free(percent);
9521 }
9522 return FALSE;
9523 }
9524
9503 /* Reposition the bar according to the percentage */ 9525 /* Reposition the bar according to the percentage */
9504 static gint _splitbar_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data) 9526 static gint _splitbar_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data)
9505 { 9527 {
9506 float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent"); 9528 float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent");
9507 9529
9508 /* Prevent infinite recursion ;) */ 9530 /* Prevent infinite recursion ;) */
9509 if(!percent || event->width < 20 || event->height < 20) 9531 if(!percent || event->width < 20 || event->height < 20)
9510 return FALSE; 9532 return FALSE;
9511 9533
9512 if(GTK_IS_HPANED(widget)) 9534 g_idle_add(_splitbar_set_percent, widget);
9513 gtk_paned_set_position(GTK_PANED(widget), (int)(event->width * (*percent / 100.0)));
9514 if(GTK_IS_VPANED(widget))
9515 gtk_paned_set_position(GTK_PANED(widget), (int)(event->height * (*percent / 100.0)));
9516 g_object_set_data(G_OBJECT(widget), "_dw_percent", NULL);
9517 free(percent);
9518 return FALSE; 9535 return FALSE;
9519 } 9536 }
9520 9537
9521 /* 9538 /*
9522 * Creates a splitbar window (widget) with given parameters. 9539 * Creates a splitbar window (widget) with given parameters.