diff --git a/include/modules/ui.hpp b/include/modules/ui.hpp
new file mode 100644
index 000000000..1d26efd5d
--- /dev/null
+++ b/include/modules/ui.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "AModule.hpp"
+
+namespace waybar::modules {
+
+class UI final : public AModule {
+ public:
+ UI(const std::string&, const std::string&, const Json::Value&);
+ virtual ~UI() = default;
+};
+
+} // namespace waybar::modules
diff --git a/meson.build b/meson.build
index 726d492bb..702fff1f6 100644
--- a/meson.build
+++ b/meson.build
@@ -183,7 +183,8 @@ src_files = files(
'src/util/rewrite_string.cpp',
'src/util/gtk_icon.cpp',
'src/util/regex_collection.cpp',
- 'src/util/css_reload_helper.cpp'
+ 'src/util/css_reload_helper.cpp',
+ 'src/modules/ui.cpp'
)
man_files = files(
@@ -543,6 +544,11 @@ install_data(
install_dir: sysconfdir / 'xdg/waybar'
)
+install_subdir(
+ 'resources/ui',
+ install_dir: sysconfdir / 'xdg/waybar'
+)
+
scdoc = dependency('scdoc', version: '>=1.9.2', native: true, required: get_option('man-pages'))
if scdoc.found()
diff --git a/resources/ui/ui-power.xml b/resources/ui/ui-power.xml
new file mode 100644
index 000000000..9a852e59b
--- /dev/null
+++ b/resources/ui/ui-power.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
diff --git a/src/factory.cpp b/src/factory.cpp
index 6c2313e38..4ad521847 100644
--- a/src/factory.cpp
+++ b/src/factory.cpp
@@ -113,6 +113,7 @@
#include "modules/custom.hpp"
#include "modules/image.hpp"
#include "modules/temperature.hpp"
+#include "modules/ui.hpp"
#include "modules/user.hpp"
waybar::Factory::Factory(const Bar& bar, const Json::Value& config) : bar_(bar), config_(config) {}
@@ -341,6 +342,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
if (ref.compare(0, 5, "cffi/") == 0 && ref.size() > 5) {
return new waybar::modules::CFFI(ref.substr(5), id, config_[name]);
}
+ if (ref.compare(0, 3, "ui/") == 0 && ref.size() > 3) {
+ return new waybar::modules::UI(ref.substr(3), id, config_[name]);
+ }
} catch (const std::exception& e) {
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());
throw std::runtime_error(err);
diff --git a/src/main.cpp b/src/main.cpp
index 442c530cb..045b2cd49 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -109,7 +109,7 @@ int main(int argc, char* argv[]) {
std::signal(SIGUSR1, SIG_IGN);
std::signal(SIGUSR2, SIG_IGN);
- std::signal(SIGINT, SIG_IGN);
+ std::signal(SIGINT, SIG_IGN);
delete client;
return ret;
diff --git a/src/modules/ui.cpp b/src/modules/ui.cpp
new file mode 100644
index 000000000..13aa1d28b
--- /dev/null
+++ b/src/modules/ui.cpp
@@ -0,0 +1,38 @@
+#include "modules/ui.hpp"
+
+#include
+#include
+
+#include
+
+waybar::modules::UI::UI(const std::string& name, const std::string& id, const Json::Value& config)
+ : AModule(config, "ui-" + name, id, false, false) {
+ if (config_["file-path"].isString()) {
+ Glib::RefPtr builder{
+ Gtk::Builder::create_from_file(config_["file-path"].asString())};
+ Glib::RefPtr uiWg{
+ Glib::RefPtr::cast_dynamic(builder->get_object(name_))};
+
+ if (uiWg) {
+ uiWg->set_name(name_);
+ if (!id.empty()) {
+ uiWg->get_style_context()->add_class(id);
+ }
+ uiWg->get_style_context()->add_class(MODULE_CLASS);
+
+ Glib::RefPtr actionGroup{Gio::SimpleActionGroup::create()};
+ Glib::RefPtr action{actionGroup->add_action_with_parameter(
+ "doAction", Glib::VARIANT_TYPE_STRING, [this](const Glib::VariantBase& param) {
+ assert(param.is_of_type(Glib::VARIANT_TYPE_STRING));
+ waybar::util::command::res res = waybar::util::command::exec(
+ Glib::VariantBase::cast_dynamic>(param).get(), "TLP");
+ })};
+
+ uiWg->insert_action_group(name_, actionGroup);
+ event_box_.add(*uiWg.get());
+ } else {
+ spdlog::error("UI: object id \"{}\" is not found at \"{}\"", name_,
+ config_["file-path"].asString());
+ }
+ }
+}