blob: beb904008550e7a5de0cab9beb162e493491bad2 (
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
|
#include "control_interface.hpp"
#include "environment.hpp"
#include "filesystem.hpp"
#include "optional.hpp"
#include "setting.hpp"
#include "wallpaper.hpp"
#include "xdg.hpp"
#include <boost/asio.hpp>
#include <csignal>
#include <iostream>
#include <set>
#include <string>
namespace
{
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);
wanda::set_wallpaper(wallpaper);
auto service = boost::asio::io_service{};
auto socket_path = wanda::xdg_path_for(wanda::xdg_directory::runtime_dir, wanda::environment{}) / ".wanda_interface";
std::clog << "[wandad::main] Initializing control interface on socket '" << socket_path.native() << "'\n";
auto interface = wanda::make_interface(service, socket_path);
if(!interface)
{
std::cerr << "[wandad::main] Failed to initialize control interface on socket '" << socket_path.native() << "'\n"
<< "[wandad::main] File already existed. Is 'wandad' running already?\n";
return;
}
if (interface->start())
{
return;
}
auto signals = boost::asio::signal_set{service, SIGINT};
signals.async_wait([&](auto const &error, auto const signal) {
if (!error && signal == SIGINT)
{
interface->shutdown();
service.stop();
}
});
service.run();
}) || [] { std::cerr << "Directory does not exist\n"; };
}
|