[libwnck/wip/muktupavels/startup-notification] screen: move SnDisplay to WnckTasklist




commit 89a96bac4018527a07f6c326a3b7b8794d1ff1b4
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Mar 8 13:19:12 2022 +0200

    screen: move SnDisplay to WnckTasklist
    
    Startup notifications are used only in WnckTasklist.

 libwnck/private.h     |  8 ------
 libwnck/screen.c      | 41 ---------------------------
 libwnck/tasklist.c    | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 libwnck/util.c        | 13 ---------
 libwnck/wnck-handle.c | 27 ------------------
 5 files changed, 76 insertions(+), 90 deletions(-)
---
diff --git a/libwnck/private.h b/libwnck/private.h
index bc83b65b..fbf7331a 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -22,7 +22,6 @@
 #ifndef WNCK_PRIVATE_H
 #define WNCK_PRIVATE_H
 
-#include <config.h>
 #include "screen.h"
 #include "window.h"
 #include "workspace.h"
@@ -31,9 +30,6 @@
 #include "pager.h"
 #include "util.h"
 #include "wnck-handle-private.h"
-#ifdef HAVE_STARTUP_NOTIFICATION
-#include <libsn/sn.h>
-#endif
 
 G_BEGIN_DECLS
 
@@ -122,10 +118,6 @@ Window     _wnck_screen_get_xroot      (WnckScreen *screen);
 Screen    *_wnck_screen_get_xscreen    (WnckScreen *screen);
 GdkScreen *_wnck_screen_get_gdk_screen (WnckScreen *screen);
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-SnDisplay* _wnck_screen_get_sn_display (WnckScreen *screen);
-#endif
-
 WnckHandle    *_wnck_screen_get_handle          (WnckScreen    *screen);
 
 void           _wnck_pager_activate_workspace   (WnckWorkspace *wspace,
diff --git a/libwnck/screen.c b/libwnck/screen.c
index 26cc5af0..3f095eef 100644
--- a/libwnck/screen.c
+++ b/libwnck/screen.c
@@ -103,10 +103,6 @@ struct _WnckScreenPrivate
 
   guint update_handler;
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-  SnDisplay *sn_display;
-#endif
-
   guint showing_desktop : 1;
 
   guint vertical_workspaces : 1;
@@ -498,30 +494,9 @@ wnck_screen_finalize (GObject *object)
   g_free (screen->priv->wm_name);
   screen->priv->wm_name = NULL;
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-  sn_display_unref (screen->priv->sn_display);
-  screen->priv->sn_display = NULL;
-#endif
-
   G_OBJECT_CLASS (wnck_screen_parent_class)->finalize (object);
 }
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-static void
-sn_error_trap_push (SnDisplay *display,
-                    Display   *xdisplay)
-{
-  _wnck_error_trap_push (xdisplay);
-}
-
-static void
-sn_error_trap_pop (SnDisplay *display,
-                   Display   *xdisplay)
-{
-  _wnck_error_trap_pop (xdisplay);
-}
-#endif /* HAVE_STARTUP_NOTIFICATION */
-
 void
 _wnck_screen_construct (WnckScreen *screen,
                         WnckHandle *handle,
@@ -535,12 +510,6 @@ _wnck_screen_construct (WnckScreen *screen,
   screen->priv->xscreen = ScreenOfDisplay (display, number);
   screen->priv->number = number;
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-  screen->priv->sn_display = sn_display_new (display,
-                                             sn_error_trap_push,
-                                             sn_error_trap_pop);
-#endif
-
   screen->priv->bg_pixmap = None;
 
   screen->priv->orig_event_mask = _wnck_select_input (screen->priv->xscreen,
@@ -2618,16 +2587,6 @@ wnck_screen_move_viewport (WnckScreen *screen,
   _wnck_change_viewport (screen->priv->xscreen, x, y);
 }
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-SnDisplay*
-_wnck_screen_get_sn_display (WnckScreen *screen)
-{
-  g_return_val_if_fail (WNCK_IS_SCREEN (screen), NULL);
-
-  return screen->priv->sn_display;
-}
-#endif /* HAVE_STARTUP_NOTIFICATION */
-
 void
 _wnck_screen_change_workspace_name (WnckScreen *screen,
                                     int         number,
diff --git a/libwnck/tasklist.c b/libwnck/tasklist.c
index 78a73ff6..fe736e30 100644
--- a/libwnck/tasklist.c
+++ b/libwnck/tasklist.c
@@ -36,6 +36,10 @@
 #include "xutils.h"
 #include "private.h"
 
+#ifdef HAVE_STARTUP_NOTIFICATION
+#include <libsn/sn.h>
+#endif
+
 /**
  * SECTION:tasklist
  * @short_description: a tasklist widget, showing the list of windows as a list
@@ -232,6 +236,7 @@ struct _WnckTasklistPrivate
   GDestroyNotify free_icon_loader_data;
 
 #ifdef HAVE_STARTUP_NOTIFICATION
+  SnDisplay *sn_display;
   SnMonitorContext *sn_context;
   guint startup_sequence_timeout;
 #endif
@@ -847,6 +852,34 @@ wnck_task_finalize (GObject *object)
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
+static GdkFilterReturn
+event_filter_cb (GdkXEvent *gdkxevent,
+                 GdkEvent  *event,
+                 gpointer   data)
+{
+#ifdef HAVE_STARTUP_NOTIFICATION
+  WnckTasklist *self;
+  XEvent *xevent = gdkxevent;
+
+  self = WNCK_TASKLIST (data);
+
+  switch (xevent->type)
+    {
+      case ClientMessage:
+        /* We're cheating as officially libsn requires
+         * us to send all events through sn_display_process_event
+         */
+        sn_display_process_event (self->priv->sn_display, xevent);
+        break;
+
+      default:
+        break;
+    }
+#endif /* HAVE_STARTUP_NOTIFICATION */
+
+  return GDK_FILTER_CONTINUE;
+}
+
 static void
 wnck_tasklist_init (WnckTasklist *tasklist)
 {
@@ -875,6 +908,8 @@ wnck_tasklist_init (WnckTasklist *tasklist)
   atk_object_set_name (atk_obj, _("Window List"));
   atk_object_set_description (atk_obj, _("Tool to switch between visible windows"));
 
+  gdk_window_add_filter (NULL, event_filter_cb, tasklist);
+
 #if 0
   /* This doesn't work because, and I think this is because we have no window;
    * therefore, we use the scroll events on task buttons instead */
@@ -895,6 +930,15 @@ wnck_tasklist_get_request_mode (GtkWidget *widget)
   return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
 }
 
+#ifdef HAVE_STARTUP_NOTIFICATION
+static gboolean
+sn_utf8_validator (const char *str,
+                   int         max_len)
+{
+  return g_utf8_validate (str, max_len, NULL);
+}
+#endif /* HAVE_STARTUP_NOTIFICATION */
+
 static void
 wnck_tasklist_class_init (WnckTasklistClass *klass)
 {
@@ -1017,6 +1061,10 @@ wnck_tasklist_class_init (WnckTasklistClass *klass)
                   0, NULL, NULL, NULL,
                   G_TYPE_NONE, 1,
                   G_TYPE_POINTER);
+
+#ifdef HAVE_STARTUP_NOTIFICATION
+  sn_set_utf8_validator (sn_utf8_validator);
+#endif /* HAVE_STARTUP_NOTIFICATION */
 }
 
 static void
@@ -1054,6 +1102,8 @@ wnck_tasklist_finalize (GObject *object)
   g_assert (tasklist->priv->startup_sequences == NULL);
   /* wnck_tasklist_free_tasks (tasklist); */
 
+  gdk_window_remove_filter (NULL, event_filter_cb, tasklist);
+
   if (tasklist->priv->skipped_windows)
     {
       wnck_tasklist_free_skipped_windows (tasklist);
@@ -2151,16 +2201,34 @@ foreach_tasklist (WnckTasklist *tasklist,
   wnck_tasklist_update_lists (tasklist);
 }
 
+#ifdef HAVE_STARTUP_NOTIFICATION
+static void
+sn_error_trap_push (SnDisplay *display,
+                    Display   *xdisplay)
+{
+  _wnck_error_trap_push (xdisplay);
+}
+
+static void
+sn_error_trap_pop (SnDisplay *display,
+                   Display   *xdisplay)
+{
+  _wnck_error_trap_pop (xdisplay);
+}
+#endif /* HAVE_STARTUP_NOTIFICATION */
+
 static void
 wnck_tasklist_realize (GtkWidget *widget)
 {
   WnckTasklist *tasklist;
   GdkScreen *gdkscreen;
+  GdkDisplay *gdkdisplay;
   int screen_number;
 
   tasklist = WNCK_TASKLIST (widget);
 
   gdkscreen = gtk_widget_get_screen (widget);
+  gdkdisplay = gdk_screen_get_display (gdkscreen);
   screen_number = gdk_x11_screen_get_screen_number (gdkscreen);
 
   tasklist->priv->screen = _wnck_handle_get_screen (tasklist->priv->handle,
@@ -2169,8 +2237,12 @@ wnck_tasklist_realize (GtkWidget *widget)
   g_assert (tasklist->priv->screen != NULL);
 
 #ifdef HAVE_STARTUP_NOTIFICATION
+  tasklist->priv->sn_display = sn_display_new (gdk_x11_display_get_xdisplay (gdkdisplay),
+                                               sn_error_trap_push,
+                                               sn_error_trap_pop);
+
   tasklist->priv->sn_context =
-    sn_monitor_context_new (_wnck_screen_get_sn_display (tasklist->priv->screen),
+    sn_monitor_context_new (tasklist->priv->sn_display,
                             wnck_screen_get_number (tasklist->priv->screen),
                             wnck_tasklist_sn_event,
                             tasklist,
@@ -2198,6 +2270,9 @@ wnck_tasklist_unrealize (GtkWidget *widget)
   tasklist->priv->screen = NULL;
 
 #ifdef HAVE_STARTUP_NOTIFICATION
+  sn_display_unref (tasklist->priv->sn_display);
+  tasklist->priv->sn_display = NULL;
+
   sn_monitor_context_unref (tasklist->priv->sn_context);
   tasklist->priv->sn_context = NULL;
 #endif
diff --git a/libwnck/util.c b/libwnck/util.c
index b1023585..795b159b 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -243,15 +243,6 @@ _make_gtk_label_normal (GtkLabel *label)
   gtk_style_context_remove_class (context, "wnck-needs-attention");
 }
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-static gboolean
-_wnck_util_sn_utf8_validator (const char *str,
-                              int         max_len)
-{
-  return g_utf8_validate (str, max_len, NULL);
-}
-#endif /* HAVE_STARTUP_NOTIFICATION */
-
 void
 _wnck_init (void)
 {
@@ -262,10 +253,6 @@ _wnck_init (void)
       bindtextdomain (GETTEXT_PACKAGE, WNCK_LOCALEDIR);
       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
-#ifdef HAVE_STARTUP_NOTIFICATION
-      sn_set_utf8_validator (_wnck_util_sn_utf8_validator);
-#endif /* HAVE_STARTUP_NOTIFICATION */
-
       done = TRUE;
     }
 }
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
index 157aabea..fc2569ab 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -67,10 +67,6 @@ filter_func (GdkXEvent *gdkxevent,
 {
   WnckHandle *self;
   XEvent *xevent = gdkxevent;
-#ifdef HAVE_STARTUP_NOTIFICATION
-  int i;
-  Display *display;
-#endif /* HAVE_STARTUP_NOTIFICATION */
 
   self = WNCK_HANDLE (data);
 
@@ -120,29 +116,6 @@ filter_func (GdkXEvent *gdkxevent,
       }
       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 *screen;
-
-          screen = _wnck_handle_get_existing_screen (self, i);
-
-          if (screen != NULL)
-            sn_display_process_event (_wnck_screen_get_sn_display (screen),
-                                      xevent);
-
-          ++i;
-        }
-#endif /* HAVE_STARTUP_NOTIFICATION */
-      break;
-
     default:
       break;
     }


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