From 231af35354c21de063b0bbae5fd2f93acc785913 Mon Sep 17 00:00:00 2001
From: dvermd <315743+dvermd@users.noreply.github.com>
Date: Sun, 10 Oct 2021 20:22:24 +0200
Subject: [PATCH] feat(ipc): hook, prev, next, reset module actions (#2528)
* WIP ipc actions
* feat(ipc): Add hook, prev, next and reset actions
Closes: #2464
* ipc: format code
* ipc: fix comparison
* Apply suggestions from code review
Co-authored-by: Patrick Ziegler
* ipc: make index 0-based
* ipc: add 0-based indexing breaking change to Changelog
* ipc: restore 1-based index for and message
* ipc: fix initial=0 throwing an error
Co-authored-by: Martin Terneborg
Co-authored-by: Patrick Ziegler
---
CHANGELOG.md | 2 +
doc/user/actions.rst | 11 +++-
include/modules/ipc.hpp | 10 ++++
src/modules/ipc.cpp | 112 +++++++++++++++++++++++++++++++---------
4 files changed, 108 insertions(+), 27 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b07d6614..47f88c97 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -132,6 +132,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([`#1441`](https://github.com/polybar/polybar/issues/1441))
- `internal/xkeyboard`: Allow configuring icons using variant
([`#2414`](https://github.com/polybar/polybar/issues/2414))
+- `custom/ipc`: Add `hook`, `next`, `prev`, `reset` actions to the ipc module
+ ([`#2464`](https://github.com/polybar/polybar/issues/2464))
### Changed
- Polybar now also reads `config.ini` when searching for config files.
diff --git a/doc/user/actions.rst b/doc/user/actions.rst
index cc6145d9..95ae2a78 100644
--- a/doc/user/actions.rst
+++ b/doc/user/actions.rst
@@ -261,9 +261,16 @@ custom/menu
custom/ipc
^^^^^^^^^^
-:``send``: *(Has Data)* Replace the contents of the module with the data passed in this action.
+.. versionadded:: 3.6.0
+
+:``send``: *(Has Data)* Replace the contents of the module with the data passed in this action.
+:``hook``: *(Has Data)* Trigger the given hook.
+
+ The data is the 0-based index of the hook to trigger.
+:``next``: Switches to the next hook and wrap around when the last hook was displayed.
+:``prev``: Switches to the previous hook and wrap around when the first hook was displayed.
+:``reset``: Reset the module to its startup state: either empty or according to the ``initial`` setting.
- .. versionadded:: 3.6.0
Deprecated Action Names
-----------------------
diff --git a/include/modules/ipc.hpp b/include/modules/ipc.hpp
index 5100736d..977847c8 100644
--- a/include/modules/ipc.hpp
+++ b/include/modules/ipc.hpp
@@ -35,9 +35,17 @@ namespace modules {
static constexpr auto TYPE = "custom/ipc";
static constexpr auto EVENT_SEND = "send";
+ static constexpr auto EVENT_HOOK = "hook";
+ static constexpr auto EVENT_NEXT = "next";
+ static constexpr auto EVENT_PREV = "prev";
+ static constexpr auto EVENT_RESET = "reset";
protected:
void action_send(const string& data);
+ void action_hook(const string& data);
+ void action_next();
+ void action_prev();
+ void action_reset();
private:
static constexpr const char* TAG_OUTPUT{"