2016-11-14 03:21:18 -05:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
#include "modules/meta/static_module.hpp"
|
2016-11-14 03:21:18 -05:00
|
|
|
#include "utils/command.hpp"
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-11-14 03:21:18 -05:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2021-09-30 09:11:31 -04:00
|
|
|
class ipc_module : public module<ipc_module> {
|
2016-11-14 03:21:18 -05:00
|
|
|
public:
|
2016-12-21 02:00:09 -05:00
|
|
|
/**
|
|
|
|
* 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);
|
2016-11-14 03:21:18 -05:00
|
|
|
|
2021-01-04 04:38:43 -05:00
|
|
|
void start() override;
|
2021-10-30 15:00:52 -04:00
|
|
|
void update();
|
2016-11-14 03:21:18 -05:00
|
|
|
string get_output();
|
2016-11-25 07:55:15 -05:00
|
|
|
bool build(builder* builder, const string& tag) const;
|
2016-12-26 04:36:14 -05:00
|
|
|
void on_message(const string& message);
|
2016-11-14 03:21:18 -05:00
|
|
|
|
2020-05-15 13:59:08 -04:00
|
|
|
static constexpr auto TYPE = "custom/ipc";
|
|
|
|
|
2021-07-11 14:42:28 -04:00
|
|
|
static constexpr auto EVENT_SEND = "send";
|
2021-10-10 14:22:24 -04:00
|
|
|
static constexpr auto EVENT_HOOK = "hook";
|
|
|
|
static constexpr auto EVENT_NEXT = "next";
|
|
|
|
static constexpr auto EVENT_PREV = "prev";
|
|
|
|
static constexpr auto EVENT_RESET = "reset";
|
2021-07-11 14:42:28 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void action_send(const string& data);
|
2021-10-10 14:22:24 -04:00
|
|
|
void action_hook(const string& data);
|
|
|
|
void action_next();
|
|
|
|
void action_prev();
|
|
|
|
void action_reset();
|
2021-07-11 14:42:28 -04:00
|
|
|
|
2021-10-30 15:00:52 -04:00
|
|
|
void hook_offset(int offset);
|
|
|
|
|
|
|
|
bool has_initial() const;
|
|
|
|
bool has_hook() const;
|
|
|
|
|
|
|
|
void set_hook(int h);
|
|
|
|
|
2016-11-14 03:21:18 -05:00
|
|
|
private:
|
2017-01-13 18:27:29 -05:00
|
|
|
static constexpr const char* TAG_OUTPUT{"<output>"};
|
2016-11-14 03:21:18 -05:00
|
|
|
vector<unique_ptr<hook>> m_hooks;
|
|
|
|
map<mousebtn, string> m_actions;
|
2017-01-13 18:27:29 -05:00
|
|
|
string m_output;
|
2021-10-30 15:00:52 -04:00
|
|
|
int m_initial{-1};
|
|
|
|
int m_current_hook{-1};
|
2021-10-10 14:22:24 -04:00
|
|
|
void exec_hook();
|
2016-11-14 03:21:18 -05:00
|
|
|
};
|
2020-05-15 13:59:08 -04:00
|
|
|
} // namespace modules
|
2016-11-14 03:21:18 -05:00
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|