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



commit aa6719bc077f77fdb4d1b676d901ea3291ff9f3f
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 | 90 ++++++++++++++++++++++-----------------------------
 libwnck/private.h     |  2 +-
 libwnck/util.c        |  2 +-
 3 files changed, 40 insertions(+), 54 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index 78d251a..00f842a 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);
@@ -325,56 +322,54 @@ wnck_application_get_pid (WnckApplication *app)
 }
 
 static void
-get_icons (WnckApplication *app)
+get_icon (WnckApplication *app)
 {
-  GdkPixbuf *icon;
-  GdkPixbuf *mini_icon;
-  gsize normal_size;
-  gsize mini_size;
-
-  icon = NULL;
-  mini_icon = NULL;
-  normal_size = _wnck_get_default_icon_size ();
-  mini_size = _wnck_get_default_mini_icon_size ();
-
-  if (_wnck_read_icons (app->priv->screen,
-                        app->priv->xwindow,
-                        app->priv->icon_cache,
-                        &icon,
-                        normal_size,
-                        &mini_icon,
-                        mini_size))
-    {
-      app->priv->need_emit_icon_changed = TRUE;
+  if (app->priv->icon != NULL)
+    return;
 
-      if (app->priv->icon)
-        g_object_unref (G_OBJECT (app->priv->icon));
+  _wnck_read_icons (app->priv->screen,
+                    app->priv->xwindow,
+                    app->priv->icon_cache,
+                    &app->priv->icon,
+                    _wnck_get_default_icon_size (),
+                    NULL,
+                    0);
 
-      if (app->priv->mini_icon)
-        g_object_unref (G_OBJECT (app->priv->mini_icon));
+  /* 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.
+   */
+}
 
-      app->priv->icon = icon;
-      app->priv->mini_icon = mini_icon;
-    }
+static void
+get_mini_icon (WnckApplication *app)
+{
+  if (app->priv->mini_icon != NULL)
+    return;
+
+  _wnck_read_icons (app->priv->screen,
+                    app->priv->xwindow,
+                    app->priv->icon_cache,
+                    NULL,
+                    0,
+                    &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_icons_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" */
@@ -417,7 +412,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;
@@ -448,7 +443,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;
@@ -604,7 +599,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_icons_changed (app);
 }
 
 void
@@ -628,7 +623,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_icons_changed (app);
 }
 
 void
@@ -663,7 +658,7 @@ _wnck_application_process_property_notify (WnckApplication *app,
     {
       _wnck_icon_cache_property_changed (app->priv->icon_cache,
                                          xevent->xproperty.atom);
-      emit_icon_changed (app);
+      _wnck_application_icons_changed (app);
     }
   else if (xevent->xproperty.atom ==
            _wnck_atom_get ("_NET_STARTUP_ID"))
@@ -680,15 +675,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 f1a4af2..01bbd89 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -95,7 +95,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_icons_changed (WnckApplication *app);
 void             _wnck_application_shutdown_all (void);
 
 WnckClassGroup  *_wnck_class_group_create        (WnckScreen     *screen,
diff --git a/libwnck/util.c b/libwnck/util.c
index e908a1c..90dd70b 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -733,7 +733,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_icons_changed (application);
         }
     }
 }


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