[metacity] window: turn into a GObject



commit 2c48b4412f8811e541412017894de6b945e21037
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Mar 12 19:55:19 2017 +0200

    window: turn into a GObject

 src/core/window-private.h |    6 +++
 src/core/window.c         |   77 ++++++++++++++++++++++++++++-----------------
 src/include/window.h      |    9 +++++-
 3 files changed, 62 insertions(+), 30 deletions(-)
---
diff --git a/src/core/window-private.h b/src/core/window-private.h
index b7949d9..379b41a 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -42,6 +42,8 @@
 #include <cairo.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
+G_BEGIN_DECLS
+
 typedef struct _MetaGroup MetaGroup;
 typedef struct _MetaWindowQueue MetaWindowQueue;
 
@@ -91,6 +93,8 @@ typedef enum {
 
 struct _MetaWindow
 {
+  GObject parent;
+
   MetaDisplay *display;
   MetaScreen *screen;
   MetaWorkspace *workspace;
@@ -733,4 +737,6 @@ gboolean meta_window_updates_are_frozen (MetaWindow *window);
 
 void meta_window_update_shape_region (MetaWindow *window);
 
+G_END_DECLS
+
 #endif
diff --git a/src/core/window.c b/src/core/window.c
index de34e64..254abf1 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -53,7 +53,6 @@
 
 static int destroying_windows_disallowed = 0;
 
-
 static void     update_sm_hints           (MetaWindow     *window);
 static void     update_net_frame_extents  (MetaWindow     *window);
 static void     restack_window            (MetaWindow     *window,
@@ -129,6 +128,8 @@ static gboolean idle_calc_showing (gpointer data);
 static gboolean idle_move_resize (gpointer data);
 static gboolean idle_update_icon (gpointer data);
 
+G_DEFINE_TYPE (MetaWindow, meta_window, G_TYPE_OBJECT)
+
 static const char*
 wm_state_to_string (int state)
 {
@@ -380,7 +381,7 @@ meta_window_new (MetaDisplay    *display,
       return NULL;
     }
 
-  window = g_new (MetaWindow, 1);
+  window = g_object_new (META_TYPE_WINDOW, NULL);
 
   window->constructing = TRUE;
 
@@ -1244,33 +1245,7 @@ meta_window_free (MetaWindow  *window,
 
   meta_error_trap_pop (window->display);
 
-  if (window->icon)
-    g_object_unref (G_OBJECT (window->icon));
-
-  if (window->mini_icon)
-    g_object_unref (G_OBJECT (window->mini_icon));
-
-  if (window->frame_bounds)
-    cairo_region_destroy (window->frame_bounds);
-
-  if (window->shape_region)
-    cairo_region_destroy (window->shape_region);
-
-  if (window->opaque_region)
-    cairo_region_destroy (window->opaque_region);
-
-  meta_icon_cache_free (&window->icon_cache);
-
-  g_free (window->sm_client_id);
-  g_free (window->wm_client_machine);
-  g_free (window->startup_id);
-  g_free (window->role);
-  g_free (window->res_class);
-  g_free (window->res_name);
-  g_free (window->title);
-  g_free (window->desc);
-  g_free (window->gtk_theme_variant);
-  g_free (window);
+  g_object_unref (window);
 }
 
 static void
@@ -9195,3 +9170,47 @@ meta_window_update_shape_region (MetaWindow *window)
 
   meta_compositor_window_shape_changed (window->display->compositor, window);
 }
+
+static void
+meta_window_finalize (GObject *object)
+{
+  MetaWindow *window;
+
+  window = META_WINDOW (object);
+
+  g_clear_object (&window->icon);
+  g_clear_object (&window->mini_icon);
+
+  g_clear_pointer (&window->frame_bounds, cairo_region_destroy);
+  g_clear_pointer (&window->shape_region, cairo_region_destroy);
+  g_clear_pointer (&window->opaque_region, cairo_region_destroy);
+
+  meta_icon_cache_free (&window->icon_cache);
+
+  g_clear_pointer (&window->sm_client_id, g_free);
+  g_clear_pointer (&window->wm_client_machine, g_free);
+  g_clear_pointer (&window->startup_id, g_free);
+  g_clear_pointer (&window->role, g_free);
+  g_clear_pointer (&window->res_class, g_free);
+  g_clear_pointer (&window->res_name, g_free);
+  g_clear_pointer (&window->title, g_free);
+  g_clear_pointer (&window->desc, g_free);
+  g_clear_pointer (&window->gtk_theme_variant, g_free);
+
+  G_OBJECT_CLASS (meta_window_parent_class)->finalize (object);
+}
+
+static void
+meta_window_class_init (MetaWindowClass *window_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (window_class);
+
+  object_class->finalize = meta_window_finalize;
+}
+
+static void
+meta_window_init (MetaWindow *window)
+{
+}
diff --git a/src/include/window.h b/src/include/window.h
index be3fbdc..1fbd9b6 100644
--- a/src/include/window.h
+++ b/src/include/window.h
@@ -20,13 +20,18 @@
 #ifndef META_WINDOW_H
 #define META_WINDOW_H
 
-#include <glib.h>
 #include <cairo.h>
+#include <glib-object.h>
 #include <X11/Xlib.h>
 
 #include "boxes.h"
 #include "types.h"
 
+G_BEGIN_DECLS
+
+#define META_TYPE_WINDOW meta_window_get_type ()
+G_DECLARE_FINAL_TYPE (MetaWindow, meta_window, META, WINDOW, GObject)
+
 MetaFrame *meta_window_get_frame (MetaWindow *window);
 gboolean meta_window_has_focus (MetaWindow *window);
 gboolean meta_window_is_shaded (MetaWindow *window);
@@ -40,4 +45,6 @@ gboolean meta_window_is_attached_dialog (MetaWindow *window);
 
 cairo_region_t *meta_window_get_frame_bounds (MetaWindow *window);
 
+G_END_DECLS
+
 #endif


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