refactor(tray): Update using eventloop

This commit is contained in:
Michael Carlberg 2016-12-03 23:01:21 +01:00
parent df85a6492e
commit d6a0c84e0b
6 changed files with 14 additions and 54 deletions

View File

@ -56,9 +56,6 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
xcb_window_t m_window; xcb_window_t m_window;
bar_settings m_opts; bar_settings m_opts;
alignment m_trayalign{alignment::NONE};
uint8_t m_trayclients{0};
string m_lastinput; string m_lastinput;
std::mutex m_mutex; std::mutex m_mutex;

View File

@ -63,13 +63,6 @@ namespace g_signals {
extern callback<const uint16_t> unicode_text_write; extern callback<const uint16_t> unicode_text_write;
extern callback<const char*, const size_t> string_write; extern callback<const char*, const size_t> string_write;
} }
/**
* Signals used to communicate with the tray manager
*/
namespace tray {
extern callback<const uint16_t> report_slotcount;
}
} }
POLYBAR_NS_END POLYBAR_NS_END

View File

@ -56,6 +56,7 @@ struct tray_settings {
uint32_t sibling{0}; uint32_t sibling{0};
uint32_t background{0}; uint32_t background{0};
bool transparent{false}; bool transparent{false};
bool detached{false};
}; };
// }}} // }}}

View File

@ -52,7 +52,6 @@ bar::bar(connection& conn, const config& config, const logger& logger, unique_pt
*/ */
bar::~bar() { bar::~bar() {
std::lock_guard<std::mutex> guard(m_mutex); std::lock_guard<std::mutex> guard(m_mutex);
g_signals::tray::report_slotcount = nullptr;
m_connection.detach_sink(this, SINK_PRIORITY_BAR); m_connection.detach_sink(this, SINK_PRIORITY_BAR);
m_tray.reset(); m_tray.reset();
} }
@ -226,7 +225,7 @@ void bar::bootstrap_tray() {
return; return;
} }
m_trayalign = settings.align; settings.detached = m_conf.get<bool>(bs, "tray-detached", false);
settings.height = m_opts.size.h; settings.height = m_opts.size.h;
settings.height -= m_opts.borders.at(edge::BOTTOM).size; settings.height -= m_opts.borders.at(edge::BOTTOM).size;
@ -303,21 +302,6 @@ void bar::bootstrap_tray() {
settings.orig_x += offset_x; settings.orig_x += offset_x;
settings.orig_y += offset_y; settings.orig_y += offset_y;
// Add tray update callback unless explicitly disabled
if (!m_conf.get<bool>(bs, "tray-detached", false)) {
g_signals::tray::report_slotcount = [this](uint16_t slots) {
m_log.trace("bar: Tray reports %lu slots", slots);
if (m_trayclients != slots) {
m_trayclients = slots;
if (!m_lastinput.empty()) {
parse(m_lastinput, true);
}
}
};
}
// Put the tray next to the bar in the window stack // Put the tray next to the bar in the window stack
settings.sibling = m_window; settings.sibling = m_window;
@ -379,10 +363,10 @@ void bar::parse(const string& data, bool force) {
m_renderer->begin(); m_renderer->begin();
if (m_trayclients) { if (m_tray->settings().configured_slots) {
if (m_tray && m_trayalign == alignment::LEFT) { if (m_tray && m_tray->settings().align == alignment::LEFT) {
m_renderer->reserve_space(edge::LEFT, m_tray->settings().configured_w); m_renderer->reserve_space(edge::LEFT, m_tray->settings().configured_w);
} else if (m_tray && m_trayalign == alignment::RIGHT) { } else if (m_tray && m_tray->settings().align == alignment::RIGHT) {
m_renderer->reserve_space(edge::RIGHT, m_tray->settings().configured_w); m_renderer->reserve_space(edge::RIGHT, m_tray->settings().configured_w);
} }
} }

View File

@ -40,13 +40,6 @@ namespace g_signals {
callback<const uint16_t> unicode_text_write{noop<const uint16_t>}; callback<const uint16_t> unicode_text_write{noop<const uint16_t>};
callback<const char*, const size_t> string_write{noop<const char*, const size_t>}; callback<const char*, const size_t> string_write{noop<const char*, const size_t>};
} }
/**
* Signals used to communicate with the tray manager
*/
namespace tray {
callback<const uint16_t> report_slotcount{noop<const uint16_t>};
}
} }
POLYBAR_NS_END POLYBAR_NS_END

View File

@ -198,8 +198,6 @@ void tray_manager::activate() {
// notify clients waiting for a manager. // notify clients waiting for a manager.
acquire_selection(); acquire_selection();
m_connection.flush();
// Notify pending tray clients // Notify pending tray clients
notify_clients(); notify_clients();
@ -207,6 +205,8 @@ void tray_manager::activate() {
if (m_othermanager != XCB_NONE && m_othermanager != m_tray) { if (m_othermanager != XCB_NONE && m_othermanager != m_tray) {
notify_clients_delayed(); notify_clients_delayed();
} }
m_connection.flush();
} }
/** /**
@ -220,9 +220,8 @@ void tray_manager::deactivate(bool clear_selection) {
m_log.info("Deactivating tray manager"); m_log.info("Deactivating tray manager");
m_activated = false; m_activated = false;
if (g_signals::tray::report_slotcount) { if (!m_opts.detached) {
m_log.trace("tray: Report empty slotcount"); g_signals::event::enqueue(eventloop::make(update_event{}, true));
g_signals::tray::report_slotcount(0);
} }
if (g_signals::bar::visibility_change) { if (g_signals::bar::visibility_change) {
@ -298,9 +297,8 @@ void tray_manager::reconfigure() {
m_opts.configured_slots = mapped_clients(); m_opts.configured_slots = mapped_clients();
// Report status if (!m_opts.detached) {
if (g_signals::tray::report_slotcount) { g_signals::event::enqueue(eventloop::make(update_event{}, true));
g_signals::tray::report_slotcount(m_opts.configured_slots);
} }
guard.unlock(); guard.unlock();
@ -316,21 +314,18 @@ void tray_manager::reconfigure() {
void tray_manager::reconfigure_window() { void tray_manager::reconfigure_window() {
m_log.trace("tray: Reconfigure window (mapped=%i, clients=%i)", static_cast<bool>(m_mapped), m_clients.size()); m_log.trace("tray: Reconfigure window (mapped=%i, clients=%i)", static_cast<bool>(m_mapped), m_clients.size());
if (!m_tray || m_hidden) { if (!m_tray) {
return; return;
} }
auto clients = mapped_clients(); auto clients = mapped_clients();
auto mapped = static_cast<bool>(m_mapped);
if (!clients && m_mapped) { if (!clients && m_mapped && !m_hidden) {
m_log.trace("tray: Reconfigure window / unmap"); m_log.trace("tray: Reconfigure window / unmap");
m_connection.unmap_window_checked(m_tray); m_connection.unmap_window_checked(m_tray);
} else if (clients && !m_mapped) { } else if (clients && !m_mapped && !m_hidden) {
m_log.trace("tray: Reconfigure window / map"); m_log.trace("tray: Reconfigure window / map");
m_connection.map_window_checked(m_tray); m_connection.map_window_checked(m_tray);
} else if (!mapped || !clients) {
return;
} }
auto width = calculate_w(); auto width = calculate_w();
@ -1086,7 +1081,6 @@ void tray_manager::handle(const evt::map_notify& evt) {
m_log.trace("tray: Received map_notify"); m_log.trace("tray: Received map_notify");
m_log.trace("tray: Update container mapped flag"); m_log.trace("tray: Update container mapped flag");
m_mapped = true; m_mapped = true;
redraw_window();
} else { } else {
auto client = find_client(evt->window); auto client = find_client(evt->window);
@ -1114,8 +1108,6 @@ void tray_manager::handle(const evt::unmap_notify& evt) {
m_log.trace("tray: Received unmap_notify"); m_log.trace("tray: Received unmap_notify");
m_log.trace("tray: Update container mapped flag"); m_log.trace("tray: Update container mapped flag");
m_mapped = false; m_mapped = false;
m_opts.configured_w = 0;
m_opts.configured_x = 0;
} else { } else {
auto client = find_client(evt->window); auto client = find_client(evt->window);