blob: 6f8dcf8a29016113d0a20d4e5dfb29805fdb4276 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "filesystem.hpp"
#include "setting.hpp"
#include "optional.hpp"
#include "control_interface.hpp"
#include <boost/asio.hpp>
#include <csignal>
#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);
auto service = boost::asio::io_service{};
auto interface = wanda::make_interface(service, ".wanda_interface");
auto status = interface->start();
if(status)
{
return;
}
auto signals = boost::asio::signal_set{service, SIGINT};
signals.async_wait([&](auto const & error, auto const signal){
if(!error && signal == SIGINT)
{
service.stop();
}
});
service.run();
}) || [] { std::cerr << "Directory does not exist\n"; };
}
|