[Xfce4-commits] <xfce4-panel:nick/gtk3> Wrapper ported for both Gtk+-2 and Gtk+-3

Peter de Ridder noreply at xfce.org
Fri Apr 5 23:52:03 CEST 2013


Updating branch refs/heads/nick/gtk3
         to 0ff5a96563d2779bbbb775b182ae87bb0229be1d (commit)
       from cc2584b1571ba65cecb312897ebe51a85b32c43b (commit)

commit 0ff5a96563d2779bbbb775b182ae87bb0229be1d
Author: Peter de Ridder <peter at xfce.org>
Date:   Fri Apr 5 21:36:18 2013 +0200

    Wrapper ported for both Gtk+-2 and Gtk+-3

 wrapper/Makefile.am    |   50 ++++++++++++++++++---
 wrapper/main.c         |    4 ++
 wrapper/wrapper-plug.c |  116 +++++++++++++++++++++++++++++++++++++++++++++---
 wrapper/wrapper-plug.h |    7 +++
 4 files changed, 164 insertions(+), 13 deletions(-)

diff --git a/wrapper/Makefile.am b/wrapper/Makefile.am
index 94bb13a..86abda1 100644
--- a/wrapper/Makefile.am
+++ b/wrapper/Makefile.am
@@ -8,12 +8,12 @@ AM_CPPFLAGS = \
 wrapperdir = $(HELPER_PATH_PREFIX)/xfce4/panel
 
 wrapper_PROGRAMS = \
-	wrapper
+	wrapper3
 
 wrapper_built_sources = \
 	wrapper-dbus-client-infos.h
 
-wrapper_SOURCES = \
+wrapper3_SOURCES = \
 	$(wrapper_built_sources) \
 	main.c \
 	wrapper-module.c \
@@ -21,27 +21,65 @@ wrapper_SOURCES = \
 	wrapper-plug.c \
 	wrapper-plug.h
 
-wrapper_CFLAGS = \
+wrapper3_CFLAGS = \
 	$(GTK_CFLAGS) \
 	$(DBUS_CFLAGS) \
 	$(GMODULE_CFLAGS) \
 	$(LIBXFCE4UTIL_CFLAGS) \
 	$(PLATFORM_CFLAGS)
 
-wrapper_LDFLAGS = \
+wrapper3_LDFLAGS = \
 	-no-undefined \
 	$(PLATFORM_LDFLAGS)
 
-wrapper_LDADD = \
+wrapper3_LDADD = \
 	$(top_builddir)/libxfce4panel/libxfce4panel-$(LIBXFCE4PANEL_VERSION_API).la \
 	$(GTK_LIBS) \
 	$(DBUS_LIBS) \
 	$(GMODULE_LIBS) \
 	$(LIBXFCE4UTIL_LIBS)
 
-wrapper_DEPENDENCIES = \
+wrapper3_DEPENDENCIES = \
 	$(top_builddir)/libxfce4panel/libxfce4panel-$(LIBXFCE4PANEL_VERSION_API).la
 
+#
+# Gtk+ 2 support library
+#
+if ENABLE_GTK2_LIBRARY
+
+wrapper_PROGRAMS += wrapper2
+
+wrapper2_SOURCES = \
+	$(wrapper_built_sources) \
+	main.c \
+	wrapper-module.c \
+	wrapper-module.h \
+	wrapper-plug.c \
+	wrapper-plug.h
+
+wrapper2_CFLAGS = \
+	$(GTK2_CFLAGS) \
+	$(DBUS_CFLAGS) \
+	$(GMODULE_CFLAGS) \
+	$(LIBXFCE4UTIL_CFLAGS) \
+	$(PLATFORM_CFLAGS)
+
+wrapper2_LDFLAGS = \
+	-no-undefined \
+	$(PLATFORM_LDFLAGS)
+
+wrapper2_LDADD = \
+	$(top_builddir)/libxfce4panel/libxfce4panel-1.0.la \
+	$(GTK2_LIBS) \
+	$(DBUS_LIBS) \
+	$(GMODULE_LIBS) \
+	$(LIBXFCE4UTIL_LIBS)
+
+wrapper2_DEPENDENCIES = \
+	$(top_builddir)/libxfce4panel/libxfce4panel-1.0.la
+
+endif
+
 if MAINTAINER_MODE
 
 wrapper-dbus-client-infos.h: $(top_builddir)/panel/panel-plugin-external-wrapper-infos.xml Makefile
diff --git a/wrapper/main.c b/wrapper/main.c
index 2420d79..0a19ec6 100644
--- a/wrapper/main.c
+++ b/wrapper/main.c
@@ -271,7 +271,11 @@ main (gint argc, gchar **argv)
   GError                  *error = NULL;
   const gchar             *filename;
   gint                     unique_id;
+#if GTK_CHECK_VERSION (3, 0, 0)
+  Window                   socket_id;
+#else
   GdkNativeWindow          socket_id;
+#endif
   const gchar             *name;
   const gchar             *display_name;
   const gchar             *comment;
diff --git a/wrapper/wrapper-plug.c b/wrapper/wrapper-plug.c
index 29cced3..d00784e 100644
--- a/wrapper/wrapper-plug.c
+++ b/wrapper/wrapper-plug.c
@@ -30,8 +30,13 @@
 
 
 static void     wrapper_plug_finalize         (GObject        *object);
+#if GTK_CHECK_VERSION (3, 0, 0)
+static gboolean wrapper_plug_draw             (GtkWidget      *widget,
+                                               cairo_t        *cr);
+#else
 static gboolean wrapper_plug_expose_event     (GtkWidget      *widget,
                                                GdkEventExpose *event);
+#endif
 static void     wrapper_plug_background_reset (WrapperPlug    *plug);
 
 
@@ -73,7 +78,11 @@ wrapper_plug_class_init (WrapperPlugClass *klass)
   gobject_class->finalize = wrapper_plug_finalize;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
+#if GTK_CHECK_VERSION (3, 0, 0)
+  gtkwidget_class->draw = wrapper_plug_draw;
+#else
   gtkwidget_class->expose_event = wrapper_plug_expose_event;
+#endif
 }
 
 
@@ -81,8 +90,13 @@ wrapper_plug_class_init (WrapperPlugClass *klass)
 static void
 wrapper_plug_init (WrapperPlug *plug)
 {
+#if GTK_CHECK_VERSION (3, 0, 0)
+  GdkVisual *visual = NULL;
+  GdkScreen *screen;
+#else
   GdkColormap *colormap = NULL;
   GdkScreen   *screen;
+#endif
 
   plug->background_alpha = 1.00;
   plug->background_color = NULL;
@@ -94,18 +108,17 @@ wrapper_plug_init (WrapperPlug *plug)
   /* allow painting, else compositing won't work */
   gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE);
 
-  /* 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 */
-  if (gtk_check_version (2, 16, 0) != NULL
-      && strcmp (wrapper_name, "systray") == 0)
-    return;
-
   /* set the colormap */
   screen = gtk_window_get_screen (GTK_WINDOW (plug));
+#if GTK_CHECK_VERSION (3, 0, 0)
+  visual = gdk_screen_get_rgba_visual (screen);
+  if (visual != NULL)
+    gtk_widget_set_visual (GTK_WIDGET (plug), visual);
+#else
   colormap = gdk_screen_get_rgba_colormap (screen);
   if (colormap != NULL)
     gtk_widget_set_colormap (GTK_WIDGET (plug), colormap);
+#endif
 }
 
 
@@ -120,6 +133,90 @@ wrapper_plug_finalize (GObject *object)
 
 
 
+#if GTK_CHECK_VERSION (3, 0, 0)
+static gboolean
+wrapper_plug_draw (GtkWidget *widget,
+                   cairo_t   *cr)
+{
+  WrapperPlug     *plug = WRAPPER_PLUG (widget);
+  GtkStyleContext *style;
+  const GdkColor  *color;
+  GdkRGBA          rgba;
+  gdouble          alpha;
+  GdkPixbuf       *pixbuf;
+  GError          *error = NULL;
+
+  if (gtk_widget_is_drawable (widget))
+    {
+      if (G_UNLIKELY (plug->background_image != NULL))
+        {
+          cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+          if (G_LIKELY (plug->background_image_cache != NULL))
+            {
+              cairo_set_source (cr, plug->background_image_cache);
+              cairo_paint (cr);
+            }
+          else
+            {
+              /* load the image in a pixbuf */
+              pixbuf = gdk_pixbuf_new_from_file (plug->background_image, &error);
+
+              if (G_LIKELY (pixbuf != NULL))
+                {
+                  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+                  g_object_unref (G_OBJECT (pixbuf));
+
+                  plug->background_image_cache = cairo_get_source (cr);
+                  cairo_pattern_reference (plug->background_image_cache);
+                  cairo_pattern_set_extend (plug->background_image_cache, CAIRO_EXTEND_REPEAT);
+                  cairo_paint (cr);
+                }
+              else
+                {
+                  /* print error message */
+                  g_warning ("Background image disabled, \"%s\" could not be loaded: %s",
+                             plug->background_image, error != NULL ? error->message : "No error");
+                  g_error_free (error);
+
+                  /* disable background image */
+                  wrapper_plug_background_reset (plug);
+                }
+            }
+        }
+      else
+        {
+          alpha = gtk_widget_is_composited (GTK_WIDGET (plug)) ? plug->background_alpha : 1.00;
+
+          if (alpha < 1.00 || plug->background_color != NULL)
+            {
+              cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+              /* get the background gdk color */
+              if (plug->background_color != NULL)
+                {
+                  color = plug->background_color;
+                  cairo_set_source_rgba (cr, PANEL_GDKCOLOR_TO_DOUBLE (color), alpha);
+                }
+              else
+                {
+                  style = gtk_widget_get_style_context (widget);
+                  gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &rgba);
+                  rgba.alpha = alpha;
+                  gdk_cairo_set_source_rgba (cr, &rgba);
+                }
+
+              /* draw the background color */
+              cairo_fill (cr);
+            }
+        }
+    }
+
+  return GTK_WIDGET_CLASS (wrapper_plug_parent_class)->draw (widget, cr);
+}
+
+#else
+
 static gboolean
 wrapper_plug_expose_event (GtkWidget      *widget,
                            GdkEventExpose *event)
@@ -199,6 +296,7 @@ wrapper_plug_expose_event (GtkWidget      *widget,
 
   return GTK_WIDGET_CLASS (wrapper_plug_parent_class)->expose_event (widget, event);
 }
+#endif
 
 
 
@@ -222,7 +320,11 @@ wrapper_plug_background_reset (WrapperPlug *plug)
 
 
 WrapperPlug *
+#if GTK_CHECK_VERSION (3, 0, 0)
+wrapper_plug_new (Window socket_id)
+#else
 wrapper_plug_new (GdkNativeWindow socket_id)
+#endif
 {
   WrapperPlug *plug;
 
diff --git a/wrapper/wrapper-plug.h b/wrapper/wrapper-plug.h
index 05853d0..386367a 100644
--- a/wrapper/wrapper-plug.h
+++ b/wrapper/wrapper-plug.h
@@ -20,6 +20,9 @@
 #define __WRAPPER_PLUG_H__
 
 #include <gtk/gtk.h>
+#if GTK_CHECK_VERSION (3, 0, 0)
+#include <gtk/gtkx.h>
+#endif
 #include <libxfce4panel/libxfce4panel.h>
 #include <libxfce4panel/xfce-panel-plugin-provider.h>
 
@@ -39,7 +42,11 @@ extern gchar *wrapper_name;
 
 GType         wrapper_plug_get_type             (void) G_GNUC_CONST;
 
+#if GTK_CHECK_VERSION (3, 0, 0)
+WrapperPlug  *wrapper_plug_new                  (Window           socket_id);
+#else
 WrapperPlug  *wrapper_plug_new                  (GdkNativeWindow  socket_id);
+#endif
 
 void          wrapper_plug_set_background_alpha (WrapperPlug     *plug,
                                                  gdouble          alpha);


More information about the Xfce4-commits mailing list