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