summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas James Alexander Thurman <tthurman@src.gnome.org>2006-04-22 01:42:06 +0000
committerThomas James Alexander Thurman <tthurman@src.gnome.org>2006-04-22 01:42:06 +0000
commit8bc7afb635d0407fe51ded70c08c9942dbc14f07 (patch)
tree365a990536bf3e04b71a7ed5f68a38bd0c8182e7
parenta524fb9c9cf74642eed605464fddda6fdab7231a (diff)
downloadmetacity-8bc7afb635d0407fe51ded70c08c9942dbc14f07.tar.gz
Pick up the newest version of each theme. #102547
-rw-r--r--doc/theme-format.txt30
-rw-r--r--src/theme-parser.c99
2 files changed, 90 insertions, 39 deletions
diff --git a/doc/theme-format.txt b/doc/theme-format.txt
index a574e89c..cb813f1e 100644
--- a/doc/theme-format.txt
+++ b/doc/theme-format.txt
@@ -1,6 +1,32 @@
-Docs on the theme format
+Themes are in a simple XML-subset format. There are multiple versions
+of the theme format, and a given theme can support more than one format.
-Themes are in a simple XML-subset format.
+Version 1: THEMEDIR/metacity-1/metacity-theme-1.xml
+ (original metacity format)
+Version 2: THEMEDIR/metacity-1/metacity-theme-2.xml
+
+The subdirectory name is "metacity-1" in all versions.
+
+As you might expect, older versions of metacity will not understand
+newer theme formats. However, newer versions will use old themes.
+Metacity will always use the newest theme format it understands that
+the X server supports. Some format versions are only supported if you
+have the right X server features.
+
+Each format *requires* the corresponding filename. If you put version
+2 format features in the metacity-1/metacity-theme-1.xml file, then
+metacity will get angry.
+
+This document has separate sections for each format version. You may
+want to read the document in reverse order, since the base features
+are discussed under version 1.
+
+New Features in Theme Format Version 2
+======================================
+(to be decided)
+
+Overview of Theme Format Version 1
+==================================
<?xml version="1.0"?>
<metacity_theme>
diff --git a/src/theme-parser.c b/src/theme-parser.c
index 7e7d47c6..5adaedf9 100644
--- a/src/theme-parser.c
+++ b/src/theme-parser.c
@@ -83,6 +83,7 @@ typedef struct
char *theme_dir; /* dir the theme is inside */
MetaTheme *theme; /* theme being parsed */
char *name; /* name of named thing being parsed */
+ guint format_version; /* theme version */
MetaFrameLayout *layout; /* layout being parsed if any */
MetaDrawOpList *op_list; /* op list being parsed if any */
MetaDrawOp *op; /* op being parsed if any */
@@ -2252,7 +2253,7 @@ parse_draw_op_element (GMarkupParseContext *context,
"x", &x, "y", &y,
"width", &width, "height", &height,
"alpha", &alpha, "filename", &filename,
- "colorize", &colorize,
+ "colorize", &colorize,
"fill_type", &fill_type,
NULL))
return;
@@ -4240,16 +4241,20 @@ text_handler (GMarkupParseContext *context,
}
}
-/* We change the filename when we break the format,
- * so themes can work with various metacity versions
- * (note, this is obsolete now because we are versioning
- * the directory this file is inside, so oh well)
+/* We were intending to put the version number
+ * in the subdirectory name, but we ended up
+ * using the filename instead. The "-1" survives
+ * as a fossil.
*/
-#define THEME_FILENAME "metacity-theme-1.xml"
-
-/* now this is versioned, /usr/share/themes/NAME/THEME_SUBDIR/THEME_FILENAME */
#define THEME_SUBDIR "metacity-1"
+/* Highest version of the theme format to
+ * look out for.
+ */
+#define THEME_VERSION 2
+
+#define METACITY_THEME_FILENAME_FORMAT "metacity-theme-%d.xml"
+
MetaTheme*
meta_theme_load (const char *theme_name,
GError **err)
@@ -4262,6 +4267,7 @@ meta_theme_load (const char *theme_name,
char *theme_file;
char *theme_dir;
MetaTheme *retval;
+ guint version;
text = NULL;
length = 0;
@@ -4273,11 +4279,14 @@ meta_theme_load (const char *theme_name,
if (meta_is_debugging ())
{
+ gchar *theme_filename = g_strdup_printf (METACITY_THEME_FILENAME_FORMAT,
+ THEME_VERSION);
+
/* Try in themes in our source tree */
theme_dir = g_build_filename ("./themes", theme_name, NULL);
theme_file = g_build_filename (theme_dir,
- THEME_FILENAME,
+ theme_filename,
NULL);
error = NULL;
@@ -4293,12 +4302,19 @@ meta_theme_load (const char *theme_name,
g_free (theme_file);
theme_file = NULL;
}
+ version = THEME_VERSION;
+
+ g_free (theme_filename);
}
- /* We try in home dir, then system dir for themes */
-
- if (text == NULL)
+ /* We try all supported versions from current to oldest */
+ for (version = THEME_VERSION; (version > 0) && (text == NULL); version--)
{
+ gchar *theme_filename = g_strdup_printf (METACITY_THEME_FILENAME_FORMAT,
+ version);
+
+ /* We try in home dir, then system dir for themes */
+
theme_dir = g_build_filename (g_get_home_dir (),
".themes",
theme_name,
@@ -4306,7 +4322,7 @@ meta_theme_load (const char *theme_name,
NULL);
theme_file = g_build_filename (theme_dir,
- THEME_FILENAME,
+ theme_filename,
NULL);
error = NULL;
@@ -4322,36 +4338,45 @@ meta_theme_load (const char *theme_name,
g_free (theme_file);
theme_file = NULL;
}
- }
- if (text == NULL)
- {
- theme_dir = g_build_filename (METACITY_DATADIR,
- "themes",
- theme_name,
- THEME_SUBDIR,
- NULL);
+ if (text == NULL)
+ {
+ theme_dir = g_build_filename (METACITY_DATADIR,
+ "themes",
+ theme_name,
+ THEME_SUBDIR,
+ NULL);
- theme_file = g_build_filename (theme_dir,
- THEME_FILENAME,
- NULL);
+ theme_file = g_build_filename (theme_dir,
+ theme_filename,
+ NULL);
- error = NULL;
- if (!g_file_get_contents (theme_file,
- &text,
- &length,
- &error))
- {
- meta_warning (_("Failed to read theme from file %s: %s\n"),
- theme_file, error->message);
- g_propagate_error (err, error);
- g_free (theme_file);
- g_free (theme_dir);
- return NULL; /* all fallbacks failed */
+ error = NULL;
+ if (!g_file_get_contents (theme_file,
+ &text,
+ &length,
+ &error))
+ {
+ meta_topic (META_DEBUG_THEMES, "Failed to read theme from file %s: %s\n",
+ theme_file, error->message);
+ g_error_free (error);
+ g_free (theme_dir);
+ g_free (theme_file);
+ theme_file = NULL;
+ }
}
+
+ g_free (theme_filename);
}
- g_assert (text);
+ if (text == NULL)
+ {
+ g_set_error (err, META_THEME_ERROR, META_THEME_ERROR_FAILED,
+ _("Failed to find a valid file for theme %s\n"),
+ theme_name);
+
+ return NULL; /* all fallbacks failed */
+ }
meta_topic (META_DEBUG_THEMES, "Parsing theme file %s\n", theme_file);