aboutsummaryrefslogtreecommitdiff
path: root/src/wandad.cpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2018-12-11 07:42:05 +0100
committerFelix Morgner <felix.morgner@gmail.com>2018-12-11 07:42:05 +0100
commited419140280553b070943b7ba539120a26ff5686 (patch)
tree3d134977a6dfae71a45c318305166d044b50320d /src/wandad.cpp
parentd3e691c9200b7b782c8acf17468068a699588a73 (diff)
downloadwanda-ed419140280553b070943b7ba539120a26ff5686.tar.xz
wanda-ed419140280553b070943b7ba539120a26ff5686.zip
wanda: restructure directory hierarchy
Diffstat (limited to 'src/wandad.cpp')
-rw-r--r--src/wandad.cpp103
1 files changed, 0 insertions, 103 deletions
diff --git a/src/wandad.cpp b/src/wandad.cpp
deleted file mode 100644
index 7321f04..0000000
--- a/src/wandad.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "command.hpp"
-#include "control_interface.hpp"
-#include "environment.hpp"
-#include "filesystem.hpp"
-#include "logging.hpp"
-#include "optional.hpp"
-#include "setting.hpp"
-#include "wallpaper.hpp"
-#include "xdg.hpp"
-
-#include <asio.hpp>
-#include <spdlog/sinks/stdout_color_sinks.h>
-
-#include <csignal>
-#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();
- };
-
- struct listener : wanda::control_interface::listener
- {
- listener(std::vector<std::filesystem::path> const & wallpapers)
- : m_wallpapers{wallpapers}
- {
- }
-
- void on_received(wanda::control_interface & interface, wanda::command command) override
- {
- switch (command.id)
- {
- case wanda::command_id::change:
- {
- auto wallpaper = wanda::random_pick(m_wallpapers);
- wanda::get_logger()->info("changing wallpaper to '{}'", wallpaper.native());
- wanda::set_wallpaper(wallpaper);
- break;
- }
- default:
- wanda::get_logger()->error("received unknown command '{}'", static_cast<int>(command.id));
- }
- }
-
- private:
- std::vector<std::filesystem::path> const & m_wallpapers;
- };
-
-} // namespace
-
-int main()
-{
- using namespace wanda::std_ext;
-
- wanda::initialize_logger(std::make_shared<spdlog::sinks::stdout_color_sink_st>());
- wanda::get_logger()->info("wanda is starting up");
-
- with(wanda::scan({"/usr/share/backgrounds"}, image_filter), [&](auto const & list) {
- auto service = asio::io_service{};
- auto socket_path = wanda::xdg_path_for(wanda::xdg_directory::runtime_dir, wanda::environment{}) / ".wanda_interface";
-
- wanda::get_logger()->info("starting control interface on '{}'", socket_path.native());
- auto listener = ::listener{list};
- auto interface = wanda::make_interface(service, socket_path, listener);
-
- if (!interface)
- {
- wanda::get_logger()->error("failed to start control interface");
- return;
- }
-
- if (interface->start())
- {
- return;
- }
-
- auto signals = asio::signal_set{service, SIGINT};
- signals.async_wait([&](auto const & error, auto const signal) {
- if (!error && signal == SIGINT)
- {
- interface->shutdown();
- service.stop();
- }
- });
-
- auto wallpaper = wanda::random_pick(list);
- wanda::set_wallpaper(wallpaper);
-
- service.run();
- }) || [&] { wanda::get_logger()->error("wallpaper directory does not exist"); };
-}