Skip to content

Commit

Permalink
Revert "dark mode: Delegate to libxapp"
Browse files Browse the repository at this point in the history
This reverts commit 233bc4a.

Xed is a bit of an exception. It's light by default but many people
want to be able to make it dark.

Using prefer-dark globally with a light theme is a no-go, it makes
firefox and many other apps dark.

This revert brings back the ability to make Xed dark without using
the global setting.
  • Loading branch information
clefebvre committed Jun 26, 2023
1 parent bcf5550 commit 40fa3ed
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 6 deletions.
6 changes: 6 additions & 0 deletions data/org.x.editor.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<description>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.</description>
</key>

<key name="prefer-dark-theme" type="b">
<default>false</default>
<summary>Prefer Dark Theme</summary>
<description>Whether xed should prefer the dark variation of the current Gtk theme if available.</description>
</key>

<key name="scheme" type="s">
<default>'tango'</default>
<summary>Style Scheme</summary>
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
55 changes: 55 additions & 0 deletions xed/resources/ui/xed-preferences-dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,61 @@
<property name="border_width">12</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label21">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Dark theme</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.1000000000000001"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box25">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">32</property>
<property name="margin_right">32</property>
<child>
<object class="GtkLabel" id="label20">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Use dark theme variant (if available)</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="prefer_dark_theme_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label22">
<property name="visible">True</property>
Expand Down
18 changes: 14 additions & 4 deletions xed/xed-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <glib/gi18n.h>
#include <libpeas/peas-extension-set.h>
#include <gtksourceview/gtksource.h>
#include <libxapp/xapp-dark-mode-manager.h>

#ifdef ENABLE_INTROSPECTION
#include <girepository.h>
Expand Down Expand Up @@ -77,7 +76,6 @@ struct _XedAppPrivate
GObject *settings;
GSettings *window_settings;
GSettings *editor_settings;
XAppDarkModeManager *dark_mode_manager;

PeasExtensionSet *extensions;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions xed/xed-preferences-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
16 changes: 16 additions & 0 deletions xed/xed-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions xed/xed-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 40fa3ed

Please sign in to comment.