[gnome-themes-standard] adwaita: improve previous commit to work without GTK modules



commit 737530bc7d8fa11c7d1e83fbcd0fc0e5256127c0
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Oct 8 18:50:52 2012 -0400

    adwaita: improve previous commit to work without GTK modules
    
    This is useful when there's no g-s-d running at all. To implement this,
    add a custom GTK2 engine that only draws menus when the shell is not
    running, and move the GTK3 code in the existing engine.

 configure.ac                                       |   29 ++--
 src/adwaita_engine.c                               |   88 +++++++++
 themes/Adwaita/Makefile.am                         |    2 +-
 themes/Adwaita/gtk-2.0/Makefile.am                 |    9 +-
 themes/Adwaita/gtk-2.0/Menu-Menubar/frame.png      |  Bin 240 -> 0 bytes
 themes/Adwaita/gtk-2.0/adwaita_engine.c            |  197 ++++++++++++++++++++
 themes/Adwaita/gtk-2.0/gtkrc                       |   26 +---
 themes/Adwaita/shell-watcher/Makefile.am           |   11 -
 .../shell-watcher/adwaita-shell-watcher.desktop    |    4 -
 themes/Adwaita/shell-watcher/gtk-2.0/Makefile.am   |    7 -
 .../shell-watcher/gtk-2.0/shell-watcher-gtk2.c     |  136 --------------
 themes/Adwaita/shell-watcher/gtk-3.0/Makefile.am   |    7 -
 .../shell-watcher/gtk-3.0/shell-watcher-gtk3.c     |  158 ----------------
 13 files changed, 310 insertions(+), 364 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9f6c4f0..691823a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,18 +48,20 @@ AC_SUBST(DEPENDENCIES_LIBS)
 GTK_VERSION=`$PKG_CONFIG --variable=gtk_binary_version gtk+-3.0`
 AC_SUBST(GTK_VERSION)
 
-AC_ARG_ENABLE([gtk-modules],
-              AC_HELP_STRING([--disable-gtk-modules],
-                             [Disable Gtk+ modules [default=no]]),
-              enable_gtk_modules=$enableval,
-              enable_gtk_modules=yes)
-AC_MSG_CHECKING([building gtk modules])
-AM_CONDITIONAL(GTK_MODULES, test "x$enable_gtk_modules" = "xyes")
-AC_MSG_RESULT([$enable_gtk_modules])
-
-if test "x$enable_gtk_modules" = "xyes"; then
-  PKG_CHECK_MODULES([WATCHER_MODULE_GTK2], [gtk+-2.0 gdk-x11-2.0])
-  PKG_CHECK_MODULES([WATCHER_MODULE_GTK3], [gtk+-3.0 gdk-x11-3.0])
+GTK2_VERSION=`$PKG_CONFIG --variable=gtk_binary_version gtk+-2.0`
+AC_SUBST(GTK2_VERSION)
+
+AC_ARG_ENABLE([gtk2-engine],
+              AC_HELP_STRING([--disable-gtk2-engine],
+                             [Disable Gtk+-2 engine [default=no]]),
+              enable_gtk2_engine=$enableval,
+              enable_gtk2_engine=yes)
+AC_MSG_CHECKING([building gtk2 engine])
+AM_CONDITIONAL(GTK2_ENGINE, test "x$enable_gtk2_engine" = "xyes")
+AC_MSG_RESULT([$enable_gtk2_engine])
+
+if test "x$enable_gtk2_engine" = "xyes"; then
+  PKG_CHECK_MODULES([GTK2_ENGINE], [gtk+-2.0 gdk-x11-2.0])
 fi
 
 GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
@@ -92,9 +94,6 @@ themes/Adwaita/gtk-3.0/Makefile
 themes/Adwaita/gtk-3.0/assets/Makefile
 themes/Adwaita/gtk-3.0/borders/Makefile
 themes/Adwaita/metacity-1/Makefile
-themes/Adwaita/shell-watcher/Makefile
-themes/Adwaita/shell-watcher/gtk-2.0/Makefile
-themes/Adwaita/shell-watcher/gtk-3.0/Makefile
 themes/HighContrast/Makefile
 themes/HighContrast/gtk-2.0/Makefile
 themes/HighContrast/gtk-3.0/Makefile
diff --git a/src/adwaita_engine.c b/src/adwaita_engine.c
index 38f3124..df44ec8 100644
--- a/src/adwaita_engine.c
+++ b/src/adwaita_engine.c
@@ -27,6 +27,7 @@
 #include <gmodule.h>
 #include <math.h>
 #include <cairo-gobject.h>
+#include <gdk/gdkx.h>
 
 #include "adwaita_utils.h"
 
@@ -38,6 +39,9 @@ typedef struct _AdwaitaEngineClass AdwaitaEngineClass;
 struct _AdwaitaEngine
 {
   GtkThemingEngine parent_object;
+
+  guint wm_watch_id;
+  GtkCssProvider *fallback_provider;
 };
 
 struct _AdwaitaEngineClass
@@ -64,8 +68,89 @@ adwaita_engine_register_types (GTypeModule *module)
 }
 
 static void
+fallback_provider_remove (AdwaitaEngine *self)
+{
+  GdkScreen *screen;
+
+  if (self->fallback_provider == NULL)
+    return;
+
+  screen = gdk_screen_get_default ();
+  gtk_style_context_remove_provider_for_screen
+    (screen, GTK_STYLE_PROVIDER (self->fallback_provider));
+  g_clear_object (&self->fallback_provider);
+}
+
+static void
+fallback_provider_add (AdwaitaEngine *self)
+{
+  GFile *resource;
+  GtkCssProvider *provider;
+  GError *error = NULL;
+  GdkScreen *screen;
+
+  if (self->fallback_provider != NULL)
+    return;
+
+  resource = g_file_new_for_uri ("resource:///org/gnome/adwaita/gtk-fallback.css");
+  provider = gtk_css_provider_new ();
+  gtk_css_provider_load_from_file (provider, resource, &error);
+  g_object_unref (resource);
+
+  if (error != NULL)
+    {
+      g_warning ("Can't load fallback CSS resource: %s", error->message);
+      g_error_free (error);
+      g_object_unref (provider);
+      return;
+    }
+
+  screen = gdk_screen_get_default ();
+  gtk_style_context_add_provider_for_screen
+    (screen, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_THEME);
+  self->fallback_provider = provider;
+}
+
+static void
+adwaita_engine_wm_changed (AdwaitaEngine *self)
+{
+  const gchar *name;
+  name = gdk_x11_screen_get_window_manager_name (gdk_screen_get_default ());
+
+  if (g_strcmp0 (name, "GNOME Shell") != 0)
+    fallback_provider_add (self);
+  else
+    fallback_provider_remove (self);
+}
+
+static void
+adwaita_engine_finalize (GObject *obj)
+{
+  AdwaitaEngine *self = ADWAITA_ENGINE (obj);
+
+  if (self->wm_watch_id != 0)
+    {
+      g_signal_handler_disconnect (gdk_screen_get_default (), self->wm_watch_id);
+      self->wm_watch_id = 0;
+    }
+
+  fallback_provider_remove (self);
+
+  G_OBJECT_CLASS (adwaita_engine_parent_class)->finalize (obj);
+}
+
+static void
 adwaita_engine_init (AdwaitaEngine *self)
 {
+  GdkScreen *screen = gdk_screen_get_default ();
+
+  if (!GDK_IS_X11_SCREEN (screen))
+    return;
+
+  self->wm_watch_id =
+    g_signal_connect_swapped (screen, "window-manager-changed",
+                              G_CALLBACK (adwaita_engine_wm_changed), self);
+  adwaita_engine_wm_changed (self);
 }
 
 static void
@@ -404,6 +489,9 @@ static void
 adwaita_engine_class_init (AdwaitaEngineClass *klass)
 {
   GtkThemingEngineClass *engine_class = GTK_THEMING_ENGINE_CLASS (klass);
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+  oclass->finalize = adwaita_engine_finalize;
 
   engine_class->render_arrow = adwaita_engine_render_arrow;
   engine_class->render_focus = adwaita_engine_render_focus;
diff --git a/themes/Adwaita/Makefile.am b/themes/Adwaita/Makefile.am
index f49e78f..50d98d2 100644
--- a/themes/Adwaita/Makefile.am
+++ b/themes/Adwaita/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = backgrounds cursors metacity-1 gtk-2.0 shell-watcher
+SUBDIRS = backgrounds cursors metacity-1 gtk-2.0
 
 if GTK3
 SUBDIRS += gtk-3.0
diff --git a/themes/Adwaita/gtk-2.0/Makefile.am b/themes/Adwaita/gtk-2.0/Makefile.am
index 0a0b272..4863025 100644
--- a/themes/Adwaita/gtk-2.0/Makefile.am
+++ b/themes/Adwaita/gtk-2.0/Makefile.am
@@ -1,4 +1,12 @@
+if GTK2_ENGINE
+enginedir = $(libdir)/gtk-2.0/$(GTK2_VERSION)/engines
+engine_LTLIBRARIES = libadwaita.la
 
+libadwaita_la_CFLAGS = $(GTK2_ENGINE_CFLAGS)
+libadwaita_la_SOURCES = adwaita_engine.c
+libadwaita_la_LDFLAGS = -module -avoid-version -no-undefined
+libadwaita_la_LIBADD =  $(GTK2_ENGINE_LIBS)
+endif
 
 themedir = $(datadir)/themes/Adwaita/gtk-2.0
 theme_DATA = gtkrc
@@ -63,7 +71,6 @@ asset_data = \
 	Lines/line-h.png \
 	Lines/line-v.png \
 	Lines/menu_line_h.png \
-	Menu-Menubar/frame.png \
 	Menu-Menubar/menubar_button.png \
 	Menu-Menubar/menubar.png \
 	Others/bg.png \
diff --git a/themes/Adwaita/gtk-2.0/adwaita_engine.c b/themes/Adwaita/gtk-2.0/adwaita_engine.c
new file mode 100644
index 0000000..593aad6
--- /dev/null
+++ b/themes/Adwaita/gtk-2.0/adwaita_engine.c
@@ -0,0 +1,197 @@
+/* Adwaita - a GTK+ engine
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors: Cosimo Cecchi <cosimoc gnome org>
+ */
+
+#include <gmodule.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+/***************************************/
+/* Register & Initialize Drawing Style */
+/***************************************/
+#define ADWAITA_TYPE_STYLE              (adwaita_style_get_type ())
+#define ADWAITA_STYLE(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), ADWAITA_TYPE_STYLE, AdwaitaStyle))
+#define ADWAITA_STYLE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), ADWAITA_TYPE_STYLE, AdwaitaStyleClass))
+#define ADWAITA_IS_STYLE(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), ADWAITA_TYPE_STYLE))
+#define ADWAITA_IS_STYLE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), ADWAITA_TYPE_STYLE))
+#define ADWAITA_STYLE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), ADWAITA_TYPE_STYLE, AdwaitaStyleClass))
+ 
+typedef struct
+{
+  GtkStyle parent_instance;
+} AdwaitaStyle;
+ 
+typedef struct
+{
+  GtkStyleClass parent_class;
+} AdwaitaStyleClass;
+
+G_DEFINE_DYNAMIC_TYPE (AdwaitaStyle, adwaita_style, GTK_TYPE_STYLE)
+
+static gboolean
+wm_is_fallback (void)
+{
+  const gchar *name;
+  name = gdk_x11_screen_get_window_manager_name (gdk_screen_get_default ());
+  return g_strcmp0 (name, "GNOME Shell") != 0;
+}
+
+static cairo_t * 
+drawable_to_cairo (GdkDrawable  *window,
+                   GdkRectangle *area)
+{
+  cairo_t *cr;
+
+  g_return_val_if_fail (window != NULL, NULL);
+
+  cr = (cairo_t*) gdk_cairo_create (window);
+  cairo_set_line_width (cr, 1.0);
+  cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+  cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+
+  if (area)
+    {
+      cairo_rectangle (cr, area->x, area->y, area->width, area->height);
+      cairo_clip_preserve (cr);
+      cairo_new_path (cr);
+    }
+
+  return cr;
+}
+
+static void
+adwaita_draw_box (GtkStyle * style,
+                  GdkWindow * window,
+                  GtkStateType state_type,
+                  GtkShadowType shadow_type,
+                  GdkRectangle * area,
+                  GtkWidget * widget,
+                  const gchar * detail, 
+                  gint x, 
+                  gint y, 
+                  gint width, 
+                  gint height)
+{
+  if (GTK_IS_MENU (widget) &&
+      g_strcmp0 (detail, "menu") == 0 &&
+      wm_is_fallback ())
+    {
+      cairo_t *cr = drawable_to_cairo (window, area);
+      cairo_pattern_t *pattern = cairo_pattern_create_linear
+        (x, y, x, y + height);
+
+      cairo_pattern_add_color_stop_rgba (pattern, 0, 1, 1, 1, 1);
+      cairo_pattern_add_color_stop_rgba (pattern, 1, 0.30, 0.30, 0.30, 1);
+      cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+
+      cairo_set_source (cr, pattern);
+      cairo_rectangle (cr, x, y, width, height);
+      cairo_stroke (cr);
+
+      cairo_destroy (cr);
+      cairo_pattern_destroy (pattern);
+    }
+}
+
+static void
+adwaita_style_init (AdwaitaStyle *style)
+{
+}
+
+static void
+adwaita_style_class_init (AdwaitaStyleClass * klass)
+{
+  GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
+ 
+  style_class->draw_box = adwaita_draw_box;
+}
+
+static void
+adwaita_style_class_finalize (AdwaitaStyleClass * klass)
+{
+}
+
+/**********************************/ 
+/* Register & Initialize RC Style */ 
+/**********************************/ 
+#define ADWAITA_TYPE_RC_STYLE              (adwaita_rc_style_get_type ())
+#define ADWAITA_RC_STYLE(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), ADWAITA_TYPE_RC_STYLE, AdwaitaRcStyle))
+#define ADWAITA_RC_STYLE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), ADWAITA_TYPE_RC_STYLE, AdwaitaRcStyleClass))
+#define ADWAITA_IS_RC_STYLE(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), ADWAITA_TYPE_RC_STYLE))
+#define ADWAITA_IS_RC_STYLE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), ADWAITA_TYPE_RC_STYLE))
+#define ADWAITA_RC_STYLE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), ADWAITA_TYPE_RC_STYLE, AdwaitaRcStyleClass))
+ 
+typedef struct
+{
+  GtkRcStyle parent_instance;
+} AdwaitaRcStyle;
+ 
+typedef struct
+{
+  GtkRcStyleClass parent_class;
+} AdwaitaRcStyleClass;
+
+G_DEFINE_DYNAMIC_TYPE (AdwaitaRcStyle, adwaita_rc_style, GTK_TYPE_RC_STYLE)
+
+static GtkStyle *
+adwaita_rc_style_create_style (GtkRcStyle *rc_style)
+{
+  return g_object_new (ADWAITA_TYPE_STYLE, NULL);
+}
+
+static void
+adwaita_rc_style_init (AdwaitaRcStyle *rc_style)
+{
+}
+
+static void
+adwaita_rc_style_class_init (AdwaitaRcStyleClass * klass)
+{
+  GtkRcStyleClass *rc_class = GTK_RC_STYLE_CLASS (klass);
+
+  rc_class->create_style = adwaita_rc_style_create_style;
+}
+
+static void
+adwaita_rc_style_class_finalize (AdwaitaRcStyleClass * klass)
+{
+}
+
+/**************** 
+ * Engine Hooks * 
+ ****************/
+void
+theme_init (GTypeModule * module)
+{
+  adwaita_rc_style_register_type (module);
+  adwaita_style_register_type (module);
+}
+ 
+void
+theme_exit (void)
+{
+}
+ 
+GtkRcStyle *
+theme_create_rc_style (void)
+{
+  return g_object_new (ADWAITA_TYPE_RC_STYLE, NULL);
+}
diff --git a/themes/Adwaita/gtk-2.0/gtkrc b/themes/Adwaita/gtk-2.0/gtkrc
index d64cb6c..efbba5a 100755
--- a/themes/Adwaita/gtk-2.0/gtkrc
+++ b/themes/Adwaita/gtk-2.0/gtkrc
@@ -587,32 +587,9 @@ style "menu"
 
 style "menu_framed_box"
 {
-	engine "pixmap"
+	engine "adwaita"
 	{
-        image
-        {
-	  function                      = BOX
-          detail                        = "menu"
-	  file			        = "Menu-Menubar/frame.png"
-	  border	                = { 1, 1, 1, 1 }
-	  stretch		        = TRUE
         }
-    }
-}
-
-style "menu_unframed_box"
-{
-	engine "pixmap"
-	{
-        image
-        {
-	  function                      = BOX
-          detail                        = "menu"
-	  file			        = "Others/null.png"
-	  border	                = { 4, 4, 4, 4 }
-	  stretch		        = TRUE
-        }
-    }
 }
 
 style "menu_item"
@@ -1965,6 +1942,7 @@ class "GtkToolbar"	                style "toolbar"
 
 widget_class "*<GtkMenuBar>*"			style "menubar"
 widget_class "*<GtkMenu>*"			style "menu"
+widget_class "*<GtkMenu>*"			style "menu_framed_box"
 widget_class "*<GtkMenuItem>*"			style "menu_item"
 widget_class "*<GtkMenuBar>.<GtkMenuItem>*"	style "menubar_item"
 widget_class "*<GtkCheckButton>*"               style "checkbutton"



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