2018-08-09 12:05:48 +02:00
|
|
|
#include "factory.hpp"
|
|
|
|
|
2019-04-18 17:52:00 +02:00
|
|
|
waybar::Factory::Factory(const Bar& bar, const Json::Value& config) : bar_(bar), config_(config) {}
|
2018-08-09 12:05:48 +02:00
|
|
|
|
2019-06-15 14:57:52 +02:00
|
|
|
waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
|
2018-08-13 14:05:13 +02:00
|
|
|
try {
|
2019-04-24 12:37:24 +02:00
|
|
|
auto hash_pos = name.find('#');
|
2018-12-18 17:30:54 +01:00
|
|
|
auto ref = name.substr(0, hash_pos);
|
|
|
|
auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : "";
|
2019-08-09 11:52:16 +02:00
|
|
|
#if defined(__linux__) && !defined(NO_FILESYSTEM)
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "battery") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::Battery(id, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2019-05-12 19:53:14 +02:00
|
|
|
#endif
|
2022-05-13 21:30:45 +02:00
|
|
|
#ifdef HAVE_GAMEMODE
|
|
|
|
if (ref == "gamemode") {
|
|
|
|
return new waybar::modules::Gamemode(id, config_[name]);
|
|
|
|
}
|
|
|
|
#endif
|
2022-03-15 17:54:06 +01:00
|
|
|
#ifdef HAVE_UPOWER
|
|
|
|
if (ref == "upower") {
|
2022-03-19 17:09:55 +01:00
|
|
|
return new waybar::modules::upower::UPower(id, config_[name]);
|
2022-03-15 17:54:06 +01:00
|
|
|
}
|
|
|
|
#endif
|
2019-04-18 17:52:00 +02:00
|
|
|
#ifdef HAVE_SWAY
|
2018-10-30 13:39:30 +01:00
|
|
|
if (ref == "sway/mode") {
|
2019-05-07 13:21:18 +02:00
|
|
|
return new waybar::modules::sway::Mode(id, config_[name]);
|
2018-10-30 13:39:30 +01:00
|
|
|
}
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "sway/workspaces") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::sway::Workspaces(id, bar_, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "sway/window") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::sway::Window(id, bar_, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2020-10-10 18:09:18 +02:00
|
|
|
if (ref == "sway/language") {
|
2022-04-06 08:37:19 +02:00
|
|
|
return new waybar::modules::sway::Language(id, config_[name]);
|
2020-10-10 18:09:18 +02:00
|
|
|
}
|
2020-05-30 12:07:38 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WLR
|
|
|
|
if (ref == "wlr/taskbar") {
|
2020-06-06 15:41:37 +02:00
|
|
|
return new waybar::modules::wlr::Taskbar(id, bar_, config_[name]);
|
|
|
|
}
|
2021-11-27 23:12:35 +01:00
|
|
|
#ifdef USE_EXPERIMENTAL
|
2020-08-05 01:17:38 +02:00
|
|
|
if (ref == "wlr/workspaces") {
|
|
|
|
return new waybar::modules::wlr::WorkspaceManager(id, bar_, config_[name]);
|
|
|
|
}
|
2020-06-06 15:41:37 +02:00
|
|
|
#endif
|
2021-11-27 23:12:35 +01:00
|
|
|
#endif
|
2020-06-06 15:41:37 +02:00
|
|
|
#ifdef HAVE_RIVER
|
|
|
|
if (ref == "river/tags") {
|
|
|
|
return new waybar::modules::river::Tags(id, bar_, config_[name]);
|
2020-05-30 12:07:38 +02:00
|
|
|
}
|
2022-05-19 21:20:04 +02:00
|
|
|
if (ref == "river/window") {
|
|
|
|
return new waybar::modules::river::Window(id, bar_, config_[name]);
|
|
|
|
}
|
2019-04-18 17:52:00 +02:00
|
|
|
#endif
|
2019-02-17 15:27:54 +01:00
|
|
|
if (ref == "idle_inhibitor") {
|
|
|
|
return new waybar::modules::IdleInhibitor(id, bar_, config_[name]);
|
|
|
|
}
|
2019-08-09 12:40:33 +02:00
|
|
|
#if defined(HAVE_MEMORY_LINUX) || defined(HAVE_MEMORY_BSD)
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "memory") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::Memory(id, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2019-08-09 12:40:33 +02:00
|
|
|
#endif
|
2019-08-11 15:10:37 +02:00
|
|
|
#if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD)
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "cpu") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::Cpu(id, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2019-08-11 15:10:37 +02:00
|
|
|
#endif
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "clock") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::Clock(id, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2019-09-23 22:25:54 +02:00
|
|
|
if (ref == "disk") {
|
|
|
|
return new waybar::modules::Disk(id, config_[name]);
|
|
|
|
}
|
2019-08-11 17:23:37 +02:00
|
|
|
#ifdef HAVE_DBUSMENU
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "tray") {
|
2019-03-22 12:25:05 +01:00
|
|
|
return new waybar::modules::SNI::Tray(id, bar_, config_[name]);
|
2018-08-29 20:36:39 +02:00
|
|
|
}
|
2019-04-18 17:52:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBNL
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "network") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::Network(id, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2019-04-18 17:52:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBUDEV
|
2019-02-19 05:11:18 +01:00
|
|
|
if (ref == "backlight") {
|
|
|
|
return new waybar::modules::Backlight(id, config_[name]);
|
|
|
|
}
|
2019-04-18 17:52:00 +02:00
|
|
|
#endif
|
2021-02-07 21:05:11 +01:00
|
|
|
#ifdef HAVE_LIBEVDEV
|
2021-07-23 15:45:07 +02:00
|
|
|
if (ref == "keyboard-state") {
|
2021-02-08 00:46:39 +01:00
|
|
|
return new waybar::modules::KeyboardState(id, bar_, config_[name]);
|
2021-02-07 21:05:11 +01:00
|
|
|
}
|
|
|
|
#endif
|
2019-04-18 17:52:00 +02:00
|
|
|
#ifdef HAVE_LIBPULSE
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref == "pulseaudio") {
|
2018-12-18 17:30:54 +01:00
|
|
|
return new waybar::modules::Pulseaudio(id, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2019-04-18 17:52:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBMPDCLIENT
|
2019-04-16 16:34:37 +02:00
|
|
|
if (ref == "mpd") {
|
|
|
|
return new waybar::modules::MPD(id, config_[name]);
|
|
|
|
}
|
2020-09-06 19:44:13 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBSNDIO
|
|
|
|
if (ref == "sndio") {
|
|
|
|
return new waybar::modules::Sndio(id, config_[name]);
|
|
|
|
}
|
2021-12-03 23:32:53 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GIO_UNIX
|
2020-01-21 15:46:08 +01:00
|
|
|
if (ref == "bluetooth") {
|
|
|
|
return new waybar::modules::Bluetooth(id, config_[name]);
|
|
|
|
}
|
2022-05-06 17:01:43 +02:00
|
|
|
if (ref == "inhibitor") {
|
|
|
|
return new waybar::modules::Inhibitor(id, bar_, config_[name]);
|
|
|
|
}
|
2022-04-06 08:37:19 +02:00
|
|
|
#endif
|
2022-05-02 18:11:21 +02:00
|
|
|
if (ref == "temperature") {
|
|
|
|
return new waybar::modules::Temperature(id, config_[name]);
|
|
|
|
}
|
2018-10-25 17:30:26 +02:00
|
|
|
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
|
2019-05-22 12:20:13 +02:00
|
|
|
return new waybar::modules::Custom(ref.substr(7), id, config_[name]);
|
2018-08-16 14:29:41 +02:00
|
|
|
}
|
2018-08-13 14:05:13 +02:00
|
|
|
} catch (const std::exception& e) {
|
|
|
|
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());
|
2018-08-19 13:39:57 +02:00
|
|
|
throw std::runtime_error(err);
|
2018-08-13 14:05:13 +02:00
|
|
|
} catch (...) {
|
|
|
|
auto err = fmt::format("Disabling module \"{}\", Unknown reason", name);
|
2018-08-19 13:39:57 +02:00
|
|
|
throw std::runtime_error(err);
|
2018-08-13 14:05:13 +02:00
|
|
|
}
|
2018-08-19 13:39:57 +02:00
|
|
|
throw std::runtime_error("Unknown module: " + name);
|
2018-08-09 12:05:48 +02:00
|
|
|
}
|