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




commit 669aa5f77cbffd775c5aaacfd01f6517dca1f14f
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 6f378d68..d5e48d93 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
-
 void           _wnck_pager_activate_workspace   (WnckWorkspace *wspace,
                                                  guint32        timestamp);
 int            _wnck_pager_get_n_workspaces     (WnckPager     *pager);
diff --git a/libwnck/screen.c b/libwnck/screen.c
index 264f49e6..35d33c22 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,
@@ -2626,16 +2595,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 757ef9be..b773247d 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
@@ -858,6 +863,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)
 {
@@ -886,6 +919,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 */
@@ -906,6 +941,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_get_property (GObject    *object,
                             guint       property_id,
@@ -1095,6 +1139,10 @@ wnck_tasklist_class_init (WnckTasklistClass *klass)
                   G_TYPE_POINTER);
 
   install_properties (object_class);
+
+#ifdef HAVE_STARTUP_NOTIFICATION
+  sn_set_utf8_validator (sn_utf8_validator);
+#endif /* HAVE_STARTUP_NOTIFICATION */
 }
 
 static void
@@ -1132,6 +1180,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);
@@ -2229,16 +2279,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,
@@ -2247,8 +2315,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,
@@ -2276,6 +2348,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 1f183a95..83659dc8 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -220,15 +220,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)
 {
@@ -239,10 +230,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 4bfa5c1d..9616283e 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -108,10 +108,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);
 
@@ -161,29 +157,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]