aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 6d1353d61dba19be611748b70b1abe63ef5fa26f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "filesystem.hpp"
#include "setting.hpp"
#include "optional.hpp"

#include <iostream>
#include <set>
#include <string>

namespace
{

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) {
      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"; };
}