1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

tray: Start tray from module

This commit is contained in:
patrick96 2022-08-28 15:15:48 +02:00
parent 1dcff9396a
commit ffcdf7d690
No known key found for this signature in database
GPG key ID: 521E5E03AEBCA1A7
6 changed files with 54 additions and 34 deletions

View file

@ -62,6 +62,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
protected:
void trigger_notification();
void start_modules();
void read_events(bool confwatch);
void process_inputdata(string&& cmd);
bool process_update(bool force);

View file

@ -3,6 +3,7 @@
#include "common.hpp"
#include "components/bar.hpp"
#include "modules/meta/static_module.hpp"
#include "x11/tray_manager.hpp"
POLYBAR_NS
namespace modules {
@ -12,6 +13,8 @@ namespace modules {
explicit tray_module(const bar_settings& bar_settings, string name_);
string get_format() const;
void start() override;
bool build(builder* builder, const string& tag) const;
void update() {}
void teardown();
@ -23,7 +26,9 @@ namespace modules {
private:
static constexpr const char* TAG_TRAY{"<tray>"};
tray_manager m_tray;
int m_width{0};
};
} // namespace modules
} // namespace modules
POLYBAR_NS_END

View file

@ -73,7 +73,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
, m_action_ctxt(forward<decltype(action_ctxt)>(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();
}

View file

@ -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<event_handler_interface*>(&*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<event_handler_interface*>(&*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<PollHandle>(m_connection.get_file_descriptor());
poll_handle.start(
UV_READABLE, [this](const auto&) { conn_cb(); },

View file

@ -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::tray_module(const bar_settings& bar_settings, string name_)
: static_module<tray_module>(bar_settings, move(name_)) {
: static_module<tray_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<tray_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

View file

@ -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();