[libwnck/wip/muktupavels/icons: 9/17] class-group: get icons in getters




commit c192b7d9d6dae70b55b52d5c6ffb3fea8ac3df9e
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Mar 14 17:38:24 2022 +0200

    class-group: get icons in getters
    
    libwnck users might not use icons at all or might use only normal
    or mini icon. Redo code to get icons only when getters are used.

 libwnck/class-group.c | 215 ++++++++++++++++++++++++++------------------------
 1 file changed, 114 insertions(+), 101 deletions(-)
---
diff --git a/libwnck/class-group.c b/libwnck/class-group.c
index 46d1f241..1f8b1a7c 100644
--- a/libwnck/class-group.c
+++ b/libwnck/class-group.c
@@ -368,114 +368,15 @@ set_name (WnckClassGroup *class_group)
     }
 }
 
-/* Walks the list of applications, trying to get an icon from them */
-static void
-get_icons_from_applications (WnckClassGroup *class_group, GdkPixbuf **icon, GdkPixbuf **mini_icon)
-{
-  GList *l;
-
-  *icon = NULL;
-  *mini_icon = NULL;
-
-  for (l = class_group->priv->windows; l; l = l->next)
-    {
-      WnckWindow *window;
-      WnckApplication *app;
-
-      window = WNCK_WINDOW (l->data);
-      app = wnck_window_get_application (window);
-      if (app)
-       {
-         *icon = wnck_application_get_icon (app);
-         *mini_icon = wnck_application_get_mini_icon (app);
-
-         if (*icon && *mini_icon)
-           return;
-         else
-           {
-             *icon = NULL;
-             *mini_icon = NULL;
-           }
-       }
-    }
-}
-
-/* Walks the list of windows, trying to get an icon from them */
-static void
-get_icons_from_windows (WnckClassGroup *class_group, GdkPixbuf **icon, GdkPixbuf **mini_icon)
-{
-  GList *l;
-
-  *icon = NULL;
-  *mini_icon = NULL;
-
-  for (l = class_group->priv->windows; l; l = l->next)
-    {
-      WnckWindow *window;
-
-      window = WNCK_WINDOW (l->data);
-
-      *icon = wnck_window_get_icon (window);
-      *mini_icon = wnck_window_get_mini_icon (window);
-
-      if (*icon && *mini_icon)
-       return;
-      else
-       {
-         *icon = NULL;
-         *mini_icon = NULL;
-       }
-    }
-}
-
-/* Gets a sensible icon and mini_icon for the class group from the application
- * group leaders or from individual windows.
- */
 static void
 set_icon (WnckClassGroup *class_group)
 {
-  GdkPixbuf *icon, *mini_icon;
-  gboolean icons_reffed = FALSE;
-
-  get_icons_from_applications (class_group, &icon, &mini_icon);
-
-  if (!icon || !mini_icon)
-    get_icons_from_windows (class_group, &icon, &mini_icon);
-
-  if (!icon || !mini_icon)
-    {
-      WnckHandle *handle;
-
-      handle = wnck_screen_get_handle (class_group->priv->screen);
-
-      _wnck_get_fallback_icons (&icon,
-                                _wnck_handle_get_default_icon_size (handle),
-                                &mini_icon,
-                                _wnck_handle_get_default_mini_icon_size (handle));
-      icons_reffed = TRUE;
-    }
-
-  g_assert (icon && mini_icon);
-
-  if (class_group->priv->icon)
-    g_object_unref (class_group->priv->icon);
-
-  if (class_group->priv->mini_icon)
-    g_object_unref (class_group->priv->mini_icon);
-
-  class_group->priv->icon = icon;
-  class_group->priv->mini_icon = mini_icon;
-
-  if (!icons_reffed)
-    {
-      g_object_ref (class_group->priv->icon);
-      g_object_ref (class_group->priv->mini_icon);
-    }
+  g_clear_object (&class_group->priv->icon);
+  g_clear_object (&class_group->priv->mini_icon);
 
   g_signal_emit (G_OBJECT (class_group), signals[ICON_CHANGED], 0);
 }
 
-
 /* Handle window's icon_changed signal, update class group icon */
 static void
 update_class_group_icon (WnckWindow     *window,
@@ -702,8 +603,64 @@ wnck_class_group_get_name (WnckClassGroup *class_group)
 GdkPixbuf *
 wnck_class_group_get_icon (WnckClassGroup *class_group)
 {
+  GdkPixbuf *icon;
+  GList *l;
+
   g_return_val_if_fail (class_group != NULL, NULL);
 
+  if (class_group->priv->icon != NULL)
+    return class_group->priv->icon;
+
+  icon = NULL;
+
+  for (l = class_group->priv->windows; l; l = l->next)
+    {
+      WnckWindow *window;
+      WnckApplication *app;
+
+      window = WNCK_WINDOW (l->data);
+      app = wnck_window_get_application (window);
+
+      if (app == NULL)
+        continue;
+
+      icon = wnck_application_get_icon (app);
+
+      if (icon != NULL)
+        break;
+    }
+
+  if (icon == NULL)
+    {
+      for (l = class_group->priv->windows; l; l = l->next)
+        {
+          WnckWindow *window;
+
+          window = WNCK_WINDOW (l->data);
+
+          icon = wnck_window_get_icon (window);
+
+          if (icon != NULL)
+            break;
+        }
+    }
+
+  if (icon != NULL)
+    {
+      class_group->priv->icon = g_object_ref (icon);
+    }
+  else
+    {
+      WnckHandle *handle;
+
+      handle = wnck_screen_get_handle (class_group->priv->screen);
+
+      _wnck_get_fallback_icons (&class_group->priv->icon,
+                                _wnck_handle_get_default_icon_size (handle),
+                                NULL,
+                                0);
+    }
+
   return class_group->priv->icon;
 }
 
@@ -724,7 +681,63 @@ wnck_class_group_get_icon (WnckClassGroup *class_group)
 GdkPixbuf *
 wnck_class_group_get_mini_icon (WnckClassGroup *class_group)
 {
+  GdkPixbuf *mini_icon;
+  GList *l;
+
   g_return_val_if_fail (class_group != NULL, NULL);
 
+  if (class_group->priv->mini_icon != NULL)
+    return class_group->priv->mini_icon;
+
+  mini_icon = NULL;
+
+  for (l = class_group->priv->windows; l; l = l->next)
+    {
+      WnckWindow *window;
+      WnckApplication *app;
+
+      window = WNCK_WINDOW (l->data);
+      app = wnck_window_get_application (window);
+
+      if (app == NULL)
+        continue;
+
+      mini_icon = wnck_application_get_mini_icon (app);
+
+      if (mini_icon != NULL)
+        break;
+    }
+
+  if (mini_icon == NULL)
+    {
+      for (l = class_group->priv->windows; l; l = l->next)
+        {
+          WnckWindow *window;
+
+          window = WNCK_WINDOW (l->data);
+
+          mini_icon = wnck_window_get_mini_icon (window);
+
+          if (mini_icon != NULL)
+            break;
+        }
+    }
+
+  if (mini_icon != NULL)
+    {
+      class_group->priv->mini_icon = g_object_ref (mini_icon);
+    }
+  else
+    {
+      WnckHandle *handle;
+
+      handle = wnck_screen_get_handle (class_group->priv->screen);
+
+      _wnck_get_fallback_icons (NULL,
+                                0,
+                                &class_group->priv->mini_icon,
+                                _wnck_handle_get_default_mini_icon_size (handle));
+    }
+
   return class_group->priv->mini_icon;
 }


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