[libwnck/wip/muktupavels/wnck-handle: 8/15] add wnck_handle_new and deprecate wnck_set_client_type



commit dee7c73434863fed0751a68a6d07deb5029cbaa8
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Aug 19 17:29:54 2019 +0300

    add wnck_handle_new and deprecate wnck_set_client_type

 libwnck/private.h             |   3 +-
 libwnck/screen.c              |  20 ++++++++
 libwnck/screen.h              |   4 ++
 libwnck/util.c                |  25 ++++++----
 libwnck/util.h                |   1 +
 libwnck/window.c              |   6 ++-
 libwnck/wnck-handle-private.h |   2 +
 libwnck/wnck-handle.c         | 106 +++++++++++++++++++++++++++++++++++++++++-
 libwnck/wnck-handle.h         |   3 ++
 libwnck/xutils.c              |  25 +++++++---
 libwnck/xutils.h              |   3 ++
 11 files changed, 181 insertions(+), 17 deletions(-)
---
diff --git a/libwnck/private.h b/libwnck/private.h
index 492fd2c..b11e685 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.h"
 #ifdef HAVE_STARTUP_NOTIFICATION
 #include <libsn/sn.h>
 #endif
@@ -38,7 +39,7 @@ G_BEGIN_DECLS
 
 #define WNCK_ACTIVATE_TIMEOUT 1
 
-WnckClientType _wnck_get_client_type (void);
+WnckHandle *_wnck_get_handle (void);
 
 gsize _wnck_get_default_icon_size (void);
 gsize _wnck_get_default_mini_icon_size (void);
diff --git a/libwnck/screen.c b/libwnck/screen.c
index 48e7c77..1eec498 100644
--- a/libwnck/screen.c
+++ b/libwnck/screen.c
@@ -69,6 +69,8 @@ static WnckScreen** screens = NULL;
 
 struct _WnckScreenPrivate
 {
+  WnckHandle *handle;
+
   int number;
   Window xroot;
   Screen *xscreen;
@@ -529,6 +531,8 @@ wnck_screen_construct (Display    *display,
                        WnckScreen *screen,
                        int         number)
 {
+  screen->priv->handle = _wnck_get_handle ();
+
   /* Create the initial state of the screen. */
   screen->priv->xroot = RootWindow (display, number);
   screen->priv->xscreen = ScreenOfDisplay (display, number);
@@ -675,6 +679,22 @@ wnck_screen_get_for_root (gulong root_window_id)
   return NULL;
 }
 
+/**
+ * wnck_screen_get_handle:
+ * @screen: a #WnckScreen.
+ *
+ * Gets the handle.
+ *
+ * Returns: (transfer none): a #WnckHandle, or %NULL.
+ */
+WnckHandle *
+wnck_screen_get_handle (WnckScreen *screen)
+{
+  g_return_val_if_fail (WNCK_IS_SCREEN (screen), NULL);
+
+  return screen->priv->handle;
+}
+
 /**
  * wnck_screen_get_number:
  * @screen: a #WnckScreen.
diff --git a/libwnck/screen.h b/libwnck/screen.h
index 3140ea5..153cf5f 100644
--- a/libwnck/screen.h
+++ b/libwnck/screen.h
@@ -33,6 +33,7 @@ G_BEGIN_DECLS
 /* forward decls */
 typedef struct _WnckApplication WnckApplication;
 typedef struct _WnckClassGroup  WnckClassGroup;
+typedef struct _WnckHandle      WnckHandle;
 typedef struct _WnckWindow      WnckWindow;
 typedef struct _WnckWorkspace   WnckWorkspace;
 
@@ -196,6 +197,9 @@ GType wnck_screen_get_type (void) G_GNUC_CONST;
 WnckScreen*    wnck_screen_get_default              (void);
 WnckScreen*    wnck_screen_get                      (int         index);
 WnckScreen*    wnck_screen_get_for_root             (gulong      root_window_id);
+
+WnckHandle*    wnck_screen_get_handle               (WnckScreen *screen);
+
 int            wnck_screen_get_number               (WnckScreen *screen);
 WnckWorkspace* wnck_screen_get_workspace            (WnckScreen *screen,
                                                      int         workspace);
diff --git a/libwnck/util.c b/libwnck/util.c
index c8e0e6e..e08fabc 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -655,16 +655,23 @@ wnck_set_client_type (WnckClientType ewmh_sourceindication_client_type)
     client_type = ewmh_sourceindication_client_type;
 }
 
-WnckClientType
-_wnck_get_client_type (void)
+static WnckHandle *wnck_handle = NULL;
+
+WnckHandle *
+_wnck_get_handle (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;
+  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;
 
-  return client_type;
+      wnck_handle = wnck_handle_new (client_type);
+    }
+
+  return wnck_handle;
 }
 
 static gsize default_icon_size = WNCK_DEFAULT_ICON_SIZE;
@@ -844,6 +851,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/util.h b/libwnck/util.h
index 8d0c77b..f17d37a 100644
--- a/libwnck/util.h
+++ b/libwnck/util.h
@@ -100,6 +100,7 @@ typedef enum {
   WNCK_CLIENT_TYPE_PAGER = 2
 } WnckClientType;
 
+G_DEPRECATED_FOR(wnck_handle_new)
 void wnck_set_client_type (WnckClientType ewmh_sourceindication_client_type);
 
 #define WNCK_DEFAULT_ICON_SIZE 32
diff --git a/libwnck/window.c b/libwnck/window.c
index fadda82..8004acf 100644
--- a/libwnck/window.c
+++ b/libwnck/window.c
@@ -33,6 +33,7 @@
 #include "xutils.h"
 #include "private.h"
 #include "wnck-enum-types.h"
+#include "wnck-handle-private.h"
 
 /**
  * SECTION:window
@@ -2359,12 +2360,15 @@ wnck_window_set_geometry (WnckWindow               *window,
                           int                       width,
                           int                       height)
 {
+  WnckHandle *handle;
   int gravity_and_flags;
   int source;
 
   g_return_if_fail (WNCK_IS_WINDOW (window));
 
-  source = _wnck_get_client_type();
+  handle = wnck_screen_get_handle (window->priv->screen);
+  source = wnck_handle_get_client_type (handle);
+
   gravity_and_flags = gravity;
   gravity_and_flags |= geometry_mask << 8;
   gravity_and_flags |= source << 12;
diff --git a/libwnck/wnck-handle-private.h b/libwnck/wnck-handle-private.h
index 163d673..13ff70f 100644
--- a/libwnck/wnck-handle-private.h
+++ b/libwnck/wnck-handle-private.h
@@ -22,6 +22,8 @@
 
 G_BEGIN_DECLS
 
+WnckClientType wnck_handle_get_client_type (WnckHandle *self);
+
 G_END_DECLS
 
 #endif
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
index f38e631..1625c10 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -25,19 +25,123 @@
 #include "config.h"
 #include "wnck-handle-private.h"
 
+#include "wnck-enum-types.h"
+
 struct _WnckHandle
 {
-  GObject parent;
+  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)
 {
 }
+
+/**
+ * wnck_handle_new:
+ * @client_type: a role for the client
+ *
+ * Creates a new #WnckHandle object with a given @client_type.
+ *
+ * Returns: (transfer full): newly created #WnckHandle.
+ */
+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)
+{
+  g_return_val_if_fail (WNCK_IS_HANDLE (self), WNCK_CLIENT_TYPE_APPLICATION);
+
+  return self->client_type;
+}
diff --git a/libwnck/wnck-handle.h b/libwnck/wnck-handle.h
index 12362d8..874d3ba 100644
--- a/libwnck/wnck-handle.h
+++ b/libwnck/wnck-handle.h
@@ -23,12 +23,15 @@
 #define WNCK_HANDLE_H
 
 #include <glib-object.h>
+#include <libwnck/util.h>
 
 G_BEGIN_DECLS
 
 #define WNCK_TYPE_HANDLE (wnck_handle_get_type ())
 G_DECLARE_FINAL_TYPE (WnckHandle, wnck_handle, WNCK, HANDLE, GObject)
 
+WnckHandle *wnck_handle_new (WnckClientType client_type);
+
 G_END_DECLS
 
 #endif
diff --git a/libwnck/xutils.c b/libwnck/xutils.c
index 74e455d..5a419e3 100644
--- a/libwnck/xutils.c
+++ b/libwnck/xutils.c
@@ -30,6 +30,7 @@
 #include "screen.h"
 #include "window.h"
 #include "private.h"
+#include "wnck-handle-private.h"
 
 gboolean
 _wnck_get_cardinal (Screen *screen,
@@ -886,11 +887,13 @@ _wnck_close (WnckScreen *screen,
              Window      xwindow,
              Time        timestamp)
 {
+  WnckHandle *handle;
   Screen *xscreen;
   Display *display;
   Window root;
   XEvent xev;
 
+  handle = wnck_screen_get_handle (screen);
   xscreen = _wnck_screen_get_xscreen (screen);
   display = DisplayOfScreen (xscreen);
   root = RootWindowOfScreen (xscreen);
@@ -903,7 +906,7 @@ _wnck_close (WnckScreen *screen,
   xev.xclient.message_type = _wnck_atom_get ("_NET_CLOSE_WINDOW");
   xev.xclient.format = 32;
   xev.xclient.data.l[0] = timestamp;
-  xev.xclient.data.l[1] = _wnck_get_client_type ();
+  xev.xclient.data.l[1] = wnck_handle_get_client_type (handle);
   xev.xclient.data.l[2] = 0;
   xev.xclient.data.l[3] = 0;
   xev.xclient.data.l[4] = 0;
@@ -933,11 +936,13 @@ void
 _wnck_keyboard_move (WnckScreen *screen,
                      Window      xwindow)
 {
+  WnckHandle *handle;
   Screen *xscreen;
   Display *display;
   Window root;
   XEvent xev;
 
+  handle = wnck_screen_get_handle (screen);
   xscreen = _wnck_screen_get_xscreen (screen);
   display = DisplayOfScreen (xscreen);
   root = RootWindowOfScreen (xscreen);
@@ -953,7 +958,7 @@ _wnck_keyboard_move (WnckScreen *screen,
   xev.xclient.data.l[1] = 0; /* unused */
   xev.xclient.data.l[2] = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
   xev.xclient.data.l[3] = 0; /* unused */
-  xev.xclient.data.l[4] = _wnck_get_client_type ();
+  xev.xclient.data.l[4] = wnck_handle_get_client_type (handle);
 
   _wnck_error_trap_push (display);
   XSendEvent (display,
@@ -968,11 +973,13 @@ void
 _wnck_keyboard_size (WnckScreen *screen,
                      Window      xwindow)
 {
+  WnckHandle *handle;
   Screen *xscreen;
   Display *display;
   Window root;
   XEvent xev;
 
+  handle = wnck_screen_get_handle (screen);
   xscreen = _wnck_screen_get_xscreen (screen);
   display = DisplayOfScreen (xscreen);
   root = RootWindowOfScreen (xscreen);
@@ -988,7 +995,7 @@ _wnck_keyboard_size (WnckScreen *screen,
   xev.xclient.data.l[1] = 0; /* unused */
   xev.xclient.data.l[2] = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
   xev.xclient.data.l[3] = 0; /* unused */
-  xev.xclient.data.l[4] = _wnck_get_client_type ();
+  xev.xclient.data.l[4] = wnck_handle_get_client_type (handle);
 
   _wnck_error_trap_push (display);
   XSendEvent (display,
@@ -1006,6 +1013,7 @@ _wnck_change_state (WnckScreen *screen,
                     Atom        state1,
                     Atom        state2)
 {
+  WnckHandle *handle;
   Screen *xscreen;
   Display *display;
   Window root;
@@ -1015,6 +1023,7 @@ _wnck_change_state (WnckScreen *screen,
 #define _NET_WM_STATE_ADD           1    /* add/set property */
 #define _NET_WM_STATE_TOGGLE        2    /* toggle property  */
 
+  handle = wnck_screen_get_handle (screen);
   xscreen = _wnck_screen_get_xscreen (screen);
   display = DisplayOfScreen (xscreen);
   root = RootWindowOfScreen (xscreen);
@@ -1029,7 +1038,7 @@ _wnck_change_state (WnckScreen *screen,
   xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
   xev.xclient.data.l[1] = state1;
   xev.xclient.data.l[2] = state2;
-  xev.xclient.data.l[3] = _wnck_get_client_type ();
+  xev.xclient.data.l[3] = wnck_handle_get_client_type (handle);
   xev.xclient.data.l[4] = 0;
 
   _wnck_error_trap_push (display);
@@ -1046,11 +1055,13 @@ _wnck_change_workspace (WnckScreen *screen,
                         Window      xwindow,
                         int         new_space)
 {
+  WnckHandle *handle;
   Screen *xscreen;
   Display *display;
   Window root;
   XEvent xev;
 
+  handle = wnck_screen_get_handle (screen);
   xscreen = _wnck_screen_get_xscreen (screen);
   display = DisplayOfScreen (xscreen);
   root = RootWindowOfScreen (xscreen);
@@ -1063,7 +1074,7 @@ _wnck_change_workspace (WnckScreen *screen,
   xev.xclient.message_type = _wnck_atom_get ("_NET_WM_DESKTOP");
   xev.xclient.format = 32;
   xev.xclient.data.l[0] = new_space;
-  xev.xclient.data.l[1] = _wnck_get_client_type ();
+  xev.xclient.data.l[1] = wnck_handle_get_client_type (handle);
   xev.xclient.data.l[2] = 0;
   xev.xclient.data.l[3] = 0;
   xev.xclient.data.l[4] = 0;
@@ -1082,6 +1093,7 @@ _wnck_activate (WnckScreen *screen,
                 Window      xwindow,
                 Time        timestamp)
 {
+  WnckHandle *handle;
   Screen *xscreen;
   Display *display;
   Window root;
@@ -1091,6 +1103,7 @@ _wnck_activate (WnckScreen *screen,
     g_warning ("Received a timestamp of 0; window activation may not "
                "function properly.\n");
 
+  handle = wnck_screen_get_handle (screen);
   xscreen = _wnck_screen_get_xscreen (screen);
   display = DisplayOfScreen (xscreen);
   root = RootWindowOfScreen (xscreen);
@@ -1102,7 +1115,7 @@ _wnck_activate (WnckScreen *screen,
   xev.xclient.window = xwindow;
   xev.xclient.message_type = _wnck_atom_get ("_NET_ACTIVE_WINDOW");
   xev.xclient.format = 32;
-  xev.xclient.data.l[0] = _wnck_get_client_type ();
+  xev.xclient.data.l[0] = wnck_handle_get_client_type (handle);
   xev.xclient.data.l[1] = timestamp;
   xev.xclient.data.l[2] = 0;
   xev.xclient.data.l[3] = 0;
diff --git a/libwnck/xutils.h b/libwnck/xutils.h
index e09666f..bfc282d 100644
--- a/libwnck/xutils.h
+++ b/libwnck/xutils.h
@@ -31,6 +31,9 @@
 
 G_BEGIN_DECLS
 
+/* forward decls */
+typedef struct _WnckScreen WnckScreen;
+
 #define WNCK_APP_WINDOW_EVENT_MASK (PropertyChangeMask | StructureNotifyMask)
 
 gboolean _wnck_get_cardinal      (Screen *screen,


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