[libwnck/wip/muktupavels/icons: 5/5] window: get icons in getters




commit 4b940d0e39ae0acafbe7e4ed3628df3cff9a319d
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Dec 19 22:28:22 2021 +0200

    window: 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/private.h |  2 +-
 libwnck/util.c    |  2 +-
 libwnck/window.c  | 89 +++++++++++++++++--------------------------------------
 3 files changed, 30 insertions(+), 63 deletions(-)
---
diff --git a/libwnck/private.h b/libwnck/private.h
index fb6594f..c373ac3 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -60,7 +60,7 @@ WnckWindow* _wnck_window_create  (Window      xwindow,
                                   gint        sort_order);
 void        _wnck_window_destroy (WnckWindow *window);
 
-void        _wnck_window_load_icons (WnckWindow *window);
+void        _wnck_window_icon_changed (WnckWindow *window);
 
 char*       _wnck_window_get_name_for_display (WnckWindow *window,
                                                gboolean    use_icon_name,
diff --git a/libwnck/util.c b/libwnck/util.c
index 9cf5b11..8aa1875 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -730,7 +730,7 @@ wnck_set_default_mini_icon_size (gsize size)
           WnckWindow *window = WNCK_WINDOW (l->data);
           WnckApplication *application = wnck_window_get_application (window);
 
-          _wnck_window_load_icons (window);
+          _wnck_window_icon_changed (window);
 
           if (WNCK_IS_APPLICATION (application))
             _wnck_application_icon_changed (application);
diff --git a/libwnck/window.c b/libwnck/window.c
index f90933f..721ee6d 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -162,7 +162,6 @@ struct _WnckWindowPrivate
   guint need_update_role : 1;
 
   guint need_emit_name_changed : 1;
-  guint need_emit_icon_changed : 1;
   guint need_emit_class_changed : 1;
   guint need_emit_role_changed : 1;
   guint need_emit_type_changed : 1;
@@ -190,7 +189,6 @@ static void emit_state_changed     (WnckWindow      *window,
                                     WnckWindowState  changed_mask,
                                     WnckWindowState  new_state);
 static void emit_workspace_changed (WnckWindow      *window);
-static void emit_icon_changed      (WnckWindow      *window);
 static void emit_actions_changed   (WnckWindow       *window,
                                     WnckWindowActions changed_mask,
                                     WnckWindowActions new_actions);
@@ -560,7 +558,6 @@ _wnck_window_create (Window      xwindow,
   window->priv->need_update_frame_extents = TRUE;
   window->priv->need_update_role = TRUE;
   window->priv->need_emit_name_changed = FALSE;
-  window->priv->need_emit_icon_changed = FALSE;
   window->priv->need_emit_class_changed = FALSE;
   window->priv->need_emit_role_changed = FALSE;
   window->priv->need_emit_type_changed = FALSE;
@@ -2119,56 +2116,40 @@ wnck_window_transient_is_most_recently_activated (WnckWindow *window)
 }
 
 static void
-get_icons (WnckWindow *window)
+ensure_icon (WnckWindow *window)
 {
-  GdkPixbuf *icon;
-  GdkPixbuf *mini_icon;
-
-  icon = NULL;
-  mini_icon = NULL;
-
-  if (_wnck_read_icon (window->priv->screen,
-                       window->priv->xwindow,
-                       window->priv->icon_cache,
-                       &icon,
-                       _wnck_get_default_icon_size ()))
-    {
-      window->priv->need_emit_icon_changed = TRUE;
-
-      if (window->priv->icon)
-        g_object_unref (G_OBJECT (window->priv->icon));
-
-      window->priv->icon = icon;
-    }
-
-  if (_wnck_read_icon (window->priv->screen,
-                       window->priv->xwindow,
-                       window->priv->mini_icon_cache,
-                       &mini_icon,
-                       _wnck_get_default_mini_icon_size ()))
-    {
-      window->priv->need_emit_icon_changed = TRUE;
+  if (window->priv->icon != NULL)
+    return;
 
-      if (window->priv->mini_icon)
-        g_object_unref (G_OBJECT (window->priv->mini_icon));
+  _wnck_read_icon (window->priv->screen,
+                   window->priv->xwindow,
+                   window->priv->icon_cache,
+                   &window->priv->icon,
+                   _wnck_get_default_icon_size ());
+}
 
-      window->priv->mini_icon = mini_icon;
-    }
+static void
+ensure_mini_icon (WnckWindow *window)
+{
+  if (window->priv->mini_icon != NULL)
+    return;
 
-  g_assert ((window->priv->icon && window->priv->mini_icon) ||
-            !(window->priv->icon || window->priv->mini_icon));
+  _wnck_read_icon (window->priv->screen,
+                   window->priv->xwindow,
+                   window->priv->mini_icon_cache,
+                   &window->priv->mini_icon,
+                   _wnck_get_default_mini_icon_size ());
 }
 
 void
-_wnck_window_load_icons (WnckWindow *window)
+_wnck_window_icon_changed (WnckWindow *window)
 {
   g_return_if_fail (WNCK_IS_WINDOW (window));
 
-  get_icons (window);
-  if (window->priv->need_emit_icon_changed)
-    queue_update (window); /* not done in get_icons since we call that from
-                            * the update
-                            */
+  g_clear_object (&window->priv->icon);
+  g_clear_object (&window->priv->mini_icon);
+
+  g_signal_emit (window, signals[ICON_CHANGED], 0);
 }
 
 /**
@@ -2188,7 +2169,7 @@ wnck_window_get_icon (WnckWindow *window)
 {
   g_return_val_if_fail (WNCK_IS_WINDOW (window), NULL);
 
-  _wnck_window_load_icons (window);
+  ensure_icon (window);
 
   return window->priv->icon;
 }
@@ -2210,7 +2191,7 @@ wnck_window_get_mini_icon (WnckWindow *window)
 {
   g_return_val_if_fail (WNCK_IS_WINDOW (window), NULL);
 
-  _wnck_window_load_icons (window);
+  ensure_mini_icon (window);
 
   return window->priv->mini_icon;
 }
@@ -2625,7 +2606,8 @@ _wnck_window_process_property_notify (WnckWindow *window,
                                          xevent->xproperty.atom);
       _wnck_icon_cache_property_changed (window->priv->mini_icon_cache,
                                          xevent->xproperty.atom);
-      queue_update (window);
+
+      _wnck_window_icon_changed (window);
     }
   else if (xevent->xproperty.atom ==
           _wnck_atom_get ("WM_HINTS"))
@@ -3315,8 +3297,6 @@ force_update_now (WnckWindow *window)
   update_frame_extents (window); /* emits signals */
   update_role (window); /* emits signals */
 
-  get_icons (window);
-
   new_state = COMPRESS_STATE (window);
 
   if (old_state != new_state)
@@ -3326,9 +3306,6 @@ force_update_now (WnckWindow *window)
     emit_actions_changed (window, old_actions ^ window->priv->actions,
                           window->priv->actions);
 
-  if (window->priv->need_emit_icon_changed)
-    emit_icon_changed (window);
-
   if (window->priv->need_emit_class_changed)
     emit_class_changed (window);
 
@@ -3339,7 +3316,6 @@ force_update_now (WnckWindow *window)
     emit_type_changed (window);
 }
 
-
 static gboolean
 update_idle (gpointer data)
 {
@@ -3396,15 +3372,6 @@ emit_workspace_changed (WnckWindow *window)
                  0);
 }
 
-static void
-emit_icon_changed (WnckWindow *window)
-{
-  window->priv->need_emit_icon_changed = FALSE;
-  g_signal_emit (G_OBJECT (window),
-                 signals[ICON_CHANGED],
-                 0);
-}
-
 static void
 emit_class_changed (WnckWindow *window)
 {


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