[libwnck/wip/muktupavels/wnck-handle-2: 2/2] xutils: move event filter to WnckHandle




commit e3037abafc273c6d73ea87f123113ef25f701efe
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Aug 19 19:13:41 2019 +0300

    xutils: move event filter to WnckHandle

 libwnck/screen.c      |   1 -
 libwnck/util.c        |   2 -
 libwnck/wnck-handle.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++
 libwnck/xutils.c      | 107 --------------------------------------------------
 libwnck/xutils.h      |   3 --
 5 files changed, 104 insertions(+), 113 deletions(-)
---
diff --git a/libwnck/screen.c b/libwnck/screen.c
index 48e7c77..d6db387 100644
--- a/libwnck/screen.c
+++ b/libwnck/screen.c
@@ -586,7 +586,6 @@ wnck_screen_get (int index)
   if (screens == NULL)
     {
       screens = g_new0 (WnckScreen*, ScreenCount (display));
-      _wnck_event_filter_init ();
     }
 
   if (screens[index] == NULL)
diff --git a/libwnck/util.c b/libwnck/util.c
index aea7d26..e908a1c 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -833,8 +833,6 @@ _wnck_get_default_display (void)
 void
 wnck_shutdown (void)
 {
-  _wnck_event_filter_shutdown ();
-
   /* Warning: this is hacky :-)
    *
    * Shutting down all WnckScreen objects will automatically unreference (and
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
index fd61761..3f39daa 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -1,4 +1,6 @@
 /*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2005-2007 Vincent Untz
  * Copyright (C) 2021 Alberts Muktupāvels
  *
  * This library is free software; you can redistribute it and/or
@@ -18,7 +20,11 @@
 #include "config.h"
 #include "wnck-handle-private.h"
 
+#include "private.h"
+#include "screen.h"
+#include "window.h"
 #include "wnck-enum-types.h"
+#include "xutils.h"
 
 #define WNCK_TYPE_HANDLE (wnck_handle_get_type ())
 G_DECLARE_FINAL_TYPE (WnckHandle, wnck_handle, WNCK, HANDLE, GObject)
@@ -46,6 +52,101 @@ static GParamSpec *handle_properties[LAST_PROP] = { NULL };
 
 G_DEFINE_TYPE (WnckHandle, wnck_handle, G_TYPE_OBJECT)
 
+static GdkFilterReturn
+filter_func (GdkXEvent *gdkxevent,
+             GdkEvent  *event,
+             gpointer   data)
+{
+  XEvent *xevent = gdkxevent;
+#ifdef HAVE_STARTUP_NOTIFICATION
+  int i;
+  Display *display;
+#endif /* HAVE_STARTUP_NOTIFICATION */
+
+  switch (xevent->type)
+    {
+    case PropertyNotify:
+      {
+        WnckScreen *screen;
+
+        screen = wnck_screen_get_for_root (xevent->xany.window);
+        if (screen != NULL)
+          _wnck_screen_process_property_notify (screen, xevent);
+        else
+          {
+            WnckWindow *window;
+            WnckApplication *app;
+
+            window = wnck_window_get (xevent->xany.window);
+            app = wnck_application_get (xevent->xany.window);
+
+            if (app)
+              _wnck_application_process_property_notify (app, xevent);
+
+            if (window)
+              _wnck_window_process_property_notify (window, xevent);
+          }
+      }
+      break;
+
+    case ConfigureNotify:
+      {
+        WnckWindow *window;
+
+        window = wnck_window_get (xevent->xconfigure.window);
+
+        if (window)
+          _wnck_window_process_configure_notify (window, xevent);
+      }
+      break;
+
+    case SelectionClear:
+      {
+        _wnck_desktop_layout_manager_process_event (xevent);
+      }
+      break;
+
+    case ClientMessage:
+#ifdef HAVE_STARTUP_NOTIFICATION
+      /* We're cheating as officially libsn requires
+       * us to send all events through sn_display_process_event
+       */
+      i = 0;
+      display = ((XAnyEvent *) xevent)->display;
+
+      while (i < ScreenCount (display))
+        {
+          WnckScreen *s;
+
+          s = _wnck_screen_get_existing (i);
+          if (s != NULL)
+            sn_display_process_event (_wnck_screen_get_sn_display (s),
+                                      xevent);
+
+          ++i;
+        }
+#endif /* HAVE_STARTUP_NOTIFICATION */
+      break;
+
+    default:
+      break;
+    }
+
+  return GDK_FILTER_CONTINUE;
+}
+
+static void
+wnck_handle_finalize (GObject *object)
+{
+  WnckHandle *self;
+
+  self = WNCK_HANDLE (object);
+
+  gdk_window_remove_filter (NULL, filter_func, self);
+
+  G_OBJECT_CLASS (wnck_handle_parent_class)->finalize (object);
+}
+
 static void
 wnck_handle_get_property (GObject    *object,
                           guint       property_id,
@@ -114,6 +215,7 @@ wnck_handle_class_init (WnckHandleClass *self_class)
 
   object_class = G_OBJECT_CLASS (self_class);
 
+  object_class->finalize = wnck_handle_finalize;
   object_class->get_property = wnck_handle_get_property;
   object_class->set_property = wnck_handle_set_property;
 
@@ -125,6 +227,8 @@ wnck_handle_init (WnckHandle *self)
 {
   self->default_icon_size = WNCK_DEFAULT_ICON_SIZE;
   self->default_mini_icon_size = WNCK_DEFAULT_MINI_ICON_SIZE;
+
+  gdk_window_add_filter (NULL, filter_func, self);
 }
 
 WnckHandle
diff --git a/libwnck/xutils.c b/libwnck/xutils.c
index 8c14234..d22ad9b 100644
--- a/libwnck/xutils.c
+++ b/libwnck/xutils.c
@@ -719,113 +719,6 @@ _wnck_error_trap_pop (Display *display)
   return gdk_x11_display_error_trap_pop (gdk_display);
 }
 
-static GdkFilterReturn
-filter_func (GdkXEvent  *gdkxevent,
-             GdkEvent   *event,
-             gpointer    data)
-{
-  XEvent *xevent = gdkxevent;
-#ifdef HAVE_STARTUP_NOTIFICATION
-  int i;
-  Display *display;
-#endif /* HAVE_STARTUP_NOTIFICATION */
-
-  switch (xevent->type)
-    {
-    case PropertyNotify:
-      {
-        WnckScreen *screen;
-
-        screen = wnck_screen_get_for_root (xevent->xany.window);
-        if (screen != NULL)
-          _wnck_screen_process_property_notify (screen, xevent);
-        else
-          {
-            WnckWindow *window;
-            WnckApplication *app;
-
-            window = wnck_window_get (xevent->xany.window);
-            app = wnck_application_get (xevent->xany.window);
-
-            if (app)
-              _wnck_application_process_property_notify (app, xevent);
-
-            if (window)
-              _wnck_window_process_property_notify (window, xevent);
-          }
-      }
-      break;
-
-    case ConfigureNotify:
-      {
-        WnckWindow *window;
-
-        window = wnck_window_get (xevent->xconfigure.window);
-
-        if (window)
-          _wnck_window_process_configure_notify (window, xevent);
-      }
-      break;
-
-    case SelectionClear:
-      {
-        _wnck_desktop_layout_manager_process_event (xevent);
-      }
-      break;
-
-    case ClientMessage:
-#ifdef HAVE_STARTUP_NOTIFICATION
-      /* We're cheating as officially libsn requires
-       * us to send all events through sn_display_process_event
-       */
-      i = 0;
-      display = ((XAnyEvent *) xevent)->display;
-
-      while (i < ScreenCount (display))
-        {
-          WnckScreen *s;
-
-          s = _wnck_screen_get_existing (i);
-          if (s != NULL)
-            sn_display_process_event (_wnck_screen_get_sn_display (s),
-                                      xevent);
-
-          ++i;
-        }
-#endif /* HAVE_STARTUP_NOTIFICATION */
-      break;
-
-    default:
-      break;
-    }
-
-  return GDK_FILTER_CONTINUE;
-}
-
-static gboolean _wnck_event_filter_initialized = FALSE;
-
-void
-_wnck_event_filter_init (void)
-{
-
-  if (!_wnck_event_filter_initialized)
-    {
-      gdk_window_add_filter (NULL, filter_func, NULL);
-      _wnck_event_filter_initialized = TRUE;
-    }
-}
-
-void
-_wnck_event_filter_shutdown (void)
-{
-
-  if (_wnck_event_filter_initialized)
-    {
-      gdk_window_remove_filter (NULL, filter_func, NULL);
-      _wnck_event_filter_initialized = FALSE;
-    }
-}
-
 int
 _wnck_xid_equal (gconstpointer v1,
                  gconstpointer v2)
diff --git a/libwnck/xutils.h b/libwnck/xutils.h
index e5ef85d..9c2f06e 100644
--- a/libwnck/xutils.h
+++ b/libwnck/xutils.h
@@ -87,9 +87,6 @@ int  _wnck_error_trap_pop  (Display *display);
 #define _wnck_atom_get(atom_name) gdk_x11_get_xatom_by_name (atom_name)
 #define _wnck_atom_name(atom)     gdk_x11_get_xatom_name (atom)
 
-void _wnck_event_filter_init (void);
-void _wnck_event_filter_shutdown (void);
-
 int   _wnck_xid_equal (gconstpointer v1,
                        gconstpointer v2);
 guint _wnck_xid_hash  (gconstpointer v);


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