[gtk+/wip/no-more-gdk-threads: 1/4] Replace gdk_threads_add_idle* with g_idle_add()



commit 9537e2aa940f3de76e4cc7edddc6fe54c8affb83
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Feb 2 15:08:02 2018 +0100

    Replace gdk_threads_add_idle* with g_idle_add()
    
    The main GDK thread lock is not portable and deprecated.
    
    The only reason why gdk_threads_add_idle() and
    gdk_threads_add_idle_full() exist is to allow invoking a callback with
    the GDK lock held, in case 3rd party libraries still use the deprecated
    gdk_threads_enter()/gdk_threads_leave() API.
    
    Since we're removing the GDK lock, and we're releasing a new major API,
    such code cannot exist any more; this means we can use the GLib API for
    installing idle callbacks.

 gdk/broadway/gdkwindow-broadway.c   |    2 +-
 gdk/quartz/gdkscreen-quartz.c       |    2 +-
 gdk/x11/gdkasync.c                  |    4 ++--
 gtk/a11y/gtkiconviewaccessible.c    |    2 +-
 gtk/gtkfilechooserwidget.c          |    8 ++++----
 gtk/gtkicontheme.c                  |    7 ++++---
 gtk/gtkmenusectionbox.c             |    9 ++++++---
 gtk/gtkprintoperation.c             |   16 ++++++++--------
 gtk/gtkprintunixdialog.c            |    3 +--
 gtk/gtkrecentchooserdefault.c       |    8 ++++----
 gtk/gtkrecentchoosermenu.c          |    8 ++++----
 gtk/gtksearchenginemodel.c          |    2 +-
 gtk/gtksearchenginesimple.c         |    4 ++--
 gtk/gtktextview.c                   |   12 ++++++------
 gtk/gtktoolbar.c                    |    2 +-
 gtk/gtktreeview.c                   |    4 ++--
 gtk/gtkwidget.c                     |    2 +-
 gtk/gtkwindow.c                     |    4 ++--
 tests/stresstest-toolbar.c          |    2 +-
 testsuite/a11y/tree-relationships.c |    2 +-
 20 files changed, 53 insertions(+), 50 deletions(-)
---
diff --git a/gdk/broadway/gdkwindow-broadway.c b/gdk/broadway/gdkwindow-broadway.c
index 12fb525..ebbd03e 100644
--- a/gdk/broadway/gdkwindow-broadway.c
+++ b/gdk/broadway/gdkwindow-broadway.c
@@ -115,7 +115,7 @@ queue_flush (GdkWindow *window)
 {
   if (flush_id == 0)
     {
-      flush_id = gdk_threads_add_idle (flush_idle, NULL);
+      flush_id = g_idle_add (flush_idle, NULL);
       g_source_set_name_by_id (flush_id, "[gtk+] flush_idle");
     }
 }
diff --git a/gdk/quartz/gdkscreen-quartz.c b/gdk/quartz/gdkscreen-quartz.c
index e1f1299..6f53f36 100644
--- a/gdk/quartz/gdkscreen-quartz.c
+++ b/gdk/quartz/gdkscreen-quartz.c
@@ -262,7 +262,7 @@ display_reconfiguration_callback (CGDirectDisplayID            display,
        */
       if (!screen->screen_changed_id)
         {
-          screen->screen_changed_id = gdk_threads_add_idle (screen_changed_idle, screen);
+          screen->screen_changed_id = g_idle_add (screen_changed_idle, screen);
           g_source_set_name_by_id (screen->screen_changed_id, "[gtk+] screen_changed_idle");
         }
     }
diff --git a/gdk/x11/gdkasync.c b/gdk/x11/gdkasync.c
index d9b84c4..31d5b4e 100644
--- a/gdk/x11/gdkasync.c
+++ b/gdk/x11/gdkasync.c
@@ -173,7 +173,7 @@ send_event_handler (Display *dpy,
       if (state->callback)
         {
           guint id;
-          id = gdk_threads_add_idle (callback_idle, state);
+          id = g_idle_add (callback_idle, state);
           g_source_set_name_by_id (id, "[gtk+] callback_idle");
         }
 
@@ -709,7 +709,7 @@ roundtrip_handler (Display *dpy,
       if (state->callback)
         {
           guint id;
-          id = gdk_threads_add_idle (roundtrip_callback_idle, state);
+          id = g_idle_add (roundtrip_callback_idle, state);
           g_source_set_name_by_id (id, "[gtk+] roundtrip_callback_idle");
         }
 
diff --git a/gtk/a11y/gtkiconviewaccessible.c b/gtk/a11y/gtkiconviewaccessible.c
index eb85522..645515a 100644
--- a/gtk/a11y/gtkiconviewaccessible.c
+++ b/gtk/a11y/gtkiconviewaccessible.c
@@ -113,7 +113,7 @@ gtk_icon_view_item_accessible_do_action (AtkAction *action,
 
   if (!item->action_idle_handler)
     {
-      item->action_idle_handler = gdk_threads_add_idle (idle_do_action, item);
+      item->action_idle_handler = g_idle_add (idle_do_action, item);
       g_source_set_name_by_id (item->action_idle_handler, "[gtk+] idle_do_action");
     }
 
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 8623fcc..47cec72 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -7447,10 +7447,10 @@ recent_start_loading (GtkFileChooserWidget *impl)
   load_data->items = NULL;
 
   /* begin lazy loading the recent files into the model */
-  priv->load_recent_id = gdk_threads_add_idle_full (G_PRIORITY_DEFAULT,
-                                                    recent_idle_load,
-                                                    load_data,
-                                                    recent_idle_cleanup);
+  priv->load_recent_id = g_idle_add_full (G_PRIORITY_DEFAULT,
+                                          recent_idle_load,
+                                          load_data,
+                                          recent_idle_cleanup);
   g_source_set_name_by_id (priv->load_recent_id, "[gtk+] recent_idle_load");
 }
 
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index af2541d..afaed8f 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -734,9 +734,10 @@ queue_theme_changed (GtkIconTheme *icon_theme)
 
   if (!priv->theme_changed_idle)
     {
-      priv->theme_changed_idle =
-        gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2,
-                                   theme_changed_idle, icon_theme, NULL);
+      priv->theme_changed_idle = g_idle_add_full (GTK_PRIORITY_RESIZE - 2,
+                                                  theme_changed_idle,
+                                                  icon_theme,
+                                                  NULL);
       g_source_set_name_by_id (priv->theme_changed_idle, "[gtk+] theme_changed_idle");
     }
 }
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 3179290..2e56e01 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -160,9 +160,12 @@ gtk_menu_section_box_schedule_separator_sync (GtkMenuSectionBox *box)
   box = box->toplevel;
 
   if (!box->separator_sync_idle)
-    box->separator_sync_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE, /* before resize... */
-                                                          gtk_menu_section_box_handle_sync_separators,
-                                                          box, NULL);
+    {
+      box->separator_sync_idle = g_idle_add_full (G_PRIORITY_HIGH_IDLE, /* before resize... */
+                                                  gtk_menu_section_box_handle_sync_separators,
+                                                  box, NULL);
+      g_source_set_name_by_id (box->separator_sync_idle, "[gtk+] menu section box handle sync separators");
+    }
 }
 
 static void
diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c
index 516f694..cd2a082 100644
--- a/gtk/gtkprintoperation.c
+++ b/gtk/gtkprintoperation.c
@@ -639,10 +639,10 @@ preview_ready (GtkPrintOperationPreview *preview,
 
   g_object_ref (preview);
       
-  id = gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE + 10,
-                                 preview_print_idle,
-                                 pop,
-                                 preview_print_idle_done);
+  id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 10,
+                        preview_print_idle,
+                        pop,
+                        preview_print_idle_done);
   g_source_set_name_by_id (id, "[gtk+] preview_print_idle");
 }
 
@@ -3076,10 +3076,10 @@ print_pages (GtkPrintOperation       *op,
       priv->manual_number_up_layout = gtk_print_settings_get_number_up_layout (priv->print_settings);
     }
   
-  priv->print_pages_idle_id = gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE + 10,
-                                                        print_pages_idle, 
-                                                        data, 
-                                                        print_pages_idle_done);
+  priv->print_pages_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 10,
+                                               print_pages_idle,
+                                               data,
+                                               print_pages_idle_done);
   g_source_set_name_by_id (priv->print_pages_idle_id, "[gtk+] print_pages_idle");
   
   /* Recursive main loop to make sure we don't exit  on sync operations  */
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index dea6fd2..6feb0aa 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -1935,8 +1935,7 @@ schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
   if (priv->mark_conflicts_id != 0)
     return;
 
-  priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
-                                        dialog);
+  priv->mark_conflicts_id = g_idle_add (mark_conflicts_callback, dialog);
   g_source_set_name_by_id (priv->mark_conflicts_id, "[gtk+] mark_conflicts_callback");
 }
 
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index a34642f..4ef3f60 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -771,10 +771,10 @@ reload_recent_items (GtkRecentChooserDefault *impl)
   set_busy_cursor (impl, TRUE);
 
   impl->priv->load_state = LOAD_EMPTY;
-  impl->priv->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
-                                             load_recent_items,
-                                             impl,
-                                             cleanup_after_load);
+  impl->priv->load_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE + 30,
+                                         load_recent_items,
+                                         impl,
+                                         cleanup_after_load);
   g_source_set_name_by_id (impl->priv->load_id, "[gtk+] load_recent_items");
 }
 
diff --git a/gtk/gtkrecentchoosermenu.c b/gtk/gtkrecentchoosermenu.c
index a99e5cc..b5480e7 100644
--- a/gtk/gtkrecentchoosermenu.c
+++ b/gtk/gtkrecentchoosermenu.c
@@ -1051,10 +1051,10 @@ gtk_recent_chooser_menu_populate (GtkRecentChooserMenu *menu)
   /* remove our menu items first */
   gtk_recent_chooser_menu_dispose_items (menu);
 
-  priv->populate_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
-                                                idle_populate_func,
-                                                pdata,
-                                                 idle_populate_clean_up);
+  priv->populate_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE + 30,
+                                       idle_populate_func,
+                                       pdata,
+                                       idle_populate_clean_up);
   g_source_set_name_by_id (priv->populate_id, "[gtk+] idle_populate_func");
 }
 
diff --git a/gtk/gtksearchenginemodel.c b/gtk/gtksearchenginemodel.c
index 6dd735d..2ff6152 100644
--- a/gtk/gtksearchenginemodel.c
+++ b/gtk/gtksearchenginemodel.c
@@ -128,7 +128,7 @@ gtk_search_engine_model_start (GtkSearchEngine *engine)
   if (model->query == NULL)
     return;
 
-  model->idle = gdk_threads_add_idle (do_search, engine);
+  model->idle = g_idle_add (do_search, engine);
   g_source_set_name_by_id (model->idle, "[gtk+] gtk_search_engine_model_start");
 }
 
diff --git a/gtk/gtksearchenginesimple.c b/gtk/gtksearchenginesimple.c
index 6daf2f8..8f5d431 100644
--- a/gtk/gtksearchenginesimple.c
+++ b/gtk/gtksearchenginesimple.c
@@ -180,7 +180,7 @@ send_batch (SearchThreadData *data)
       batch->hits = data->hits;
       batch->thread_data = data;
 
-      id = gdk_threads_add_idle (search_thread_add_hits_idle, batch);
+      id = g_idle_add (search_thread_add_hits_idle, batch);
       g_source_set_name_by_id (id, "[gtk+] search_thread_add_hits_idle");
     }
 
@@ -287,7 +287,7 @@ search_thread_func (gpointer user_data)
   if (!g_cancellable_is_cancelled (data->cancellable))
     send_batch (data);
 
-  id = gdk_threads_add_idle (search_thread_done_idle, data);
+  id = g_idle_add (search_thread_done_idle, data);
   g_source_set_name_by_id (id, "[gtk+] search_thread_done_idle");
 
   return NULL;
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 9679c65..9dbfa52 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -2659,10 +2659,10 @@ queue_update_im_spot_location (GtkTextView *text_view)
    * so we don't wait until the entire buffer has been validated. */
   if (!priv->im_spot_idle)
     {
-      priv->im_spot_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
-                                                     do_update_im_spot_location,
-                                                     text_view,
-                                                     NULL);
+      priv->im_spot_idle = g_idle_add_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
+                                            do_update_im_spot_location,
+                                            text_view,
+                                            NULL);
       g_source_set_name_by_id (priv->im_spot_idle, "[gtk+] do_update_im_spot_location");
     }
 }
@@ -4397,7 +4397,7 @@ gtk_text_view_invalidate (GtkTextView *text_view)
   
   if (!priv->first_validate_idle)
     {
-      priv->first_validate_idle = gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, 
first_validate_callback, text_view, NULL);
+      priv->first_validate_idle = g_idle_add_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, 
text_view, NULL);
       g_source_set_name_by_id (priv->first_validate_idle, "[gtk+] first_validate_callback");
       DV (g_print (G_STRLOC": adding first validate idle %d\n",
                    priv->first_validate_idle));
@@ -4405,7 +4405,7 @@ gtk_text_view_invalidate (GtkTextView *text_view)
       
   if (!priv->incremental_validate_idle)
     {
-      priv->incremental_validate_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, 
incremental_validate_callback, text_view, NULL);
+      priv->incremental_validate_idle = g_idle_add_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, 
incremental_validate_callback, text_view, NULL);
       g_source_set_name_by_id (priv->incremental_validate_idle, "[gtk+] incremental_validate_callback");
       DV (g_print (G_STRLOC": adding incremental validate idle %d\n",
                    priv->incremental_validate_idle));
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index a513abb..262ab9f 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -1002,7 +1002,7 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
   
   if (!priv->idle_id)
     {
-      priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
+      priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
       g_source_set_name_by_id (priv->idle_id, "[gtk+] slide_idle_handler");
     }
 
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index d829f0c..8571151 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -6726,7 +6726,7 @@ install_presize_handler (GtkTreeView *tree_view)
   if (! tree_view->priv->validate_rows_timer)
     {
       tree_view->priv->validate_rows_timer =
-       gdk_threads_add_idle_full (GTK_TREE_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows, tree_view, 
NULL);
+       g_idle_add_full (GTK_TREE_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows, tree_view, NULL);
       g_source_set_name_by_id (tree_view->priv->validate_rows_timer, "[gtk+] validate_rows");
     }
 }
@@ -6755,7 +6755,7 @@ install_scroll_sync_handler (GtkTreeView *tree_view)
   if (!tree_view->priv->scroll_sync_timer)
     {
       tree_view->priv->scroll_sync_timer =
-       gdk_threads_add_idle_full (GTK_TREE_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, 
tree_view, NULL);
+       g_idle_add_full (GTK_TREE_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, 
NULL);
       g_source_set_name_by_id (tree_view->priv->scroll_sync_timer, "[gtk+] scroll_sync_handler");
     }
 }
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b138629..d67c7a9 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -11813,7 +11813,7 @@ gtk_widget_queue_tooltip_query (GtkWidget *widget)
 
   if (tooltip_query_id == 0)
     {
-      tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
+      tooltip_query_id = g_idle_add (tooltip_query_idle, NULL);
       g_source_set_name_by_id (tooltip_query_id, "[gtk+] tooltip_query_idle");
     }
 }
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 147e505..296aa5d 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -2930,7 +2930,7 @@ _gtk_window_notify_keys_changed (GtkWindow *window)
 
   if (!priv->keys_changed_handler)
     {
-      priv->keys_changed_handler = gdk_threads_add_idle (handle_keys_changed, window);
+      priv->keys_changed_handler = g_idle_add (handle_keys_changed, window);
       g_source_set_name_by_id (priv->keys_changed_handler, "[gtk+] handle_keys_changed");
     }
 }
@@ -11027,7 +11027,7 @@ gtk_window_update_debugging (void)
   if (inspector_window &&
       gtk_window_update_debugging_id == 0)
     {
-      gtk_window_update_debugging_id = gdk_threads_add_idle (update_debugging, NULL);
+      gtk_window_update_debugging_id = g_idle_add (update_debugging, NULL);
       g_source_set_name_by_id (gtk_window_update_debugging_id, "[gtk+] gtk_window_update_debugging");
     }
 }
diff --git a/tests/stresstest-toolbar.c b/tests/stresstest-toolbar.c
index 8bce079..bbf745e 100644
--- a/tests/stresstest-toolbar.c
+++ b/tests/stresstest-toolbar.c
@@ -142,7 +142,7 @@ main (gint argc, gchar **argv)
 
   gtk_widget_show (GTK_WIDGET (info.window));
   
-  gdk_threads_add_idle (stress_test_old_api, &info);
+  g_idle_add (stress_test_old_api, &info);
 
   gtk_widget_show (GTK_WIDGET (info.window));
   
diff --git a/testsuite/a11y/tree-relationships.c b/testsuite/a11y/tree-relationships.c
index 34f45b6..e23f7b5 100644
--- a/testsuite/a11y/tree-relationships.c
+++ b/testsuite/a11y/tree-relationships.c
@@ -219,7 +219,7 @@ static void
 process_pending_idles ()
 {
   GMainLoop *loop = g_main_loop_new (NULL, FALSE);
-  gdk_threads_add_idle (quit_loop, loop);
+  g_idle_add (quit_loop, loop);
   g_main_loop_run (loop);
 }
 


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