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,37 +501,12 @@ bool controller::try_forward_legacy_action(const string& cmd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process stored input data
|
||||
*/
|
||||
void controller::process_inputdata() {
|
||||
if (m_inputdata.empty()) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
|
||||
const string cmd = std::move(m_inputdata);
|
||||
m_inputdata = string{};
|
||||
|
||||
m_log.trace("controller: Processing inputdata: %s", cmd);
|
||||
|
||||
// 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);
|
||||
} catch (runtime_error& e) {
|
||||
m_log.err("Invalid action string (reason: %s)", e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
m_log.info("Forwarding action to modules (name: '%s', action: '%s', data: '%s') ", module_name, action, data);
|
||||
m_log.info("Forwarding action to modules (module: '%s', action: '%s', data: '%s')", module_name, action, data);
|
||||
|
||||
int num_delivered = 0;
|
||||
|
||||
@ -547,10 +522,35 @@ void controller::process_inputdata() {
|
||||
}
|
||||
|
||||
if (num_delivered == 0) {
|
||||
m_log.err("There exists no module with name '%s' (input: %s)", module_name, cmd);
|
||||
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
|
||||
*/
|
||||
void controller::process_inputdata() {
|
||||
if (m_inputdata.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const string cmd = std::move(m_inputdata);
|
||||
m_inputdata = string{};
|
||||
|
||||
m_log.trace("controller: Processing inputdata: %s", cmd);
|
||||
|
||||
// Every command that starts with '#' is considered an action string.
|
||||
if (cmd.front() == '#') {
|
||||
try {
|
||||
this->forward_action(actions_util::parse_action_string(cmd));
|
||||
} catch (runtime_error& e) {
|
||||
m_log.err("Invalid action string (action: %s, reason: %s)", cmd, e.what());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user