feat(ipc): allow receiving arbitrary text on IPC socket (#2463)
This adds the 'send' action to the ipc module that can be used to send arbitrary text to the module: polybar-msg action "#ipc.send.%{F#4444ff}hello%{F-}" * feat(ipc): allow receiving arbitrary text on IPC socket Instead of just allowing hook numbers to be executed, the user can send arbitrary text and the IPC module will put it in the bar. The IPC payload format is extended to accept an arbitrary string if the first character after the module name is ':'. polybar-msg hook test :'%{F#4444ff}hello%{F-}' Fix #2455 * Use actions for sending data to ipc module * ipc: Don't use exceptions when no hooks are defined * Update src/modules/ipc.cpp Co-authored-by: patrick96 <p.ziegler96@gmail.com>
This commit is contained in:
parent
523e4d6313
commit
5f3462240c
@ -98,6 +98,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Added `occupied-scroll = true` option to bspwm module.
|
||||
Allows scrolling only through occupied desktops only.
|
||||
([`#2427`](https://github.com/polybar/polybar/issues/2427))
|
||||
- `custom/ipc`: `send` action to send arbitrary strings to be displayed in the module.
|
||||
([`#2455`](https://github.com/polybar/polybar/issues/2455))
|
||||
|
||||
### Changed
|
||||
- Slight changes to the value ranges the different ramp levels are responsible
|
||||
|
@ -258,6 +258,13 @@ custom/menu
|
||||
The data has the form ``N-M`` and the action will execute the command
|
||||
in ``menu-N-M-exec``.
|
||||
|
||||
custom/ipc
|
||||
^^^^^^^^^^
|
||||
|
||||
:``send``: *(Has Data)* Replace the contents of the module with the data passed in this action.
|
||||
|
||||
.. versionadded:: 3.6.0
|
||||
|
||||
Deprecated Action Names
|
||||
-----------------------
|
||||
|
||||
|
@ -34,6 +34,11 @@ namespace modules {
|
||||
|
||||
static constexpr auto TYPE = "custom/ipc";
|
||||
|
||||
static constexpr auto EVENT_SEND = "send";
|
||||
|
||||
protected:
|
||||
void action_send(const string& data);
|
||||
|
||||
private:
|
||||
static constexpr const char* TAG_OUTPUT{"<output>"};
|
||||
vector<unique_ptr<hook>> m_hooks;
|
||||
|
@ -13,15 +13,15 @@ namespace modules {
|
||||
* create formatting tags
|
||||
*/
|
||||
ipc_module::ipc_module(const bar_settings& bar, string name_) : static_module<ipc_module>(bar, move(name_)) {
|
||||
m_router->register_action_with_data(EVENT_SEND, &ipc_module::action_send);
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
for (auto&& command : m_conf.get_list<string>(name(), "hook")) {
|
||||
for (auto&& command : m_conf.get_list<string>(name(), "hook", {})) {
|
||||
m_hooks.emplace_back(std::make_unique<hook>(hook{name() + to_string(++index), command}));
|
||||
}
|
||||
|
||||
if (m_hooks.empty()) {
|
||||
throw module_error("No hooks defined");
|
||||
}
|
||||
m_log.info("%s: Loaded %d hooks", name(), m_hooks.size());
|
||||
|
||||
if ((m_initial = m_conf.get(name(), "initial", 0_z)) && m_initial > m_hooks.size()) {
|
||||
throw module_error("Initial hook out of bounds (defined: " + to_string(m_hooks.size()) + ")");
|
||||
@ -125,6 +125,11 @@ namespace modules {
|
||||
broadcast();
|
||||
}
|
||||
}
|
||||
|
||||
void ipc_module::action_send(const string& data) {
|
||||
m_output = data;
|
||||
broadcast();
|
||||
}
|
||||
} // namespace modules
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
Loading…
Reference in New Issue
Block a user