From 55cbe285809a6d63424fc92b0cde887ee919a0db Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 29 2022 18:48:09 +0000 Subject: [PATCH 1/4] Fix visibility in dark mode gnome-shell uses a different setting when dark mode is active. Account for that when checking whether the current background corresponds to the setting's default value. --- diff --git a/extension.js b/extension.js index 403cc5a..7994e5d 100644 --- a/extension.js +++ b/extension.js @@ -54,6 +54,9 @@ class BackgroundLogo extends St.Widget { this._logoFile = null; this._settings = ExtensionUtils.getSettings(); + this._ifaceSettings = new Gio.Settings({ + schema_id: 'org.gnome.desktop.interface', + }); this._settings.connect('changed::logo-file', this._updateLogo.bind(this)); @@ -197,7 +200,11 @@ class BackgroundLogo extends St.Widget { _updateVisibility() { const { background } = this._backgroundActor.content; - let defaultUri = background._settings.get_default_value('picture-uri'); + const colorScheme = this._ifaceSettings.get_string('color-scheme'); + const uriKey = colorScheme === 'prefer-dark' + ? 'picture-uri-dark' + : 'picture-uri'; + const defaultUri = background._settings.get_default_value(uriKey); let file = Gio.File.new_for_commandline_arg(defaultUri.deep_unpack()); let visible; From 878dd487168f8f5e4015c194f32df5bfc1b4d3bb Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 29 2022 18:48:19 +0000 Subject: [PATCH 2/4] Use different logo file in dark mode As gnome-shell uses a different background in dark mode, it makes sense to do the same for the overlaid logo (instead of expecting the same logo to work equally well in both). --- diff --git a/extension.js b/extension.js index 7994e5d..e53ae1f 100644 --- a/extension.js +++ b/extension.js @@ -60,6 +60,8 @@ class BackgroundLogo extends St.Widget { this._settings.connect('changed::logo-file', this._updateLogo.bind(this)); + this._settings.connect('changed::logo-file-dark', + this._updateLogo.bind(this)); this._settings.connect('changed::logo-size', this._updateScale.bind(this)); this._settings.connect('changed::logo-position', @@ -105,7 +107,11 @@ class BackgroundLogo extends St.Widget { } _updateLogo() { - let filename = this._settings.get_string('logo-file'); + const colorScheme = this._ifaceSettings.get_string('color-scheme'); + const fileKey = colorScheme === 'prefer-dark' + ? 'logo-file-dark' + : 'logo-file'; + const filename = this._settings.get_string(fileKey); let file = Gio.File.new_for_commandline_arg(filename); if (this._logoFile && this._logoFile.equal(file)) return; diff --git a/schemas/org.fedorahosted.background-logo-extension.gschema.xml b/schemas/org.fedorahosted.background-logo-extension.gschema.xml index 74bc3a8..14f6793 100644 --- a/schemas/org.fedorahosted.background-logo-extension.gschema.xml +++ b/schemas/org.fedorahosted.background-logo-extension.gschema.xml @@ -17,6 +17,11 @@ Logo file The full logo file path + + '/usr/share/fedora-logos/fedora_darkbackground.svg' + Logo file in dark mode + The full logo file path for dark mode + 'bottom-right' From 2f8569f0ec1a96fc58859cb42043e16b7227bc45 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 29 2022 23:56:29 +0000 Subject: [PATCH 3/4] prefs: Allow setting dark logo file The group is getting quite crowded with the additional row, but I don't have a better idea for now … --- diff --git a/prefs.js b/prefs.js index 8070a96..6970695 100644 --- a/prefs.js +++ b/prefs.js @@ -146,6 +146,7 @@ class LogoGroup extends Adw.PreferencesGroup { super._init({ title: 'Logo' }); this._settings = settings; + this._fileChooserKey = ''; const filter = new Gtk.FileFilter(); filter.add_pixbuf_formats(); @@ -158,25 +159,42 @@ class LogoGroup extends Adw.PreferencesGroup { this._fileChooser.connect('response', (dlg, response) => { if (response !== Gtk.ResponseType.ACCEPT) return; - this._settings.set_string('logo-file', dlg.get_file().get_path()); + this._settings.set_string(this._fileChooserKey, + dlg.get_file().get_path()); }); this._filenameLabel = new Gtk.Label(); + this._filenameDarkLabel = new Gtk.Label(); this._settings.connect('changed::logo-file', - () => this._updateFilenameLabel()); - this._updateFilenameLabel(); + () => this._updateFilenameLabels()); + this._settings.connect('changed::logo-file-dark', + () => this._updateFilenameLabels()); + this._updateFilenameLabels(); const filenameRow = new Adw.ActionRow({ title: 'Filename', activatable: true, }); filenameRow.connect('activated', () => { + this._fileChooserKey = 'logo-file'; this._fileChooser.transient_for = this.get_root(); this._fileChooser.show(); }); filenameRow.add_suffix(this._filenameLabel); this.add(filenameRow); + const filenameDarkRow = new Adw.ActionRow({ + title: 'Filename (dark)', + activatable: true, + }); + filenameDarkRow.connect('activated', () => { + this._fileChooserKey = 'logo-file-dark'; + this._fileChooser.transient_for = this.get_root(); + this._fileChooser.show(); + }); + filenameDarkRow.add_suffix(this._filenameDarkLabel); + this.add(filenameDarkRow); + const positionModel = new Gio.ListStore({ item_type: LogoPosition }); positionModel.append(new LogoPosition('Center', 'center')); positionModel.append(new LogoPosition('Bottom left', 'bottom-left')); @@ -248,9 +266,12 @@ class LogoGroup extends Adw.PreferencesGroup { return adj; } - _updateFilenameLabel() { + _updateFilenameLabels() { const filename = this._settings.get_string('logo-file'); this._filenameLabel.label = GLib.basename(filename); + + const filenameDark = this._settings.get_string('logo-file-dark'); + this._filenameDarkLabel.label = GLib.basename(filenameDark); } on_destroy() { From 46ff6960b0405f9871febe28e202f2879f1aa6ad Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 30 2022 00:02:03 +0000 Subject: [PATCH 4/4] prefs: React to dark-mode changes Instead of always showing the default background and logo, preview the dark alternatives when dark mode is active. --- diff --git a/prefs.js b/prefs.js index 6970695..f2eada9 100644 --- a/prefs.js +++ b/prefs.js @@ -25,12 +25,19 @@ class PreviewGroup extends Adw.PreferencesGroup { this._settings = settings; this._settings.connect('changed', (s, key) => { - if (key === 'logo-file' || + if (key === this._logoKey || key === 'logo-size') this._logo = null; this._preview.queue_draw(); }); + this._styleManager = Adw.StyleManager.get_default(); + this._styleManager.connect('notify::dark', () => { + this._background = null; + this._logo = null; + this._preview.queue_draw(); + }); + this._preview = new Gtk.DrawingArea({ halign: Gtk.Align.CENTER, margin_bottom: 12, @@ -77,7 +84,10 @@ class PreviewGroup extends Adw.PreferencesGroup { _createBackgroundThumbnail(width, height) { let settings = new Gio.Settings({ schema_id: BACKGROUND_SCHEMA }); - let uri = settings.get_default_value('picture-uri').deep_unpack(); + const bgKey = this._styleManager.dark + ? 'picture-uri-dark' + : 'picture-uri'; + let uri = settings.get_default_value(bgKey).deep_unpack(); let file = Gio.File.new_for_commandline_arg(uri); if (uri.endsWith('.xml')) @@ -88,7 +98,10 @@ class PreviewGroup extends Adw.PreferencesGroup { } _createLogoThumbnail(width) { - let filename = this._settings.get_string('logo-file'); + this._logoKey = this._styleManager.dark + ? 'logo-file-dark' + : 'logo-file'; + let filename = this._settings.get_string(this._logoKey); let file = Gio.File.new_for_commandline_arg(filename); let pixbuf = GdkPixbuf.Pixbuf.new_from_file(file.get_path()); let size = this._settings.get_double('logo-size') / 100;