tray: Start tray from module
This commit is contained in:
parent
1dcff9396a
commit
ffcdf7d690
@ -62,6 +62,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void trigger_notification();
|
void trigger_notification();
|
||||||
|
void start_modules();
|
||||||
void read_events(bool confwatch);
|
void read_events(bool confwatch);
|
||||||
void process_inputdata(string&& cmd);
|
void process_inputdata(string&& cmd);
|
||||||
bool process_update(bool force);
|
bool process_update(bool force);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "components/bar.hpp"
|
#include "components/bar.hpp"
|
||||||
#include "modules/meta/static_module.hpp"
|
#include "modules/meta/static_module.hpp"
|
||||||
|
#include "x11/tray_manager.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
namespace modules {
|
namespace modules {
|
||||||
@ -12,6 +13,8 @@ namespace modules {
|
|||||||
explicit tray_module(const bar_settings& bar_settings, string name_);
|
explicit tray_module(const bar_settings& bar_settings, string name_);
|
||||||
string get_format() const;
|
string get_format() const;
|
||||||
|
|
||||||
|
void start() override;
|
||||||
|
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
void update() {}
|
void update() {}
|
||||||
void teardown();
|
void teardown();
|
||||||
@ -23,6 +26,8 @@ namespace modules {
|
|||||||
private:
|
private:
|
||||||
static constexpr const char* TAG_TRAY{"<tray>"};
|
static constexpr const char* TAG_TRAY{"<tray>"};
|
||||||
|
|
||||||
|
tray_manager m_tray;
|
||||||
|
|
||||||
int m_width{0};
|
int m_width{0};
|
||||||
};
|
};
|
||||||
} // namespace modules
|
} // namespace modules
|
||||||
|
@ -73,7 +73,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||||||
, m_action_ctxt(forward<decltype(action_ctxt)>(action_ctxt)) {
|
, m_action_ctxt(forward<decltype(action_ctxt)>(action_ctxt)) {
|
||||||
string bs{m_conf.section()};
|
string bs{m_conf.section()};
|
||||||
|
|
||||||
m_tray = tray_manager::make(m_opts);
|
// m_tray = tray_manager::make(m_opts);
|
||||||
|
|
||||||
// Get available RandR outputs
|
// Get available RandR outputs
|
||||||
auto monitor_name = m_conf.get(bs, "monitor", ""s);
|
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) {
|
void bar::handle(const evt::expose& evt) {
|
||||||
if (evt->window == m_opts.x_data.window && evt->count == 0) {
|
if (evt->window == m_opts.x_data.window && evt->count == 0) {
|
||||||
if (m_tray->running()) {
|
// if (m_tray->running()) {
|
||||||
broadcast_visibility();
|
// broadcast_visibility();
|
||||||
}
|
// }
|
||||||
|
|
||||||
m_log.trace("bar: Received expose event");
|
m_log.trace("bar: Received expose event");
|
||||||
m_renderer->flush();
|
m_renderer->flush();
|
||||||
@ -907,7 +907,7 @@ void bar::start(const string& tray_module_name) {
|
|||||||
m_renderer->end();
|
m_renderer->end();
|
||||||
|
|
||||||
m_log.trace("bar: Setup tray manager");
|
m_log.trace("bar: Setup tray manager");
|
||||||
m_tray->setup(tray_module_name);
|
// m_tray->setup(tray_module_name);
|
||||||
|
|
||||||
broadcast_visibility();
|
broadcast_visibility();
|
||||||
}
|
}
|
||||||
|
@ -100,27 +100,6 @@ bool controller::run(bool writeback, string snapshot_dst, bool confwatch) {
|
|||||||
|
|
||||||
m_sig.attach(this);
|
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();
|
m_connection.flush();
|
||||||
|
|
||||||
read_events(confwatch);
|
read_events(confwatch);
|
||||||
@ -242,6 +221,29 @@ void controller::screenshot_handler() {
|
|||||||
trigger_update(true);
|
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
|
* Read events from configured file descriptors
|
||||||
*/
|
*/
|
||||||
@ -252,6 +254,8 @@ void controller::read_events(bool confwatch) {
|
|||||||
m_bar->start(m_tray_module_name);
|
m_bar->start(m_tray_module_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start_modules();
|
||||||
|
|
||||||
auto& poll_handle = m_loop.handle<PollHandle>(m_connection.get_file_descriptor());
|
auto& poll_handle = m_loop.handle<PollHandle>(m_connection.get_file_descriptor());
|
||||||
poll_handle.start(
|
poll_handle.start(
|
||||||
UV_READABLE, [this](const auto&) { conn_cb(); },
|
UV_READABLE, [this](const auto&) { conn_cb(); },
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
#include "modules/tray.hpp"
|
#include "modules/tray.hpp"
|
||||||
|
|
||||||
#include "modules/meta/base.inl"
|
#include "modules/meta/base.inl"
|
||||||
|
#include "x11/background_manager.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
namespace modules {
|
namespace modules {
|
||||||
template class module<tray_module>;
|
template class module<tray_module>;
|
||||||
|
|
||||||
tray_module::tray_module(const bar_settings& bar_settings, string name_)
|
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_formatter->add(DEFAULT_FORMAT, TAG_TRAY, {TAG_TRAY});
|
||||||
m_sig.attach(this);
|
m_sig.attach(this);
|
||||||
}
|
}
|
||||||
@ -16,6 +18,11 @@ namespace modules {
|
|||||||
return DEFAULT_FORMAT;
|
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 {
|
bool tray_module::build(builder* builder, const string& tag) const {
|
||||||
if (tag == TAG_TRAY) {
|
if (tag == TAG_TRAY) {
|
||||||
builder->control(tags::controltag::t);
|
builder->control(tags::controltag::t);
|
||||||
|
@ -65,15 +65,13 @@ tray_manager::~tray_manager() {
|
|||||||
deactivate();
|
deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO load settings from module section
|
||||||
|
*/
|
||||||
void tray_manager::setup(const string& tray_module_name) {
|
void tray_manager::setup(const string& tray_module_name) {
|
||||||
const config& conf = config::make();
|
const config& conf = config::make();
|
||||||
auto bs = conf.section();
|
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();
|
auto inner_area = m_bar_opts.inner_area();
|
||||||
unsigned client_height = inner_area.height;
|
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;
|
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
|
// Activate the tray manager
|
||||||
query_atom();
|
query_atom();
|
||||||
activate();
|
activate();
|
||||||
|
Loading…
Reference in New Issue
Block a user