[Xfce4-commits] <xfce4-panel:master> Change colormap handling.

Nick Schermer noreply at xfce.org
Sun Jul 11 16:54:02 CEST 2010


Updating branch refs/heads/master
         to e6c42caef3e76f0446e4dba87342af26f683e778 (commit)
       from 13f5459a4a1a75746a5adf19fa9dedd3bd956477 (commit)

commit e6c42caef3e76f0446e4dba87342af26f683e778
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Jul 11 16:51:43 2010 +0200

    Change colormap handling.
    
    Always try to set the rgba colormap so we don't need to
    restart plugins when compositing changes.

 libxfce4panel/xfce-panel-macros-46.h |   15 ++----
 panel/panel-base-window.c            |   91 +++++++++++++---------------------
 wrapper/wrapper-plug.c               |   18 ++-----
 3 files changed, 44 insertions(+), 80 deletions(-)

diff --git a/libxfce4panel/xfce-panel-macros-46.h b/libxfce4panel/xfce-panel-macros-46.h
index 3c28106..d7905c2 100644
--- a/libxfce4panel/xfce-panel-macros-46.h
+++ b/libxfce4panel/xfce-panel-macros-46.h
@@ -262,7 +262,6 @@ G_BEGIN_DECLS
 #define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL(construct_func, preinit_func, check_func) \
   static GdkAtom          _xpp_atom = GDK_NONE; \
   static gdouble          _xpp_alpha = 1.00; \
-  static gboolean         _xpp_composited = FALSE; \
   static guint            _xpp_bg_style = 0; \
   static GdkColor         _xpp_bg_color = { 0, }; \
   static const gchar     *_xpp_bg_image = NULL; \
@@ -313,7 +312,7 @@ G_BEGIN_DECLS
             \
           case PROVIDER_PROP_TYPE_SET_BACKGROUND_ALPHA: \
             _xpp_alpha = value / 100.00; \
-            if (_xpp_composited) \
+            if (gtk_widget_is_composited (plug)) \
               gtk_widget_queue_draw (plug); \
             break; \
             \
@@ -489,7 +488,7 @@ G_BEGIN_DECLS
       } \
     else \
       { \
-        real_alpha = _xpp_composited ? _xpp_alpha : 1.00; \
+        real_alpha = gtk_widget_is_composited (plug) ? _xpp_alpha : 1.00; \
         \
         if (_xpp_bg_style == 1 || real_alpha < 1.00) \
           { \
@@ -580,14 +579,10 @@ G_BEGIN_DECLS
     gtk_widget_set_app_paintable (plug, TRUE); \
     \
     screen = gtk_widget_get_screen (plug); \
-    _xpp_composited = gtk_widget_is_composited (plug); \
-    if (_xpp_composited) \
-      colormap = gdk_screen_get_rgba_colormap (screen); \
+    \
+    colormap = gdk_screen_get_rgba_colormap (screen); \
     if (colormap == NULL) \
-      { \
-        colormap = gdk_screen_get_rgb_colormap (screen); \
-        _xpp_composited = FALSE; \
-      } \
+      colormap = gdk_screen_get_rgb_colormap (screen); \
     if (colormap != NULL) \
       gtk_widget_set_colormap (plug, colormap); \
     \
diff --git a/panel/panel-base-window.c b/panel/panel-base-window.c
index 5638b8f..cd06464 100644
--- a/panel/panel-base-window.c
+++ b/panel/panel-base-window.c
@@ -58,8 +58,6 @@ 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_data             (PanelBaseWindow      *window,
@@ -651,70 +649,63 @@ panel_base_window_composited_changed (GtkWidget *widget)
   GdkColormap     *colormap = NULL;
   gboolean         was_composited = window->is_composited;
   gboolean         was_visible;
-  GtkWidget       *itembar;
   GdkScreen       *screen;
+  gboolean         colormap_changed;
+  gboolean         colormap_rgba = FALSE;
 
   panel_return_if_fail (PANEL_IS_BASE_WINDOW (widget));
 
-  /* check if the window is visible, if so, hide and unrealize it */
-  was_visible = GTK_WIDGET_VISIBLE (widget);
-  if (was_visible)
-    {
-      gtk_widget_hide (widget);
-      gtk_widget_unrealize (widget);
-    }
-
-  panel_debug (PANEL_DEBUG_DOMAIN_BASE_WINDOW, "set compositing=%s, was visible=%s",
-               PANEL_DEBUG_BOOL (gtk_widget_is_composited (widget)),
-               PANEL_DEBUG_BOOL (was_visible));
-
-  /* clear cairo image cache */
-  if (window->priv->bg_image_cache != NULL)
-    {
-      cairo_pattern_destroy (window->priv->bg_image_cache);
-      window->priv->bg_image_cache = NULL;
-    }
-
   /* get the widget screen */
   screen = gtk_window_get_screen (GTK_WINDOW (widget));
   panel_return_if_fail (GDK_IS_SCREEN (screen));
 
-  /* get the rgba colormap if compositing is supported */
-  if (gtk_widget_is_composited (widget))
-    colormap = gdk_screen_get_rgba_colormap (screen);
-
-  /* fallback to the old colormap */
-  if (colormap == NULL)
+  /* get the rgba colormap */
+  colormap = gdk_screen_get_rgba_colormap (screen);
+  if (G_UNLIKELY (colormap == NULL))
     {
       window->is_composited = FALSE;
       colormap = gdk_screen_get_rgb_colormap (screen);
     }
   else
     {
-      window->is_composited = TRUE;
+      colormap_rgba = TRUE;
+      window->is_composited = gtk_widget_is_composited (widget);
       gtk_window_set_opacity (GTK_WINDOW (widget), window->priv->leave_opacity);
     }
 
-  /* set the new colormap */
   panel_return_if_fail (GDK_IS_COLORMAP (colormap));
-  gtk_widget_set_colormap (widget, colormap);
+  colormap_changed = gtk_widget_get_colormap (widget) != colormap;
 
+  panel_debug (PANEL_DEBUG_DOMAIN_BASE_WINDOW,
+               "set new colormap; composited=%s, rgba=%s, visible=%s",
+               PANEL_DEBUG_BOOL (gtk_widget_is_composited (widget)),
+               PANEL_DEBUG_BOOL (colormap_rgba),
+               PANEL_DEBUG_BOOL (GTK_WIDGET_VISIBLE (widget)));
+
+  was_visible = GTK_WIDGET_VISIBLE (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);
-        }
+      gtk_widget_hide (widget);
+
+      if (colormap_changed)
+        gtk_widget_unrealize (widget);
+    }
+
+  /* clear cairo image cache */
+  if (window->priv->bg_image_cache != NULL)
+    {
+      cairo_pattern_destroy (window->priv->bg_image_cache);
+      window->priv->bg_image_cache = NULL;
+    }
+
+  if (colormap_changed)
+    gtk_widget_set_colormap (widget, colormap);
 
+  if (was_visible)
+    {
       /* restore the window */
-      gtk_widget_realize (widget);
+      if (colormap_changed)
+        gtk_widget_realize (widget);
       gtk_widget_show (widget);
     }
 
@@ -725,20 +716,6 @@ 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/wrapper/wrapper-plug.c b/wrapper/wrapper-plug.c
index cdeb124..0d81564 100644
--- a/wrapper/wrapper-plug.c
+++ b/wrapper/wrapper-plug.c
@@ -45,9 +45,6 @@ struct _WrapperPlug
 {
   GtkPlug __parent__;
 
-  /* whether the wrapper has a rgba colormap */
-  guint            is_composited : 1;
-
   /* background information */
   gdouble          background_alpha;
   GdkColor        *background_color;
@@ -106,16 +103,11 @@ wrapper_plug_init (WrapperPlug *plug)
 
   /* set the colormap */
   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);
+  colormap = gdk_screen_get_rgba_colormap (screen);
   if (colormap == NULL)
-    {
-      colormap = gdk_screen_get_rgb_colormap (screen);
-      plug->is_composited = FALSE;
-    }
-
+    colormap = gdk_screen_get_rgb_colormap (screen);
   if (colormap != NULL)
     gtk_widget_set_colormap (GTK_WIDGET (plug), colormap);
 }
@@ -188,7 +180,7 @@ wrapper_plug_expose_event (GtkWidget      *widget,
         }
       else
         {
-          alpha = plug->is_composited ? plug->background_alpha : 1.00;
+          alpha = gtk_widget_is_composited (GTK_WIDGET (plug)) ? plug->background_alpha : 1.00;
 
           if (alpha < 1.00 || plug->background_color != NULL)
             {
@@ -260,7 +252,7 @@ wrapper_plug_set_background_alpha (WrapperPlug *plug,
   plug->background_alpha = CLAMP (alpha, 0.00, 1.00);
 
   /* redraw */
-  if (plug->is_composited)
+  if (gtk_widget_is_composited (GTK_WIDGET (plug)))
     gtk_widget_queue_draw (GTK_WIDGET (plug));
 }
 



More information about the Xfce4-commits mailing list