From fdfc0d1bac8c390508366d14d80c149a23d59606 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 27 Aug 2021 10:55:27 -0400 Subject: FileManager: Listen for changes to Desktop wallpaper in config Since there's no global API for being able to just assign a callback function to config changes, I've made an inline struct in desktop mode with the sole purpose of checking to see if the Wallpaper entry has changed, and then updates GUI::Desktop. It's pretty neat seeing the wallpaper change as soon as you edit the config file :^) --- Userland/Applications/FileManager/main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 7dbab9afb7..b2ae3dae75 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2021, Mustafa Quraish * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -93,6 +95,7 @@ int main(int argc, char** argv) Config::pledge_domains({ "FileManager", "WindowManager" }); Config::monitor_domain("FileManager"); + Config::monitor_domain("WindowManager"); if (is_desktop_mode) return run_in_desktop_mode(); @@ -439,6 +442,14 @@ int run_in_desktop_mode() } }; + struct BackgroundWallpaperListener : Config::Listener { + virtual void config_string_did_change(String const& domain, String const& group, String const& key, String const& value) override + { + if (domain == "WindowManager" && group == "Background" && key == "Wallpaper") + GUI::Desktop::the().set_wallpaper(value, false); + } + } wallpaper_listener; + auto selected_wallpaper = Config::read_string("WindowManager", "Background", "Wallpaper", ""); if (!selected_wallpaper.is_empty()) { GUI::Desktop::the().set_wallpaper(selected_wallpaper, false); -- cgit v1.2.3