From 90964d30baf9088d2444dcdf3c2fa6a4c7ad1301 Mon Sep 17 00:00:00 2001
From: Bobby Rong <rjl931189261@126.com>
Date: Sun, 30 Jan 2022 12:40:25 +0800
Subject: [PATCH] pantheon.switchboard-plug-about: introduces a wallpaper meson
 flag

After some thought, it doesn't make sense to just keep the wallpaper.
---
 .../about/add-wallpaper-option.patch          | 82 +++++++++++++++++++
 .../apps/switchboard-plugs/about/default.nix  | 15 ++--
 .../about/fix-background-path.patch           | 13 ---
 3 files changed, 91 insertions(+), 19 deletions(-)
 create mode 100644 pkgs/desktops/pantheon/apps/switchboard-plugs/about/add-wallpaper-option.patch
 delete mode 100644 pkgs/desktops/pantheon/apps/switchboard-plugs/about/fix-background-path.patch

diff --git a/pkgs/desktops/pantheon/apps/switchboard-plugs/about/add-wallpaper-option.patch b/pkgs/desktops/pantheon/apps/switchboard-plugs/about/add-wallpaper-option.patch
new file mode 100644
index 000000000000..657ea7a260c9
--- /dev/null
+++ b/pkgs/desktops/pantheon/apps/switchboard-plugs/about/add-wallpaper-option.patch
@@ -0,0 +1,82 @@
+From cc47fa33893e6840463ef8d59f9f4de4b7563726 Mon Sep 17 00:00:00 2001
+From: Bobby Rong <rjl931189261@126.com>
+Date: Sat, 4 Dec 2021 22:00:38 +0800
+Subject: [PATCH] Add meson option for overlaying logo on wallpaper
+
+---
+ meson.build                        | 8 ++++++++
+ meson_options.txt                  | 1 +
+ src/Views/OperatingSystemView.vala | 8 ++++++++
+ 3 files changed, 17 insertions(+)
+ create mode 100644 meson_options.txt
+
+diff --git a/meson.build b/meson.build
+index 2125de6e..cbe3cadd 100644
+--- a/meson.build
++++ b/meson.build
+@@ -20,6 +20,14 @@ add_project_arguments(
+ vapi_dir = join_paths(meson.current_source_dir(), 'vapi')
+ add_project_arguments(['--vapidir', vapi_dir], language: 'vala')
+ 
++vala_flags = []
++
++if get_option('wallpaper')
++    vala_flags += ['--define', 'WALLPAPER']
++endif
++
++add_project_arguments(vala_flags, language: 'vala')
++
+ subdir('data')
+ subdir('src')
+ subdir('po')
+diff --git a/meson_options.txt b/meson_options.txt
+new file mode 100644
+index 00000000..8cef0bb3
+--- /dev/null
++++ b/meson_options.txt
+@@ -0,0 +1 @@
++option('wallpaper', type : 'boolean', value : true, description : 'Overlay logo on default wallpaper')
+diff --git a/src/Views/OperatingSystemView.vala b/src/Views/OperatingSystemView.vala
+index fdb92e7e..6110d1aa 100644
+--- a/src/Views/OperatingSystemView.vala
++++ b/src/Views/OperatingSystemView.vala
+@@ -39,6 +39,7 @@ public class About.OperatingSystemView : Gtk.Grid {
+             logo_icon_name = "distributor-logo";
+         }
+ 
++#if WALLPAPER
+         var logo = new Hdy.Avatar (128, "", false) {
+             // In case the wallpaper can't be loaded, we don't want an icon or text
+             icon_name = "invalid-icon-name",
+@@ -53,6 +54,7 @@ public class About.OperatingSystemView : Gtk.Grid {
+             }
+         });
+         logo.get_style_context ().add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
++#endif
+ 
+         var icon = new Gtk.Image () {
+             icon_name = logo_icon_name + "-symbolic",
+@@ -64,9 +66,11 @@ public class About.OperatingSystemView : Gtk.Grid {
+         icon_style_context.add_class ("logo");
+         icon_style_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
+ 
++#if WALLPAPER
+         var logo_overlay = new Gtk.Overlay ();
+         logo_overlay.add (logo);
+         logo_overlay.add_overlay (icon);
++#endif
+ 
+         // Intentionally not using GLib.OsInfoKey.PRETTY_NAME here because we
+         // want more granular control over text formatting
+@@ -145,7 +149,11 @@ public class About.OperatingSystemView : Gtk.Grid {
+             valign = Gtk.Align.CENTER,
+             vexpand = true
+         };
++#if WALLPAPER
+         software_grid.attach (logo_overlay, 0, 0, 1, 4);
++#else
++        software_grid.attach (icon, 0, 0, 1, 4);
++#endif
+         software_grid.attach (title, 1, 0, 3);
+ 
+         software_grid.attach (kernel_version_label, 1, 2, 3);
diff --git a/pkgs/desktops/pantheon/apps/switchboard-plugs/about/default.nix b/pkgs/desktops/pantheon/apps/switchboard-plugs/about/default.nix
index 03964284ed73..29fce055f5f4 100644
--- a/pkgs/desktops/pantheon/apps/switchboard-plugs/about/default.nix
+++ b/pkgs/desktops/pantheon/apps/switchboard-plugs/about/default.nix
@@ -2,7 +2,6 @@
 , stdenv
 , fetchFromGitHub
 , nix-update-script
-, substituteAll
 , meson
 , ninja
 , pkg-config
@@ -30,11 +29,10 @@ stdenv.mkDerivation rec {
   };
 
   patches = [
-    # Use NixOS's default wallpaper
-    (substituteAll {
-      src = ./fix-background-path.patch;
-      default_wallpaper = "${nixos-artwork.wallpapers.simple-dark-gray.gnomeFilePath}";
-    })
+    # Introduces a wallpaper meson flag.
+    # The wallpapaper path does not exist on NixOS, let's just remove the wallpaper.
+    # https://github.com/elementary/switchboard-plug-about/pull/236
+    ./add-wallpaper-option.patch
   ];
 
   nativeBuildInputs = [
@@ -55,6 +53,11 @@ stdenv.mkDerivation rec {
     switchboard
   ];
 
+  mesonFlags = [
+    # This option is introduced in add-wallpaper-option.patch
+    "-Dwallpaper=false"
+  ];
+
   passthru = {
     updateScript = nix-update-script {
       attrPath = "pantheon.${pname}";
diff --git a/pkgs/desktops/pantheon/apps/switchboard-plugs/about/fix-background-path.patch b/pkgs/desktops/pantheon/apps/switchboard-plugs/about/fix-background-path.patch
deleted file mode 100644
index 6fea88691331..000000000000
--- a/pkgs/desktops/pantheon/apps/switchboard-plugs/about/fix-background-path.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/src/Views/OperatingSystemView.vala b/src/Views/OperatingSystemView.vala
-index fdb92e7e..4161538e 100644
---- a/src/Views/OperatingSystemView.vala
-+++ b/src/Views/OperatingSystemView.vala
-@@ -47,7 +47,7 @@ public class About.OperatingSystemView : Gtk.Grid {
-         };
-         logo.set_image_load_func ((size) => {
-             try {
--                return new Gdk.Pixbuf.from_file_at_scale ("/usr/share/backgrounds/elementaryos-default", -1, size, true);
-+                return new Gdk.Pixbuf.from_file_at_scale ("@default_wallpaper@", -1, size, true);
-             } catch (Error e) {
-                 critical (e.message);
-             }