refactor(ipc): Rename signals
This commit is contained in:
parent
334c454eec
commit
baaba4adf9
@ -43,8 +43,8 @@ namespace sig_ui = signals::ui;
|
|||||||
namespace sig_ipc = signals::ipc;
|
namespace sig_ipc = signals::ipc;
|
||||||
|
|
||||||
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit_terminate, sig_ev::exit_reload,
|
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit_terminate, sig_ev::exit_reload,
|
||||||
sig_ev::update, sig_ev::notify_change, sig_ev::check_state, sig_ipc::process_action,
|
sig_ev::update, sig_ev::notify_change, sig_ev::check_state, sig_ipc::action, sig_ipc::command,
|
||||||
sig_ipc::process_command, sig_ipc::process_hook, sig_ui::button_press> {
|
sig_ipc::hook, sig_ui::button_press> {
|
||||||
public:
|
public:
|
||||||
using make_type = unique_ptr<controller>;
|
using make_type = unique_ptr<controller>;
|
||||||
static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch);
|
static make_type make(unique_ptr<ipc>&& ipc, unique_ptr<inotify_watch>&& config_watch);
|
||||||
@ -69,9 +69,9 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
|
|||||||
bool on(const sig_ev::exit_reload& evt);
|
bool on(const sig_ev::exit_reload& evt);
|
||||||
bool on(const sig_ev::check_state& evt);
|
bool on(const sig_ev::check_state& evt);
|
||||||
bool on(const sig_ui::button_press& evt);
|
bool on(const sig_ui::button_press& evt);
|
||||||
bool on(const sig_ipc::process_action& evt);
|
bool on(const sig_ipc::action& evt);
|
||||||
bool on(const sig_ipc::process_command& evt);
|
bool on(const sig_ipc::command& evt);
|
||||||
bool on(const sig_ipc::process_hook& evt);
|
bool on(const sig_ipc::hook& evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
connection& m_connection;
|
connection& m_connection;
|
||||||
|
@ -100,9 +100,9 @@ namespace signals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
DEFINE_VALUE_SIGNAL(20, process_command, ipc_command);
|
DEFINE_VALUE_SIGNAL(20, command, string);
|
||||||
DEFINE_VALUE_SIGNAL(21, process_hook, ipc_hook);
|
DEFINE_VALUE_SIGNAL(21, hook, string);
|
||||||
DEFINE_VALUE_SIGNAL(22, process_action, ipc_action);
|
DEFINE_VALUE_SIGNAL(22, action, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
|
template <uint8_t Priority, typename Signal, typename... Signals>
|
||||||
|
class signal_receiver;
|
||||||
|
|
||||||
namespace signals {
|
namespace signals {
|
||||||
namespace eventqueue {
|
namespace eventqueue {
|
||||||
struct exit_terminate;
|
struct exit_terminate;
|
||||||
@ -13,9 +16,9 @@ namespace signals {
|
|||||||
struct update;
|
struct update;
|
||||||
}
|
}
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
struct process_command;
|
struct command;
|
||||||
struct process_hook;
|
struct hook;
|
||||||
struct process_action;
|
struct action;
|
||||||
}
|
}
|
||||||
namespace ui {
|
namespace ui {
|
||||||
struct tick;
|
struct tick;
|
||||||
|
@ -31,7 +31,7 @@ namespace modules {
|
|||||||
void update() {}
|
void update() {}
|
||||||
string get_output();
|
string get_output();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
void on_message(const ipc_hook& message);
|
void on_message(const string& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr auto TAG_OUTPUT = "<output>";
|
static constexpr auto TAG_OUTPUT = "<output>";
|
||||||
|
@ -9,18 +9,19 @@
|
|||||||
#include "components/types.hpp"
|
#include "components/types.hpp"
|
||||||
#include "events/signal.hpp"
|
#include "events/signal.hpp"
|
||||||
#include "events/signal_emitter.hpp"
|
#include "events/signal_emitter.hpp"
|
||||||
|
#include "events/signal_receiver.hpp"
|
||||||
#include "modules/meta/event_handler.hpp"
|
#include "modules/meta/event_handler.hpp"
|
||||||
#include "modules/meta/factory.hpp"
|
#include "modules/meta/factory.hpp"
|
||||||
#include "utils/command.hpp"
|
#include "utils/command.hpp"
|
||||||
#include "utils/factory.hpp"
|
#include "utils/factory.hpp"
|
||||||
#include "utils/inotify.hpp"
|
#include "utils/inotify.hpp"
|
||||||
#include "utils/process.hpp"
|
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
#include "x11/connection.hpp"
|
#include "x11/connection.hpp"
|
||||||
|
#include "x11/events.hpp"
|
||||||
#include "x11/extensions/all.hpp"
|
#include "x11/extensions/all.hpp"
|
||||||
#include "x11/tray_manager.hpp"
|
#include "x11/tray_manager.hpp"
|
||||||
#include "x11/xutils.hpp"
|
#include "x11/types.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
@ -543,9 +544,8 @@ bool controller::on(const sig_ui::button_press& evt) {
|
|||||||
/**
|
/**
|
||||||
* Process ipc action messages
|
* Process ipc action messages
|
||||||
*/
|
*/
|
||||||
bool controller::on(const sig_ipc::process_action& evt) {
|
bool controller::on(const sig_ipc::action& evt) {
|
||||||
string action{(*evt()).payload};
|
string action{*evt()};
|
||||||
action.erase(0, strlen(ipc_action::prefix));
|
|
||||||
|
|
||||||
if (action.empty()) {
|
if (action.empty()) {
|
||||||
m_log.err("Cannot enqueue empty ipc action");
|
m_log.err("Cannot enqueue empty ipc action");
|
||||||
@ -560,9 +560,8 @@ bool controller::on(const sig_ipc::process_action& evt) {
|
|||||||
/**
|
/**
|
||||||
* Process ipc command messages
|
* Process ipc command messages
|
||||||
*/
|
*/
|
||||||
bool controller::on(const sig_ipc::process_command& evt) {
|
bool controller::on(const sig_ipc::command& evt) {
|
||||||
string command{(*evt()).payload};
|
string command{*evt()};
|
||||||
command.erase(0, strlen(ipc_command::prefix));
|
|
||||||
|
|
||||||
if (command.empty()) {
|
if (command.empty()) {
|
||||||
return false;
|
return false;
|
||||||
@ -582,8 +581,8 @@ bool controller::on(const sig_ipc::process_command& evt) {
|
|||||||
/**
|
/**
|
||||||
* Process ipc hook messages
|
* Process ipc hook messages
|
||||||
*/
|
*/
|
||||||
bool controller::on(const sig_ipc::process_hook& evt) {
|
bool controller::on(const sig_ipc::hook& evt) {
|
||||||
const ipc_hook hook{*evt()};
|
string hook{*evt()};
|
||||||
|
|
||||||
for (const auto& block : m_modules) {
|
for (const auto& block : m_modules) {
|
||||||
for (const auto& module : block.second) {
|
for (const auto& module : block.second) {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
using namespace signals::ipc;
|
namespace sig_ipc = signals::ipc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create instance
|
* Create instance
|
||||||
@ -68,17 +68,11 @@ void ipc::receive_message() {
|
|||||||
string payload{string_util::trim(string{buffer}, '\n')};
|
string payload{string_util::trim(string{buffer}, '\n')};
|
||||||
|
|
||||||
if (payload.find(ipc_command::prefix) == 0) {
|
if (payload.find(ipc_command::prefix) == 0) {
|
||||||
ipc_command msg{};
|
m_sig.emit(sig_ipc::command{payload.substr(strlen(ipc_command::prefix))});
|
||||||
memcpy(msg.payload, &payload[0], payload.size());
|
|
||||||
m_sig.emit(process_command{move(msg)});
|
|
||||||
} else if (payload.find(ipc_hook::prefix) == 0) {
|
} else if (payload.find(ipc_hook::prefix) == 0) {
|
||||||
ipc_hook msg{};
|
m_sig.emit(sig_ipc::hook{payload.substr(strlen(ipc_hook::prefix))});
|
||||||
memcpy(msg.payload, &payload[0], payload.size());
|
|
||||||
m_sig.emit(process_hook{move(msg)});
|
|
||||||
} else if (payload.find(ipc_action::prefix) == 0) {
|
} else if (payload.find(ipc_action::prefix) == 0) {
|
||||||
ipc_action msg{};
|
m_sig.emit(sig_ipc::action{payload.substr(strlen(ipc_action::prefix))});
|
||||||
memcpy(msg.payload, &payload[0], payload.size());
|
|
||||||
m_sig.emit(process_action{move(msg)});
|
|
||||||
} else if (!payload.empty()) {
|
} else if (!payload.empty()) {
|
||||||
m_log.warn("Received unknown ipc message: (payload=%s)", payload);
|
m_log.warn("Received unknown ipc message: (payload=%s)", payload);
|
||||||
}
|
}
|
||||||
|
@ -80,11 +80,11 @@ namespace modules {
|
|||||||
* configured from the user config and
|
* configured from the user config and
|
||||||
* execute its command
|
* execute its command
|
||||||
*/
|
*/
|
||||||
void ipc_module::on_message(const ipc_hook& message) {
|
void ipc_module::on_message(const string& message) {
|
||||||
bool match = false;
|
bool match = false;
|
||||||
|
|
||||||
for (auto&& hook : m_hooks) {
|
for (auto&& hook : m_hooks) {
|
||||||
if (ipc_hook::prefix + hook->payload != message.payload) {
|
if (hook->payload != message) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user