diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in
index 322ad49b..9418cda9 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/debian/control b/debian/control
index 6e84ffed..c433a54d 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ Build-Depends: debhelper-compat (= 12),
libgtk-3-dev,
libgtksourceview-4-dev,
libpeas-dev,
- libxapp-dev (>= 2.5.0),
+ libxapp-dev (>= 1.9),
libx11-dev,
libxml2-dev,
python3,
diff --git a/meson.build b/meson.build
index d9bc5cff..8a39348d 100644
--- a/meson.build
+++ b/meson.build
@@ -34,7 +34,7 @@ libpeas = dependency('libpeas-1.0', version: '>= 1.12.0')
libpeas_gtk = dependency('libpeas-gtk-1.0', version: '>= 1.12.0')
gir_dep = dependency('gobject-introspection-1.0', version: '>= 1.42.0', required: false)
gmodule = dependency('gmodule-2.0')
-xapp = dependency('xapp', version: '>= 2.5.0')
+xapp = dependency('xapp', version: '>= 1.9.0')
X11 = dependency('x11')
pango = dependency('pango')
diff --git a/xed/resources/ui/xed-preferences-dialog.ui b/xed/resources/ui/xed-preferences-dialog.ui
index 5f6c070f..2929d33d 100644
--- a/xed/resources/ui/xed-preferences-dialog.ui
+++ b/xed/resources/ui/xed-preferences-dialog.ui
@@ -1203,6 +1203,61 @@
12
vertical
6
+
+
+
+ False
+ False
+ 0
+
+
+
+
+
+ False
+ True
+ 1
+
+
True
diff --git a/xed/xed-app.c b/xed/xed-app.c
index bfddbe52..1ccf033b 100644
--- a/xed/xed-app.c
+++ b/xed/xed-app.c
@@ -36,7 +36,6 @@
#include
#include
#include
-#include
#ifdef ENABLE_INTROSPECTION
#include
@@ -77,7 +76,6 @@ struct _XedAppPrivate
GObject *settings;
GSettings *window_settings;
GSettings *editor_settings;
- XAppDarkModeManager *dark_mode_manager;
PeasExtensionSet *extensions;
@@ -167,7 +165,6 @@ xed_app_dispose (GObject *object)
g_clear_object (&app->priv->window_settings);
g_clear_object (&app->priv->editor_settings);
- g_clear_object (&app->priv->dark_mode_manager);
g_clear_object (&app->priv->settings);
g_clear_object (&app->priv->page_setup);
g_clear_object (&app->priv->print_settings);
@@ -209,6 +206,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
theme_changed (GtkSettings *settings,
GParamSpec *pspec,
@@ -302,7 +311,8 @@ xed_app_startup (GApplication *application)
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");
- app->priv->dark_mode_manager = xapp_dark_mode_manager_new (FALSE);
+
+ set_initial_theme_style (app);
/* Load custom css */
css_file = g_file_new_for_uri ("resource:///org/x/editor/css/xed-style.css");
diff --git a/xed/xed-preferences-dialog.c b/xed/xed-preferences-dialog.c
index e9a3ed77..fe44e451 100644
--- a/xed/xed-preferences-dialog.c
+++ b/xed/xed-preferences-dialog.c
@@ -127,6 +127,7 @@ struct _XedPreferencesDialog
GtkWidget *tab_scrolling_switch;
/* Style scheme */
+ GtkWidget *prefer_dark_theme_switch;
GtkWidget *schemes_list;
GtkWidget *install_scheme_button;
GtkWidget *uninstall_scheme_button;
@@ -200,6 +201,7 @@ xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, ensure_newline_switch);
/* Theme page widgets */
+ gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, prefer_dark_theme_switch);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, schemes_list);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, install_scheme_button);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, uninstall_scheme_button);
@@ -855,6 +857,13 @@ setup_theme_page (XedPreferencesDialog *dlg)
xed_debug (DEBUG_PREFS);
+ /* Prefer dark theme */
+ g_settings_bind (dlg->editor_settings,
+ XED_SETTINGS_PREFER_DARK_THEME,
+ dlg->prefer_dark_theme_switch,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
/* Style scheme */
scheme = get_default_color_scheme (dlg);
diff --git a/xed/xed-settings.c b/xed/xed-settings.c
index 22977922..5002a428 100644
--- a/xed/xed-settings.c
+++ b/xed/xed-settings.c
@@ -174,6 +174,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,
@@ -363,6 +377,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 a49f3ff3..71790c8e 100644
--- a/xed/xed-settings.h
+++ b/xed/xed-settings.h
@@ -72,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"