feat(ipc). Per hook format (#2810)
* Added format-x support for ipc_module, tested with demo config * Certain cases not working * Certain cases not working, build * Changed label to output tag, Mixing of default formats wont work * created changelog
This commit is contained in:
parent
e9713185cb
commit
54b75f23ab
@ -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))
|
- `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
|
||||||
|
- 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/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))
|
- `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))
|
- `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))
|
||||||
|
@ -29,6 +29,7 @@ namespace modules {
|
|||||||
void start() override;
|
void start() override;
|
||||||
void update();
|
void update();
|
||||||
string get_output();
|
string get_output();
|
||||||
|
string get_format() const;
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
void on_message(const string& message);
|
void on_message(const string& message);
|
||||||
|
|
||||||
|
@ -59,8 +59,12 @@ namespace modules {
|
|||||||
for (auto& hook : m_hooks) {
|
for (auto& hook : m_hooks) {
|
||||||
hook->command = pid_token(hook->command);
|
hook->command = pid_token(hook->command);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT});
|
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();
|
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
|
* Output content retrieved from hook commands
|
||||||
*/
|
*/
|
||||||
@ -150,7 +165,8 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
} catch (const std::invalid_argument& err) {
|
} catch (const std::invalid_argument& err) {
|
||||||
m_log.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);
|
name(), data, m_hooks.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user