[gtk/wip/otte/icontheme: 1/11] icontheme: Remove gtk_icon_theme_get_default()



commit 079f50e280e419a2d44cd1ed38e7e14ffce2a7a5
Author: Benjamin Otte <otte redhat com>
Date:   Sat Feb 1 23:38:49 2020 +0100

    icontheme: Remove gtk_icon_theme_get_default()
    
    The API encouraged wrong usage - most of the users were indeed wrong.
    
    Use the correct version instead:
      gtk_icon_theme_get_for_display (gtk_widget_get_display ())

 demos/gtk-demo/fishbowl.c            |  4 +++-
 demos/gtk-demo/shortcuts.c           |  2 +-
 demos/gtk-demo/textview.c            |  7 ++++---
 demos/icon-browser/iconbrowserwin.c  | 18 ++++++++++++++----
 docs/reference/gtk/gtk4-sections.txt |  1 -
 gtk/gtkaboutdialog.c                 |  4 ++--
 gtk/gtkapplication-quartz-menu.c     |  2 +-
 gtk/gtkapplication.c                 |  2 +-
 gtk/gtkbuilder.c                     |  3 ++-
 gtk/gtkcssimageicontheme.c           |  2 +-
 gtk/gtkicontheme.c                   | 29 +++++------------------------
 gtk/gtkicontheme.h                   |  2 --
 gtk/gtkwindow.c                      |  2 +-
 tests/testclipboard2.c               |  2 +-
 tests/testdnd2.c                     |  4 +++-
 testsuite/gtk/check-icon-names.c     |  3 ++-
 testsuite/gtk/icontheme.c            |  2 +-
 17 files changed, 42 insertions(+), 47 deletions(-)
---
diff --git a/demos/gtk-demo/fishbowl.c b/demos/gtk-demo/fishbowl.c
index 77c63d561e..dd3619df73 100644
--- a/demos/gtk-demo/fishbowl.c
+++ b/demos/gtk-demo/fishbowl.c
@@ -60,8 +60,10 @@ create_icon (void)
 {
   GtkWidget *image;
 
-  image = gtk_image_new_from_icon_name (get_random_icon_name (gtk_icon_theme_get_default ()));
+  image = gtk_image_new ();
   gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
+  gtk_image_set_from_icon_name (GTK_IMAGE (image),
+                                get_random_icon_name (gtk_icon_theme_get_for_display (gtk_widget_get_display 
(image))));
 
   return image;
 }
diff --git a/demos/gtk-demo/shortcuts.c b/demos/gtk-demo/shortcuts.c
index b0be7d11cc..8182035499 100644
--- a/demos/gtk-demo/shortcuts.c
+++ b/demos/gtk-demo/shortcuts.c
@@ -76,7 +76,7 @@ do_shortcuts (GtkWidget *do_widget)
   if (!icons_added)
     {
       icons_added = TRUE;
-      gtk_icon_theme_add_resource_path (gtk_icon_theme_get_default (), "/icons");
+      gtk_icon_theme_add_resource_path (gtk_icon_theme_get_for_display (gtk_widget_get_display (do_widget)), 
"/icons");
     }
 
   g_type_ensure (G_TYPE_FILE_ICON);
diff --git a/demos/gtk-demo/textview.c b/demos/gtk-demo/textview.c
index 39ae7315ca..395bd155f0 100644
--- a/demos/gtk-demo/textview.c
+++ b/demos/gtk-demo/textview.c
@@ -124,15 +124,16 @@ create_tags (GtkTextBuffer *buffer)
 }
 
 static void
-insert_text (GtkTextBuffer *buffer)
+insert_text (GtkTextView *view)
 {
+  GtkTextBuffer *buffer = gtk_text_view_get_buffer (view);
   GtkTextIter iter;
   GtkTextIter start, end;
   GdkTexture *texture;
   GtkIconTheme *icon_theme;
   GtkIcon *icon;
 
-  icon_theme = gtk_icon_theme_get_default ();
+  icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (view)));
   icon = gtk_icon_theme_lookup_icon (icon_theme,
                                      "gtk3-demo",
                                      32, 1,
@@ -508,7 +509,7 @@ do_textview (GtkWidget *do_widget)
       gtk_container_add (GTK_CONTAINER (sw), view2);
 
       create_tags (buffer);
-      insert_text (buffer);
+      insert_text (GTK_TEXT_VIEW (view1));
 
       attach_widgets (GTK_TEXT_VIEW (view1));
       attach_widgets (GTK_TEXT_VIEW (view2));
diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c
index 793f7cf199..d40f1a8364 100644
--- a/demos/icon-browser/iconbrowserwin.c
+++ b/demos/icon-browser/iconbrowserwin.c
@@ -60,6 +60,12 @@ struct _IconBrowserWindowClass
 
 G_DEFINE_TYPE(IconBrowserWindow, icon_browser_window, GTK_TYPE_APPLICATION_WINDOW);
 
+static GtkIconTheme *
+icon_browser_window_get_icon_theme (IconBrowserWindow *win)
+{
+  return gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (win)));
+}
+
 static void
 search_text_changed (GtkEntry *entry, IconBrowserWindow *win)
 {
@@ -83,6 +89,7 @@ set_image (GtkWidget *image, const gchar *name, gint size)
 static void
 item_activated (GtkIconView *icon_view, GtkTreePath *path, IconBrowserWindow *win)
 {
+  GtkIconTheme *icon_theme = icon_browser_window_get_icon_theme (win);
   GtkTreeIter iter;
   gchar *name;
   gchar *description;
@@ -99,7 +106,7 @@ item_activated (GtkIconView *icon_view, GtkTreePath *path, IconBrowserWindow *wi
                       ICON_STORE_DESCRIPTION_COLUMN, &description,
                       -1);
 
-  if (name == NULL || !gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), name))
+  if (name == NULL || !gtk_icon_theme_has_icon (icon_theme, name))
     {
       g_free (description);
       return;
@@ -144,18 +151,19 @@ add_icon (IconBrowserWindow *win,
           const gchar       *description,
           const gchar       *context)
 {
+  GtkIconTheme *icon_theme = icon_browser_window_get_icon_theme (win);
   gchar *regular_name;
   gchar *symbolic_name;
 
   regular_name = g_strdup (name);
-  if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), regular_name))
+  if (!gtk_icon_theme_has_icon (icon_theme, regular_name))
     {
       g_free (regular_name);
       regular_name = NULL;
     }
 
   symbolic_name = g_strconcat (name, "-symbolic", NULL);
-  if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), symbolic_name))
+  if (!gtk_icon_theme_has_icon (icon_theme, symbolic_name))
     {
       g_free (symbolic_name);
       symbolic_name = NULL;
@@ -404,13 +412,15 @@ static void
 get_file (GValue   *value,
           gpointer  data)
 {
+  GtkIconTheme *icon_theme;
   const char *name;
   GtkIcon *info;
   GFile *file;
 
   name = gtk_image_get_icon_name (GTK_IMAGE (data));
+  icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (data)));
 
-  info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), name, 32, 1, 0);
+  info = gtk_icon_theme_lookup_icon (icon_theme, name, 32, 1, 0);
   file = g_file_new_for_path (gtk_icon_get_filename (info));
   g_value_set_object (value, file);
   g_object_unref (file);
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 723e620a6e..90d7bf19a2 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4995,7 +4995,6 @@ GTK_TYPE_ICON_THEME_ERROR
 GTK_TYPE_ICON_LOOKUP_FLAGS
 GtkIconThemeError
 gtk_icon_theme_new
-gtk_icon_theme_get_default
 gtk_icon_theme_get_for_display
 gtk_icon_theme_set_display
 gtk_icon_theme_set_search_path
diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c
index 4b38d343f4..a662612b47 100644
--- a/gtk/gtkaboutdialog.c
+++ b/gtk/gtkaboutdialog.c
@@ -1831,8 +1831,8 @@ gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
 
   if (icon_name)
     {
-      gint *sizes = gtk_icon_theme_get_icon_sizes (gtk_icon_theme_get_default (),
-                                                   icon_name);
+      GtkIconTheme *icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET 
(about)));
+      gint *sizes = gtk_icon_theme_get_icon_sizes (icon_theme, icon_name);
       gint i, best_size = 0;
 
       for (i = 0; sizes[i]; i++)
diff --git a/gtk/gtkapplication-quartz-menu.c b/gtk/gtkapplication-quartz-menu.c
index 751b90bc18..56ab759bf6 100644
--- a/gtk/gtkapplication-quartz-menu.c
+++ b/gtk/gtkapplication-quartz-menu.c
@@ -291,7 +291,7 @@ icon_loaded (GObject      *object,
           parsed = TRUE;
         }
 
-      theme = gtk_icon_theme_get_default ();
+      theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
 
 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
        /* we need a run-time check for the backingScaleFactor selector because we
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 774a0e4b47..a60feee9e5 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -214,7 +214,7 @@ gtk_application_load_resources (GtkApplication *application)
     GtkIconTheme *default_theme;
     gchar *iconspath;
 
-    default_theme = gtk_icon_theme_get_default ();
+    default_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
     iconspath = g_strconcat (base_path, "/icons/", NULL);
     gtk_icon_theme_add_resource_path (default_theme, iconspath);
     g_free (iconspath);
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index 2cc72e004b..c400799dfe 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -2168,7 +2168,8 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
               g_error_free (tmp_error);
 
               /* fall back to a missing image */
-              theme = gtk_icon_theme_get_default ();
+              /* FIXME: this should be using the correct display */
+              theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
 
               icon = gtk_icon_theme_lookup_icon (theme, "image-missing", 16, 1,
                                                  GTK_ICON_LOOKUP_USE_BUILTIN);
diff --git a/gtk/gtkcssimageicontheme.c b/gtk/gtkcssimageicontheme.c
index 03bbc2795f..244324ffdb 100644
--- a/gtk/gtkcssimageicontheme.c
+++ b/gtk/gtkcssimageicontheme.c
@@ -201,7 +201,7 @@ _gtk_css_image_icon_theme_class_init (GtkCssImageIconThemeClass *klass)
 static void
 _gtk_css_image_icon_theme_init (GtkCssImageIconTheme *icon_theme)
 {
-  icon_theme->icon_theme = gtk_icon_theme_get_default ();
+  icon_theme->icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
   icon_theme->scale = 1;
   icon_theme->cached_size = -1;
   icon_theme->cached_icon = NULL;
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index d437094063..0651985368 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -78,14 +78,14 @@
  * directly is also simple. The #GtkIconTheme object acts
  * as a database of all the icons in the current theme. You
  * can create new #GtkIconTheme objects, but it’s much more
- * efficient to use the standard icon theme for the #GdkDisplay
+ * efficient to use the standard icon theme of the #GtkWidget
  * so that the icon information is shared with other people
  * looking up icons.
  * |[<!-- language="C" -->
  * GtkIconTheme *icon_theme;
  * GtkIcon *icon;
  *
- * icon_theme = gtk_icon_theme_get_default ();
+ * icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (my_widget));
  * icon = gtk_icon_theme_lookup_icon (icon_theme,
  *                                    "my-icon-name", // icon name
  *                                    48, // icon size
@@ -707,9 +707,8 @@ G_DEFINE_TYPE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT)
  *
  * Creates a new icon theme object. Icon theme objects are used
  * to lookup up an icon by name in a particular icon theme.
- * Usually, you’ll want to use gtk_icon_theme_get_default()
- * or gtk_icon_theme_get_for_display() rather than creating
- * a new icon theme object for scratch.
+ * Usually, you’ll want to use gtk_icon_theme_get_for_display()
+ * rather than creating a new icon theme object for scratch.
  *
  * Returns: the newly created #GtkIconTheme object.
  */
@@ -719,23 +718,6 @@ gtk_icon_theme_new (void)
   return g_object_new (GTK_TYPE_ICON_THEME, NULL);
 }
 
-/**
- * gtk_icon_theme_get_default:
- *
- * Gets the icon theme for the default display. See
- * gtk_icon_theme_get_for_display().
- *
- * Returns: (transfer none): A unique #GtkIconTheme associated with
- *     the default display. This icon theme is associated with
- *     the display and can be used as long as the display
- *     is open. Do not ref or unref it.
- */
-GtkIconTheme *
-gtk_icon_theme_get_default (void)
-{
-  return gtk_icon_theme_get_for_display (gdk_display_get_default ());
-}
-
 static void
 load_theme_thread  (GTask        *task,
                     gpointer      source_object,
@@ -1374,8 +1356,7 @@ gtk_icon_theme_add_resource_path (GtkIconTheme *self,
  *
  * Sets the name of the icon theme that the #GtkIconTheme object uses
  * overriding system configuration. This function cannot be called
- * on the icon theme objects returned from gtk_icon_theme_get_default()
- * and gtk_icon_theme_get_for_display().
+ * on the icon theme objects returned from gtk_icon_theme_get_for_display().
  */
 void
 gtk_icon_theme_set_custom_theme (GtkIconTheme *self,
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index a11959a61b..54655c8531 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -109,8 +109,6 @@ GType         gtk_icon_theme_get_type              (void) G_GNUC_CONST;
 GDK_AVAILABLE_IN_ALL
 GtkIconTheme *gtk_icon_theme_new                   (void);
 GDK_AVAILABLE_IN_ALL
-GtkIconTheme *gtk_icon_theme_get_default           (void);
-GDK_AVAILABLE_IN_ALL
 GtkIconTheme *gtk_icon_theme_get_for_display       (GdkDisplay                  *display);
 GDK_AVAILABLE_IN_ALL
 void          gtk_icon_theme_set_display           (GtkIconTheme                *self,
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 76295d9695..c9e274a110 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -4111,7 +4111,7 @@ gtk_window_get_icon_for_size (GtkWindow *window,
   if (!name)
     return NULL;
 
-  info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+  info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET 
(window))),
                                      name, size, priv->scale,
                                      GTK_ICON_LOOKUP_FORCE_SIZE);
   if (info == NULL)
diff --git a/tests/testclipboard2.c b/tests/testclipboard2.c
index 3523051ef2..9e5d37bcf4 100644
--- a/tests/testclipboard2.c
+++ b/tests/testclipboard2.c
@@ -286,7 +286,7 @@ get_button_list (GdkClipboard *clipboard,
                        "Empty");
 
   g_value_init (&value, GDK_TYPE_PIXBUF);
-  icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+  icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gdk_clipboard_get_display (clipboard)),
                                      "utilities-terminal",
                                      48, 1, 0);
   texture = gtk_icon_download_texture (icon, NULL);
diff --git a/tests/testdnd2.c b/tests/testdnd2.c
index 11d604fee5..7204ff7e9c 100644
--- a/tests/testdnd2.c
+++ b/tests/testdnd2.c
@@ -227,7 +227,9 @@ update_source_icon (GtkDragSource *source,
   int hot_x, hot_y;
   int size = 48;
 
-  icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+  icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (
+                                         gtk_widget_get_display (
+                                             gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER 
(source)))),
                                      icon_name, size, 1, 0);
   switch (hotspot)
     {
diff --git a/testsuite/gtk/check-icon-names.c b/testsuite/gtk/check-icon-names.c
index 3d15f072e5..a5bc6756d1 100644
--- a/testsuite/gtk/check-icon-names.c
+++ b/testsuite/gtk/check-icon-names.c
@@ -73,13 +73,14 @@ static char *icon_names[] = {
 static void
 test_icon_existence (gconstpointer icon_name)
 {
+  GtkIconTheme *icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
   GtkIcon *info;
 
   /* Not using generic fallback and builtins here, as we explicitly want to check the
    * icon theme.
    * The icon size is randomly chosen.
    */
-  info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), icon_name, 16, 1, 
GTK_ICON_LOOKUP_DIR_LTR);
+  info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 16, 1, GTK_ICON_LOOKUP_DIR_LTR);
   if (info == NULL)
     {
       g_test_message ("Failed to look up icon for \"%s\"", (char *) icon_name);
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
index 9563ad2908..a478b296d4 100644
--- a/testsuite/gtk/icontheme.c
+++ b/testsuite/gtk/icontheme.c
@@ -687,7 +687,7 @@ test_nonsquare_symbolic (void)
   g_assert_cmpint (width, !=, height);
 
   /* now load it through GtkIconTheme */
-  icon_theme = gtk_icon_theme_get_default ();
+  icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
   file = g_file_new_for_path (path);
   icon = g_file_icon_new (file);
   info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon,


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