changeset 2301:69b06073a87d

GTK4: The "realize" signal is not quite the same as "size-allocate" so if the widget allocation is too small keep requesting it be called again until the size is valid.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 08 Feb 2021 23:07:52 +0000
parents 6e47d510dbbb
children 785775b9002f
files gtk4/dw.c
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/gtk4/dw.c	Mon Feb 08 10:49:50 2021 +0000
+++ b/gtk4/dw.c	Mon Feb 08 23:07:52 2021 +0000
@@ -8587,7 +8587,7 @@
 }
 
 /* Function to do delayed positioning */
-gboolean _splitbar_set_percent(gpointer data)
+gboolean _dw_splitbar_set_percent(gpointer data)
 {
    GtkWidget *widget = data;
    float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent");
@@ -8598,18 +8598,23 @@
 
       gtk_widget_get_allocation(widget, &alloc);
 
-      if(gtk_orientable_get_orientation(GTK_ORIENTABLE(widget)) == GTK_ORIENTATION_HORIZONTAL)
-         gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.width * (*percent / 100.0)));
+      if(alloc.width > 10 && alloc.height > 10)
+      {
+         if(gtk_orientable_get_orientation(GTK_ORIENTABLE(widget)) == GTK_ORIENTATION_HORIZONTAL)
+            gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.width * (*percent / 100.0)));
+         else
+            gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.height * (*percent / 100.0)));
+         g_object_set_data(G_OBJECT(widget), "_dw_percent", NULL);
+         free(percent);
+      }
       else
-         gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.height * (*percent / 100.0)));
-      g_object_set_data(G_OBJECT(widget), "_dw_percent", NULL);
-      free(percent);
+         return TRUE;
    }
    return FALSE;
 }
 
 /* Reposition the bar according to the percentage */
-static gint _splitbar_realize(GtkWidget *widget, gpointer data)
+static gint _dw_splitbar_realize(GtkWidget *widget, gpointer data)
 {
    float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent");
 
@@ -8617,7 +8622,7 @@
    if(!percent)
       return FALSE;
 
-   g_idle_add(_splitbar_set_percent, widget);
+   g_idle_add(_dw_splitbar_set_percent, widget);
    return FALSE;
 }
 
@@ -8645,7 +8650,7 @@
    g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
    *percent = 50.0;
    g_object_set_data(G_OBJECT(tmp), "_dw_percent", (gpointer)percent);
-   g_signal_connect(G_OBJECT(tmp), "realize", G_CALLBACK(_splitbar_realize), NULL);
+   g_signal_connect(G_OBJECT(tmp), "realize", G_CALLBACK(_dw_splitbar_realize), NULL);
    gtk_widget_show(tmp);
    return tmp;
 }