#38 Fix visibility in dark mode
Merged 2 years ago by fmuellner. Opened 2 years ago by fmuellner.
fmuellner/background-logo-extension fix-dark-mode  into  master

prefs: React to dark-mode changes
Florian Müllner • 2 years ago  
prefs: Allow setting dark logo file
Florian Müllner • 2 years ago  
Use different logo file in dark mode
Florian Müllner • 2 years ago  
Fix visibility in dark mode
Florian Müllner • 2 years ago  
file modified
+15 -2
@@ -54,9 +54,14 @@ 

          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));

+         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',
@@ -102,7 +107,11 @@ 

      }

  

      _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;
@@ -197,7 +206,11 @@ 

  

      _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;

file modified
+41 -7
@@ -25,12 +25,19 @@ 

  

          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 @@ 

  

      _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 @@ 

      }

  

      _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;
@@ -146,6 +159,7 @@ 

          super._init({ title: 'Logo' });

  

          this._settings = settings;

+         this._fileChooserKey = '';

  

          const filter = new Gtk.FileFilter();

          filter.add_pixbuf_formats();
@@ -158,25 +172,42 @@ 

          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 +279,12 @@ 

          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() {

@@ -17,6 +17,11 @@ 

        <summary>Logo file</summary>

        <description>The full logo file path</description>

      </key>

+     <key type="s" name="logo-file-dark">

+       <default>'/usr/share/fedora-logos/fedora_darkbackground.svg'</default>

+       <summary>Logo file in dark mode</summary>

+       <description>The full logo file path for dark mode</description>

+     </key>

      <key name="logo-position"

           enum="org.fedorahosted.background-logo-extension.Position">

        <default>'bottom-right'</default>

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.

rebased onto 55cbe28

2 years ago

2 new commits added

  • prefs: React to dark-mode changes
  • prefs: Allow setting dark logo file
2 years ago

Pull-Request has been merged by fmuellner

2 years ago