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




commit 04637b311c0c7edcba6d7b1031548ee79344bff1
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  | 98 ++++++++++++++++++++-----------------------------------
 3 files changed, 37 insertions(+), 65 deletions(-)
---
diff --git a/libwnck/private.h b/libwnck/private.h
index dbe02c2a..fd4a34b1 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -55,7 +55,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 cd0b24b6..a99662fc 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -209,7 +209,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 d45a538a..398e590a 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -160,7 +160,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;
@@ -188,7 +187,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);
@@ -544,7 +542,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;
@@ -2112,63 +2109,52 @@ wnck_window_transient_is_most_recently_activated (WnckWindow *window)
 }
 
 static void
-get_icons (WnckWindow *window)
+ensure_icon (WnckWindow *window)
 {
   WnckHandle *handle;
-  GdkPixbuf *icon;
-  GdkPixbuf *mini_icon;
-  gsize normal_size;
-  gsize mini_size;
-
-  handle = _wnck_screen_get_handle (window->priv->screen);
+  gsize size;
 
-  icon = NULL;
-  mini_icon = NULL;
-  normal_size = _wnck_handle_get_default_icon_size (handle);
-  mini_size = _wnck_handle_get_default_mini_icon_size (handle);
-
-  if (_wnck_read_icon (window->priv->screen,
-                       window->priv->xwindow,
-                       window->priv->icon_cache,
-                       &icon,
-                       normal_size))
-    {
-      window->priv->need_emit_icon_changed = TRUE;
+  if (window->priv->icon != NULL)
+    return;
 
-      if (window->priv->icon)
-        g_object_unref (G_OBJECT (window->priv->icon));
+  handle = _wnck_screen_get_handle (window->priv->screen);
+  size = _wnck_handle_get_default_icon_size (handle);
 
-      window->priv->icon = icon;
-    }
+  _wnck_read_icon (window->priv->screen,
+                   window->priv->xwindow,
+                   window->priv->icon_cache,
+                   &window->priv->icon,
+                   size);
+}
 
-  if (_wnck_read_icon (window->priv->screen,
-                       window->priv->xwindow,
-                       window->priv->mini_icon_cache,
-                       &mini_icon,
-                       mini_size))
-    {
-      window->priv->need_emit_icon_changed = TRUE;
+static void
+ensure_mini_icon (WnckWindow *window)
+{
+  WnckHandle *handle;
+  gsize size;
 
-      if (window->priv->mini_icon)
-        g_object_unref (G_OBJECT (window->priv->mini_icon));
+  if (window->priv->mini_icon != NULL)
+    return;
 
-      window->priv->mini_icon = mini_icon;
-    }
+  handle = _wnck_screen_get_handle (window->priv->screen);
+  size = _wnck_handle_get_default_mini_icon_size (handle);
 
-  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,
+                   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 +2174,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 +2196,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;
 }
@@ -2628,7 +2614,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"))
@@ -3325,8 +3312,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)
@@ -3336,9 +3321,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);
 
@@ -3349,7 +3331,6 @@ force_update_now (WnckWindow *window)
     emit_type_changed (window);
 }
 
-
 static gboolean
 update_idle (gpointer data)
 {
@@ -3406,15 +3387,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]