refactor: Move module type string into modules
This allows us to identify module by their type and it is also better to store the module type as part of the module instead of having it hardcoded in factory.hpp
This commit is contained in:
parent
06012af3aa
commit
d592eea966
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "settings.hpp"
|
|
||||||
#include "modules/meta/event_module.hpp"
|
#include "modules/meta/event_module.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ POLYBAR_NS
|
|||||||
namespace alsa {
|
namespace alsa {
|
||||||
class mixer;
|
class mixer;
|
||||||
class control;
|
class control;
|
||||||
}
|
} // namespace alsa
|
||||||
|
|
||||||
namespace modules {
|
namespace modules {
|
||||||
enum class mixer { NONE = 0, MASTER, SPEAKER, HEADPHONE };
|
enum class mixer { NONE = 0, MASTER, SPEAKER, HEADPHONE };
|
||||||
@ -29,6 +29,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/alsa";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
@ -62,6 +64,6 @@ namespace modules {
|
|||||||
atomic<bool> m_headphones{false};
|
atomic<bool> m_headphones{false};
|
||||||
atomic<int> m_volume{0};
|
atomic<int> m_volume{0};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
#include "components/config.hpp"
|
#include "components/config.hpp"
|
||||||
#include "modules/meta/inotify_module.hpp"
|
#include "modules/meta/inotify_module.hpp"
|
||||||
#include "modules/meta/input_handler.hpp"
|
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
namespace modules {
|
namespace modules {
|
||||||
class backlight_module : public inotify_module<backlight_module>, public input_handler {
|
class backlight_module : public inotify_module<backlight_module> {
|
||||||
public:
|
public:
|
||||||
struct brightness_handle {
|
struct brightness_handle {
|
||||||
void filepath(const string& path);
|
void filepath(const string& path);
|
||||||
@ -27,6 +26,8 @@ namespace modules {
|
|||||||
bool on_event(inotify_event* event);
|
bool on_event(inotify_event* event);
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/backlight";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
|
@ -54,6 +54,8 @@ namespace modules {
|
|||||||
string get_format() const;
|
string get_format() const;
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/battery";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
state current_state();
|
state current_state();
|
||||||
int current_percentage();
|
int current_percentage();
|
||||||
@ -106,6 +108,6 @@ namespace modules {
|
|||||||
chrono::system_clock::time_point m_lastpoll;
|
chrono::system_clock::time_point m_lastpoll;
|
||||||
thread m_subthread;
|
thread m_subthread;
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -47,6 +47,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/bspwm";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
@ -91,6 +93,6 @@ namespace modules {
|
|||||||
// used while formatting output
|
// used while formatting output
|
||||||
size_t m_index{0U};
|
size_t m_index{0U};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -12,11 +12,13 @@ namespace modules {
|
|||||||
bool update();
|
bool update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/counter";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr auto TAG_COUNTER = "<counter>";
|
static constexpr auto TAG_COUNTER = "<counter>";
|
||||||
|
|
||||||
int m_counter{0};
|
int m_counter{0};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "settings.hpp"
|
|
||||||
#include "modules/meta/timer_module.hpp"
|
#include "modules/meta/timer_module.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -24,6 +24,8 @@ namespace modules {
|
|||||||
bool update();
|
bool update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/cpu";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool read_values();
|
bool read_values();
|
||||||
float get_load(size_t core) const;
|
float get_load(size_t core) const;
|
||||||
@ -46,6 +48,6 @@ namespace modules {
|
|||||||
float m_total = 0;
|
float m_total = 0;
|
||||||
vector<float> m_load;
|
vector<float> m_load;
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "modules/meta/timer_module.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "modules/meta/timer_module.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -16,6 +16,8 @@ namespace modules {
|
|||||||
bool update();
|
bool update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/date";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
@ -41,6 +43,6 @@ namespace modules {
|
|||||||
|
|
||||||
std::atomic<bool> m_toggled{false};
|
std::atomic<bool> m_toggled{false};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "components/config.hpp"
|
#include "components/config.hpp"
|
||||||
#include "settings.hpp"
|
|
||||||
#include "modules/meta/timer_module.hpp"
|
#include "modules/meta/timer_module.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -42,6 +42,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/fs";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr auto FORMAT_MOUNTED = "format-mounted";
|
static constexpr auto FORMAT_MOUNTED = "format-mounted";
|
||||||
static constexpr auto FORMAT_UNMOUNTED = "format-unmounted";
|
static constexpr auto FORMAT_UNMOUNTED = "format-unmounted";
|
||||||
@ -66,6 +68,6 @@ namespace modules {
|
|||||||
// used while formatting output
|
// used while formatting output
|
||||||
size_t m_index{0_z};
|
size_t m_index{0_z};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -18,6 +18,8 @@ namespace modules {
|
|||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
string get_format() const;
|
string get_format() const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/github";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void update_label(int);
|
void update_label(int);
|
||||||
int get_number_of_notification();
|
int get_number_of_notification();
|
||||||
|
@ -51,6 +51,8 @@ namespace modules {
|
|||||||
bool update();
|
bool update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/i3";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ namespace modules {
|
|||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
void on_message(const string& message);
|
void on_message(const string& message);
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "custom/ipc";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr const char* TAG_OUTPUT{"<output>"};
|
static constexpr const char* TAG_OUTPUT{"<output>"};
|
||||||
vector<unique_ptr<hook>> m_hooks;
|
vector<unique_ptr<hook>> m_hooks;
|
||||||
@ -39,6 +41,6 @@ namespace modules {
|
|||||||
string m_output;
|
string m_output;
|
||||||
size_t m_initial;
|
size_t m_initial;
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -15,6 +15,8 @@ namespace modules {
|
|||||||
bool update();
|
bool update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/memory";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr const char* TAG_LABEL{"<label>"};
|
static constexpr const char* TAG_LABEL{"<label>"};
|
||||||
static constexpr const char* TAG_BAR_USED{"<bar-used>"};
|
static constexpr const char* TAG_BAR_USED{"<bar-used>"};
|
||||||
@ -40,6 +42,6 @@ namespace modules {
|
|||||||
ramp_t m_ramp_swapused;
|
ramp_t m_ramp_swapused;
|
||||||
ramp_t m_ramp_swapfree;
|
ramp_t m_ramp_swapfree;
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -22,6 +22,8 @@ namespace modules {
|
|||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
void update() {}
|
void update() {}
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "custom/menu";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
@ -42,6 +44,6 @@ namespace modules {
|
|||||||
|
|
||||||
std::atomic<int> m_level{-1};
|
std::atomic<int> m_level{-1};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -22,7 +22,6 @@ using std::map;
|
|||||||
|
|
||||||
#define DEFAULT_FORMAT "format"
|
#define DEFAULT_FORMAT "format"
|
||||||
|
|
||||||
#define DEFINE_MODULE(name, type) struct name : public type<name>
|
|
||||||
#define CONST_MOD(name) static_cast<name const&>(*this)
|
#define CONST_MOD(name) static_cast<name const&>(*this)
|
||||||
#define CAST_MOD(name) static_cast<name*>(this)
|
#define CAST_MOD(name) static_cast<name*>(this)
|
||||||
|
|
||||||
@ -101,6 +100,11 @@ namespace modules {
|
|||||||
public:
|
public:
|
||||||
virtual ~module_interface() {}
|
virtual ~module_interface() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type users have to specify in the module section `type` key
|
||||||
|
*/
|
||||||
|
virtual string type() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module name w/o 'module/' prefix
|
* Module name w/o 'module/' prefix
|
||||||
*/
|
*/
|
||||||
@ -123,6 +127,8 @@ namespace modules {
|
|||||||
module(const bar_settings bar, string name);
|
module(const bar_settings bar, string name);
|
||||||
~module() noexcept;
|
~module() noexcept;
|
||||||
|
|
||||||
|
string type() const;
|
||||||
|
|
||||||
string name_raw() const;
|
string name_raw() const;
|
||||||
string name() const;
|
string name() const;
|
||||||
bool running() const;
|
bool running() const;
|
||||||
@ -134,6 +140,8 @@ namespace modules {
|
|||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
string input_handler_name() const;
|
string input_handler_name() const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void broadcast();
|
void broadcast();
|
||||||
void idle();
|
void idle();
|
||||||
@ -155,8 +163,8 @@ namespace modules {
|
|||||||
mutex m_sleeplock;
|
mutex m_sleeplock;
|
||||||
std::condition_variable m_sleephandler;
|
std::condition_variable m_sleephandler;
|
||||||
|
|
||||||
string m_name;
|
const string m_name;
|
||||||
string m_name_raw;
|
const string m_name_raw;
|
||||||
unique_ptr<builder> m_builder;
|
unique_ptr<builder> m_builder;
|
||||||
unique_ptr<module_formatter> m_formatter;
|
unique_ptr<module_formatter> m_formatter;
|
||||||
vector<thread> m_threads;
|
vector<thread> m_threads;
|
||||||
|
@ -46,6 +46,11 @@ namespace modules {
|
|||||||
return m_name_raw;
|
return m_name_raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Impl>
|
||||||
|
string module<Impl>::type() const {
|
||||||
|
return string(CONST_MOD(Impl).TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Impl>
|
template <typename Impl>
|
||||||
bool module<Impl>::running() const {
|
bool module<Impl>::running() const {
|
||||||
return static_cast<bool>(m_enabled);
|
return static_cast<bool>(m_enabled);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
#include "modules/backlight.hpp"
|
#include "modules/backlight.hpp"
|
||||||
#include "modules/battery.hpp"
|
#include "modules/battery.hpp"
|
||||||
#include "modules/bspwm.hpp"
|
#include "modules/bspwm.hpp"
|
||||||
@ -43,9 +42,7 @@
|
|||||||
#if ENABLE_XKEYBOARD
|
#if ENABLE_XKEYBOARD
|
||||||
#include "modules/xkeyboard.hpp"
|
#include "modules/xkeyboard.hpp"
|
||||||
#endif
|
#endif
|
||||||
#if not(ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_PULSEAUDIO && ENABLE_CURL && ENABLE_XKEYBOARD)
|
|
||||||
#include "modules/unsupported.hpp"
|
#include "modules/unsupported.hpp"
|
||||||
#endif
|
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -53,63 +50,63 @@ using namespace modules;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
module_interface* make_module(string&& name, const bar_settings& bar, string module_name, const logger& m_log) {
|
module_interface* make_module(string&& name, const bar_settings& bar, string module_name, const logger& m_log) {
|
||||||
if (name == "internal/counter") {
|
if (name == counter_module::TYPE) {
|
||||||
return new counter_module(bar, move(module_name));
|
return new counter_module(bar, move(module_name));
|
||||||
} else if (name == "internal/backlight") {
|
} else if (name == backlight_module::TYPE) {
|
||||||
return new backlight_module(bar, move(module_name));
|
return new backlight_module(bar, move(module_name));
|
||||||
} else if (name == "internal/battery") {
|
} else if (name == battery_module::TYPE) {
|
||||||
return new battery_module(bar, move(module_name));
|
return new battery_module(bar, move(module_name));
|
||||||
} else if (name == "internal/bspwm") {
|
} else if (name == bspwm_module::TYPE) {
|
||||||
return new bspwm_module(bar, move(module_name));
|
return new bspwm_module(bar, move(module_name));
|
||||||
} else if (name == "internal/cpu") {
|
} else if (name == cpu_module::TYPE) {
|
||||||
return new cpu_module(bar, move(module_name));
|
return new cpu_module(bar, move(module_name));
|
||||||
} else if (name == "internal/date") {
|
} else if (name == date_module::TYPE) {
|
||||||
return new date_module(bar, move(module_name));
|
return new date_module(bar, move(module_name));
|
||||||
} else if (name == "internal/github") {
|
} else if (name == github_module::TYPE) {
|
||||||
return new github_module(bar, move(module_name));
|
return new github_module(bar, move(module_name));
|
||||||
} else if (name == "internal/fs") {
|
} else if (name == fs_module::TYPE) {
|
||||||
return new fs_module(bar, move(module_name));
|
return new fs_module(bar, move(module_name));
|
||||||
} else if (name == "internal/memory") {
|
} else if (name == memory_module::TYPE) {
|
||||||
return new memory_module(bar, move(module_name));
|
return new memory_module(bar, move(module_name));
|
||||||
} else if (name == "internal/i3") {
|
} else if (name == i3_module::TYPE) {
|
||||||
return new i3_module(bar, move(module_name));
|
return new i3_module(bar, move(module_name));
|
||||||
} else if (name == "internal/mpd") {
|
} else if (name == mpd_module::TYPE) {
|
||||||
return new mpd_module(bar, move(module_name));
|
return new mpd_module(bar, move(module_name));
|
||||||
} else if (name == "internal/volume") {
|
} else if (name == "internal/volume") {
|
||||||
m_log.warn("internal/volume is deprecated, use internal/alsa instead");
|
m_log.warn("internal/volume is deprecated, use %s instead", alsa_module::TYPE);
|
||||||
return new alsa_module(bar, move(module_name));
|
return new alsa_module(bar, move(module_name));
|
||||||
} else if (name == "internal/alsa") {
|
} else if (name == alsa_module::TYPE) {
|
||||||
return new alsa_module(bar, move(module_name));
|
return new alsa_module(bar, move(module_name));
|
||||||
} else if (name == "internal/pulseaudio") {
|
} else if (name == pulseaudio_module::TYPE) {
|
||||||
return new pulseaudio_module(bar, move(module_name));
|
return new pulseaudio_module(bar, move(module_name));
|
||||||
} else if (name == "internal/network") {
|
} else if (name == network_module::TYPE) {
|
||||||
return new network_module(bar, move(module_name));
|
return new network_module(bar, move(module_name));
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
} else if (name == "internal/systray") {
|
} else if (name == systray_module::TYPE) {
|
||||||
return new systray_module(bar, move(module_name));
|
return new systray_module(bar, move(module_name));
|
||||||
#endif
|
#endif
|
||||||
} else if (name == "internal/temperature") {
|
} else if (name == temperature_module::TYPE) {
|
||||||
return new temperature_module(bar, move(module_name));
|
return new temperature_module(bar, move(module_name));
|
||||||
} else if (name == "internal/xbacklight") {
|
} else if (name == xbacklight_module::TYPE) {
|
||||||
return new xbacklight_module(bar, move(module_name));
|
return new xbacklight_module(bar, move(module_name));
|
||||||
} else if (name == "internal/xkeyboard") {
|
} else if (name == xkeyboard_module::TYPE) {
|
||||||
return new xkeyboard_module(bar, move(module_name));
|
return new xkeyboard_module(bar, move(module_name));
|
||||||
} else if (name == "internal/xwindow") {
|
} else if (name == xwindow_module::TYPE) {
|
||||||
return new xwindow_module(bar, move(module_name));
|
return new xwindow_module(bar, move(module_name));
|
||||||
} else if (name == "internal/xworkspaces") {
|
} else if (name == xworkspaces_module::TYPE) {
|
||||||
return new xworkspaces_module(bar, move(module_name));
|
return new xworkspaces_module(bar, move(module_name));
|
||||||
} else if (name == "custom/text") {
|
} else if (name == text_module::TYPE) {
|
||||||
return new text_module(bar, move(module_name));
|
return new text_module(bar, move(module_name));
|
||||||
} else if (name == "custom/script") {
|
} else if (name == script_module::TYPE) {
|
||||||
return new script_module(bar, move(module_name));
|
return new script_module(bar, move(module_name));
|
||||||
} else if (name == "custom/menu") {
|
} else if (name == menu_module::TYPE) {
|
||||||
return new menu_module(bar, move(module_name));
|
return new menu_module(bar, move(module_name));
|
||||||
} else if (name == "custom/ipc") {
|
} else if (name == ipc_module::TYPE) {
|
||||||
return new ipc_module(bar, move(module_name));
|
return new ipc_module(bar, move(module_name));
|
||||||
} else {
|
} else {
|
||||||
throw application_error("Unknown module: " + name);
|
throw application_error("Unknown module: " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#include "utils/env.hpp"
|
|
||||||
#include "adapters/mpd.hpp"
|
#include "adapters/mpd.hpp"
|
||||||
#include "modules/meta/event_module.hpp"
|
#include "modules/meta/event_module.hpp"
|
||||||
|
#include "utils/env.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -24,6 +24,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/mpd";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
@ -103,6 +105,6 @@ namespace modules {
|
|||||||
string m_toggle_on_color;
|
string m_toggle_on_color;
|
||||||
string m_toggle_off_color;
|
string m_toggle_off_color;
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -18,6 +18,8 @@ namespace modules {
|
|||||||
string get_format() const;
|
string get_format() const;
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/network";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void subthread_routine();
|
void subthread_routine();
|
||||||
|
|
||||||
@ -53,6 +55,6 @@ namespace modules {
|
|||||||
bool m_accumulate{false};
|
bool m_accumulate{false};
|
||||||
bool m_unknown_up{false};
|
bool m_unknown_up{false};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "settings.hpp"
|
|
||||||
#include "modules/meta/event_module.hpp"
|
#include "modules/meta/event_module.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -22,6 +22,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/pulseaudio";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
@ -51,6 +53,6 @@ namespace modules {
|
|||||||
atomic<int> m_volume{0};
|
atomic<int> m_volume{0};
|
||||||
atomic<double> m_decibels{0};
|
atomic<double> m_decibels{0};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -18,6 +18,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "custom/script";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
chrono::duration<double> process(const mutex_wrapper<function<chrono::duration<double>()>>& handler) const;
|
chrono::duration<double> process(const mutex_wrapper<function<chrono::duration<double>()>>& handler) const;
|
||||||
bool check_condition();
|
bool check_condition();
|
||||||
@ -44,6 +46,6 @@ namespace modules {
|
|||||||
|
|
||||||
bool m_stopping{false};
|
bool m_stopping{false};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -19,6 +19,8 @@ namespace modules {
|
|||||||
void update();
|
void update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/systray";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ namespace modules {
|
|||||||
|
|
||||||
bool m_hidden{false};
|
bool m_hidden{false};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
|
||||||
#include "settings.hpp"
|
|
||||||
#include "modules/meta/timer_module.hpp"
|
#include "modules/meta/timer_module.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -18,6 +18,8 @@ namespace modules {
|
|||||||
string get_format() const;
|
string get_format() const;
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/temperature";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr auto TAG_LABEL = "<label>";
|
static constexpr auto TAG_LABEL = "<label>";
|
||||||
static constexpr auto TAG_LABEL_WARN = "<label-warn>";
|
static constexpr auto TAG_LABEL_WARN = "<label-warn>";
|
||||||
@ -39,6 +41,6 @@ namespace modules {
|
|||||||
// Whether or not to show units with the %temperature-X% tokens
|
// Whether or not to show units with the %temperature-X% tokens
|
||||||
bool m_units{true};
|
bool m_units{true};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -12,7 +12,9 @@ namespace modules {
|
|||||||
void update() {}
|
void update() {}
|
||||||
string get_format() const;
|
string get_format() const;
|
||||||
string get_output();
|
string get_output();
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "custom/text";
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#if ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_PULSEAUDIO && ENABLE_CURL && ENABLE_XKEYBOARD
|
|
||||||
#error "Support has been enabled for all optional modules"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "modules/meta/base.hpp"
|
#include "modules/meta/base.hpp"
|
||||||
#include "modules/meta/base.inl"
|
#include "modules/meta/base.inl"
|
||||||
@ -17,6 +14,9 @@ namespace modules {
|
|||||||
MODULE_NAME(const bar_settings, string) { \
|
MODULE_NAME(const bar_settings, string) { \
|
||||||
throw application_error("No built-in support for '" + string{MODULE_TYPE} + "'"); \
|
throw application_error("No built-in support for '" + string{MODULE_TYPE} + "'"); \
|
||||||
} \
|
} \
|
||||||
|
string type() const { \
|
||||||
|
return ""; \
|
||||||
|
} \
|
||||||
string name_raw() const { \
|
string name_raw() const { \
|
||||||
return ""; \
|
return ""; \
|
||||||
} \
|
} \
|
||||||
@ -61,6 +61,6 @@ namespace modules {
|
|||||||
#if not ENABLE_XKEYBOARD
|
#if not ENABLE_XKEYBOARD
|
||||||
DEFINE_UNSUPPORTED_MODULE(xkeyboard_module, "internal/xkeyboard");
|
DEFINE_UNSUPPORTED_MODULE(xkeyboard_module, "internal/xkeyboard");
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "components/config.hpp"
|
#include "components/config.hpp"
|
||||||
#include "settings.hpp"
|
|
||||||
#include "modules/meta/event_handler.hpp"
|
#include "modules/meta/event_handler.hpp"
|
||||||
#include "modules/meta/static_module.hpp"
|
#include "modules/meta/static_module.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
#include "x11/extensions/randr.hpp"
|
#include "x11/extensions/randr.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
@ -21,11 +21,8 @@ namespace modules {
|
|||||||
* This module is a lot faster, it's more responsive and it will
|
* This module is a lot faster, it's more responsive and it will
|
||||||
* be dormant until new values are reported. Inotify watches
|
* be dormant until new values are reported. Inotify watches
|
||||||
* are a bit random when it comes to proc-/sysfs.
|
* are a bit random when it comes to proc-/sysfs.
|
||||||
*
|
|
||||||
* TODO: Implement backlight configuring using scroll events
|
|
||||||
*/
|
*/
|
||||||
class xbacklight_module : public static_module<xbacklight_module>,
|
class xbacklight_module : public static_module<xbacklight_module>, public event_handler<evt::randr_notify> {
|
||||||
public event_handler<evt::randr_notify> {
|
|
||||||
public:
|
public:
|
||||||
explicit xbacklight_module(const bar_settings& bar, string name_);
|
explicit xbacklight_module(const bar_settings& bar, string name_);
|
||||||
|
|
||||||
@ -33,6 +30,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/xbacklight";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void handle(const evt::randr_notify& evt);
|
void handle(const evt::randr_notify& evt);
|
||||||
bool input(string&& cmd);
|
bool input(string&& cmd);
|
||||||
@ -56,6 +55,6 @@ namespace modules {
|
|||||||
bool m_scroll{true};
|
bool m_scroll{true};
|
||||||
std::atomic<int> m_percentage{0};
|
std::atomic<int> m_percentage{0};
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -26,6 +26,8 @@ namespace modules {
|
|||||||
void update();
|
void update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/xkeyboard";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool query_keyboard();
|
bool query_keyboard();
|
||||||
bool blacklisted(const string& indicator_name);
|
bool blacklisted(const string& indicator_name);
|
||||||
@ -42,7 +44,7 @@ namespace modules {
|
|||||||
static constexpr const char* FORMAT_DEFAULT{"<label-layout> <label-indicator>"};
|
static constexpr const char* FORMAT_DEFAULT{"<label-layout> <label-indicator>"};
|
||||||
static constexpr const char* DEFAULT_LAYOUT_ICON{"layout-icon-default"};
|
static constexpr const char* DEFAULT_LAYOUT_ICON{"layout-icon-default"};
|
||||||
static constexpr const char* DEFAULT_INDICATOR_ICON{"indicator-icon-default"};
|
static constexpr const char* DEFAULT_INDICATOR_ICON{"indicator-icon-default"};
|
||||||
|
|
||||||
static constexpr const char* EVENT_SWITCH{"xkeyboard/switch"};
|
static constexpr const char* EVENT_SWITCH{"xkeyboard/switch"};
|
||||||
|
|
||||||
connection& m_connection;
|
connection& m_connection;
|
||||||
@ -63,6 +65,6 @@ namespace modules {
|
|||||||
iconset_t m_indicator_icons_on;
|
iconset_t m_indicator_icons_on;
|
||||||
iconset_t m_indicator_icons_off;
|
iconset_t m_indicator_icons_off;
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -30,16 +30,14 @@ namespace modules {
|
|||||||
*/
|
*/
|
||||||
class xwindow_module : public static_module<xwindow_module>, public event_handler<evt::property_notify> {
|
class xwindow_module : public static_module<xwindow_module>, public event_handler<evt::property_notify> {
|
||||||
public:
|
public:
|
||||||
enum class state {
|
enum class state { NONE, ACTIVE, EMPTY };
|
||||||
NONE,
|
|
||||||
ACTIVE,
|
|
||||||
EMPTY
|
|
||||||
};
|
|
||||||
explicit xwindow_module(const bar_settings&, string);
|
explicit xwindow_module(const bar_settings&, string);
|
||||||
|
|
||||||
void update(bool force = false);
|
void update(bool force = false);
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/xwindow";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void handle(const evt::property_notify& evt);
|
void handle(const evt::property_notify& evt);
|
||||||
|
|
||||||
@ -51,6 +49,6 @@ namespace modules {
|
|||||||
map<state, label_t> m_statelabels;
|
map<state, label_t> m_statelabels;
|
||||||
label_t m_label;
|
label_t m_label;
|
||||||
};
|
};
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -50,8 +50,7 @@ namespace modules {
|
|||||||
/**
|
/**
|
||||||
* Module used to display EWMH desktops
|
* Module used to display EWMH desktops
|
||||||
*/
|
*/
|
||||||
class xworkspaces_module : public static_module<xworkspaces_module>,
|
class xworkspaces_module : public static_module<xworkspaces_module>, public event_handler<evt::property_notify> {
|
||||||
public event_handler<evt::property_notify> {
|
|
||||||
public:
|
public:
|
||||||
explicit xworkspaces_module(const bar_settings& bar, string name_);
|
explicit xworkspaces_module(const bar_settings& bar, string name_);
|
||||||
|
|
||||||
@ -59,6 +58,8 @@ namespace modules {
|
|||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
|
static constexpr auto TYPE = "internal/xworkspaces";
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void handle(const evt::property_notify& evt);
|
void handle(const evt::property_notify& evt);
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ void controller::process_inputdata() {
|
|||||||
// Forwards the action to all input handlers that match the name
|
// Forwards the action to all input handlers that match the name
|
||||||
for (auto&& handler : m_inputhandlers) {
|
for (auto&& handler : m_inputhandlers) {
|
||||||
if (handler->input_handler_name() == handler_name) {
|
if (handler->input_handler_name() == handler_name) {
|
||||||
if(!handler->input(string{action})) {
|
if (!handler->input(string{action})) {
|
||||||
m_log.warn("The '%s' module does not support the '%s' action.", handler_name, action);
|
m_log.warn("The '%s' module does not support the '%s' action.", handler_name, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,9 +432,8 @@ void controller::process_inputdata() {
|
|||||||
|
|
||||||
if (num_delivered == 0) {
|
if (num_delivered == 0) {
|
||||||
m_log.err("There exists no input handler with name '%s' (input: %s)", handler_name, cmd);
|
m_log.err("There exists no input handler with name '%s' (input: %s)", handler_name, cmd);
|
||||||
}
|
} else {
|
||||||
else {
|
m_log.info("Delivered input to %d input handler%s", num_delivered, num_delivered > 1 ? "s" : "");
|
||||||
m_log.info("Delivered input to %d input handler%s", num_delivered, num_delivered > 1? "s": "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -600,7 +599,7 @@ size_t controller::setup_modules(alignment align) {
|
|||||||
try {
|
try {
|
||||||
auto type = m_conf.get("module/" + module_name, "type");
|
auto type = m_conf.get("module/" + module_name, "type");
|
||||||
|
|
||||||
if (type == "custom/ipc" && !m_ipc) {
|
if (type == ipc_module::TYPE && !m_ipc) {
|
||||||
throw application_error("Inter-process messaging needs to be enabled");
|
throw application_error("Inter-process messaging needs to be enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "modules/date.hpp"
|
#include "modules/date.hpp"
|
||||||
#include "drawtypes/label.hpp"
|
|
||||||
|
|
||||||
|
#include "drawtypes/label.hpp"
|
||||||
#include "modules/meta/base.inl"
|
#include "modules/meta/base.inl"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
@ -93,6 +93,6 @@ namespace modules {
|
|||||||
wakeup();
|
wakeup();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
} // namespace modules
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
Loading…
Reference in New Issue
Block a user