Remove unsupported.hpp (#2956)

* Remove unsupported.hpp

* Rename names.hpp to types.hpp

* Replace macro by function

* Add missing cassert include in controller.cpp
This commit is contained in:
dvermd 2023-05-08 19:36:12 +02:00 committed by GitHub
parent 031a29332a
commit f5169abde2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 126 additions and 95 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/event_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
POLYBAR_NS
@ -29,7 +30,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/alsa";
static constexpr auto TYPE = ALSA_TYPE;
static constexpr auto EVENT_INC = "inc";
static constexpr auto EVENT_DEC = "dec";

View File

@ -2,6 +2,7 @@
#include "components/config.hpp"
#include "modules/meta/inotify_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
POLYBAR_NS
@ -26,7 +27,7 @@ namespace modules {
bool on_event(const inotify_event& event);
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/backlight";
static constexpr auto TYPE = BACKLIGHT_TYPE;
static constexpr const char* EVENT_INC = "inc";
static constexpr const char* EVENT_DEC = "dec";

View File

@ -2,6 +2,7 @@
#include "common.hpp"
#include "modules/meta/inotify_module.hpp"
#include "modules/meta/types.hpp"
POLYBAR_NS
@ -55,7 +56,7 @@ namespace modules {
string get_format() const;
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/battery";
static constexpr auto TYPE = BATTERY_TYPE;
protected:
state current_state();

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/event_module.hpp"
#include "modules/meta/types.hpp"
#include "utils/bspwm.hpp"
POLYBAR_NS
@ -47,7 +48,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/bspwm";
static constexpr auto TYPE = BSPWM_TYPE;
static constexpr auto EVENT_FOCUS = "focus";
static constexpr auto EVENT_NEXT = "next";

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
POLYBAR_NS
@ -12,7 +13,7 @@ namespace modules {
bool update();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/counter";
static constexpr auto TYPE = COUNTER_TYPE;
private:
static constexpr auto TAG_COUNTER = "<counter>";

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
POLYBAR_NS
@ -26,7 +27,7 @@ namespace modules {
string get_format() const;
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/cpu";
static constexpr auto TYPE = CPU_TYPE;
protected:
bool read_values();

View File

@ -6,6 +6,7 @@
#include <iostream>
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
POLYBAR_NS
@ -17,7 +18,7 @@ namespace modules {
bool update();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/date";
static constexpr auto TYPE = DATE_TYPE;
static constexpr auto EVENT_TOGGLE = "toggle";

View File

@ -2,6 +2,7 @@
#include "components/config.hpp"
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
POLYBAR_NS
@ -42,7 +43,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/fs";
static constexpr auto TYPE = FS_TYPE;
private:
static constexpr auto FORMAT_MOUNTED = "format-mounted";

View File

@ -3,6 +3,7 @@
#include <atomic>
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
#include "utils/http.hpp"
@ -20,7 +21,7 @@ namespace modules {
bool build(builder* builder, const string& tag) const;
string get_format() const;
static constexpr auto TYPE = "internal/github";
static constexpr auto TYPE = GITHUB_TYPE;
private:
void update_label(int);

View File

@ -4,6 +4,7 @@
#include "components/config.hpp"
#include "modules/meta/event_module.hpp"
#include "modules/meta/types.hpp"
#include "utils/i3.hpp"
#include "utils/io.hpp"
@ -51,7 +52,7 @@ namespace modules {
bool update();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/i3";
static constexpr auto TYPE = I3_TYPE;
static constexpr auto EVENT_FOCUS = "focus";
static constexpr auto EVENT_NEXT = "next";

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
#include "utils/command.hpp"
POLYBAR_NS
@ -33,7 +34,7 @@ namespace modules {
bool build(builder* builder, const string& tag) const;
void on_message(const string& message);
static constexpr auto TYPE = "custom/ipc";
static constexpr auto TYPE = IPC_TYPE;
static constexpr auto EVENT_SEND = "send";
static constexpr auto EVENT_HOOK = "hook";

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
POLYBAR_NS
@ -16,7 +17,7 @@ namespace modules {
string get_format() const;
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/memory";
static constexpr auto TYPE = MEMORY_TYPE;
private:
static constexpr const char* TAG_LABEL{"<label>"};

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
POLYBAR_NS
@ -22,7 +23,7 @@ namespace modules {
bool build(builder* builder, const string& tag) const;
void update() {}
static constexpr auto TYPE = "custom/menu";
static constexpr auto TYPE = MENU_TYPE;
static constexpr auto EVENT_OPEN = "open";
static constexpr auto EVENT_CLOSE = "close";

View File

@ -43,4 +43,3 @@
#if ENABLE_XKEYBOARD
#include "modules/xkeyboard.hpp"
#endif
#include "modules/unsupported.hpp"

View File

@ -0,0 +1,37 @@
#pragma once
#include "common.hpp"
POLYBAR_NS
namespace modules {
static constexpr const char ALSA_TYPE[] = "internal/alsa";
static constexpr const char BACKLIGHT_TYPE[] = "internal/backlight";
static constexpr const char BATTERY_TYPE[] = "internal/battery";
static constexpr const char BSPWM_TYPE[] = "internal/bspwm";
static constexpr const char COUNTER_TYPE[] = "internal/counter";
static constexpr const char CPU_TYPE[] = "internal/cpu";
static constexpr const char DATE_TYPE[] = "internal/date";
static constexpr const char FS_TYPE[] = "internal/fs";
static constexpr const char GITHUB_TYPE[] = "internal/github";
static constexpr const char I3_TYPE[] = "internal/i3";
static constexpr const char MEMORY_TYPE[] = "internal/memory";
static constexpr const char MPD_TYPE[] = "internal/mpd";
static constexpr const char NETWORK_TYPE[] = "internal/network";
static constexpr const char PULSEAUDIO_TYPE[] = "internal/pulseaudio";
static constexpr const char TEMPERATURE_TYPE[] = "internal/temperature";
static constexpr const char TRAY_TYPE[] = "internal/tray";
static constexpr const char XBACKLIGHT_TYPE[] = "internal/xbacklight";
static constexpr const char XKEYBOARD_TYPE[] = "internal/xkeyboard";
static constexpr const char XWINDOW_TYPE[] = "internal/xwindow";
static constexpr const char XWORKSPACES_TYPE[] = "internal/xworkspaces";
static constexpr const char IPC_TYPE[] = "custom/ipc";
static constexpr const char MENU_TYPE[] = "custom/menu";
static constexpr const char SCRIPT_TYPE[] = "custom/script";
static constexpr const char TEXT_TYPE[] = "custom/text";
} // namespace modules
POLYBAR_NS_END

View File

@ -4,6 +4,7 @@
#include "adapters/mpd.hpp"
#include "modules/meta/event_module.hpp"
#include "modules/meta/types.hpp"
#include "utils/env.hpp"
POLYBAR_NS
@ -24,7 +25,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/mpd";
static constexpr auto TYPE = MPD_TYPE;
static constexpr const char* EVENT_PLAY = "play";
static constexpr const char* EVENT_PAUSE = "pause";

View File

@ -3,6 +3,7 @@
#include "adapters/net.hpp"
#include "components/config.hpp"
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
POLYBAR_NS
@ -18,7 +19,7 @@ namespace modules {
string get_format() const;
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/network";
static constexpr auto TYPE = NETWORK_TYPE;
protected:
void subthread_routine();

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/event_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
POLYBAR_NS
@ -22,7 +23,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/pulseaudio";
static constexpr auto TYPE = PULSEAUDIO_TYPE;
static constexpr auto EVENT_INC = "inc";
static constexpr auto EVENT_DEC = "dec";

View File

@ -2,6 +2,7 @@
#include "adapters/script_runner.hpp"
#include "modules/meta/base.hpp"
#include "modules/meta/types.hpp"
#include "utils/command.hpp"
#include "utils/io.hpp"
@ -20,7 +21,7 @@ namespace modules {
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "custom/script";
static constexpr auto TYPE = SCRIPT_TYPE;
protected:
bool check_condition();

View File

@ -3,6 +3,7 @@
#include <istream>
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
POLYBAR_NS
@ -18,7 +19,7 @@ namespace modules {
string get_format() const;
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/temperature";
static constexpr auto TYPE = TEMPERATURE_TYPE;
private:
static constexpr auto TAG_LABEL = "<label>";

View File

@ -1,6 +1,7 @@
#pragma once
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
POLYBAR_NS
@ -14,7 +15,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "custom/text";
static constexpr auto TYPE = TEXT_TYPE;
private:
static constexpr const char* TAG_LABEL{"<label>"};

View File

@ -3,6 +3,7 @@
#include "common.hpp"
#include "components/bar.hpp"
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
#include "x11/tray_manager.hpp"
POLYBAR_NS
@ -17,7 +18,7 @@ class tray_module : public static_module<tray_module> {
bool build(builder* builder, const string& tag) const;
void update() {}
static constexpr auto TYPE = "internal/tray";
static constexpr auto TYPE = TRAY_TYPE;
private:
static constexpr const char* TAG_TRAY{"<tray>"};

View File

@ -1,68 +0,0 @@
#pragma once
#include "modules/meta/base.hpp"
#include "modules/meta/base.inl"
POLYBAR_NS
namespace modules {
struct module_interface;
#define DEFINE_UNSUPPORTED_MODULE(MODULE_NAME, MODULE_TYPE) \
class MODULE_NAME : public module_interface { \
public: \
MODULE_NAME(const bar_settings, string, const config&) { \
throw application_error("No built-in support for '" + string{MODULE_TYPE} + "'"); \
} \
static constexpr auto TYPE = MODULE_TYPE; \
string type() const override { \
return ""; \
} \
string name_raw() const override { \
return ""; \
} \
string name() const override { \
return ""; \
} \
bool running() const override { \
return false; \
} \
bool visible() const override { \
return false; \
} \
void start() override {} \
void stop() override {} \
void join() override {} \
void halt(string) override {} \
string contents() override { \
return ""; \
} \
bool input(const string&, const string&) override { \
return false; \
} \
}
#if not ENABLE_I3
DEFINE_UNSUPPORTED_MODULE(i3_module, "internal/i3");
#endif
#if not ENABLE_MPD
DEFINE_UNSUPPORTED_MODULE(mpd_module, "internal/mpd");
#endif
#if not ENABLE_NETWORK
DEFINE_UNSUPPORTED_MODULE(network_module, "internal/network");
#endif
#if not ENABLE_ALSA
DEFINE_UNSUPPORTED_MODULE(alsa_module, "internal/alsa");
#endif
#if not ENABLE_PULSEAUDIO
DEFINE_UNSUPPORTED_MODULE(pulseaudio_module, "internal/pulseaudio");
#endif
#if not ENABLE_CURL
DEFINE_UNSUPPORTED_MODULE(github_module, "internal/github");
#endif
#if not ENABLE_XKEYBOARD
DEFINE_UNSUPPORTED_MODULE(xkeyboard_module, "internal/xkeyboard");
#endif
} // namespace modules
POLYBAR_NS_END

View File

@ -3,6 +3,7 @@
#include "components/config.hpp"
#include "modules/meta/event_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"
#include "x11/extensions/randr.hpp"
@ -30,7 +31,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/xbacklight";
static constexpr auto TYPE = XBACKLIGHT_TYPE;
static constexpr const char* EVENT_INC = "inc";
static constexpr const char* EVENT_DEC = "dec";

View File

@ -6,6 +6,7 @@
#include "drawtypes/layouticonset.hpp"
#include "modules/meta/event_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
#include "x11/extensions/xkb.hpp"
#include "x11/window.hpp"
@ -27,7 +28,7 @@ namespace modules {
void update();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/xkeyboard";
static constexpr auto TYPE = XKEYBOARD_TYPE;
static constexpr const char* EVENT_SWITCH = "switch";

View File

@ -2,6 +2,7 @@
#include "modules/meta/event_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
#include "x11/ewmh.hpp"
#include "x11/icccm.hpp"
#include "x11/window.hpp"
@ -38,7 +39,7 @@ namespace modules {
void update();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/xwindow";
static constexpr auto TYPE = XWINDOW_TYPE;
protected:
void handle(const evt::property_notify& evt) override;

View File

@ -2,6 +2,7 @@
#include "modules/meta/event_handler.hpp"
#include "modules/meta/static_module.hpp"
#include "modules/meta/types.hpp"
#include "x11/ewmh.hpp"
POLYBAR_NS
@ -50,7 +51,7 @@ namespace modules {
string get_output();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/xworkspaces";
static constexpr auto TYPE = XWORKSPACES_TYPE;
static constexpr auto EVENT_FOCUS = "focus";
static constexpr auto EVENT_NEXT = "next";

View File

@ -1,6 +1,7 @@
#include "components/controller.hpp"
#include <csignal>
#include <cassert>
#include <utility>
#include "components/bar.hpp"

View File

@ -36,6 +36,16 @@ namespace modules {
return std::make_pair(std::string(M::TYPE), get_factory<M>());
}
template<const char* module_type>
static factory_map::value_type map_entry_unsupported() {
return {
module_type,
[](const bar_settings&, string&&, const config&) -> module_t {
throw application_error("No built-in support for '" + string(module_type) + "'");
}
};
}
/**
* Factory function for each module type.
*/
@ -46,17 +56,45 @@ namespace modules {
map_entry<bspwm_module>(),
map_entry<cpu_module>(),
map_entry<date_module>(),
#if ENABLE_CURL
map_entry<github_module>(),
#else
map_entry_unsupported<GITHUB_TYPE>(),
#endif
map_entry<fs_module>(),
map_entry<memory_module>(),
#if ENABLE_I3
map_entry<i3_module>(),
#else
map_entry_unsupported<I3_TYPE>(),
#endif
#if ENABLE_MPD
map_entry<mpd_module>(),
#else
map_entry_unsupported<MPD_TYPE>(),
#endif
#if ENABLE_ALSA
map_entry<alsa_module>(),
#else
map_entry_unsupported<ALSA_TYPE>(),
#endif
#if ENABLE_PULSEAUDIO
map_entry<pulseaudio_module>(),
#else
map_entry_unsupported<PULSEAUDIO_TYPE>(),
#endif
#if ENABLE_NETWORK
map_entry<network_module>(),
#else
map_entry_unsupported<NETWORK_TYPE>(),
#endif
map_entry<temperature_module>(),
map_entry<xbacklight_module>(),
#if ENABLE_XKEYBOARD
map_entry<xkeyboard_module>(),
#else
map_entry_unsupported<XKEYBOARD_TYPE>(),
#endif
map_entry<xwindow_module>(),
map_entry<xworkspaces_module>(),
map_entry<tray_module>(),
@ -70,8 +108,8 @@ namespace modules {
string actual_type = type;
if (type == "internal/volume") {
log.warn("internal/volume is deprecated, use %s instead", string(alsa_module::TYPE));
actual_type = alsa_module::TYPE;
log.warn("internal/volume is deprecated, use %s instead", ALSA_TYPE);
actual_type = ALSA_TYPE;
}
auto it = factories.find(actual_type);