diff options
author | Mustafa Quraish <mustafaq9@gmail.com> | 2021-08-27 10:55:27 -0400 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-10-10 01:15:34 -0700 |
commit | fdfc0d1bac8c390508366d14d80c149a23d59606 (patch) | |
tree | d3ee44b7f0f5ba1574e1e5c378043facc19e81b5 /Userland/Applications/FileManager/main.cpp | |
parent | 4bf88436cbfa920678b9d7ce9669f1cdedfc7064 (diff) | |
download | serenity-fdfc0d1bac8c390508366d14d80c149a23d59606.zip |
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 :^)
Diffstat (limited to 'Userland/Applications/FileManager/main.cpp')
-rw-r--r-- | Userland/Applications/FileManager/main.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
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 <kling@serenityos.org> * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,6 +15,7 @@ #include <AK/URL.h> #include <Applications/FileManager/FileManagerWindowGML.h> #include <LibConfig/Client.h> +#include <LibConfig/Listener.h> #include <LibCore/ArgsParser.h> #include <LibCore/File.h> #include <LibCore/StandardPaths.h> @@ -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); |