Commit 7ecb3e03 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

theme: redo theme settings

parent c9f01260
......@@ -2,6 +2,8 @@ NULL =
gsettings_SCHEMAS = \
org.gnome.metacity.gschema.xml \
org.gnome.metacity.keybindings.gschema.xml \
org.gnome.metacity.theme.gschema.xml \
$(NULL)
@GSETTINGS_RULES@
......
<schemalist gettext-domain="metacity">
<enum id="org.gnome.metacity.MetaPlacementMode">
<value nick="smart" value="0" />
<value nick="cascade" value="1" />
......@@ -10,25 +9,20 @@
<schema id="org.gnome.metacity" path="/org/gnome/metacity/">
<key name="compositing-manager" type="b">
<default>true</default>
<summary>Compositing Manager</summary>
<key name="alt-tab-thumbnails" type="b">
<default>false</default>
<summary>Show window content thumbnail in Alt-Tab</summary>
<description>
Determines whether Metacity is a compositing manager.
If set to true, Metacity will show window content thumbnails in the
Alt-Tab window instead of only icons.
</description>
</key>
<key name="reduced-resources" type="b">
<default>false</default>
<summary>If true, trade off usability for less resource usage</summary>
<key name="compositing-manager" type="b">
<default>true</default>
<summary>Compositing Manager</summary>
<description>
If true, Metacity will give the user less feedback by using wireframes,
avoiding animations, or other means. This is a significant reduction
in usability for many users, but may allow legacy applications to
continue working, and may also be a useful tradeoff
for terminal servers.
However, the wireframe feature is disabled when accessibility is on.
Determines whether Metacity is a compositing manager.
</description>
</key>
......@@ -58,36 +52,22 @@
</description>
</key>
<key name="alt-tab-thumbnails" type="b">
<key name="reduced-resources" type="b">
<default>false</default>
<summary>Show window content thumbnail in Alt-Tab</summary>
<summary>If true, trade off usability for less resource usage</summary>
<description>
If set to true, Metacity will show window content thumbnails in the
Alt-Tab window instead of only icons.
</description>
</key>
If true, Metacity will give the user less feedback by using wireframes,
avoiding animations, or other means. This is a significant reduction
in usability for many users, but may allow legacy applications to
continue working, and may also be a useful tradeoff
for terminal servers.
<key name="theme" type="s">
<default>'Adwaita'</default>
<summary>Current theme</summary>
<description>
The theme determines the appearance of window borders, titlebar,
and so forth.
However, the wireframe feature is disabled when accessibility is on.
</description>
</key>
</schema>
<schema id="org.gnome.metacity.keybindings" path="/org/gnome/metacity/keybindings/">
<key name="toggle-tiled-left" type="as">
<default><![CDATA[['<Super>Left']]]></default>
</key>
<key name="toggle-tiled-right" type="as">
<default><![CDATA[['<Super>Right']]]></default>
</key>
<child schema="org.gnome.metacity.keybindings" name="keybindings" />
<child schema="org.gnome.metacity.theme" name="theme" />
</schema>
</schemalist>
<schemalist gettext-domain="metacity">
<schema id="org.gnome.metacity.keybindings" path="/org/gnome/metacity/keybindings/">
<key name="toggle-tiled-left" type="as">
<default><![CDATA[['<Super>Left']]]></default>
</key>
<key name="toggle-tiled-right" type="as">
<default><![CDATA[['<Super>Right']]]></default>
</key>
</schema>
</schemalist>
<schemalist gettext-domain="metacity">
<enum id="org.gnome.metacity.MetaThemeType">
<value nick="gtk" value="0" />
<value nick="metacity" value="1" />
</enum>
<schema id="org.gnome.metacity.theme" path="/org/gnome/metacity/theme/">
<key name="name" type="s">
<default>''</default>
<summary>Theme Name</summary>
<description>
This setting is only used if Metacity is selected as theme type. You
MUST provide valid Metacity theme name, otherwise Metacity will fall
back to default GTK+ theme - Adwaita.
</description>
</key>
<key name="type" enum="org.gnome.metacity.MetaThemeType">
<default>'gtk'</default>
<summary>Theme Type</summary>
<description>
Metacity supports two theme types - GTK+ (gtk.css) and Metacity
(metacity-theme-x.xml).
GTK+ theme: all data is loaded from CSS. This is same theme that is
used by mutter for server side decorations and by GTK+ for client side
decorations.
Metacity theme: data is loaded from metacity-theme-x.xml and css. Using
this theme type you MUST provide valid theme name.
</description>
</key>
</schema>
</schemalist>
......@@ -4589,7 +4589,7 @@ out:
if (!error && !retval)
{
g_set_error (&error, META_THEME_ERROR, META_THEME_ERROR_FAILED,
_("Failed to find a valid file for theme %s"), name);
_("Failed to find a valid file for theme '%s'"), name);
}
if (error)
......
......@@ -591,65 +591,3 @@ meta_theme_draw_frame (MetaTheme *theme,
mini_icon,
icon);
}
/**
* The current theme. (Themes are singleton.)
*/
static MetaTheme *meta_current_theme = NULL;
MetaTheme*
meta_theme_get_current (void)
{
return meta_current_theme;
}
void
meta_theme_set_current (const gchar *name,
gboolean force_reload,
gboolean composited,
const PangoFontDescription *titlebar_font)
{
MetaTheme *new_theme;
GError *error;
g_debug ("Setting current theme to '%s'", name);
if (!force_reload && meta_current_theme)
{
gchar *theme_name;
theme_name = meta_theme_get_name (meta_current_theme);
if (g_strcmp0 (name, theme_name) == 0)
{
g_free (theme_name);
return;
}
g_free (theme_name);
}
if (name != NULL && strcmp (name, "") != 0)
new_theme = meta_theme_new (META_THEME_TYPE_METACITY);
else
new_theme = meta_theme_new (META_THEME_TYPE_GTK);
meta_theme_set_composited (new_theme, composited);
meta_theme_set_titlebar_font (new_theme, titlebar_font);
error = NULL;
if (!meta_theme_load (new_theme, name, &error))
{
g_warning (_("Failed to load theme '%s': %s"), name, error->message);
g_error_free (error);
g_object_unref (new_theme);
}
else
{
if (meta_current_theme)
g_object_unref (meta_current_theme);
meta_current_theme = new_theme;
g_debug ("New theme is '%s'", name);
}
}
......@@ -210,13 +210,6 @@ void meta_theme_draw_frame (MetaTheme
GdkPixbuf *mini_icon,
GdkPixbuf *icon);
MetaTheme *meta_theme_get_current (void);
void meta_theme_set_current (const gchar *name,
gboolean force_reload,
gboolean composited,
const PangoFontDescription *titlebar_font);
G_END_DECLS
#endif
......@@ -3,6 +3,8 @@
data/applications/metacity.desktop.in
data/keybindings/keybindings.pot
data/schemas/org.gnome.metacity.gschema.xml
data/schemas/org.gnome.metacity.keybindings.gschema.xml
data/schemas/org.gnome.metacity.theme.gschema.xml
data/ui/theme-viewer-window.ui
libmetacity/meta-color-spec.c
libmetacity/meta-draw-op.c
......
......@@ -108,6 +108,7 @@ metacity_SOURCES= \
ui/tile-preview.c \
include/tile-preview.h \
ui/ui.c \
ui/ui-private.h \
$(NULL)
bin_PROGRAMS=metacity
......
......@@ -2363,8 +2363,7 @@ event_callback (XEvent *event,
display->atom__METACITY_RELOAD_THEME_MESSAGE)
{
meta_verbose ("Received reload theme request\n");
meta_ui_set_current_theme (meta_prefs_get_theme (),
TRUE);
meta_ui_reload_theme ();
meta_display_retheme_all ();
}
else if (event->xclient.message_type ==
......
......@@ -45,47 +45,10 @@ prefs_changed_callback (MetaPreference preference,
{
MetaFrame *frame = (MetaFrame *) data;
switch (preference)
if (preference == META_PREF_COMPOSITING_MANAGER)
{
case META_PREF_COMPOSITING_MANAGER:
frame->need_reapply_frame_shape = TRUE;
update_shape (frame);
break;
case META_PREF_MOUSE_BUTTON_MODS:
case META_PREF_FOCUS_MODE:
case META_PREF_FOCUS_NEW_WINDOWS:
case META_PREF_ATTACH_MODAL_DIALOGS:
case META_PREF_RAISE_ON_CLICK:
case META_PREF_ACTION_DOUBLE_CLICK_TITLEBAR:
case META_PREF_ACTION_MIDDLE_CLICK_TITLEBAR:
case META_PREF_ACTION_RIGHT_CLICK_TITLEBAR:
case META_PREF_AUTO_RAISE:
case META_PREF_AUTO_RAISE_DELAY:
case META_PREF_THEME:
case META_PREF_TITLEBAR_FONT:
case META_PREF_NUM_WORKSPACES:
case META_PREF_KEYBINDINGS:
case META_PREF_DISABLE_WORKAROUNDS:
case META_PREF_BUTTON_LAYOUT:
case META_PREF_WORKSPACE_NAMES:
case META_PREF_VISUAL_BELL:
case META_PREF_AUDIBLE_BELL:
case META_PREF_VISUAL_BELL_TYPE:
case META_PREF_REDUCED_RESOURCES:
case META_PREF_GNOME_ACCESSIBILITY:
case META_PREF_GNOME_ANIMATIONS:
case META_PREF_CURSOR_THEME:
case META_PREF_CURSOR_SIZE:
case META_PREF_RESIZE_WITH_RIGHT_BUTTON:
case META_PREF_EDGE_TILING:
case META_PREF_FORCE_FULLSCREEN:
case META_PREF_PLACEMENT_MODE:
case META_PREF_ALT_TAB_THUMBNAILS:
break;
default:
break;
frame->need_reapply_frame_shape = TRUE;
update_shape (frame);
}
}
......
......@@ -453,41 +453,7 @@ main (int argc, char **argv)
meta_prefs_init ();
meta_prefs_add_listener (prefs_changed_callback, NULL);
meta_ui_set_current_theme (meta_prefs_get_theme (), FALSE);
/* Try to find some theme that'll work if the theme preference
* doesn't exist. First try Simple (the default theme) then just
* try anything in the themes directory.
*/
if (!meta_ui_have_a_theme ())
meta_ui_set_current_theme ("Simple", FALSE);
if (!meta_ui_have_a_theme ())
{
const char *dir_entry = NULL;
GError *err = NULL;
GDir *themes_dir = NULL;
if (!(themes_dir = g_dir_open (METACITY_DATADIR"/themes", 0, &err)))
{
meta_fatal (_("Failed to scan themes directory: %s\n"), err->message);
g_error_free (err);
}
else
{
while (((dir_entry = g_dir_read_name (themes_dir)) != NULL) &&
(!meta_ui_have_a_theme ()))
{
meta_ui_set_current_theme (dir_entry, FALSE);
}
g_dir_close (themes_dir);
}
}
if (!meta_ui_have_a_theme ())
meta_fatal (_("Could not find a theme! Be sure %s exists and contains the usual themes.\n"),
METACITY_DATADIR"/themes");
meta_ui_reload_theme ();
/* Connect to SM as late as possible - but before managing display,
* or we might try to manage a window before we have the session
......@@ -601,9 +567,10 @@ prefs_changed_callback (MetaPreference pref,
{
switch (pref)
{
case META_PREF_THEME:
case META_PREF_THEME_NAME:
case META_PREF_THEME_TYPE:
case META_PREF_COMPOSITING_MANAGER:
meta_ui_set_current_theme (meta_prefs_get_theme (), TRUE);
meta_ui_reload_theme ();
meta_display_retheme_all ();
break;
......
......@@ -55,6 +55,7 @@
* a GSettings instance for */
#define SCHEMA_GENERAL "org.gnome.desktop.wm.preferences"
#define SCHEMA_METACITY "org.gnome.metacity"
#define SCHEMA_METACITY_THEME "org.gnome.metacity.theme"
#define SCHEMA_INTERFACE "org.gnome.desktop.interface"
#define SETTINGS(s) g_hash_table_lookup (settings_schemas, (s))
......@@ -71,7 +72,8 @@ static GDesktopFocusMode focus_mode = G_DESKTOP_FOCUS_MODE_CLICK;
static GDesktopFocusNewWindows focus_new_windows = G_DESKTOP_FOCUS_NEW_WINDOWS_SMART;
static gboolean raise_on_click = TRUE;
static gboolean attach_modal_dialogs = FALSE;
static char* current_theme = NULL;
static gchar *current_theme_name = NULL;
static MetaThemeType current_theme_type = META_THEME_TYPE_GTK;
static int num_workspaces = 4;
static GDesktopTitlebarAction action_double_click_titlebar = G_DESKTOP_TITLEBAR_ACTION_TOGGLE_MAXIMIZE;
static GDesktopTitlebarAction action_middle_click_titlebar = G_DESKTOP_TITLEBAR_ACTION_LOWER;
......@@ -253,6 +255,13 @@ static MetaEnumPreference preferences_enum[] =
},
&placement_mode,
},
{
{ "type",
SCHEMA_METACITY_THEME,
META_PREF_THEME_TYPE,
},
&current_theme_type,
},
{ { NULL, 0, 0 }, NULL },
};
......@@ -375,14 +384,6 @@ static MetaStringPreference preferences_string[] =
mouse_button_mods_handler,
NULL,
},
{
{ "theme",
SCHEMA_METACITY,
META_PREF_THEME,
},
theme_name_handler,
NULL,
},
{
{ KEY_TITLEBAR_FONT,
SCHEMA_GENERAL,
......@@ -407,6 +408,14 @@ static MetaStringPreference preferences_string[] =
NULL,
&cursor_theme,
},
{
{ "name",
SCHEMA_METACITY_THEME,
META_PREF_THEME_NAME,
},
theme_name_handler,
NULL,
},
{ { NULL, 0, 0 }, NULL },
};
......@@ -849,6 +858,10 @@ meta_prefs_init (void)
g_signal_connect (settings, "changed", G_CALLBACK (settings_changed), NULL);
g_hash_table_insert (settings_schemas, g_strdup (SCHEMA_METACITY), settings);
settings = g_settings_new (SCHEMA_METACITY_THEME);
g_signal_connect (settings, "changed", G_CALLBACK (settings_changed), NULL);
g_hash_table_insert (settings_schemas, g_strdup (SCHEMA_METACITY_THEME), settings);
/* Individual keys we watch outside of our schemas */
settings = g_settings_new (SCHEMA_INTERFACE);
g_signal_connect (settings, "changed::" KEY_GNOME_ACCESSIBILITY,
......@@ -991,10 +1004,16 @@ meta_prefs_get_raise_on_click (void)
return raise_on_click;
}
const char*
meta_prefs_get_theme (void)
const gchar *
meta_prefs_get_theme_name (void)
{
return current_theme;
return current_theme_name;
}
MetaThemeType
meta_prefs_get_theme_type (void)
{
return current_theme_type;
}
const char*
......@@ -1063,17 +1082,12 @@ theme_name_handler (GVariant *value,
*result = NULL; /* ignored */
string_value = g_variant_get_string (value, NULL);
if (g_strcmp0 (current_theme, string_value) != 0)
if (g_strcmp0 (current_theme_name, string_value) != 0)
{
if (current_theme)
g_free (current_theme);
g_free (current_theme_name);
current_theme_name = g_strdup (string_value);
if (!string_value || !*string_value)
current_theme = NULL;
else
current_theme = g_strdup (string_value);
queue_changed (META_PREF_THEME);
queue_changed (META_PREF_THEME_NAME);
}
return TRUE;
......@@ -1218,8 +1232,11 @@ meta_preference_to_string (MetaPreference pref)
case META_PREF_RAISE_ON_CLICK:
return "RAISE_ON_CLICK";
case META_PREF_THEME:
return "THEME";
case META_PREF_THEME_NAME:
return "THEME_NAME";
case META_PREF_THEME_TYPE:
return "THEME_TYPE";
case META_PREF_TITLEBAR_FONT:
return "TITLEBAR_FONT";
......
......@@ -26,7 +26,7 @@
/* This header is a "common" one between the UI and core side */
#include "common.h"
#include "types.h"
#include <libmetacity/meta-button-layout.h>
#include <libmetacity/meta-theme.h>
#include <pango/pango-font.h>
#include <gdesktop-enums.h>
......@@ -43,7 +43,8 @@ typedef enum
META_PREF_ACTION_RIGHT_CLICK_TITLEBAR,
META_PREF_AUTO_RAISE,
META_PREF_AUTO_RAISE_DELAY,
META_PREF_THEME,
META_PREF_THEME_NAME,
META_PREF_THEME_TYPE,
META_PREF_TITLEBAR_FONT,
META_PREF_NUM_WORKSPACES,
META_PREF_KEYBINDINGS,
......@@ -93,7 +94,10 @@ GDesktopFocusMode meta_prefs_get_focus_mode (void);
GDesktopFocusNewWindows meta_prefs_get_focus_new_windows (void);
gboolean meta_prefs_get_attach_modal_dialogs (void);
gboolean meta_prefs_get_raise_on_click (void);
const char* meta_prefs_get_theme (void);
const gchar *meta_prefs_get_theme_name (void);
MetaThemeType meta_prefs_get_theme_type (void);
/* returns NULL if GTK default should be used */
const PangoFontDescription* meta_prefs_get_titlebar_font (void);
int meta_prefs_get_num_workspaces (void);
......@@ -294,7 +298,3 @@ gboolean meta_prefs_bell_is_audible (void);
GDesktopVisualBellType meta_prefs_get_visual_bell_type (void);
#endif
......@@ -156,9 +156,7 @@ GdkPixbuf* meta_ui_get_default_mini_icon (MetaUI *ui);
gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay,
Window xwindow);
void meta_ui_set_current_theme (const char *name,
gboolean force_reload);
gboolean meta_ui_have_a_theme (void);
void meta_ui_reload_theme (void);
/* Not a real key symbol but means "key above the tab key"; this is
* used as the default keybinding for cycle_group.
......
......@@ -32,6 +32,7 @@
#include "fixedtip.h"
#include "prefs.h"
#include "ui.h"
#include "ui-private.h"
#include <cairo-xlib.h>
......@@ -352,7 +353,7 @@ meta_frames_font_changed (MetaFrames *frames)
MetaTheme *theme;
const PangoFontDescription *titlebar_font;
theme = meta_theme_get_current ();
theme = meta_ui_get_theme ();
titlebar_font = meta_prefs_get_titlebar_font ();
meta_theme_set_titlebar_font (theme, titlebar_font);
......@@ -409,7 +410,7 @@ meta_frames_style_updated (GtkWidget *widget)
frames = META_FRAMES (widget);
theme = meta_theme_get_current ();
theme = meta_ui_get_theme ();
compositing_manager = meta_prefs_get_compositing_manager ();
meta_theme_set_composited (theme, compositing_manager);
......@@ -443,8 +444,7 @@ meta_frames_ensure_layout (MetaFrames *frames,
META_CORE_GET_FRAME_TYPE, &type,
META_CORE_GET_END);
style = meta_theme_get_frame_style (meta_theme_get_current (),
type, flags);
style = meta_theme_get_frame_style (meta_ui_get_theme (), type, flags);
if (style != frame->cache_style)
{
......@@ -474,7 +474,7 @@ meta_frames_ensure_layout (MetaFrames *frames,
pango_layout_set_auto_dir (frame->text_layout, FALSE);
pango_layout_set_single_paragraph_mode (frame->text_layout, TRUE);
current = meta_theme_get_current ();
current = meta_ui_get_theme ();
font_desc = meta_theme_create_font_desc (current, frame->theme_variant);
meta_frame_style_apply_scale (style, font_desc);
......@@ -530,7 +530,7 @@ meta_frames_calc_geometry (MetaFrames *frames,
meta_prefs_get_button_layout (&button_layout);
meta_theme_calc_geometry (meta_theme_get_current (),
meta_theme_calc_geometry (meta_ui_get_theme (),
frame->theme_variant,
type,
frame->text_height,
......@@ -722,7 +722,7 @@ meta_ui_frame_get_borders (MetaFrames *frames,
* by the core move/resize code to decide on the client
* window size
*/
meta_theme_get_frame_borders (meta_theme_get_current (),
meta_theme_get_frame_borders (meta_ui_get_theme (),
frame->theme_variant,
type,
frame->text_height,
......@@ -2261,7 +2261,7 @@ populate_cache (MetaFrames *frames,
return;
}
meta_theme_get_frame_borders (meta_theme_get_current (),
meta_theme_get_frame_borders (meta_ui_get_theme (),
frame->theme_variant,
frame_type,
frame->text_height,
......@@ -2374,7 +2374,8 @@ subtract_client_area (cairo_region_t *region,
META_CORE_GET_CLIENT_WIDTH, &area.width,
META_CORE_GET_CLIENT_HEIGHT, &area.height,
META_CORE_GET_END);
meta_theme_get_frame_borders (meta_theme_get_current (),
meta_theme_get_frame_borders (meta_ui_get_theme (),
frame->theme_variant,
type, frame->text_height, flags,
&borders);
......@@ -2720,7 +2721,7 @@ meta_frames_paint (MetaFrames *frames,