[gnome-themes-standard] adwaita: override menu frame style when not running under the Shell



commit 9c62ba404fa8a76d1c56cce4f066e94ccc637900
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Oct 6 00:27:07 2012 -0400

    adwaita: override menu frame style when not running under the Shell
    
    When we're not running under the shell, we're not guaranteed to have
    shadows rendered around menus; this is especially the case for fallback
    mode.
    Since we don't really have a way of loading a different theme for
    fallback mode from the settings daemon (or there might not even be a
    settings daemon around in case we're running on a completely different
    environment), we have to detect the presence of the Shell ourselves.
    Install a GTK module for this (both for GTK2 and GTK3), that watches the
    WM name on the GdkScreen and dynamically injects or removes frames on
    menus when the WM name matches GNOME Shell.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=660271

 configure.ac                                       |   17 ++
 themes/Adwaita/Makefile.am                         |    2 +-
 themes/Adwaita/gtk-2.0/Makefile.am                 |    1 +
 themes/Adwaita/gtk-2.0/Menu-Menubar/frame.png      |  Bin 0 -> 240 bytes
 themes/Adwaita/gtk-2.0/gtkrc                       |   30 ++++
 themes/Adwaita/gtk-3.0/Makefile.am                 |    1 +
 themes/Adwaita/gtk-3.0/gtk-fallback.css            |   15 ++
 themes/Adwaita/gtk-3.0/gtk.gresource.xml           |    1 +
 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 ++++++++++++++++++++
 14 files changed, 389 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 901f189..9f6c4f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +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])
+fi
+
 GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
 AC_SUBST(GLIB_COMPILE_RESOURCES)
 
@@ -78,6 +92,9 @@ 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/themes/Adwaita/Makefile.am b/themes/Adwaita/Makefile.am
index 50d98d2..f49e78f 100644
--- a/themes/Adwaita/Makefile.am
+++ b/themes/Adwaita/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = backgrounds cursors metacity-1 gtk-2.0
+SUBDIRS = backgrounds cursors metacity-1 gtk-2.0 shell-watcher
 
 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 332fa52..0a0b272 100644
--- a/themes/Adwaita/gtk-2.0/Makefile.am
+++ b/themes/Adwaita/gtk-2.0/Makefile.am
@@ -63,6 +63,7 @@ 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/Menu-Menubar/frame.png b/themes/Adwaita/gtk-2.0/Menu-Menubar/frame.png
new file mode 100644
index 0000000..9780b55
Binary files /dev/null and b/themes/Adwaita/gtk-2.0/Menu-Menubar/frame.png differ
diff --git a/themes/Adwaita/gtk-2.0/gtkrc b/themes/Adwaita/gtk-2.0/gtkrc
index 00ee21d..d64cb6c 100755
--- a/themes/Adwaita/gtk-2.0/gtkrc
+++ b/themes/Adwaita/gtk-2.0/gtkrc
@@ -585,6 +585,36 @@ style "menu"
     }
 }
 
+style "menu_framed_box"
+{
+	engine "pixmap"
+	{
+        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"
 {
 	xthickness	= 2
diff --git a/themes/Adwaita/gtk-3.0/Makefile.am b/themes/Adwaita/gtk-3.0/Makefile.am
index 998ba12..5452dd1 100644
--- a/themes/Adwaita/gtk-3.0/Makefile.am
+++ b/themes/Adwaita/gtk-3.0/Makefile.am
@@ -15,6 +15,7 @@ EXTRA_DIST = \
 	gtk.gresource.xml \
 	gtk.css \
 	gtk-dark.css \
+	gtk-fallback.css \
 	gtk-main.css \
 	gtk-main-common.css \
 	gtk-main-dark.css \
diff --git a/themes/Adwaita/gtk-3.0/gtk-fallback.css b/themes/Adwaita/gtk-3.0/gtk-fallback.css
new file mode 100644
index 0000000..d6308d5
--- /dev/null
+++ b/themes/Adwaita/gtk-3.0/gtk-fallback.css
@@ -0,0 +1,15 @@
+.menu {
+    border-image: linear-gradient(to top,
+                                  alpha(@borders, 0.80),
+                                  alpha(@borders, 0.60) 33%,
+                                  alpha(@borders, 0.50) 66%,
+                                  alpha(@borders, 0.15)) 1 1 1 1/ 1px 1px 1px 1px;
+}
+
+.menubar .menu {
+    border-image: linear-gradient(to top,
+                                  alpha(@borders, 0.80),
+                                  alpha(@borders, 0.60) 33%,
+                                  alpha(@borders, 0.50) 66%,
+                                  transparent 99%) 1 1 1 1/ 1px 1px 1px 1px;
+}
diff --git a/themes/Adwaita/gtk-3.0/gtk.gresource.xml b/themes/Adwaita/gtk-3.0/gtk.gresource.xml
index 287e9db..d8eba61 100644
--- a/themes/Adwaita/gtk-3.0/gtk.gresource.xml
+++ b/themes/Adwaita/gtk-3.0/gtk.gresource.xml
@@ -212,5 +212,6 @@
     <file>gtk-main.css</file>
     <file>gtk-main-common.css</file>
     <file>gtk-main-dark.css</file>
+    <file>gtk-fallback.css</file>
   </gresource>
 </gresources>
diff --git a/themes/Adwaita/shell-watcher/Makefile.am b/themes/Adwaita/shell-watcher/Makefile.am
new file mode 100644
index 0000000..1a8c09c
--- /dev/null
+++ b/themes/Adwaita/shell-watcher/Makefile.am
@@ -0,0 +1,11 @@
+SUBDIRS = $(NULL)
+settings_daemon_desktop_files = adwaita-shell-watcher.desktop
+
+if GTK_MODULES
+SUBDIRS += gtk-2.0 gtk-3.0
+
+settings_daemon_modulesdir = $(libdir)/gnome-settings-daemon-3.0/gtk-modules/
+settings_daemon_modules_DATA = $(settings_daemon_desktop_files)
+endif
+
+EXTRA_DIST = $(settings_daemon_desktop_files)
diff --git a/themes/Adwaita/shell-watcher/adwaita-shell-watcher.desktop b/themes/Adwaita/shell-watcher/adwaita-shell-watcher.desktop
new file mode 100644
index 0000000..260103b
--- /dev/null
+++ b/themes/Adwaita/shell-watcher/adwaita-shell-watcher.desktop
@@ -0,0 +1,4 @@
+[GTK Module]
+Name=Adwaita Shell Watcher
+Description=Adwaita Theme Shell Watcher
+X-GTK-Module-Name=shellwatcher
diff --git a/themes/Adwaita/shell-watcher/gtk-2.0/Makefile.am b/themes/Adwaita/shell-watcher/gtk-2.0/Makefile.am
new file mode 100644
index 0000000..9abd92b
--- /dev/null
+++ b/themes/Adwaita/shell-watcher/gtk-2.0/Makefile.am
@@ -0,0 +1,7 @@
+moduledir = $(libdir)/gtk-2.0/modules
+module_LTLIBRARIES = libshellwatcher.la
+
+libshellwatcher_la_SOURCES = shell-watcher-gtk2.c
+libshellwatcher_la_CFLAGS = -I. $(WATCHER_MODULE_GTK2_CFLAGS)
+libshellwatcher_la_LIBADD = $(WATCHER_MODULE_GTK2_LIBS)
+libshellwatcher_la_LDFLAGS = -no-undefined -module -avoid-version -rpath $(moduledir)
diff --git a/themes/Adwaita/shell-watcher/gtk-2.0/shell-watcher-gtk2.c b/themes/Adwaita/shell-watcher/gtk-2.0/shell-watcher-gtk2.c
new file mode 100644
index 0000000..5a4e849
--- /dev/null
+++ b/themes/Adwaita/shell-watcher/gtk-2.0/shell-watcher-gtk2.c
@@ -0,0 +1,136 @@
+/* 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 <glib.h>
+#include <gmodule.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+void g_module_unload  (GModule *module);
+int  gtk_module_init (int *argc, char** argv[]);
+
+static gulong settings_id = 0;
+static guint wm_watch_id = 0;
+static gboolean initialized = FALSE;
+
+static void
+maybe_reset_styles (void)
+{
+  /* don't reset styles at startup */
+  if (initialized)
+    gtk_rc_reset_styles (gtk_settings_get_default ());
+  initialized = TRUE;
+}
+
+static void
+fallback_style_remove (void)
+{
+  gtk_rc_parse_string ("widget_class \"*<GtkMenu>\" style \"menu_unframed_box\"");
+  maybe_reset_styles ();
+}
+
+static void
+fallback_style_add (void)
+{
+  gtk_rc_parse_string ("widget_class \"*<GtkMenu>\" style \"menu_framed_box\"");
+  maybe_reset_styles ();
+}
+
+static void
+wm_changed (void)
+{
+  const gchar *name;
+  name = gdk_x11_screen_get_window_manager_name (gdk_screen_get_default ());
+
+  if (g_strcmp0 (name, "GNOME Shell") != 0)
+    fallback_style_add ();
+  else
+    fallback_style_remove ();
+}
+
+static void
+wm_watch_remove (void)
+{
+  if (wm_watch_id != 0)
+    {
+      g_signal_handler_disconnect (gdk_screen_get_default (), wm_watch_id);
+      wm_watch_id = 0;
+    }
+}
+
+static void
+wm_watch_install (void)
+{
+  if (wm_watch_id == 0)
+    {
+      GdkScreen *screen = gdk_screen_get_default ();
+
+#ifdef GDK_WINDOWING_X11
+      wm_watch_id = g_signal_connect (screen, "window-manager-changed",
+                                      G_CALLBACK (wm_changed), NULL);
+      wm_changed ();
+#endif
+    }
+}
+
+void
+g_module_unload (GModule *module)
+{
+  wm_watch_remove ();
+
+  if (settings_id != 0)
+    {
+      g_signal_handler_disconnect (gtk_settings_get_default (), settings_id);
+      settings_id = 0;
+    }
+}
+
+static void
+maybe_watch_wm (void)
+{
+  GtkSettings *settings;
+  gchar *theme_name;
+
+  settings = gtk_settings_get_default ();
+  g_object_get (settings, "gtk-theme-name", &theme_name);
+
+  if (g_strcmp0 (theme_name, "Adwaita") == 0)
+    {
+      wm_watch_install ();
+    }
+  else
+    {
+      wm_watch_remove ();
+      fallback_provider_remove ();
+    }
+
+  g_free (theme_name);
+}
+
+int
+gtk_module_init (int *argc, char** argv[])
+{
+  maybe_watch_wm ();
+  settings_id = g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",
+                                  G_CALLBACK (maybe_watch_wm), NULL);
+
+  return 0;
+}
diff --git a/themes/Adwaita/shell-watcher/gtk-3.0/Makefile.am b/themes/Adwaita/shell-watcher/gtk-3.0/Makefile.am
new file mode 100644
index 0000000..10ab222
--- /dev/null
+++ b/themes/Adwaita/shell-watcher/gtk-3.0/Makefile.am
@@ -0,0 +1,7 @@
+moduledir = $(libdir)/gtk-3.0/modules
+module_LTLIBRARIES = libshellwatcher.la
+
+libshellwatcher_la_SOURCES = shell-watcher-gtk3.c
+libshellwatcher_la_CFLAGS = -I. $(WATCHER_MODULE_GTK3_CFLAGS)
+libshellwatcher_la_LIBADD = $(WATCHER_MODULE_GTK3_LIBS)
+libshellwatcher_la_LDFLAGS = -no-undefined -module -avoid-version -rpath $(moduledir)
diff --git a/themes/Adwaita/shell-watcher/gtk-3.0/shell-watcher-gtk3.c b/themes/Adwaita/shell-watcher/gtk-3.0/shell-watcher-gtk3.c
new file mode 100644
index 0000000..2de2145
--- /dev/null
+++ b/themes/Adwaita/shell-watcher/gtk-3.0/shell-watcher-gtk3.c
@@ -0,0 +1,158 @@
+/* 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 <glib.h>
+#include <gmodule.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+void g_module_unload  (GModule *module);
+int  gtk_module_init (int *argc, char** argv[]);
+
+static gulong settings_id = 0;
+static guint wm_watch_id = 0;
+static GtkCssProvider *fallback_provider = NULL;
+
+static void
+fallback_provider_remove (void)
+{
+  GdkScreen *screen;
+
+  if (fallback_provider == NULL)
+    return;
+
+  screen = gdk_screen_get_default ();
+  gtk_style_context_remove_provider_for_screen
+    (screen, GTK_STYLE_PROVIDER (fallback_provider));
+  g_clear_object (&fallback_provider);
+}
+
+static void
+fallback_provider_add (void)
+{
+  GFile *resource;
+  GtkCssProvider *provider;
+  GError *error = NULL;
+  GdkScreen *screen;
+
+  if (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);
+      return;
+    }
+
+  screen = gdk_screen_get_default ();
+  gtk_style_context_add_provider_for_screen
+    (screen, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_THEME);
+  fallback_provider = provider;
+}
+
+static void
+wm_changed (void)
+{
+  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 ();
+  else
+    fallback_provider_remove ();
+}
+
+static void
+wm_watch_remove (void)
+{
+  if (wm_watch_id != 0)
+    {
+      g_signal_handler_disconnect (gdk_screen_get_default (), wm_watch_id);
+      wm_watch_id = 0;
+    }
+}
+
+static void
+wm_watch_install (void)
+{
+  if (wm_watch_id == 0)
+    {
+      GdkScreen *screen = gdk_screen_get_default ();
+
+      if (!GDK_IS_X11_SCREEN (screen))
+        return;
+
+      wm_watch_id = g_signal_connect (screen, "window-manager-changed",
+                                      G_CALLBACK (wm_changed), NULL);
+      wm_changed ();
+    }
+}
+
+void
+g_module_unload (GModule *module)
+{
+  wm_watch_remove ();
+  fallback_provider_remove ();
+
+  if (settings_id != 0)
+    {
+      g_signal_handler_disconnect (gtk_settings_get_default (), settings_id);
+      settings_id = 0;
+    }
+}
+
+static void
+maybe_watch_wm (void)
+{
+  GtkSettings *settings;
+  gchar *theme_name;
+
+  settings = gtk_settings_get_default ();
+  g_object_get (settings, "gtk-theme-name", &theme_name);
+
+  if (g_strcmp0 (theme_name, "Adwaita") == 0)
+    {
+      wm_watch_install ();
+    }
+  else
+    {
+      wm_watch_remove ();
+      fallback_provider_remove ();
+    }
+
+  g_free (theme_name);
+}
+
+int
+gtk_module_init (int *argc, char** argv[])
+{
+  maybe_watch_wm ();
+  settings_id = g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",
+                                  G_CALLBACK (maybe_watch_wm), NULL);
+
+  return 0;
+}



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