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