From b2c5d8e0e228031844f28ecd91fb841f11842fb2 Mon Sep 17 00:00:00 2001 From: raffael0 <43984260+raffael0@users.noreply.github.com> Date: Thu, 16 Jun 2022 12:53:49 +0200 Subject: [PATCH] tray: implement hiding functionality (#2723) * tray hiding works * clang-format * Implemented suggestions --- include/events/signal.hpp | 3 ++ include/events/signal_fwd.hpp | 3 +- include/x11/tray_manager.hpp | 13 +++++---- src/components/renderer.cpp | 3 ++ src/x11/tray_manager.cpp | 52 ++++++++++++++++++++--------------- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/include/events/signal.hpp b/include/events/signal.hpp index f54f0684..3df6388b 100644 --- a/include/events/signal.hpp +++ b/include/events/signal.hpp @@ -110,6 +110,9 @@ namespace signals { struct tray_pos_change : public detail::value_signal { using base_type::base_type; }; + struct tray_visibility : public detail::value_signal { + using base_type::base_type; + }; } // namespace ui_tray } // namespace signals diff --git a/include/events/signal_fwd.hpp b/include/events/signal_fwd.hpp index 0e422b21..59e60169 100644 --- a/include/events/signal_fwd.hpp +++ b/include/events/signal_fwd.hpp @@ -38,7 +38,8 @@ namespace signals { struct mapped_clients; struct tray_width_change; struct tray_pos_change; - } + struct tray_visibility; + } // namespace ui_tray } // namespace signals POLYBAR_NS_END diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp index 2c230cc1..7a7ebcbc 100644 --- a/include/x11/tray_manager.hpp +++ b/include/x11/tray_manager.hpp @@ -65,11 +65,12 @@ struct tray_settings { bool detached{false}; }; -class tray_manager : public xpp::event::sink, - public signal_receiver { +class tray_manager + : public xpp::event::sink, + public signal_receiver { public: using make_type = unique_ptr; static make_type make(const bar_settings& settings); @@ -122,6 +123,7 @@ class tray_manager : public xpp::event::sink& client, bool reconfigure = true); void remove_client(xcb_window_t win, bool reconfigure = true); unsigned int mapped_clients() const; + bool change_visibility(bool visible); void handle(const evt::expose& evt) override; void handle(const evt::visibility_notify& evt) override; @@ -139,6 +141,7 @@ class tray_manager : public xpp::event::sink( block_x(context.get_relative_tray_position().first) + context.get_relative_tray_position().second); m_sig.emit(signals::ui_tray::tray_pos_change{absolute_x}); + m_sig.emit(signals::ui_tray::tray_visibility{true}); + } else { + m_sig.emit(signals::ui_tray::tray_visibility{false}); } } diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index a466bd41..98405559 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -914,6 +914,29 @@ unsigned int tray_manager::mapped_clients() const { return mapped_clients; } +bool tray_manager::change_visibility(bool visible) { + unsigned int clients{mapped_clients()}; + + m_log.trace("tray: visibility_change (state=%i, activated=%i, mapped=%i, hidden=%i)", visible, + static_cast(m_activated), static_cast(m_mapped), static_cast(m_hidden)); + + m_hidden = !visible; + + if (!m_activated) { + return false; + } else if (!m_hidden && !m_mapped && clients) { + m_connection.map_window(m_tray); + } else if ((!clients || m_hidden) && m_mapped) { + m_connection.unmap_window(m_tray); + } else if (m_mapped && !m_hidden && clients) { + redraw_window(); + } + + m_connection.flush(); + + return true; +} + /** * Event callback : XCB_EXPOSE */ @@ -1024,7 +1047,8 @@ void tray_manager::handle(const evt::property_notify& evt) { } // React an wallpaper change, if bar has transparency - if (m_opts.transparent && (evt->atom == _XROOTPMAP_ID || evt->atom == _XSETROOT_ID || evt->atom == ESETROOT_PMAP_ID)) { + if (m_opts.transparent && + (evt->atom == _XROOTPMAP_ID || evt->atom == _XSETROOT_ID || evt->atom == ESETROOT_PMAP_ID)) { redraw_window(true); return; } @@ -1132,27 +1156,7 @@ void tray_manager::handle(const evt::unmap_notify& evt) { * toggle the tray window whenever the visibility of the bar window changes. */ bool tray_manager::on(const signals::ui::visibility_change& evt) { - bool visible{evt.cast()}; - unsigned int clients{mapped_clients()}; - - m_log.trace("tray: visibility_change (state=%i, activated=%i, mapped=%i, hidden=%i)", visible, - static_cast(m_activated), static_cast(m_mapped), static_cast(m_hidden)); - - m_hidden = !visible; - - if (!m_activated) { - return false; - } else if (!m_hidden && !m_mapped && clients) { - m_connection.map_window(m_tray); - } else if ((!clients || m_hidden) && m_mapped) { - m_connection.unmap_window(m_tray); - } else if (m_mapped && !m_hidden && clients) { - redraw_window(); - } - - m_connection.flush(); - - return true; + return change_visibility(evt.cast()); } bool tray_manager::on(const signals::ui::dim_window& evt) { @@ -1178,4 +1182,8 @@ bool tray_manager::on(const signals::ui_tray::tray_pos_change& evt) { return true; } +bool tray_manager::on(const signals::ui_tray::tray_visibility& evt) { + return change_visibility(evt.cast()); +} + POLYBAR_NS_END