diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in
index 215a150..371ebf4 100644
--- a/data/org.x.editor.gschema.xml.in
+++ b/data/org.x.editor.gschema.xml.in
@@ -41,6 +41,12 @@
A custom font that will be used for the editing area. This will only take effect if the "Use Default Font" option is turned off.
+
+ false
+ Prefer Dark Theme
+ Whether xed should prefer the dark variation of the current Gtk theme if available.
+
+
'tango'
Style Scheme
diff --git a/xed/resources/ui/xed-preferences-dialog.ui b/xed/resources/ui/xed-preferences-dialog.ui
index 8aa0957..7194dd4 100755
--- a/xed/resources/ui/xed-preferences-dialog.ui
+++ b/xed/resources/ui/xed-preferences-dialog.ui
@@ -1118,6 +1118,22 @@
0
+
+
+
+ False
+ False
+ 1
+
+
diff --git a/xed/xed-app.c b/xed/xed-app.c
index 930d6cf..ffb202c 100644
--- a/xed/xed-app.c
+++ b/xed/xed-app.c
@@ -80,6 +80,7 @@ struct _XedAppPrivate
GObject *settings;
GSettings *window_settings;
+ GSettings *editor_settings;
PeasExtensionSet *extensions;
@@ -168,6 +169,7 @@ xed_app_dispose (GObject *object)
XedApp *app = XED_APP (object);
g_clear_object (&app->priv->window_settings);
+ g_clear_object (&app->priv->editor_settings);
g_clear_object (&app->priv->settings);
g_clear_object (&app->priv->page_setup);
g_clear_object (&app->priv->print_settings);
@@ -209,6 +211,18 @@ extension_removed (PeasExtensionSet *extensions,
peas_extension_call (exten, "deactivate");
}
+static void
+set_initial_theme_style (XedApp *app)
+{
+ if (g_settings_get_boolean (app->priv->editor_settings, XED_SETTINGS_PREFER_DARK_THEME))
+ {
+ GtkSettings *gtk_settings;
+
+ gtk_settings = gtk_settings_get_default ();
+ g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL);
+ }
+}
+
static void
xed_app_startup (GApplication *application)
{
@@ -248,6 +262,9 @@ xed_app_startup (GApplication *application)
/* Load settings */
app->priv->settings = xed_settings_new ();
app->priv->window_settings = g_settings_new ("org.x.editor.state.window");
+ app->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor");
+
+ set_initial_theme_style (app);
/*
* We use the default gtksourceview style scheme manager so that plugins
diff --git a/xed/xed-preferences-dialog.c b/xed/xed-preferences-dialog.c
index 0046c4a..7045259 100755
--- a/xed/xed-preferences-dialog.c
+++ b/xed/xed-preferences-dialog.c
@@ -89,6 +89,7 @@ struct _XedPreferencesDialogPrivate
GtkWidget *font_hbox;
/* Style Scheme */
+ GtkWidget *prefer_dark_theme_checkbutton;
GtkListStore *schemes_treeview_model;
GtkWidget *schemes_treeview;
GtkWidget *install_scheme_button;
@@ -1050,6 +1051,12 @@ setup_font_colors_page (XedPreferencesDialog *dlg)
{
setup_font_colors_page_font_section (dlg);
setup_font_colors_page_style_scheme_section (dlg);
+
+ g_settings_bind (dlg->priv->editor,
+ XED_SETTINGS_PREFER_DARK_THEME,
+ dlg->priv->prefer_dark_theme_checkbutton,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
}
static void
@@ -1127,6 +1134,7 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg)
dlg->priv->default_font_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "default_font_checkbutton"));
dlg->priv->font_button = GTK_WIDGET (gtk_builder_get_object (builder, "font_button"));
dlg->priv->font_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "font_hbox"));
+ dlg->priv->prefer_dark_theme_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "prefer_dark_theme_checkbutton"));
dlg->priv->schemes_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "schemes_treeview"));
dlg->priv->install_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "install_scheme_button"));
dlg->priv->uninstall_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "uninstall_scheme_button"));
diff --git a/xed/xed-settings.c b/xed/xed-settings.c
index b484aeb..3a1d02d 100644
--- a/xed/xed-settings.c
+++ b/xed/xed-settings.c
@@ -176,6 +176,20 @@ on_editor_font_changed (GSettings *settings,
g_free (font);
}
+static void
+on_prefer_dark_theme_changed (GSettings *settings,
+ const gchar *key,
+ XedSettings *xs)
+{
+ GtkSettings *gtk_settings;
+ gboolean prefer_dark_theme;
+
+ prefer_dark_theme = g_settings_get_boolean (xs->priv->editor, XED_SETTINGS_PREFER_DARK_THEME);
+ gtk_settings = gtk_settings_get_default ();
+
+ g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", prefer_dark_theme, NULL);
+}
+
static void
on_scheme_changed (GSettings *settings,
const gchar *key,
@@ -375,6 +389,8 @@ xed_settings_init (XedSettings *xs)
G_CALLBACK (on_use_default_font_changed), xs);
g_signal_connect (xs->priv->editor, "changed::editor-font",
G_CALLBACK (on_editor_font_changed), xs);
+ g_signal_connect (xs->priv->editor, "changed::prefer-dark-theme",
+ G_CALLBACK (on_prefer_dark_theme_changed), xs);
g_signal_connect (xs->priv->editor, "changed::scheme",
G_CALLBACK (on_scheme_changed), xs);
g_signal_connect (xs->priv->editor, "changed::auto-save",
diff --git a/xed/xed-settings.h b/xed/xed-settings.h
index cf1b736..f65c01f 100644
--- a/xed/xed-settings.h
+++ b/xed/xed-settings.h
@@ -55,19 +55,10 @@ struct _XedSettingsClass
GObjectClass parent_class;
};
-// typedef enum {
-// XED_TOOLBAR_SYSTEM = 0,
-// XED_TOOLBAR_ICONS,
-// XED_TOOLBAR_ICONS_AND_TEXT,
-// XED_TOOLBAR_ICONS_BOTH_HORIZ
-// } XedToolbarSetting;
-
GType xed_settings_get_type (void) G_GNUC_CONST;
GObject *xed_settings_new (void);
-// XedLockdownMask xed_settings_get_lockdown (XedSettings *xs);
-
gchar *xed_settings_get_system_font (XedSettings *xs);
/* Utility functions */
@@ -81,6 +72,7 @@ void xed_settings_set_list (GSettings *settings,
/* key constants */
#define XED_SETTINGS_USE_DEFAULT_FONT "use-default-font"
#define XED_SETTINGS_EDITOR_FONT "editor-font"
+#define XED_SETTINGS_PREFER_DARK_THEME "prefer-dark-theme"
#define XED_SETTINGS_SCHEME "scheme"
#define XED_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy"
#define XED_SETTINGS_AUTO_SAVE "auto-save"