mutter/patches/ubuntu/darkMode-Add-support-to-Yaru-theme-color-variants.patch
Ward Nakchbandi (Cosmic Fusion) deaf92469b
2023-10-03 21:58:03 +03:00

82 lines
3.2 KiB
Diff

From: =?utf-8?b?Ik1hcmNvIFRyZXZpc2FuIChUcmV2acOxbyki?= <mail@3v1n0.net>
Date: Wed, 24 Aug 2022 19:15:36 +0200
Subject: darkMode: Add support to Yaru theme color variants
Support switching to dark mode when using the Yaru theme color accents.
---
js/ui/status/darkMode.js | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/js/ui/status/darkMode.js b/js/ui/status/darkMode.js
index 4e68a74..321a88b 100644
--- a/js/ui/status/darkMode.js
+++ b/js/ui/status/darkMode.js
@@ -1,5 +1,6 @@
import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
+import St from 'gi://St';
import * as Main from '../main.js';
@@ -19,6 +20,9 @@ class DarkModeToggle extends QuickToggle {
this._changedId = this._settings.connect('changed::color-scheme',
() => this._sync());
+ St.Settings.get().connect('notify::gtk-theme', () => this._sync());
+ St.Settings.get().connect('notify::gtk-theme-variant', () => this._sync());
+
this.connectObject(
'destroy', () => this._settings.run_dispose(),
'clicked', () => this._toggleMode(),
@@ -28,13 +32,49 @@ class DarkModeToggle extends QuickToggle {
_toggleMode() {
Main.layoutManager.screenTransition.run();
+ const preferDark = !this.checked;
+ const {gtkTheme, gtkThemeVariant} = St.Settings.get();
+ const themeVariant = gtkThemeVariant?.toLowerCase();
this._settings.set_string('color-scheme',
this.checked ? 'default' : 'prefer-dark');
+
+ if (gtkTheme === 'Yaru')
+ this._setYaruSettings(themeVariant, preferDark);
+ }
+
+ _setYaruSettings(themeVariant, preferDark) {
+ const currentlyDark = themeVariant === 'dark' || themeVariant?.endsWith('-dark');
+ if (currentlyDark)
+ themeVariant = themeVariant.slice(0, -'-dark'.length);
+
+ if (currentlyDark !== preferDark) {
+ const newTheme = `Yaru${
+ themeVariant ? `-${themeVariant}` : ''}${
+ preferDark ? '-dark' : ''}`;
+
+ this._settings.set_string('gtk-theme', newTheme);
+ this._settings.set_string('icon-theme', newTheme);
+ }
+
+ const schemaSource = Gio.SettingsSchemaSource.get_default();
+ const geditSchema = schemaSource.lookup('org.gnome.gedit.preferences.editor', true);
+
+ if (geditSchema) {
+ const geditSettings = Gio.Settings.new_full(geditSchema, null, null);
+ const geditScheme = geditSettings.get_user_value('scheme')?.unpack();
+
+ if (geditScheme?.startsWith('Yaru') &&
+ geditScheme.endsWith('-dark') !== preferDark)
+ geditSettings.set_string('scheme', `Yaru${preferDark ? '-dark' : ''}`);
+ }
}
_sync() {
const colorScheme = this._settings.get_string('color-scheme');
- const checked = colorScheme === 'prefer-dark';
+ const {gtkTheme, gtkThemeVariant} = St.Settings.get();
+ let checked = colorScheme === 'prefer-dark';
+ if (gtkTheme === 'Yaru' && !gtkThemeVariant?.endsWith('dark'))
+ checked = false;
if (this.checked !== checked)
this.set({checked});
}