diff --git a/capplets/appearance/appearance-style.c b/capplets/appearance/appearance-style.c
index f66b826..f04e8c9 100644
--- a/capplets/appearance/appearance-style.c
+++ b/capplets/appearance/appearance-style.c
@@ -785,7 +785,7 @@ create_thumbnail (const gchar *name, GdkPixbuf *default_thumb, AppearanceData *d
     GnomeThemeInfo *info;
     info = gnome_theme_info_find (name);
     if (info != NULL && info->has_metacity) {
-      generate_metacity_theme_thumbnail_async (info,
+      generate_metacity_theme_thumbnail_async (info, "",
           (ThemeThumbnailFunc) metacity_theme_thumbnail_cb, data, NULL);
     }
   }
@@ -823,7 +823,7 @@ changed_on_disk_cb (GnomeThemeCommonInfo *theme,
         else if (change_type == GNOME_THEME_CHANGE_CHANGED)
           update_in_treeview ("window_themes_list", info->name, info->name, data);
 
-        generate_metacity_theme_thumbnail_async (info,
+        generate_metacity_theme_thumbnail_async (info, "",
             (ThemeThumbnailFunc) metacity_theme_thumbnail_cb, data, NULL);
       }
     }
diff --git a/capplets/appearance/appearance-themes.c b/capplets/appearance/appearance-themes.c
index 308e7ab..13ff7dc 100644
--- a/capplets/appearance/appearance-themes.c
+++ b/capplets/appearance/appearance-themes.c
@@ -161,9 +161,12 @@ theme_thumbnail_generate (GnomeThemeMetaInfo *info, AppearanceData *data)
   if (thumb != NULL) {
     theme_thumbnail_update (thumb, info->name, data, FALSE);
     g_object_unref (thumb);
-  } else
-    generate_meta_theme_thumbnail_async (info,
+  } else {
+    gchar *button_layout = gconf_client_get_string (data->client, METACITY_BUTTON_LAYOUT_KEY, NULL);
+    generate_meta_theme_thumbnail_async (info, button_layout,
         (ThemeThumbnailFunc) theme_thumbnail_done_cb, data, NULL);
+    g_free (button_layout);
+  }
 }
 
 static void
@@ -924,6 +927,44 @@ theme_gconf_changed (GConfClient *client,
   theme_details_changed_cb (data);
 }
 
+static void
+theme_button_layout_changed (GConfClient *client,
+                             guint conn_id,
+                             GConfEntry *entry,
+                             AppearanceData *data)
+{
+  GtkIconView *icon_view;
+  gchar *button_layout, *last_button_layout;
+
+  icon_view = GTK_ICON_VIEW (appearance_capplet_get_widget (data, "theme_list"));
+
+  button_layout = gconf_client_get_string (data->client, METACITY_BUTTON_LAYOUT_KEY, NULL);  
+  last_button_layout = gconf_client_get_string (data->client, THUMBNAIL_BUTTON_LAYOUT_KEY, NULL);
+  if (!button_layout || !last_button_layout || strcmp (button_layout, last_button_layout)) {
+    GtkTreeModel *model = gtk_icon_view_get_model (icon_view);
+    GtkTreeIter iter;
+
+    if (gtk_tree_model_get_iter_first (model, &iter)) {
+        do {
+          gchar *name;
+          GnomeThemeMetaInfo *info;
+
+          gtk_tree_model_get (model, &iter, COL_NAME, &name, -1);
+          info = gnome_theme_meta_info_find (name);
+          g_free (name);
+          if (!info)
+            info = data->theme_custom;
+
+          //generate_meta_theme_thumbnail_async (info, button_layout,
+          //    (ThemeThumbnailFunc) theme_thumbnail_done_cb, data, NULL);
+        } while (gtk_tree_model_iter_next (model, &iter));
+    }
+  }
+  gconf_client_set_string (data->client, THUMBNAIL_BUTTON_LAYOUT_KEY, button_layout, NULL);
+  g_free (button_layout);
+  g_free (last_button_layout);
+}
+
 static gint
 theme_list_sort_func (GnomeThemeMetaInfo *a,
                       GnomeThemeMetaInfo *b)
@@ -1143,6 +1184,7 @@ themes_init (AppearanceData *data)
   gconf_client_add_dir (data->client, "/apps/metacity/general", GCONF_CLIENT_PRELOAD_NONE, NULL);
   gconf_client_add_dir (data->client, "/desktop/gnome/interface", GCONF_CLIENT_PRELOAD_NONE, NULL);
   gconf_client_notify_add (data->client, METACITY_THEME_KEY, (GConfClientNotifyFunc) theme_gconf_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, METACITY_BUTTON_LAYOUT_KEY, (GConfClientNotifyFunc) theme_button_layout_changed, data, NULL, NULL);
   gconf_client_notify_add (data->client, CURSOR_THEME_KEY, (GConfClientNotifyFunc) theme_gconf_changed, data, NULL, NULL);
 #ifdef HAVE_XCURSOR
   gconf_client_notify_add (data->client, CURSOR_SIZE_KEY, (GConfClientNotifyFunc) theme_gconf_changed, data, NULL, NULL);
diff --git a/capplets/appearance/appearance.h b/capplets/appearance/appearance.h
index c598b06..9205fc7 100644
--- a/capplets/appearance/appearance.h
+++ b/capplets/appearance/appearance.h
@@ -30,6 +30,7 @@
 #define APPEARANCE_KEY_DIR "/apps/control-center/appearance"
 #define MORE_THEMES_URL_KEY APPEARANCE_KEY_DIR "/more_themes_url"
 #define MORE_BACKGROUNDS_URL_KEY APPEARANCE_KEY_DIR "/more_backgrounds_url"
+#define THUMBNAIL_BUTTON_LAYOUT_KEY APPEARANCE_KEY_DIR "/metacity_button_layout"
 
 typedef struct
 {
diff --git a/capplets/appearance/theme-util.h b/capplets/appearance/theme-util.h
index b6f453b..62c53d0 100644
--- a/capplets/appearance/theme-util.h
+++ b/capplets/appearance/theme-util.h
@@ -20,6 +20,7 @@
 
 #define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme"
 #define METACITY_THEME_KEY "/apps/metacity/general/theme"
+#define METACITY_BUTTON_LAYOUT_KEY "/apps/metacity/general/button_layout"
 #define ICON_THEME_KEY "/desktop/gnome/interface/icon_theme"
 #define NOTIFICATION_THEME_KEY "/apps/notification-daemon/theme"
 #define COLOR_SCHEME_KEY "/desktop/gnome/interface/gtk_color_scheme"
diff --git a/capplets/common/theme-thumbnail.c b/capplets/common/theme-thumbnail.c
index 094cb8e..c1823e8 100644
--- a/capplets/common/theme-thumbnail.c
+++ b/capplets/common/theme-thumbnail.c
@@ -52,6 +52,7 @@ enum
   READING_CONTROL_THEME_NAME,
   READING_GTK_COLOR_SCHEME,
   READING_WM_THEME_NAME,
+  READING_WM_BUTTON_LAYOUT,
   READING_ICON_THEME_NAME,
   READING_APPLICATION_FONT,
   WRITING_PIXBUF_DATA
@@ -64,6 +65,7 @@ typedef struct
   GByteArray *control_theme_name;
   GByteArray *gtk_color_scheme;
   GByteArray *wm_theme_name;
+  GByteArray *wm_button_layout;
   GByteArray *icon_theme_name;
   GByteArray *application_font;
 } ThemeThumbnailData;
@@ -72,6 +74,7 @@ typedef struct
 {
   gchar *thumbnail_type;
   gpointer theme_info;
+  gchar *button_layout;
   ThemeThumbnailFunc func;
   gpointer user_data;
   GDestroyNotify destroy;
@@ -209,6 +212,22 @@ create_folder_icon (char *icon_theme_name)
   return folder_icon;
 }
 
+static void
+meta_preview_set_button_layout_from_string (MetaPreview *preview, const char *layout)
+{
+  MetaButtonLayout button_layout;
+
+  button_layout.left_buttons[0] = META_BUTTON_FUNCTION_CLOSE;
+  button_layout.left_buttons_has_spacer[0] = FALSE;
+  button_layout.left_buttons[1] = META_BUTTON_FUNCTION_MINIMIZE;
+  button_layout.left_buttons_has_spacer[1] = FALSE;
+  button_layout.left_buttons[2] = META_BUTTON_FUNCTION_MAXIMIZE;
+  button_layout.left_buttons_has_spacer[2] = FALSE;
+  button_layout.left_buttons[3] = META_BUTTON_FUNCTION_LAST;
+  button_layout.right_buttons[0] = META_BUTTON_FUNCTION_LAST;
+  meta_preview_set_button_layout (preview, &button_layout);
+}
+
 static GdkPixbuf *
 create_meta_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
 {
@@ -290,6 +309,7 @@ create_meta_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
 
   meta_preview_set_frame_flags (META_PREVIEW (preview), flags);
   meta_preview_set_theme (META_PREVIEW (preview), theme);
+  meta_preview_set_button_layout_from_string (META_PREVIEW (preview), (char *) theme_thumbnail_data->wm_button_layout->data);
   meta_preview_set_title (META_PREVIEW (preview), "");
 
   gtk_window_set_default_size (GTK_WINDOW (window), META_THUMBNAIL_SIZE, META_THUMBNAIL_SIZE);
@@ -464,6 +484,7 @@ create_metacity_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
   preview = meta_preview_new ();
   meta_preview_set_frame_flags (META_PREVIEW (preview), flags);
   meta_preview_set_theme (META_PREVIEW (preview), theme);
+  meta_preview_set_button_layout_from_string (META_PREVIEW (preview), (char *) theme_thumbnail_data->wm_button_layout->data);
   meta_preview_set_title (META_PREVIEW (preview), "");
   gtk_container_add (GTK_CONTAINER (window), preview);
 
@@ -602,6 +623,22 @@ handle_bytes (const gchar        *buffer,
           g_byte_array_append (theme_thumbnail_data->wm_theme_name, ptr, nil - ptr + 1);
           bytes_read -= (nil - ptr + 1);
           ptr = nil + 1;
+          theme_thumbnail_data->status = READING_WM_BUTTON_LAYOUT;
+        }
+        break;
+
+      case READING_WM_BUTTON_LAYOUT:
+        nil = memchr (ptr, '\000', bytes_read);
+        if (nil == NULL)
+        {
+          g_byte_array_append (theme_thumbnail_data->wm_button_layout, ptr, bytes_read);
+          bytes_read = 0;
+        }
+        else
+        {
+          g_byte_array_append (theme_thumbnail_data->wm_button_layout, ptr, nil - ptr + 1);
+          bytes_read -= (nil - ptr + 1);
+          ptr = nil + 1;
           theme_thumbnail_data->status = READING_ICON_THEME_NAME;
         }
         break;
@@ -710,6 +747,7 @@ message_from_capplet (GIOChannel   *source,
         g_byte_array_set_size (theme_thumbnail_data->control_theme_name, 0);
         g_byte_array_set_size (theme_thumbnail_data->gtk_color_scheme, 0);
         g_byte_array_set_size (theme_thumbnail_data->wm_theme_name, 0);
+        g_byte_array_set_size (theme_thumbnail_data->wm_button_layout, 0);
         g_byte_array_set_size (theme_thumbnail_data->icon_theme_name, 0);
         g_byte_array_set_size (theme_thumbnail_data->application_font, 0);
         theme_thumbnail_data->status = READY_FOR_THEME;
@@ -743,6 +781,7 @@ generate_next_in_queue (void)
 
   if (!strcmp (item->thumbnail_type, THUMBNAIL_TYPE_META))
     generate_meta_theme_thumbnail_async ((GnomeThemeMetaInfo *) item->theme_info,
+                                         item->button_layout,
                                          item->func,
                                          item->user_data,
                                          item->destroy);
@@ -753,6 +792,7 @@ generate_next_in_queue (void)
                                         item->destroy);
   else if (!strcmp (item->thumbnail_type, THUMBNAIL_TYPE_METACITY))
     generate_metacity_theme_thumbnail_async ((GnomeThemeInfo *) item->theme_info,
+                                             item->button_layout,
                                              item->func,
                                              item->user_data,
                                              item->destroy);
@@ -762,6 +802,7 @@ generate_next_in_queue (void)
                                          item->user_data,
                                          item->destroy);
 
+  g_free (item->button_layout);
   g_free (item);
 }
 
@@ -861,6 +902,7 @@ send_thumbnail_request (gchar *thumbnail_type,
                         gchar *gtk_theme_name,
                         gchar *gtk_color_scheme,
                         gchar *metacity_theme_name,
+                        gchar *metacity_button_layout,
                         gchar *icon_theme_name,
                         gchar *application_font)
 {
@@ -881,6 +923,11 @@ send_thumbnail_request (gchar *thumbnail_type,
   else
     write (pipe_to_factory_fd[1], "", 1);
 
+  if (metacity_button_layout)
+    write (pipe_to_factory_fd[1], metacity_button_layout, strlen (metacity_button_layout) + 1);
+  else
+    write (pipe_to_factory_fd[1], "", 1);
+
   if (icon_theme_name)
     write (pipe_to_factory_fd[1], icon_theme_name, strlen (icon_theme_name) + 1);
   else
@@ -953,6 +1000,7 @@ generate_theme_thumbnail (gchar *thumbnail_type,
                           gchar *gtk_theme_name,
                           gchar *gtk_color_scheme,
                           gchar *metacity_theme_name,
+                          gchar *metacity_button_layout,
                           gchar *icon_theme_name,
                           gchar *application_font)
 {
@@ -963,6 +1011,7 @@ generate_theme_thumbnail (gchar *thumbnail_type,
                           gtk_theme_name,
                           gtk_color_scheme,
                           metacity_theme_name,
+                          metacity_button_layout,
                           icon_theme_name,
                           application_font);
 
@@ -970,12 +1019,13 @@ generate_theme_thumbnail (gchar *thumbnail_type,
 }
 
 GdkPixbuf *
-generate_meta_theme_thumbnail (GnomeThemeMetaInfo *theme_info)
+generate_meta_theme_thumbnail (GnomeThemeMetaInfo *theme_info, gchar *button_layout)
 {
   return generate_theme_thumbnail (THUMBNAIL_TYPE_META,
                                    theme_info->gtk_theme_name,
                                    theme_info->gtk_color_scheme,
                                    theme_info->metacity_theme_name,
+                                   button_layout,
                                    theme_info->icon_theme_name,
                                    theme_info->application_font);
 }
@@ -992,17 +1042,19 @@ generate_gtk_theme_thumbnail (GnomeThemeInfo *theme_info)
                                    scheme,
                                    NULL,
                                    NULL,
+                                   NULL,
                                    NULL);
   g_free (scheme);
 }
 
 GdkPixbuf *
-generate_metacity_theme_thumbnail (GnomeThemeInfo *theme_info)
+generate_metacity_theme_thumbnail (GnomeThemeInfo *theme_info, gchar *button_layout)
 {
   return generate_theme_thumbnail (THUMBNAIL_TYPE_METACITY,
                                    NULL,
                                    NULL,
                                    theme_info->name,
+                                   button_layout,
                                    NULL,
                                    NULL);
 }
@@ -1014,6 +1066,7 @@ generate_icon_theme_thumbnail (GnomeThemeIconInfo *theme_info)
                                    NULL,
                                    NULL,
                                    NULL,
+                                   NULL,
                                    theme_info->name,
                                    NULL);
 }
@@ -1025,6 +1078,7 @@ generate_theme_thumbnail_async (gpointer            theme_info,
                                 gchar              *gtk_theme_name,
                                 gchar              *gtk_color_scheme,
                                 gchar              *metacity_theme_name,
+                                gchar              *metacity_button_layout,
                                 gchar              *icon_theme_name,
                                 gchar              *application_font,
                                 ThemeThumbnailFunc  func,
@@ -1038,6 +1092,7 @@ generate_theme_thumbnail_async (gpointer            theme_info,
     item = g_new0 (ThemeQueueItem, 1);
     item->thumbnail_type = thumbnail_type;
     item->theme_info = theme_info;
+    item->button_layout = g_strdup (metacity_button_layout);
     item->func = func;
     item->user_data = user_data;
     item->destroy = destroy;
@@ -1076,12 +1131,14 @@ generate_theme_thumbnail_async (gpointer            theme_info,
                           gtk_theme_name,
                           gtk_color_scheme,
                           metacity_theme_name,
+                          metacity_button_layout,
                           icon_theme_name,
                           application_font);
 }
 
 void
 generate_meta_theme_thumbnail_async (GnomeThemeMetaInfo *theme_info,
+                                     gchar              *button_layout,
                                      ThemeThumbnailFunc  func,
                                      gpointer            user_data,
                                      GDestroyNotify      destroy)
@@ -1092,6 +1149,7 @@ generate_meta_theme_thumbnail_async (GnomeThemeMetaInfo *theme_info,
                                          theme_info->gtk_theme_name,
                                          theme_info->gtk_color_scheme,
                                          theme_info->metacity_theme_name,
+                                         button_layout,
                                          theme_info->icon_theme_name,
                                          theme_info->application_font,
                                          func, user_data, destroy);
@@ -1111,6 +1169,7 @@ generate_gtk_theme_thumbnail_async (GnomeThemeInfo *theme_info,
                                   theme_info->name,
                                   THUMBNAIL_TYPE_GTK,
                                   theme_info->name,
+                                  NULL,
                                   scheme,
                                   NULL,
                                   NULL,
@@ -1121,6 +1180,7 @@ generate_gtk_theme_thumbnail_async (GnomeThemeInfo *theme_info,
 
 void
 generate_metacity_theme_thumbnail_async (GnomeThemeInfo *theme_info,
+                                         gchar              *button_layout,
                                          ThemeThumbnailFunc  func,
                                          gpointer            user_data,
                                          GDestroyNotify      destroy)
@@ -1131,6 +1191,7 @@ generate_metacity_theme_thumbnail_async (GnomeThemeInfo *theme_info,
                                          NULL,
                                          NULL,
                                          theme_info->name,
+                                         button_layout,
                                          NULL,
                                          NULL,
                                          func, user_data, destroy);
@@ -1148,6 +1209,7 @@ generate_icon_theme_thumbnail_async (GnomeThemeIconInfo *theme_info,
                                          NULL,
                                          NULL,
                                          NULL,
+                                         NULL,
                                          theme_info->name,
                                          NULL,
                                          func, user_data, destroy);
@@ -1188,6 +1250,7 @@ theme_thumbnail_factory_init (int argc, char *argv[])
     data.control_theme_name = g_byte_array_new ();
     data.gtk_color_scheme = g_byte_array_new ();
     data.wm_theme_name = g_byte_array_new ();
+    data.wm_button_layout = g_byte_array_new ();
     data.icon_theme_name = g_byte_array_new ();
     data.application_font = g_byte_array_new ();
 
diff --git a/capplets/common/theme-thumbnail.h b/capplets/common/theme-thumbnail.h
index 4a433dc..6a55403 100644
--- a/capplets/common/theme-thumbnail.h
+++ b/capplets/common/theme-thumbnail.h
@@ -9,12 +9,15 @@ typedef void (* ThemeThumbnailFunc)          (GdkPixbuf          *pixbuf,
                                               gchar              *theme_name,
                                               gpointer            data);
 
-GdkPixbuf *generate_meta_theme_thumbnail     (GnomeThemeMetaInfo *theme_info);
+GdkPixbuf *generate_meta_theme_thumbnail     (GnomeThemeMetaInfo *theme_info,
+                                              gchar              *button_layout);
 GdkPixbuf *generate_gtk_theme_thumbnail      (GnomeThemeInfo     *theme_info);
-GdkPixbuf *generate_metacity_theme_thumbnail (GnomeThemeInfo     *theme_info);
+GdkPixbuf *generate_metacity_theme_thumbnail (GnomeThemeInfo     *theme_info,
+                                              gchar              *button_layout);
 GdkPixbuf *generate_icon_theme_thumbnail     (GnomeThemeIconInfo *theme_info);
 
 void generate_meta_theme_thumbnail_async     (GnomeThemeMetaInfo *theme_info,
+                                              gchar              *button_layout,
                                               ThemeThumbnailFunc  func,
                                               gpointer            data,
                                               GDestroyNotify      destroy);
@@ -23,6 +26,7 @@ void generate_gtk_theme_thumbnail_async      (GnomeThemeInfo     *theme_info,
                                               gpointer            data,
                                               GDestroyNotify      destroy);
 void generate_metacity_theme_thumbnail_async (GnomeThemeInfo     *theme_info,
+                                              gchar              *button_layout,
                                               ThemeThumbnailFunc  func,
                                               gpointer            data,
                                               GDestroyNotify      destroy);
