[balsa] balsa-index: Use a low priority idle handler



commit 7f457d65e4ac64ebe1c33ca5388251bb9e440ccb
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jan 13 19:30:27 2020 -0500

    balsa-index: Use a low priority idle handler
    
    balsa-index: Use a low priority idle handler instead of a
    timeout to schedule scroll-on-open. That's enough to let
    GtkTreeView do its layout work before the scroll-on-open handler
    gets called.
    
    * src/balsa-index.c (bndx_scroll_on_open_idle), (balsa_index_scroll_on_open):

 ChangeLog         | 10 ++++++++++
 src/balsa-index.c | 38 +++++++++++++++++++-------------------
 2 files changed, 29 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cb7401bd2..f681bc32e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-01-13  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       balsa-index: Use a low priority idle handler instead of a
+       timeout to schedule scroll-on-open. That's enough to let
+       GtkTreeView do its layout work before the scroll-on-open handler
+       gets called.
+
+       * src/balsa-index.c (bndx_scroll_on_open_idle),
+       (balsa_index_scroll_on_open):
+
 2020-01-12  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Stop using gtk_main_iteration_do()
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 3c6d97fca..12ceeb9c8 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -838,9 +838,8 @@ bndx_scroll_on_open_idle(BalsaIndex *bindex)
 
     first_unread = libbalsa_mailbox_get_first_unread(mailbox);
     if (first_unread > 0) {
-       unsigned msgno = first_unread;
         libbalsa_mailbox_set_first_unread(mailbox, 0);
-        if (!libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL)) {
+        if (!libbalsa_mailbox_msgno_find(mailbox, first_unread, &path, NULL)) {
             gtk_widget_show(GTK_WIDGET(bindex));
             return FALSE; /* Oops! */
         }
@@ -865,21 +864,20 @@ bndx_scroll_on_open_idle(BalsaIndex *bindex)
         g_object_get_data(G_OBJECT(mailbox), BALSA_INDEX_VIEW_ON_OPEN);
     g_object_set_data(G_OBJECT(mailbox), BALSA_INDEX_VIEW_ON_OPEN, NULL);
 
-    if (gtk_tree_view_get_model(tree_view)) {
-        if ((view_on_open && GPOINTER_TO_INT(view_on_open))
-            || balsa_app.view_message_on_open) {
-            bndx_select_row(bindex, path);
-        } else {
-            GtkTreeSelection *selection;
-            gulong changed_id = bindex->selection_changed_id;
-
-            selection = gtk_tree_view_get_selection(tree_view);
-            g_signal_handler_block(selection, changed_id);
-            gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
-            gtk_tree_selection_unselect_all(selection);
-            g_signal_handler_unblock(selection, changed_id);
-        }
+    if ((view_on_open && GPOINTER_TO_INT(view_on_open))
+        || balsa_app.view_message_on_open) {
+        bndx_select_row(bindex, path);
+    } else {
+        GtkTreeSelection *selection;
+        gulong changed_id = bindex->selection_changed_id;
+
+        selection = gtk_tree_view_get_selection(tree_view);
+        g_signal_handler_block(selection, changed_id);
+        gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
+        gtk_tree_selection_unselect_all(selection);
+        g_signal_handler_unblock(selection, changed_id);
     }
+
     gtk_tree_path_free(path);
     gtk_widget_show(GTK_WIDGET(bindex));
 
@@ -891,11 +889,13 @@ balsa_index_scroll_on_open(BalsaIndex * bindex)
 {
     /* Scroll in an idle handler, because the mailbox is perhaps being
      * opened in its own idle handler. */
-    /* Actually use a 500 millisecond timeout, bacause the handler will
-     * reschedule itself until messages are loaded and threaded. */
+    /* Use low priority, so that GtkTreeView's layout idle handlers get
+     * to finish the layout first. */
     if (bindex->scroll_on_open_idle_id == 0) {
         bindex->scroll_on_open_idle_id =
-            g_timeout_add(500, (GSourceFunc) bndx_scroll_on_open_idle, bindex);
+            g_idle_add_full(G_PRIORITY_LOW,
+                            (GSourceFunc) bndx_scroll_on_open_idle,
+                            bindex, NULL);
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]