From d6a0c84e0b1b41f63903141acaced667760e9d02 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sat, 3 Dec 2016 23:01:21 +0100 Subject: [PATCH] refactor(tray): Update using eventloop --- include/components/bar.hpp | 3 --- include/components/signals.hpp | 7 ------- include/x11/tray.hpp | 1 + src/components/bar.cpp | 24 ++++-------------------- src/components/signals.cpp | 7 ------- src/x11/tray.cpp | 26 +++++++++----------------- 6 files changed, 14 insertions(+), 54 deletions(-) diff --git a/include/components/bar.hpp b/include/components/bar.hpp index 16c3e95b..3d7e69fb 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -56,9 +56,6 @@ class bar : public xpp::event::sink unicode_text_write; extern callback string_write; } - - /** - * Signals used to communicate with the tray manager - */ - namespace tray { - extern callback report_slotcount; - } } POLYBAR_NS_END diff --git a/include/x11/tray.hpp b/include/x11/tray.hpp index 8aefb929..38cd0b84 100644 --- a/include/x11/tray.hpp +++ b/include/x11/tray.hpp @@ -56,6 +56,7 @@ struct tray_settings { uint32_t sibling{0}; uint32_t background{0}; bool transparent{false}; + bool detached{false}; }; // }}} diff --git a/src/components/bar.cpp b/src/components/bar.cpp index 56907825..db6ffbbf 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -52,7 +52,6 @@ bar::bar(connection& conn, const config& config, const logger& logger, unique_pt */ bar::~bar() { std::lock_guard guard(m_mutex); - g_signals::tray::report_slotcount = nullptr; m_connection.detach_sink(this, SINK_PRIORITY_BAR); m_tray.reset(); } @@ -226,7 +225,7 @@ void bar::bootstrap_tray() { return; } - m_trayalign = settings.align; + settings.detached = m_conf.get(bs, "tray-detached", false); settings.height = m_opts.size.h; settings.height -= m_opts.borders.at(edge::BOTTOM).size; @@ -303,21 +302,6 @@ void bar::bootstrap_tray() { settings.orig_x += offset_x; settings.orig_y += offset_y; - // Add tray update callback unless explicitly disabled - if (!m_conf.get(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 settings.sibling = m_window; @@ -379,10 +363,10 @@ void bar::parse(const string& data, bool force) { m_renderer->begin(); - if (m_trayclients) { - if (m_tray && m_trayalign == alignment::LEFT) { + if (m_tray->settings().configured_slots) { + if (m_tray && m_tray->settings().align == alignment::LEFT) { 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); } } diff --git a/src/components/signals.cpp b/src/components/signals.cpp index 184d0e31..ff5ab739 100644 --- a/src/components/signals.cpp +++ b/src/components/signals.cpp @@ -40,13 +40,6 @@ namespace g_signals { callback unicode_text_write{noop}; callback string_write{noop}; } - - /** - * Signals used to communicate with the tray manager - */ - namespace tray { - callback report_slotcount{noop}; - } } POLYBAR_NS_END diff --git a/src/x11/tray.cpp b/src/x11/tray.cpp index 1211b739..7613c500 100644 --- a/src/x11/tray.cpp +++ b/src/x11/tray.cpp @@ -198,8 +198,6 @@ void tray_manager::activate() { // notify clients waiting for a manager. acquire_selection(); - m_connection.flush(); - // Notify pending tray clients notify_clients(); @@ -207,6 +205,8 @@ void tray_manager::activate() { if (m_othermanager != XCB_NONE && m_othermanager != m_tray) { notify_clients_delayed(); } + + m_connection.flush(); } /** @@ -220,9 +220,8 @@ void tray_manager::deactivate(bool clear_selection) { m_log.info("Deactivating tray manager"); m_activated = false; - if (g_signals::tray::report_slotcount) { - m_log.trace("tray: Report empty slotcount"); - g_signals::tray::report_slotcount(0); + if (!m_opts.detached) { + g_signals::event::enqueue(eventloop::make(update_event{}, true)); } if (g_signals::bar::visibility_change) { @@ -298,9 +297,8 @@ void tray_manager::reconfigure() { m_opts.configured_slots = mapped_clients(); - // Report status - if (g_signals::tray::report_slotcount) { - g_signals::tray::report_slotcount(m_opts.configured_slots); + if (!m_opts.detached) { + g_signals::event::enqueue(eventloop::make(update_event{}, true)); } guard.unlock(); @@ -316,21 +314,18 @@ void tray_manager::reconfigure() { void tray_manager::reconfigure_window() { m_log.trace("tray: Reconfigure window (mapped=%i, clients=%i)", static_cast(m_mapped), m_clients.size()); - if (!m_tray || m_hidden) { + if (!m_tray) { return; } auto clients = mapped_clients(); - auto mapped = static_cast(m_mapped); - if (!clients && m_mapped) { + if (!clients && m_mapped && !m_hidden) { m_log.trace("tray: Reconfigure window / unmap"); 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_connection.map_window_checked(m_tray); - } else if (!mapped || !clients) { - return; } 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: Update container mapped flag"); m_mapped = true; - redraw_window(); } else { 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: Update container mapped flag"); m_mapped = false; - m_opts.configured_w = 0; - m_opts.configured_x = 0; } else { auto client = find_client(evt->window);