feat(ipc): <label> support (#2841)

* Label = %output% working

* build fix

* Output as deprecated, Label as default

* Corrections

 * Corrections Simplified

* Changelog updated
This commit is contained in:
Madhav Prabhu C M 2022-10-23 14:17:22 +05:30 committed by GitHub
parent 1e582accb8
commit 30e1cc2595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 9 deletions

View File

@ -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 TAG_LABEL (`<label>`) in ipc module ([`#2841`](https://github.com/polybar/polybar/pull/2841)) by [@madhavpcm](https://github.com/madhavpcm).
- 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))

View File

@ -54,12 +54,17 @@ namespace modules {
bool has_hook() const;
void set_hook(int h);
void update_output() ;
private:
static constexpr const char* TAG_OUTPUT{"<output>"};
static constexpr auto TAG_OUTPUT = "<output>";
static constexpr auto TAG_LABEL = "<label>";
label_t m_label;
vector<unique_ptr<hook>> m_hooks;
map<mousebtn, string> m_actions;
string m_output;
int m_initial{-1};
int m_current_hook{-1};
void exec_hook();

View File

@ -2,6 +2,7 @@
#include <unistd.h>
#include "drawtypes/label.hpp"
#include "modules/meta/base.inl"
POLYBAR_NS
@ -59,11 +60,14 @@ namespace modules {
for (auto& hook : m_hooks) {
hook->command = pid_token(hook->command);
}
m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT});
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_OUTPUT});
m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%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});
m_formatter->add_optional(format_i, {TAG_LABEL});
}
}
@ -122,12 +126,14 @@ namespace modules {
* Output content retrieved from hook commands
*/
bool ipc_module::build(builder* builder, const string& tag) const {
if (tag == TAG_OUTPUT) {
if (tag == TAG_LABEL) {
builder->node(m_label);
return true;
} else if (tag == TAG_OUTPUT) {
builder->node(m_output);
return true;
} else {
return false;
}
return false;
}
/**
@ -150,7 +156,7 @@ namespace modules {
void ipc_module::action_send(const string& data) {
m_output = data;
broadcast();
update_output();
}
void ipc_module::action_hook(const string& data) {
@ -185,7 +191,8 @@ namespace modules {
} else {
m_current_hook = -1;
m_output.clear();
broadcast();
update_output();
}
}
@ -238,6 +245,14 @@ namespace modules {
m_output.clear();
}
update_output();
}
void ipc_module::update_output() {
if (m_label) {
m_label->reset_tokens();
m_label->replace_token("%output%", m_output);
}
broadcast();
}
} // namespace modules