[libwnck/wip/muktupavels/icons: 10/16] icon-cache: turn into a GObject




commit 13f75bc0ac2594319675d98df1c03feb3d2ac382
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Mar 14 18:43:26 2022 +0200

    icon-cache: turn into a GObject

 libwnck/application.c             |  2 +-
 libwnck/window.c                  |  2 +-
 libwnck/wnck-icon-cache-private.h |  4 ++--
 libwnck/wnck-icon-cache.c         | 41 ++++++++++++++++++++++++++++++---------
 4 files changed, 36 insertions(+), 13 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index 7e489db7..bb3c2069 100644
--- a/libwnck/application.c
+++ b/libwnck/application.c
@@ -153,7 +153,7 @@ wnck_application_finalize (GObject *object)
   g_free (application->priv->name);
   application->priv->name = NULL;
 
-  g_clear_pointer (&application->priv->icon_cache, _wnck_icon_cache_free);
+  g_clear_object (&application->priv->icon_cache);
 
   g_free (application->priv->startup_id);
   application->priv->startup_id = NULL;
diff --git a/libwnck/window.c b/libwnck/window.c
index b2cd2a74..fdae373d 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -407,7 +407,7 @@ wnck_window_finalize (GObject *object)
   g_free (window->priv->session_id_utf8);
   window->priv->session_id_utf8 = NULL;
 
-  g_clear_pointer (&window->priv->icon_cache, _wnck_icon_cache_free);
+  g_clear_object (&window->priv->icon_cache);
 
   g_free (window->priv->startup_id);
   window->priv->startup_id = NULL;
diff --git a/libwnck/wnck-icon-cache-private.h b/libwnck/wnck-icon-cache-private.h
index 751cac00..b9c754d3 100644
--- a/libwnck/wnck-icon-cache-private.h
+++ b/libwnck/wnck-icon-cache-private.h
@@ -27,11 +27,11 @@
 
 G_BEGIN_DECLS
 
-typedef struct _WnckIconCache WnckIconCache;
+#define WNCK_TYPE_ICON_CACHE (_wnck_icon_cache_get_type ())
+G_DECLARE_FINAL_TYPE (WnckIconCache, _wnck_icon_cache, WNCK, ICON_CACHE, GObject)
 
 WnckIconCache *_wnck_icon_cache_new                  (Window          xwindow,
                                                       WnckScreen     *screen);
-void           _wnck_icon_cache_free                 (WnckIconCache  *icon_cache);
 void           _wnck_icon_cache_property_changed     (WnckIconCache  *icon_cache,
                                                       Atom            atom);
 gboolean       _wnck_icon_cache_get_icon_invalidated (WnckIconCache  *icon_cache);
diff --git a/libwnck/wnck-icon-cache.c b/libwnck/wnck-icon-cache.c
index 992877f1..193b3260 100644
--- a/libwnck/wnck-icon-cache.c
+++ b/libwnck/wnck-icon-cache.c
@@ -42,6 +42,8 @@ typedef enum
 
 struct _WnckIconCache
 {
+  GObject parent;
+
   Window xwindow;
   WnckScreen *screen;
 
@@ -57,6 +59,8 @@ struct _WnckIconCache
   guint net_wm_icon_dirty : 1;
 };
 
+G_DEFINE_TYPE (WnckIconCache, _wnck_icon_cache, G_TYPE_OBJECT)
+
 static gboolean
 find_best_size (gulong  *data,
                 gulong   nitems,
@@ -507,13 +511,40 @@ scaled_from_pixdata (guchar *pixdata,
   return dest;
 }
 
+static void
+_wnck_icon_cache_finalize (GObject *object)
+{
+  WnckIconCache *self;
+
+  self = WNCK_ICON_CACHE (object);
+
+  clear_icon_cache (self, FALSE);
+
+  G_OBJECT_CLASS (_wnck_icon_cache_parent_class)->finalize (object);
+}
+
+static void
+_wnck_icon_cache_class_init (WnckIconCacheClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->finalize = _wnck_icon_cache_finalize;
+}
+
+static void
+_wnck_icon_cache_init (WnckIconCache *self)
+{
+}
+
 WnckIconCache*
 _wnck_icon_cache_new (Window      xwindow,
                       WnckScreen *screen)
 {
   WnckIconCache *icon_cache;
 
-  icon_cache = g_slice_new0 (WnckIconCache);
+  icon_cache = g_object_new (WNCK_TYPE_ICON_CACHE, NULL);
 
   icon_cache->xwindow = xwindow;
   icon_cache->screen = screen;
@@ -530,14 +561,6 @@ _wnck_icon_cache_new (Window      xwindow,
   return icon_cache;
 }
 
-void
-_wnck_icon_cache_free (WnckIconCache *icon_cache)
-{
-  clear_icon_cache (icon_cache, FALSE);
-
-  g_slice_free (WnckIconCache, icon_cache);
-}
-
 void
 _wnck_icon_cache_property_changed (WnckIconCache *icon_cache,
                                    Atom           atom)


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