[Xfce4-commits] <xfce4-panel:master> Restart external plugins on compositing changes.

Nick Schermer noreply at xfce.org
Thu Mar 4 22:50:01 CET 2010


Updating branch refs/heads/master
         to 0ca54af6cf1bd52e66d248b2f7e4ca0ab150fce0 (commit)
       from b6421c95be7527e271c10c929d28eb3d502510cf (commit)

commit 0ca54af6cf1bd52e66d248b2f7e4ca0ab150fce0
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Mar 4 22:45:35 2010 +0100

    Restart external plugins on compositing changes.
    
    This makes the whole thing more reliable. Switching
    compositing on-the-fly for sockets is a bit tricky.

 libxfce4panel/xfce-panel-macros-46.h |   58 +++++------------------
 panel/panel-base-window.c            |   30 ++++++++++++
 panel/panel-plugin-external-46.c     |   22 +++++++++
 panel/panel-plugin-external.c        |   42 ++++++++++------
 plugins/tasklist/tasklist-widget.c   |    2 +-
 wrapper/wrapper-plug.c               |   86 ++++++---------------------------
 6 files changed, 108 insertions(+), 132 deletions(-)

diff --git a/libxfce4panel/xfce-panel-macros-46.h b/libxfce4panel/xfce-panel-macros-46.h
index f930766..88a0335 100644
--- a/libxfce4panel/xfce-panel-macros-46.h
+++ b/libxfce4panel/xfce-panel-macros-46.h
@@ -430,47 +430,6 @@ enum /*< skip >*/
       gtk_main_quit (); \
   } \
   \
-  static void \
-  _xpp_set_colormap (GtkWidget *plug) \
-  { \
-    GdkColormap *colormap = NULL; \
-    GdkScreen   *screen; \
-    gboolean     restore; \
-    \
-    g_return_if_fail (GTK_IS_WIDGET (plug)); \
-    \
-    restore = GTK_WIDGET_REALIZED (plug); \
-    if (restore) \
-      { \
-        gtk_widget_hide (plug); \
-        gtk_widget_unrealize (plug); \
-      } \
-    \
-    screen = gtk_widget_get_screen (plug); \
-    \
-    _xpp_composited = gtk_widget_is_composited (plug); \
-    \
-    if (_xpp_composited) \
-      colormap = gdk_screen_get_rgba_colormap (screen); \
-    \
-    if (colormap == NULL) \
-      { \
-        colormap = gdk_screen_get_rgb_colormap (screen); \
-        _xpp_composited = FALSE; \
-      } \
-    \
-    if (colormap != NULL) \
-      gtk_widget_set_colormap (plug, colormap); \
-    \
-    if (restore) \
-      { \
-        gtk_widget_realize (plug); \
-        gtk_widget_show (plug); \
-      } \
-    \
-    gtk_widget_queue_draw (plug); \
-  } \
-  \
   gint \
   main (gint argc, gchar **argv) \
   { \
@@ -479,6 +438,7 @@ enum /*< skip >*/
     GtkWidget       *xpp; \
     gint             unique_id; \
     GdkNativeWindow  socket_id; \
+    GdkColormap     *colormap = NULL; \
     \
     if (G_UNLIKELY (argc < PLUGIN_ARGV_ARGUMENTS)) \
       { \
@@ -510,12 +470,20 @@ enum /*< skip >*/
         G_CALLBACK (_xpp_plug_embedded), NULL); \
     g_signal_connect (G_OBJECT (plug), "expose-event", \
         G_CALLBACK (_xpp_expose_event), NULL); \
-    g_signal_connect (G_OBJECT (plug), "composited-changed", \
-        G_CALLBACK (_xpp_set_colormap), NULL); \
     \
     gtk_widget_set_app_paintable (plug, TRUE); \
-    if (gtk_widget_is_composited (plug)) \
-      _xpp_set_colormap (plug); \
+    \
+    screen = gtk_widget_get_screen (plug); \
+    _xpp_composited = gtk_widget_is_composited (plug); \
+    if (_xpp_composited) \
+      colormap = gdk_screen_get_rgba_colormap (screen); \
+    if (colormap == NULL) \
+      { \
+        colormap = gdk_screen_get_rgb_colormap (screen); \
+        _xpp_composited = FALSE; \
+      } \
+    if (colormap != NULL) \
+      gtk_widget_set_colormap (plug, colormap); \
     \
     unique_id = strtol (argv[PLUGIN_ARGV_UNIQUE_ID], NULL, 0); \
     xpp = g_object_new (XFCE_TYPE_PANEL_PLUGIN, \
diff --git a/panel/panel-base-window.c b/panel/panel-base-window.c
index 8d4e6c5..4fc683f 100644
--- a/panel/panel-base-window.c
+++ b/panel/panel-base-window.c
@@ -29,6 +29,7 @@
 #include <libxfce4panel/xfce-panel-plugin-provider.h>
 #include <common/panel-private.h>
 #include <panel/panel-base-window.h>
+#include <panel/panel-window.h>
 #include <panel/panel-plugin-external.h>
 #include <panel/panel-plugin-external-46.h>
 
@@ -56,6 +57,8 @@ static gboolean panel_base_window_enter_notify_event          (GtkWidget
 static gboolean panel_base_window_leave_notify_event          (GtkWidget            *widget,
                                                                GdkEventCrossing     *event);
 static void     panel_base_window_composited_changed          (GtkWidget            *widget);
+static void     panel_base_window_update_provider_info        (GtkWidget            *widget,
+                                                               gpointer              user_data);
 static gboolean panel_base_window_active_timeout              (gpointer              user_data);
 static void     panel_base_window_active_timeout_destroyed    (gpointer              user_data);
 static void     panel_base_window_set_plugin_background_alpha (GtkWidget            *widget,
@@ -467,6 +470,7 @@ panel_base_window_composited_changed (GtkWidget *widget)
   GdkColormap     *colormap = NULL;
   gboolean         was_composited = window->is_composited;
   gboolean         was_visible;
+  GtkWidget       *itembar;
   GdkScreen       *screen;
 
   panel_return_if_fail (PANEL_IS_BASE_WINDOW (widget));
@@ -505,6 +509,18 @@ panel_base_window_composited_changed (GtkWidget *widget)
 
   if (was_visible)
     {
+      /* we destroyed all external plugin during unrealize, so queue
+       * new provider information for the panel window (not the
+       * autohide window) */
+      if (PANEL_IS_WINDOW (widget))
+        {
+          itembar = gtk_bin_get_child (GTK_BIN (window));
+          panel_return_if_fail (GTK_IS_CONTAINER (itembar));
+          if (G_LIKELY (itembar != NULL))
+            gtk_container_foreach (GTK_CONTAINER (itembar),
+                panel_base_window_update_provider_info, window);
+        }
+
       /* restore the window */
       gtk_widget_realize (widget);
       gtk_widget_show (widget);
@@ -517,6 +533,20 @@ panel_base_window_composited_changed (GtkWidget *widget)
 
 
 
+static void
+panel_base_window_update_provider_info (GtkWidget *widget,
+                                        gpointer   user_data)
+{
+  panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (widget));
+  panel_return_if_fail (PANEL_IS_WINDOW (user_data));
+
+  if (PANEL_IS_PLUGIN_EXTERNAL (widget)
+      || PANEL_IS_PLUGIN_EXTERNAL_46 (widget))
+    panel_window_set_povider_info (user_data, widget);
+}
+
+
+
 static gboolean
 panel_base_window_active_timeout (gpointer user_data)
 {
diff --git a/panel/panel-plugin-external-46.c b/panel/panel-plugin-external-46.c
index 451611d..fca8ccf 100644
--- a/panel/panel-plugin-external-46.c
+++ b/panel/panel-plugin-external-46.c
@@ -59,6 +59,7 @@ static void         panel_plugin_external_46_set_property          (GObject
                                                                     const GValue                     *value,
                                                                     GParamSpec                       *pspec);
 static void         panel_plugin_external_46_realize               (GtkWidget                        *widget);
+static void         panel_plugin_external_46_unrealize             (GtkWidget                        *widget);
 static gboolean     panel_plugin_external_46_client_event          (GtkWidget                        *widget,
                                                                     GdkEventClient                   *event);
 static gboolean     panel_plugin_external_46_plug_removed          (GtkSocket                        *socket);
@@ -169,6 +170,7 @@ panel_plugin_external_46_class_init (PanelPluginExternal46Class *klass)
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
   gtkwidget_class->realize = panel_plugin_external_46_realize;
+  gtkwidget_class->unrealize = panel_plugin_external_46_unrealize;
   gtkwidget_class->client_event = panel_plugin_external_46_client_event;
 
   gtksocket_class = GTK_SOCKET_CLASS (klass);
@@ -405,6 +407,26 @@ panel_plugin_external_46_realize (GtkWidget *widget)
 
 
 
+static void
+panel_plugin_external_46_unrealize (GtkWidget *widget)
+{
+  PanelPluginExternal46  *external = PANEL_PLUGIN_EXTERNAL_46 (widget);
+
+  /* the plug is not embedded anymore */
+  external->plug_embedded = FALSE;
+
+  if (external->watch_id != 0)
+    {
+      /* remove the child watch so we don't leave zomies */
+      g_source_remove (external->watch_id);
+      g_child_watch_add (external->pid, (GChildWatchFunc) g_spawn_close_pid, NULL);
+    }
+
+  (*GTK_WIDGET_CLASS (panel_plugin_external_46_parent_class)->unrealize) (widget);
+}
+
+
+
 static gboolean
 panel_plugin_external_46_client_event (GtkWidget      *widget,
                                        GdkEventClient *event)
diff --git a/panel/panel-plugin-external.c b/panel/panel-plugin-external.c
index 7f63b38..14eec04 100644
--- a/panel/panel-plugin-external.c
+++ b/panel/panel-plugin-external.c
@@ -63,8 +63,8 @@ static void         panel_plugin_external_set_property          (GObject
                                                                  guint                              prop_id,
                                                                  const GValue                      *value,
                                                                  GParamSpec                        *pspec);
-static void         panel_plugin_external_destroy               (GtkObject                         *object);
 static void         panel_plugin_external_realize               (GtkWidget                         *widget);
+static void         panel_plugin_external_unrealize             (GtkWidget                         *widget);
 static gboolean     panel_plugin_external_plug_removed          (GtkSocket                         *socket);
 static void         panel_plugin_external_plug_added            (GtkSocket                         *socket);
 static gboolean     panel_plugin_external_dbus_reply            (PanelPluginExternal               *external,
@@ -177,7 +177,6 @@ static void
 panel_plugin_external_class_init (PanelPluginExternalClass *klass)
 {
   GObjectClass   *gobject_class;
-  GtkObjectClass *gtkobject_class;
   GtkWidgetClass *gtkwidget_class;
   GtkSocketClass *gtksocket_class;
 
@@ -187,11 +186,9 @@ panel_plugin_external_class_init (PanelPluginExternalClass *klass)
   gobject_class->set_property = panel_plugin_external_set_property;
   gobject_class->get_property = panel_plugin_external_get_property;
 
-  gtkobject_class = GTK_OBJECT_CLASS (klass);
-  gtkobject_class->destroy = panel_plugin_external_destroy;
-
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
   gtkwidget_class->realize = panel_plugin_external_realize;
+  gtkwidget_class->unrealize = panel_plugin_external_unrealize;
 
   gtksocket_class = GTK_SOCKET_CLASS (klass);
   gtksocket_class->plug_removed = panel_plugin_external_plug_removed;
@@ -404,17 +401,6 @@ panel_plugin_external_set_property (GObject      *object,
 
 
 static void
-panel_plugin_external_destroy (GtkObject *object)
-{
-  panel_plugin_external_queue_add_noop (PANEL_PLUGIN_EXTERNAL (object),
-                                        TRUE, SIGNAL_WRAPPER_QUIT);
-
-  (*GTK_OBJECT_CLASS (panel_plugin_external_parent_class)->destroy) (object);
-}
-
-
-
-static void
 panel_plugin_external_realize (GtkWidget *widget)
 {
   PanelPluginExternal  *external = PANEL_PLUGIN_EXTERNAL (widget);
@@ -484,6 +470,30 @@ panel_plugin_external_realize (GtkWidget *widget)
 
 
 
+static void
+panel_plugin_external_unrealize (GtkWidget *widget)
+{
+  PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (widget);
+
+  /* the plug is not embedded anymore */
+  external->plug_embedded = FALSE;
+
+  if (external->watch_id != 0)
+    {
+      /* remove the child watch so we don't leave zomies */
+      g_source_remove (external->watch_id);
+      g_child_watch_add (external->pid, (GChildWatchFunc) g_spawn_close_pid, NULL);
+    }
+
+  /* quit the plugin */
+  panel_plugin_external_queue_add_noop (PANEL_PLUGIN_EXTERNAL (widget),
+                                        TRUE, SIGNAL_WRAPPER_QUIT);
+
+  (*GTK_WIDGET_CLASS (panel_plugin_external_parent_class)->unrealize) (widget);
+}
+
+
+
 static gboolean
 panel_plugin_external_plug_removed (GtkSocket *socket)
 {
diff --git a/plugins/tasklist/tasklist-widget.c b/plugins/tasklist/tasklist-widget.c
index 6f9cf70..5d2f2d3 100644
--- a/plugins/tasklist/tasklist-widget.c
+++ b/plugins/tasklist/tasklist-widget.c
@@ -802,7 +802,7 @@ xfce_tasklist_size_allocate (GtkWidget     *widget,
   /* swap integers with vertical orientation */
   if (!tasklist->horizontal)
     TRANSPOSE_AREA (area);
-  panel_return_if_fail (area.height == tasklist->size);
+  /*panel_return_if_fail (area.height == tasklist->size);*/
 
   /* TODO if we compare the allocation with the requisition we can
    * do a fast path to the child allocation, i think */
diff --git a/wrapper/wrapper-plug.c b/wrapper/wrapper-plug.c
index 49e1539..cb537bc 100644
--- a/wrapper/wrapper-plug.c
+++ b/wrapper/wrapper-plug.c
@@ -31,7 +31,6 @@
 
 static gboolean wrapper_plug_expose_event (GtkWidget      *widget,
                                            GdkEventExpose *event);
-static void     wrapper_plug_set_colormap (WrapperPlug    *plug);
 
 
 
@@ -76,19 +75,16 @@ wrapper_plug_class_init (WrapperPlugClass *klass)
 static void
 wrapper_plug_init (WrapperPlug *plug)
 {
-  /* init vars */
+  GdkColormap *colormap = NULL;
+  GdkScreen   *screen;
+
   plug->background_alpha = 1.00;
-  plug->is_composited = FALSE;
 
   gtk_widget_set_name (GTK_WIDGET (plug), "XfcePanelWrapper");
 
   /* allow painting, else compositing won't work */
   gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE);
 
-  /* connect signal to monitor the compositor changes */
-  g_signal_connect (G_OBJECT (plug), "composited-changed",
-      G_CALLBACK (wrapper_plug_set_colormap), NULL);
-
   /* old versions of gtk don't support transparent tray icons, if we
    * set an argb colormap on the tray, the icons won't be embedded because
    * the socket-plugin implementation requires identical colormaps */
@@ -97,7 +93,19 @@ wrapper_plug_init (WrapperPlug *plug)
     return;
 
   /* set the colormap */
-  wrapper_plug_set_colormap (plug);
+  screen = gtk_window_get_screen (GTK_WINDOW (plug));
+  plug->is_composited = gtk_widget_is_composited (GTK_WIDGET (plug));
+
+  if (plug->is_composited)
+    colormap = gdk_screen_get_rgba_colormap (screen);
+  if (colormap == NULL)
+    {
+      colormap = gdk_screen_get_rgb_colormap (screen);
+      plug->is_composited = FALSE;
+    }
+
+  if (colormap != NULL)
+    gtk_widget_set_colormap (GTK_WIDGET (plug), colormap);
 }
 
 
@@ -143,68 +151,6 @@ wrapper_plug_expose_event (GtkWidget      *widget,
 
 
 
-static void
-wrapper_plug_set_colormap (WrapperPlug *plug)
-{
-  GdkColormap *colormap = NULL;
-  GdkScreen   *screen;
-  gboolean     restore;
-  GtkWidget   *widget = GTK_WIDGET (plug);
-  gint         root_x, root_y;
-
-  panel_return_if_fail (WRAPPER_IS_PLUG (plug));
-
-  /* whether the widget was previously visible */
-  restore = GTK_WIDGET_REALIZED (widget);
-
-  /* unrealize the window if needed */
-  if (restore)
-    {
-      /* store the window position */
-      gtk_window_get_position (GTK_WINDOW (plug), &root_x, &root_y);
-
-      /* hide the widget */
-      gtk_widget_hide (widget);
-      gtk_widget_unrealize (widget);
-    }
-
-  /* set bool */
-  plug->is_composited = gtk_widget_is_composited (widget);
-
-  /* get the screen */
-  screen = gtk_window_get_screen (GTK_WINDOW (plug));
-
-  /* try to get the rgba colormap */
-  if (plug->is_composited)
-    colormap = gdk_screen_get_rgba_colormap (screen);
-
-  /* get the default colormap */
-  if (colormap == NULL)
-    {
-      colormap = gdk_screen_get_rgb_colormap (screen);
-      plug->is_composited = FALSE;
-    }
-
-  /* set the colormap */
-  if (colormap)
-    gtk_widget_set_colormap (widget, colormap);
-
-  /* restore the window */
-  if (restore)
-    {
-      /* restore the position */
-      gtk_window_move (GTK_WINDOW (plug), root_x, root_y);
-
-      /* show the widget again */
-      gtk_widget_realize (widget);
-      gtk_widget_show (widget);
-    }
-
-  gtk_widget_queue_draw (widget);
-}
-
-
-
 WrapperPlug *
 wrapper_plug_new (GdkNativeWindow socket_id)
 {



More information about the Xfce4-commits mailing list