From ffcdf7d690c01a168a3d870cb292630c9d8332b5 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 28 Aug 2022 15:15:48 +0200
Subject: [PATCH] tray: Start tray from module
---
include/components/controller.hpp | 1 +
include/modules/tray.hpp | 7 ++++-
src/components/bar.cpp | 10 +++----
src/components/controller.cpp | 46 +++++++++++++++++--------------
src/modules/tray.cpp | 11 ++++++--
src/x11/tray_manager.cpp | 13 +++++----
6 files changed, 54 insertions(+), 34 deletions(-)
diff --git a/include/components/controller.hpp b/include/components/controller.hpp
index cb0a72e7..70edcaf7 100644
--- a/include/components/controller.hpp
+++ b/include/components/controller.hpp
@@ -62,6 +62,7 @@ class controller : public signal_receiver"};
+ tray_manager m_tray;
+
int m_width{0};
};
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/components/bar.cpp b/src/components/bar.cpp
index 5e2eb0d3..ffa8985b 100644
--- a/src/components/bar.cpp
+++ b/src/components/bar.cpp
@@ -73,7 +73,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
, m_action_ctxt(forward(action_ctxt)) {
string bs{m_conf.section()};
- m_tray = tray_manager::make(m_opts);
+ // m_tray = tray_manager::make(m_opts);
// Get available RandR outputs
auto monitor_name = m_conf.get(bs, "monitor", ""s);
@@ -840,9 +840,9 @@ void bar::handle(const evt::button_press& evt) {
*/
void bar::handle(const evt::expose& evt) {
if (evt->window == m_opts.x_data.window && evt->count == 0) {
- if (m_tray->running()) {
- broadcast_visibility();
- }
+ // if (m_tray->running()) {
+ // broadcast_visibility();
+ // }
m_log.trace("bar: Received expose event");
m_renderer->flush();
@@ -907,7 +907,7 @@ void bar::start(const string& tray_module_name) {
m_renderer->end();
m_log.trace("bar: Setup tray manager");
- m_tray->setup(tray_module_name);
+ // m_tray->setup(tray_module_name);
broadcast_visibility();
}
diff --git a/src/components/controller.cpp b/src/components/controller.cpp
index bf953d49..84f77c2a 100644
--- a/src/components/controller.cpp
+++ b/src/components/controller.cpp
@@ -100,27 +100,6 @@ bool controller::run(bool writeback, string snapshot_dst, bool confwatch) {
m_sig.attach(this);
- size_t started_modules{0};
- for (const auto& module : m_modules) {
- auto evt_handler = dynamic_cast(&*module);
-
- if (evt_handler != nullptr) {
- evt_handler->connect(m_connection);
- }
-
- try {
- m_log.info("Starting %s", module->name());
- module->start();
- started_modules++;
- } catch (const application_error& err) {
- m_log.err("Failed to start '%s' (reason: %s)", module->name(), err.what());
- }
- }
-
- if (!started_modules) {
- throw application_error("No modules started");
- }
-
m_connection.flush();
read_events(confwatch);
@@ -242,6 +221,29 @@ void controller::screenshot_handler() {
trigger_update(true);
}
+void controller::start_modules() {
+ size_t started_modules{0};
+ for (const auto& module : m_modules) {
+ auto evt_handler = dynamic_cast(&*module);
+
+ if (evt_handler != nullptr) {
+ evt_handler->connect(m_connection);
+ }
+
+ try {
+ m_log.info("Starting %s", module->name());
+ module->start();
+ started_modules++;
+ } catch (const application_error& err) {
+ m_log.err("Failed to start '%s' (reason: %s)", module->name(), err.what());
+ }
+ }
+
+ if (!started_modules) {
+ throw application_error("No modules started");
+ }
+}
+
/**
* Read events from configured file descriptors
*/
@@ -252,6 +254,8 @@ void controller::read_events(bool confwatch) {
m_bar->start(m_tray_module_name);
}
+ start_modules();
+
auto& poll_handle = m_loop.handle(m_connection.get_file_descriptor());
poll_handle.start(
UV_READABLE, [this](const auto&) { conn_cb(); },
diff --git a/src/modules/tray.cpp b/src/modules/tray.cpp
index c38fd8f2..d333c4c1 100644
--- a/src/modules/tray.cpp
+++ b/src/modules/tray.cpp
@@ -1,13 +1,15 @@
#include "modules/tray.hpp"
#include "modules/meta/base.inl"
+#include "x11/background_manager.hpp"
POLYBAR_NS
namespace modules {
template class module;
tray_module::tray_module(const bar_settings& bar_settings, string name_)
- : static_module(bar_settings, move(name_)) {
+ : static_module(bar_settings, move(name_))
+ , m_tray(connection::make(), signal_emitter::make(), m_log, bar_settings) {
m_formatter->add(DEFAULT_FORMAT, TAG_TRAY, {TAG_TRAY});
m_sig.attach(this);
}
@@ -16,6 +18,11 @@ namespace modules {
return DEFAULT_FORMAT;
}
+ void tray_module::start() {
+ m_tray.setup(name_raw());
+ this->static_module::start();
+ }
+
bool tray_module::build(builder* builder, const string& tag) const {
if (tag == TAG_TRAY) {
builder->control(tags::controltag::t);
@@ -36,5 +43,5 @@ namespace modules {
m_sig.detach(this);
}
-} // namespace modules
+} // namespace modules
POLYBAR_NS_END
diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp
index 46f732f7..f890ec24 100644
--- a/src/x11/tray_manager.cpp
+++ b/src/x11/tray_manager.cpp
@@ -65,15 +65,13 @@ tray_manager::~tray_manager() {
deactivate();
}
+/**
+ * TODO load settings from module section
+ */
void tray_manager::setup(const string& tray_module_name) {
const config& conf = config::make();
auto bs = conf.section();
- // TODO remove check once part of tray module
- if (tray_module_name.empty()) {
- return;
- }
-
auto inner_area = m_bar_opts.inner_area();
unsigned client_height = inner_area.height;
@@ -99,6 +97,11 @@ void tray_manager::setup(const string& tray_module_name) {
m_opts.selection_owner = m_bar_opts.x_data.window;
+ if (m_bar_opts.x_data.window == XCB_NONE) {
+ m_log.err("tray: No bar window found, disabling tray");
+ return;
+ }
+
// Activate the tray manager
query_atom();
activate();