diff --git a/CHANGELOG.md b/CHANGELOG.md index 13701c47..98aea186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `custom/text`: The `content` setting and all its properties are deprecated in favor of `format` with the same functionality. ([`#2676`](https://github.com/polybar/polybar/pull/2676)) ### Added +- Added support for format-i for each hook-i defined in ipc module ([`#2775`](https://github.com/polybar/polybar/issues/2775), [`#2810`](https://github.com/polybar/polybar/pull/2810)) by [@madhavpcm](https://github.com/madhavpcm). - `internal/temperature`: `%temperature-k%` token displays the temperature in kelvin ([`#2774`](https://github.com/polybar/polybar/discussions/2774), [`#2784`](https://github.com/polybar/polybar/pull/2784)) - `internal/pulseaudio`: `reverse-scroll` option ([`#2664`](https://github.com/polybar/polybar/pull/2664)) - `custom/script`: Repeat interval for script failure (`interval-fail`) and `exec-if` (`interval-if`) ([`#943`](https://github.com/polybar/polybar/issues/943), [`#2606`](https://github.com/polybar/polybar/issues/2606), [`#2630`](https://github.com/polybar/polybar/pull/2630)) diff --git a/include/modules/ipc.hpp b/include/modules/ipc.hpp index b59f17c4..11fdcff4 100644 --- a/include/modules/ipc.hpp +++ b/include/modules/ipc.hpp @@ -29,6 +29,7 @@ namespace modules { void start() override; void update(); string get_output(); + string get_format() const; bool build(builder* builder, const string& tag) const; void on_message(const string& message); diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp index b8627036..41ee3fea 100644 --- a/src/modules/ipc.cpp +++ b/src/modules/ipc.cpp @@ -59,8 +59,12 @@ namespace modules { for (auto& hook : m_hooks) { hook->command = pid_token(hook->command); } - m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT}); + + for (size_t i = 0; i < m_hooks.size(); i++) { + string format_i = "format-" + to_string(i); + m_formatter->add_optional(format_i, {TAG_OUTPUT}); + } } /** @@ -103,6 +107,17 @@ namespace modules { return m_builder->flush(); } + string ipc_module::get_format() const { + if (m_current_hook != -1 && (size_t)m_current_hook < m_hooks.size()) { + string format_i = "format-" + to_string(m_current_hook); + if (m_formatter->has_format(format_i)) { + return format_i; + } else { + return DEFAULT_FORMAT; + } + } + return DEFAULT_FORMAT; + } /** * Output content retrieved from hook commands */ @@ -150,7 +165,8 @@ namespace modules { } } catch (const std::invalid_argument& err) { m_log.err( - "%s: Hook action received '%s' cannot be converted to a valid hook index. Defined hooks goes from 0 to %zu.", + "%s: Hook action received '%s' cannot be converted to a valid hook index. Defined hooks goes from 0 to " + "%zu.", name(), data, m_hooks.size() - 1); } }