[libwnck/wip/muktupavels/private-wnck-handle] add private WnckHandle object




commit 0ffa580fb2c52525d3277271ef5e9dc5801f7679
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat May 8 18:19:52 2021 +0300

    add private WnckHandle object
    
    WnckHandle in future will be used as main entry point into library.
    
    This will allow to have multiple tasklists in same process with
    different settings. Also this will allow to cleanup resources
    without worrying that calling wnck_shutdown might affect other
    applets or plugins that might use libwnck in same process.
    
    https://gitlab.gnome.org/GNOME/libwnck/-/issues/136

 libwnck/meson.build           |   2 +
 libwnck/private.h             |   3 +
 libwnck/util.c                |  29 ++++++---
 libwnck/wnck-handle-private.h |  33 ++++++++++
 libwnck/wnck-handle.c         | 137 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 197 insertions(+), 7 deletions(-)
---
diff --git a/libwnck/meson.build b/libwnck/meson.build
index 0cd68fc..04f30d6 100644
--- a/libwnck/meson.build
+++ b/libwnck/meson.build
@@ -37,6 +37,8 @@ sources = [
   'util.c',
   'window-action-menu.c',
   'window.c',
+  'wnck-handle-private.h',
+  'wnck-handle.c',
   'wnck-image-menu-item-private.h',
   'wnck-image-menu-item.c',
   'workspace.c',
diff --git a/libwnck/private.h b/libwnck/private.h
index 492fd2c..f1a4af2 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -30,6 +30,7 @@
 #include "xutils.h"
 #include "pager.h"
 #include "util.h"
+#include "wnck-handle-private.h"
 #ifdef HAVE_STARTUP_NOTIFICATION
 #include <libsn/sn.h>
 #endif
@@ -38,6 +39,8 @@ G_BEGIN_DECLS
 
 #define WNCK_ACTIVATE_TIMEOUT 1
 
+WnckHandle *_wnck_get_handle (void);
+
 WnckClientType _wnck_get_client_type (void);
 
 gsize _wnck_get_default_icon_size (void);
diff --git a/libwnck/util.c b/libwnck/util.c
index c8e0e6e..b3d8750 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -655,16 +655,29 @@ wnck_set_client_type (WnckClientType ewmh_sourceindication_client_type)
     client_type = ewmh_sourceindication_client_type;
 }
 
+static WnckHandle *wnck_handle = NULL;
+
+WnckHandle *
+_wnck_get_handle (void)
+{
+  if (wnck_handle == NULL)
+    {
+      /* If the type hasn't been set yet, use the default--treat it as a
+       * normal application.
+       */
+      if (client_type == 0)
+        client_type = WNCK_CLIENT_TYPE_APPLICATION;
+
+      wnck_handle = _wnck_handle_new (client_type);
+    }
+
+  return wnck_handle;
+}
+
 WnckClientType
 _wnck_get_client_type (void)
 {
-  /* If the type hasn't been set yet, use the default--treat it as a
-   * normal application.
-   */
-  if (client_type == 0)
-    client_type = WNCK_CLIENT_TYPE_APPLICATION;
-
-  return client_type;
+  return _wnck_handle_get_client_type (_wnck_get_handle ());
 }
 
 static gsize default_icon_size = WNCK_DEFAULT_ICON_SIZE;
@@ -844,6 +857,8 @@ wnck_shutdown (void)
   _wnck_screen_shutdown_all ();
   _wnck_window_shutdown_all ();
 
+  g_clear_object (&wnck_handle);
+
 #ifdef HAVE_XRES
   if (xres_removeid != 0)
     g_source_remove (xres_removeid);
diff --git a/libwnck/wnck-handle-private.h b/libwnck/wnck-handle-private.h
new file mode 100644
index 0000000..156821a
--- /dev/null
+++ b/libwnck/wnck-handle-private.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2021 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WNCK_HANDLE_PRIVATE_H
+#define WNCK_HANDLE_PRIVATE_H
+
+#include "util.h"
+
+G_BEGIN_DECLS
+
+typedef struct _WnckHandle WnckHandle;
+
+WnckHandle     *_wnck_handle_new             (WnckClientType  client_type);
+
+WnckClientType  _wnck_handle_get_client_type (WnckHandle     *self);
+
+G_END_DECLS
+
+#endif
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
new file mode 100644
index 0000000..c49a640
--- /dev/null
+++ b/libwnck/wnck-handle.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2021 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "wnck-handle-private.h"
+
+#include "wnck-enum-types.h"
+
+#define WNCK_TYPE_HANDLE (wnck_handle_get_type ())
+G_DECLARE_FINAL_TYPE (WnckHandle, wnck_handle, WNCK, HANDLE, GObject)
+
+struct _WnckHandle
+{
+  GObject        parent;
+
+  WnckClientType client_type;
+};
+
+enum
+{
+  PROP_0,
+
+  PROP_CLIENT_TYPE,
+
+  LAST_PROP
+};
+
+static GParamSpec *handle_properties[LAST_PROP] = { NULL };
+
+G_DEFINE_TYPE (WnckHandle, wnck_handle, G_TYPE_OBJECT)
+
+static void
+wnck_handle_get_property (GObject    *object,
+                          guint       property_id,
+                          GValue     *value,
+                          GParamSpec *pspec)
+{
+  WnckHandle *self;
+
+  self = WNCK_HANDLE (object);
+
+  switch (property_id)
+    {
+      case PROP_CLIENT_TYPE:
+        g_value_set_enum (value, self->client_type);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+wnck_handle_set_property (GObject      *object,
+                          guint         property_id,
+                          const GValue *value,
+                          GParamSpec   *pspec)
+{
+  WnckHandle *self;
+
+  self = WNCK_HANDLE (object);
+
+  switch (property_id)
+    {
+      case PROP_CLIENT_TYPE:
+        self->client_type = g_value_get_enum (value);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+install_properties (GObjectClass *object_class)
+{
+  handle_properties[PROP_CLIENT_TYPE] =
+    g_param_spec_enum ("client-type",
+                       "client-type",
+                       "client-type",
+                       WNCK_TYPE_CLIENT_TYPE,
+                       WNCK_CLIENT_TYPE_APPLICATION,
+                       G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class,
+                                     LAST_PROP,
+                                     handle_properties);
+}
+
+static void
+wnck_handle_class_init (WnckHandleClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->get_property = wnck_handle_get_property;
+  object_class->set_property = wnck_handle_set_property;
+
+  install_properties (object_class);
+}
+
+static void
+wnck_handle_init (WnckHandle *self)
+{
+}
+
+WnckHandle
+*_wnck_handle_new (WnckClientType client_type)
+{
+  return g_object_new (WNCK_TYPE_HANDLE,
+                       "client-type", client_type,
+                       NULL);
+}
+
+WnckClientType
+_wnck_handle_get_client_type (WnckHandle *self)
+{
+  return self->client_type;
+}


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