mirror of https://github.com/polybar/polybar.git
controller: Cleanup process_inputdata
This commit is contained in:
parent
1afb333858
commit
ff3340e062
|
@ -10,6 +10,7 @@
|
|||
#include "events/signal_receiver.hpp"
|
||||
#include "events/types.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/actions.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "x11/types.hpp"
|
||||
|
||||
|
@ -74,6 +75,7 @@ class controller
|
|||
private:
|
||||
size_t setup_modules(alignment align);
|
||||
|
||||
bool forward_action(const actions_util::action& cmd);
|
||||
bool try_forward_legacy_action(const string& cmd);
|
||||
|
||||
connection& m_connection;
|
||||
|
|
|
@ -9,6 +9,9 @@ namespace modules {
|
|||
POLYBAR_NS
|
||||
|
||||
namespace actions_util {
|
||||
|
||||
using action = std::tuple<string, string, string>;
|
||||
|
||||
string get_action_string(const modules::module_interface& module, string action, string data);
|
||||
|
||||
/**
|
||||
|
@ -22,7 +25,7 @@ namespace actions_util {
|
|||
* same result.
|
||||
* \throws runtime_error If the action string is malformed
|
||||
*/
|
||||
std::tuple<string, string, string> parse_action_string(string action);
|
||||
action parse_action_string(string action);
|
||||
} // namespace actions_util
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
|
@ -501,6 +501,35 @@ bool controller::try_forward_legacy_action(const string& cmd) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool controller::forward_action(const actions_util::action& action_triple) {
|
||||
string module_name = std::get<0>(action_triple);
|
||||
string action = std::get<1>(action_triple);
|
||||
string data = std::get<2>(action_triple);
|
||||
|
||||
m_log.info("Forwarding action to modules (module: '%s', action: '%s', data: '%s')", module_name, action, data);
|
||||
|
||||
int num_delivered = 0;
|
||||
|
||||
// Forwards the action to all modules that match the name
|
||||
for (auto&& module : m_modules) {
|
||||
if (module->name_raw() == module_name) {
|
||||
if (!module->input(action, data)) {
|
||||
m_log.err("The '%s' module does not support the '%s' action.", module_name, action);
|
||||
}
|
||||
|
||||
num_delivered++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_delivered == 0) {
|
||||
m_log.err("Could not forward action to module: No module named '%s' (action: '%s', data: '%s')", module_name,
|
||||
action, data);
|
||||
} else {
|
||||
m_log.info("Delivered action to %d module%s", num_delivered, num_delivered > 1 ? "s" : "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process stored input data
|
||||
*/
|
||||
|
@ -516,41 +545,12 @@ void controller::process_inputdata() {
|
|||
|
||||
// Every command that starts with '#' is considered an action string.
|
||||
if (cmd.front() == '#') {
|
||||
string module_name;
|
||||
string action;
|
||||
string data;
|
||||
|
||||
try {
|
||||
auto res = actions_util::parse_action_string(cmd);
|
||||
|
||||
module_name = std::get<0>(res);
|
||||
action = std::get<1>(res);
|
||||
data = std::get<2>(res);
|
||||
this->forward_action(actions_util::parse_action_string(cmd));
|
||||
} catch (runtime_error& e) {
|
||||
m_log.err("Invalid action string (reason: %s)", e.what());
|
||||
return;
|
||||
m_log.err("Invalid action string (action: %s, reason: %s)", cmd, e.what());
|
||||
}
|
||||
|
||||
m_log.info("Forwarding action to modules (name: '%s', action: '%s', data: '%s') ", module_name, action, data);
|
||||
|
||||
int num_delivered = 0;
|
||||
|
||||
// Forwards the action to all modules that match the name
|
||||
for (auto&& module : m_modules) {
|
||||
if (module->name_raw() == module_name) {
|
||||
if (!module->input(action, data)) {
|
||||
m_log.err("The '%s' module does not support the '%s' action.", module_name, action);
|
||||
}
|
||||
|
||||
num_delivered++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_delivered == 0) {
|
||||
m_log.err("There exists no module with name '%s' (input: %s)", module_name, cmd);
|
||||
} else {
|
||||
m_log.info("Delivered action to %d module%s", num_delivered, num_delivered > 1 ? "s" : "");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue