diff options
author | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2016-02-23 03:10:39 +0200 |
---|---|---|
committer | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2016-02-23 03:10:39 +0200 |
commit | 7ecb3e035c593703601bedb855010fbdc3b7cb16 (patch) | |
tree | b9ac8d1c35f5284d26df43e9364a0e574cd0ada8 /src | |
parent | c9f01260c4cbb2212113a9669db3522301fadaf3 (diff) | |
download | metacity-7ecb3e035c593703601bedb855010fbdc3b7cb16.tar.gz |
theme: redo theme settings
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/core/display.c | 3 | ||||
-rw-r--r-- | src/core/frame.c | 43 | ||||
-rw-r--r-- | src/core/main.c | 41 | ||||
-rw-r--r-- | src/core/prefs.c | 63 | ||||
-rw-r--r-- | src/include/prefs.h | 14 | ||||
-rw-r--r-- | src/include/ui.h | 4 | ||||
-rw-r--r-- | src/ui/frames.c | 21 | ||||
-rw-r--r-- | src/ui/ui-private.h | 29 | ||||
-rw-r--r-- | src/ui/ui.c | 108 |
10 files changed, 182 insertions, 145 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d652ad11..4f3f6ec4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/core/display.c b/src/core/display.c index 5c262d9f..1cffd62f 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -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 == diff --git a/src/core/frame.c b/src/core/frame.c index f806f668..93ed8847 100644 --- a/src/core/frame.c +++ b/src/core/frame.c @@ -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); } } diff --git a/src/core/main.c b/src/core/main.c index 306356a6..85ec4245 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -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; diff --git a/src/core/prefs.c b/src/core/prefs.c index b547dfb4..04d65959 100644 --- a/src/core/prefs.c +++ b/src/core/prefs.c @@ -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, + }, + ¤t_theme_type, + }, { { NULL, 0, 0 }, NULL }, }; @@ -376,14 +385,6 @@ static MetaStringPreference preferences_string[] = NULL, }, { - { "theme", - SCHEMA_METACITY, - META_PREF_THEME, - }, - theme_name_handler, - NULL, - }, - { { KEY_TITLEBAR_FONT, SCHEMA_GENERAL, META_PREF_TITLEBAR_FONT, @@ -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"; diff --git a/src/include/prefs.h b/src/include/prefs.h index 529d8c05..166c3361 100644 --- a/src/include/prefs.h +++ b/src/include/prefs.h @@ -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 - - - - diff --git a/src/include/ui.h b/src/include/ui.h index e1f53891..353d1a02 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -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. diff --git a/src/ui/frames.c b/src/ui/frames.c index a7bd8d89..92191017 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -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, meta_prefs_get_button_layout (&button_layout); - meta_theme_draw_frame (meta_theme_get_current (), + meta_theme_draw_frame (meta_ui_get_theme (), frame->theme_variant, cr, type, diff --git a/src/ui/ui-private.h b/src/ui/ui-private.h new file mode 100644 index 00000000..88a1b02c --- /dev/null +++ b/src/ui/ui-private.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2016 Alberts Muktupāvels + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef META_UI_PRIVATE_H +#define META_UI_PRIVATE_H + +#include <libmetacity/meta-theme.h> + +G_BEGIN_DECLS + +MetaTheme *meta_ui_get_theme (void); + +G_END_DECLS + +#endif diff --git a/src/ui/ui.c b/src/ui/ui.c index ef22a4bb..40140369 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -19,8 +19,11 @@ * along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" + #include "prefs.h" #include "ui.h" +#include "ui-private.h" #include "frames.h" #include "util.h" #include "menu.h" @@ -31,6 +34,11 @@ #include <cairo-xlib.h> #include <libmetacity/meta-theme.h> +/** + * The current theme. (Themes are singleton.) + */ +static MetaTheme *meta_current_theme = NULL; + static void meta_ui_accelerator_parse (const char *accel, guint *keysym, guint *keycode, @@ -667,51 +675,105 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameFlags flags, MetaFrameBorders *borders) { - int text_height; - PangoContext *context; + MetaTheme *theme; + const gchar *theme_variant; PangoFontDescription *font_desc; + PangoContext *context; + gint text_height; - if (meta_ui_have_a_theme ()) - { - MetaTheme *current; + theme = meta_ui_get_theme (); + theme_variant = NULL; - current = meta_theme_get_current (); + font_desc = meta_theme_create_font_desc (theme, theme_variant); + context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); - font_desc = meta_theme_create_font_desc (current, NULL); - context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); + text_height = meta_pango_font_desc_get_text_height (font_desc, context); + pango_font_description_free (font_desc); - text_height = meta_pango_font_desc_get_text_height (font_desc, context); - pango_font_description_free (font_desc); + meta_theme_get_frame_borders (theme, theme_variant, type, + text_height, flags, borders); +} - meta_theme_get_frame_borders (current, - NULL, /* FIXME: theme variant*/ - type, text_height, flags, - borders); +MetaTheme * +meta_ui_get_theme (void) +{ + return meta_current_theme; +} + +static gchar * +get_theme_name (MetaThemeType theme_type) +{ + gchar *theme_name; + + if (theme_type == META_THEME_TYPE_METACITY) + { + theme_name = g_strdup (meta_prefs_get_theme_name ()); } else { - meta_frame_borders_clear (borders); + GtkSettings *settings; + + settings = gtk_settings_get_default (); + + g_object_get (settings, "gtk-theme-name", &theme_name, NULL); } + + return theme_name; } -void -meta_ui_set_current_theme (const char *name, - gboolean force_reload) +static MetaTheme * +load_theme (MetaThemeType theme_type, + const gchar *theme_name) { + MetaTheme *theme; gboolean compositing_manager; const PangoFontDescription *titlebar_font; + GError *error; + + theme = meta_theme_new (theme_type); compositing_manager = meta_prefs_get_compositing_manager (); + meta_theme_set_composited (theme, compositing_manager); + titlebar_font = meta_prefs_get_titlebar_font (); + meta_theme_set_titlebar_font (theme, titlebar_font); - meta_theme_set_current (name, force_reload, compositing_manager, titlebar_font); - meta_invalidate_default_icons (); + error = NULL; + if (!meta_theme_load (theme, theme_name, &error)) + { + g_warning ("%s", error->message); + g_error_free (error); + + g_object_unref (theme); + return NULL; + } + + return theme; } -gboolean -meta_ui_have_a_theme (void) +void +meta_ui_reload_theme (void) { - return meta_theme_get_current () != NULL; + MetaThemeType theme_type; + gchar *theme_name; + MetaTheme *theme; + + theme_type = meta_prefs_get_theme_type (); + theme_name = get_theme_name (theme_type); + + theme = load_theme (theme_type, theme_name); + g_free (theme_name); + + if (theme == NULL) + { + g_warning (_("Falling back to default GTK+ theme - Adwaita")); + theme = load_theme (META_THEME_TYPE_GTK, "Adwaita"); + } + + g_set_object (&meta_current_theme, theme); + g_assert (meta_current_theme); + + meta_invalidate_default_icons (); } static void |