231af35354
* 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 <p.ziegler96@gmail.com> * 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 <martinterneborg@protonmail.com> Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "modules/meta/static_module.hpp"
|
|
#include "utils/command.hpp"
|
|
|
|
POLYBAR_NS
|
|
|
|
namespace modules {
|
|
/**
|
|
* Module that allow users to configure hooks on
|
|
* received ipc messages. The hook will execute the defined
|
|
* shell script and the resulting output will be used
|
|
* as the module content.
|
|
*/
|
|
class ipc_module : public module<ipc_module> {
|
|
public:
|
|
/**
|
|
* Hook structure that will be fired
|
|
* when receiving a message with specified id
|
|
*/
|
|
struct hook {
|
|
string payload;
|
|
string command;
|
|
};
|
|
|
|
public:
|
|
explicit ipc_module(const bar_settings&, string);
|
|
|
|
void start() override;
|
|
void update() {}
|
|
string get_output();
|
|
bool build(builder* builder, const string& tag) const;
|
|
void on_message(const string& message);
|
|
|
|
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{"<output>"};
|
|
vector<unique_ptr<hook>> m_hooks;
|
|
map<mousebtn, string> m_actions;
|
|
string m_output;
|
|
size_t m_initial;
|
|
size_t m_current_hook;
|
|
void exec_hook();
|
|
};
|
|
} // namespace modules
|
|
|
|
POLYBAR_NS_END
|