From 8566051336c438f80b6e3db91d2e19ce6acba2b1 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Sat, 11 Nov 2023 03:36:02 +0100 Subject: [PATCH 1/6] fix(tray): Allow module to disappear for empty tray Modules that don't produce any output are hidden by the controller (don't have margins or separators). The tray module should also do that for `format = ` when there are no icons. This required the visibility handling to be tied to the module visibility instead of being handled by the renderer. Otherwise, the renderer would hide the tray (because the %{Pt} tag was never sent) and the tray would not unhide when new icons appeared; it can't differentiate between hidden because empty and hidden because the module is hidden by the user (the latter is the reason the renderer does hiding at all). Fixes #3036 --- CHANGELOG.md | 5 +++++ include/modules/meta/base.hpp | 2 +- include/modules/tray.hpp | 10 ++++++++++ include/x11/tray_manager.hpp | 3 ++- src/components/renderer.cpp | 9 +++------ src/modules/tray.cpp | 23 +++++++++++++++++++++-- src/x11/tray_manager.cpp | 2 +- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62a622cd..37016db9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- `internal/tray`: The module must use the `` tag (this is the default) ([`#3037`](https://github.com/polybar/polybar/pull/3037)) + +## Fixed +- `internal/tray`: Fixed `module-margin` and `separator` being applied to completely empty tray module ([`#3036`](https://github.com/polybar/polybar/issues/3036), [`#3037`](https://github.com/polybar/polybar/pull/3037)) ## [3.7.0] - 2023-11-05 ### Breaking diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp index 80e41a2f..a49e1b0c 100644 --- a/include/modules/meta/base.hpp +++ b/include/modules/meta/base.hpp @@ -189,7 +189,7 @@ namespace modules { string get_format() const; string get_output(); - void set_visible(bool value); + virtual void set_visible(bool value); void action_module_toggle(); void action_module_show(); diff --git a/include/modules/tray.hpp b/include/modules/tray.hpp index add0a845..f7ec365e 100644 --- a/include/modules/tray.hpp +++ b/include/modules/tray.hpp @@ -8,11 +8,21 @@ POLYBAR_NS namespace modules { +/** + * Wraps the tray_manager in a module. + * + * The module produces the `%{Pt}` formatting tag, which is used by the renderer + * to place the tray. + * The visibility of the tray icons is directly tied to the visibility of the + * module. + */ class tray_module : public static_module { public: explicit tray_module(const bar_settings& bar_settings, string name_, const config&); string get_format() const; + void set_visible(bool value) override; + void start() override; bool build(builder* builder, const string& tag) const; diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp index 466b7cbc..1c0302a8 100644 --- a/include/x11/tray_manager.hpp +++ b/include/x11/tray_manager.hpp @@ -103,6 +103,8 @@ class manager : public xpp::event::sink()) { - int absolute_x = static_cast( - block_x(context.get_relative_tray_position().first) + context.get_relative_tray_position().second); + auto [alignment, pos] = context.get_relative_tray_position(); + if (alignment != alignment::NONE) { + int absolute_x = static_cast(block_x(alignment) + pos); 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/modules/tray.cpp b/src/modules/tray.cpp index 23c73448..93bb47bf 100644 --- a/src/modules/tray.cpp +++ b/src/modules/tray.cpp @@ -8,27 +8,46 @@ namespace modules { template class module; tray_module::tray_module(const bar_settings& bar_settings, string name_, const config& config) - : static_module(bar_settings, move(name_), config) + : static_module(bar_settings, std::move(name_), config) , m_tray(connection::make(), signal_emitter::make(), m_log, bar_settings, [&] { this->broadcast(); }) { m_formatter->add(DEFAULT_FORMAT, TAG_TRAY, {TAG_TRAY}); + + /* There are a bunch of edge cases with regards to tray visiblity when the + * tag is not there (in that case the tray icons should under no + * circumnstances appear). To avoid this, we simply disallow the situation. + * The module is basically useless without that tag anyway. + */ + if (!m_formatter->has(TAG_TRAY, DEFAULT_FORMAT)) { + throw module_error("The " + std::string(TAG_TRAY) + " tag is required in " + name() + "." + DEFAULT_FORMAT); + } + + // Otherwise the tray does not see the initial module visibility + m_tray.change_visibility(visible()); } string tray_module::get_format() const { return DEFAULT_FORMAT; } + void tray_module::set_visible(bool value) { + m_tray.change_visibility(value); + static_module::set_visible(value); + } + void tray_module::start() { m_tray.setup(m_conf, name()); this->static_module::start(); } bool tray_module::build(builder* builder, const string& tag) const { - if (tag == TAG_TRAY) { + // Don't produce any output if the tray is empty so that the module can be hidden + if (tag == TAG_TRAY && m_tray.get_width() > 0) { builder->control(tags::controltag::t); extent_val offset_extent = {extent_type::PIXEL, static_cast(m_tray.get_width())}; builder->offset(offset_extent); return true; } + return false; } diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index 09fa288e..28c70787 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -522,7 +522,7 @@ void manager::clean_clients() { } bool manager::change_visibility(bool visible) { - if (!is_active() || m_hidden == !visible) { + if (m_hidden == !visible) { return false; } From cbfbba070026afb9eeba83e1057494c05dbf7022 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Sat, 11 Nov 2023 03:47:55 +0100 Subject: [PATCH 2/6] Remove tray_visibility signal No longer needed since tray visibility is now controlled directly by the enclosing module --- include/events/signal.hpp | 3 --- include/events/signal_fwd.hpp | 1 - include/x11/legacy_tray_manager.hpp | 16 +++++++--------- include/x11/tray_manager.hpp | 15 +++++++-------- src/x11/legacy_tray_manager.cpp | 8 -------- src/x11/tray_manager.cpp | 4 ---- 6 files changed, 14 insertions(+), 33 deletions(-) diff --git a/include/events/signal.hpp b/include/events/signal.hpp index f25f92d4..016c8779 100644 --- a/include/events/signal.hpp +++ b/include/events/signal.hpp @@ -104,9 +104,6 @@ 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 7d4e26e4..5ac85c7b 100644 --- a/include/events/signal_fwd.hpp +++ b/include/events/signal_fwd.hpp @@ -36,7 +36,6 @@ namespace signals { } // namespace ui namespace ui_tray { struct tray_pos_change; - struct tray_visibility; } // namespace ui_tray } // namespace signals diff --git a/include/x11/legacy_tray_manager.hpp b/include/x11/legacy_tray_manager.hpp index 9ac61f7e..b65f3e28 100644 --- a/include/x11/legacy_tray_manager.hpp +++ b/include/x11/legacy_tray_manager.hpp @@ -116,14 +116,13 @@ class tray_client { unsigned int m_height; }; -class tray_manager - : public xpp::event::sink, - public signal_receiver, - public non_copyable_mixin, - public non_movable_mixin { +class tray_manager : public xpp::event::sink, + public signal_receiver, + public non_copyable_mixin, + public non_movable_mixin { public: using make_type = unique_ptr; static make_type make(const bar_settings& settings); @@ -194,7 +193,6 @@ class tray_manager bool on(const signals::ui::dim_window& evt) override; bool on(const signals::ui::update_background& evt) override; bool on(const signals::ui_tray::tray_pos_change& evt) override; - bool on(const signals::ui_tray::tray_visibility& evt) override; private: connection& m_connection; diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp index 1c0302a8..08129c02 100644 --- a/include/x11/tray_manager.hpp +++ b/include/x11/tray_manager.hpp @@ -76,13 +76,13 @@ struct tray_settings { using on_update = std::function; -class manager : public xpp::event::sink, - public signal_receiver, - non_copyable_mixin, - non_movable_mixin { +class manager + : public xpp::event::sink, + public signal_receiver, + non_copyable_mixin, + non_movable_mixin { public: explicit manager(connection& conn, signal_emitter& emitter, const logger& logger, const bar_settings& bar_opts, on_update on_update); @@ -146,7 +146,6 @@ class manager : public xpp::event::sink Date: Sat, 11 Nov 2023 03:54:18 +0100 Subject: [PATCH 3/6] build: Add missing headers in common.hpp --- CHANGELOG.md | 3 +++ include/common.hpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37016db9..d880c87e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Build +- Fixed missing header when using `libc++` in clang 15 and below + ### Changed - `internal/tray`: The module must use the `` tag (this is the default) ([`#3037`](https://github.com/polybar/polybar/pull/3037)) diff --git a/include/common.hpp b/include/common.hpp index 3e776f75..e6714c8f 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -1,9 +1,11 @@ #pragma once +#include #include #include #include #include +#include #include #include "settings.hpp" From c552df3b6603c4afa171f699545059cd5f9d55f2 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Thu, 16 Nov 2023 22:19:41 +0100 Subject: [PATCH 4/6] fix: Modules did not validate tags used in formats The 'value' variable that was used for validation, was empty because it was used in a move at the beginning of the function. Fixes #3043 --- CHANGELOG.md | 1 + src/modules/meta/base.cpp | 16 ++++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d880c87e..52803e82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `internal/tray`: The module must use the `` tag (this is the default) ([`#3037`](https://github.com/polybar/polybar/pull/3037)) ## Fixed +- Modules did not validate that all tags (e.g. `