diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/main.cpp b/src/main.cpp index 38fdf7f..6d1353d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,28 +1,50 @@ +#include "filesystem.hpp" #include "setting.hpp" #include "optional.hpp" #include <iostream> +#include <set> #include <string> -#include <typeinfo> +namespace +{ -int main() +void set_wallpaper(std::filesystem::path wallpaper) { using namespace wanda::literals; using namespace wanda::std_ext; using namespace std::string_literals; - with("org.gnome.desktop.background"_setting, [](auto &setting) { - with(setting["picture-uri"_key], [](auto &value) { - std::visit([](auto &&value) { - using ValueType = std::decay_t<decltype(value)>; - if constexpr (std::is_same_v<ValueType, std::string>) - { - std::cout << value << '\n'; - } - }, - *value); - std::cout << (value = "file:///"s) << '\n'; + with("org.gnome.desktop.background"_setting, [&](auto &setting) { + with(setting["picture-uri"_key], [&](auto &value) { + value = "file://" + wallpaper.native(); }) || [] { std::cerr << "No such key!\n"; }; }) || [] { std::cerr << "No such setting!\n"; }; } + +constexpr auto image_filter = [](auto const &path) { + static auto const extensions = std::set<std::filesystem::path>{ + std::filesystem::path{".jpg"}, + std::filesystem::path{".png"}, + }; + + if (!std::filesystem::is_regular_file(path)) + { + return false; + } + + return extensions.find(path.extension()) != extensions.cend(); +}; + +} // namespace + +int main() +{ + using namespace wanda::std_ext; + + with(wanda::scan({"/usr/share/backgrounds"}, image_filter), [](auto const &list) { + auto wallpaper = wanda::random_pick(list); + std::cout << "changing wallpaper to " << wallpaper << '\n'; + set_wallpaper(wallpaper); + }) || [] { std::cerr << "Directory does not exist\n"; }; +} |
