[libwnck/wip/muktupavels/icons: 10/11] application: get icons in getters




commit d81a3fc380043f7e2d7048f7eb9629dbac5ef824
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Dec 19 22:16:20 2021 +0200

    application: 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/application.c | 89 ++++++++++++++++++++-------------------------------
 libwnck/private.h     |  2 +-
 libwnck/util.c        |  2 +-
 3 files changed, 36 insertions(+), 57 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index deea5b94..9a8f222e 100644
--- a/libwnck/application.c
+++ b/libwnck/application.c
@@ -73,8 +73,6 @@ struct _WnckApplicationPrivate
   char *startup_id;
 
   guint name_from_leader : 1; /* name is from group leader */
-
-  guint need_emit_icon_changed : 1;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (WnckApplication, wnck_application, G_TYPE_OBJECT);
@@ -86,7 +84,6 @@ enum {
 };
 
 static void emit_name_changed (WnckApplication *app);
-static void emit_icon_changed (WnckApplication *app);
 
 static void reset_name  (WnckApplication *app);
 static void update_name (WnckApplication *app);
@@ -318,60 +315,50 @@ wnck_application_get_pid (WnckApplication *app)
 }
 
 static void
-get_icons (WnckApplication *app)
+get_icon (WnckApplication *app)
 {
-  GdkPixbuf *icon;
-  GdkPixbuf *mini_icon;
-
-  icon = NULL;
-  mini_icon = NULL;
-
-  if (_wnck_read_icon (app->priv->screen,
-                       app->priv->xwindow,
-                       app->priv->icon_cache,
-                       &icon,
-                       _wnck_get_default_icon_size ()))
-    {
-      app->priv->need_emit_icon_changed = TRUE;
-
-      if (app->priv->icon)
-        g_object_unref (G_OBJECT (app->priv->icon));
+  if (app->priv->icon != NULL)
+    return;
 
-      app->priv->icon = icon;
-    }
+  _wnck_read_icon (app->priv->screen,
+                    app->priv->xwindow,
+                    app->priv->icon_cache,
+                    &app->priv->icon,
+                    _wnck_get_default_icon_size ());
 
-  if (_wnck_read_icon (app->priv->screen,
-                       app->priv->xwindow,
-                       app->priv->mini_icon_cache,
-                       &mini_icon,
-                       _wnck_get_default_mini_icon_size ()))
-    {
-      app->priv->need_emit_icon_changed = TRUE;
+  /* FIXME we should really fall back to using the icon
+   * for one of the windows. But then we need to be more
+   * complicated about icon_changed and when the icon
+   * needs updating and all that.
+   */
+}
 
-      if (app->priv->mini_icon)
-        g_object_unref (G_OBJECT (app->priv->mini_icon));
+static void
+get_mini_icon (WnckApplication *app)
+{
+  if (app->priv->mini_icon != NULL)
+    return;
 
-      app->priv->mini_icon = mini_icon;
-    }
+  _wnck_read_icon (app->priv->screen,
+                   app->priv->xwindow,
+                   app->priv->mini_icon_cache,
+                   &app->priv->mini_icon,
+                   _wnck_get_default_mini_icon_size ());
 
   /* FIXME we should really fall back to using the icon
    * for one of the windows. But then we need to be more
    * complicated about icon_changed and when the icon
    * needs updating and all that.
    */
-
-  g_assert ((app->priv->icon && app->priv->mini_icon) ||
-            !(app->priv->icon || app->priv->mini_icon));
 }
 
 void
-_wnck_application_load_icons (WnckApplication *app)
+_wnck_application_icon_changed (WnckApplication *app)
 {
-  g_return_if_fail (WNCK_IS_APPLICATION (app));
+  g_clear_object (&app->priv->icon);
+  g_clear_object (&app->priv->mini_icon);
 
-  get_icons (app);
-  if (app->priv->need_emit_icon_changed)
-    emit_icon_changed (app);
+  g_signal_emit (app, signals[ICON_CHANGED], 0);
 }
 
 /* Prefer to get group icon from a window of type "normal" */
@@ -414,7 +401,7 @@ wnck_application_get_icon (WnckApplication *app)
 {
   g_return_val_if_fail (WNCK_IS_APPLICATION (app), NULL);
 
-  _wnck_application_load_icons (app);
+  get_icon (app);
 
   if (app->priv->icon)
     return app->priv->icon;
@@ -445,7 +432,7 @@ wnck_application_get_mini_icon (WnckApplication *app)
 {
   g_return_val_if_fail (WNCK_IS_APPLICATION (app), NULL);
 
-  _wnck_application_load_icons (app);
+  get_mini_icon (app);
 
   if (app->priv->mini_icon)
     return app->priv->mini_icon;
@@ -605,7 +592,7 @@ _wnck_application_add_window (WnckApplication *app,
   /* see if we're using icon from a window */
   if (app->priv->icon == NULL ||
       app->priv->mini_icon == NULL)
-    emit_icon_changed (app);
+    _wnck_application_icon_changed (app);
 }
 
 void
@@ -629,7 +616,7 @@ _wnck_application_remove_window (WnckApplication *app,
   /* see if we're using icon from a window */
   if (app->priv->icon == NULL ||
       app->priv->mini_icon == NULL)
-    emit_icon_changed (app);
+    _wnck_application_icon_changed (app);
 }
 
 void
@@ -666,7 +653,8 @@ _wnck_application_process_property_notify (WnckApplication *app,
                                          xevent->xproperty.atom);
       _wnck_icon_cache_property_changed (app->priv->mini_icon_cache,
                                          xevent->xproperty.atom);
-      emit_icon_changed (app);
+
+      _wnck_application_icon_changed (app);
     }
   else if (xevent->xproperty.atom ==
            _wnck_atom_get ("_NET_STARTUP_ID"))
@@ -683,15 +671,6 @@ emit_name_changed (WnckApplication *app)
                  0);
 }
 
-static void
-emit_icon_changed (WnckApplication *app)
-{
-  app->priv->need_emit_icon_changed = FALSE;
-  g_signal_emit (G_OBJECT (app),
-                 signals[ICON_CHANGED],
-                 0);
-}
-
 static void
 reset_name  (WnckApplication *app)
 {
diff --git a/libwnck/private.h b/libwnck/private.h
index 26a34377..1ab47131 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -93,7 +93,7 @@ void _wnck_application_remove_window (WnckApplication *app,
 WnckApplication* _wnck_application_create  (Window           xwindow,
                                             WnckScreen      *screen);
 void             _wnck_application_destroy (WnckApplication *app);
-void             _wnck_application_load_icons (WnckApplication *app);
+void             _wnck_application_icon_changed (WnckApplication *app);
 
 WnckClassGroup  *_wnck_class_group_create        (WnckScreen     *screen,
                                                   const char     *res_class);
diff --git a/libwnck/util.c b/libwnck/util.c
index fa06c345..9af64850 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -223,7 +223,7 @@ wnck_set_default_mini_icon_size (gsize size)
           _wnck_window_load_icons (window);
 
           if (WNCK_IS_APPLICATION (application))
-            _wnck_application_load_icons (application);
+            _wnck_application_icon_changed (application);
         }
     }
 }


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