From 6cb3f65f1a09b3e169941a5a3069dc0c7a68c070 Mon Sep 17 00:00:00 2001
From: Pavel Kirilin <win10@list.ru>
Date: Sat, 21 Mar 2020 16:17:59 +0400
Subject: [PATCH] Added reset command. Description: - Added command to reset
 default wallpapers.

Signed-off-by: Pavel Kirilin <win10@list.ru>
---
 Cargo.toml        | 3 ++-
 lib/background.rs | 5 ++++-
 lib/config/mod.rs | 9 ++++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 54598f5..69e0f47 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,5 +45,6 @@ features = [
 [dependencies.x11rb]            # Used to interact with X11.
 version = "0.4.1"
 features = [
-    "all-extensions"
+    "xinerama",
+    "xproto"
 ]
\ No newline at end of file
diff --git a/lib/background.rs b/lib/background.rs
index 3318ca6..fa7cbe3 100644
--- a/lib/background.rs
+++ b/lib/background.rs
@@ -5,6 +5,8 @@ use dbus::Message;
 
 use crate::img_processors::process_image;
 use crate::result::MBGResult;
+use crate::display::update_bg;
+use crate::config::Config;
 
 
 pub fn reset_background_handler(_: (), _: &Connection, message: &Message) -> bool {
@@ -19,7 +21,8 @@ pub fn reset_background_handler(_: (), _: &Connection, message: &Message) -> boo
 
 pub fn nitrogen_restore() {
     info!("Reset BG");
-    let out = Command::new("nitrogen").arg("--restore").output();
+    let config = Config::get_props();
+    let out = Command::new("sh").arg("-c").arg(config.reset_command.as_str()).output();
     if let Err(restore_error) = out {
         error!("Can't restore background: {}", restore_error.to_string());
     }
diff --git a/lib/config/mod.rs b/lib/config/mod.rs
index b1cde04..97279bb 100644
--- a/lib/config/mod.rs
+++ b/lib/config/mod.rs
@@ -12,15 +12,22 @@ pub mod logger;
 pub struct Config {
     #[serde(default)]
     pub blender: Vec<u8>,
+    #[serde(default = "reset_command_default")]
+    pub reset_command: String,
     #[serde(default)]
     pub logger: logger::LoggerConfig,
     #[serde(default)]
     pub processors: Vec<image_processors::ProcessorParams>,
 }
 
+pub fn reset_command_default() -> String {
+    String::from("nitrogen --restore")
+}
+
 impl Config {
     fn new() -> Self {
         Config {
+            reset_command: reset_command_default(),
             ..Default::default()
         }
     }
@@ -63,7 +70,7 @@ impl Config {
         let mut config_path = home_dir.unwrap();
         config_path.push(".mbg.toml");
         let mut conf_file = File::create(config_path)?;
-        let mut default_conf = Self::default();
+        let mut default_conf = Self::new();
         default_conf
             .processors
             .push(image_processors::ProcessorParams::default());
-- 
GitLab