actions: Forward data of legacy actions

Some actions have data attached (e.g. xworkspaces-focus=N), the
forwarding logic now matches the keys in the legacy_actions map as
prefixes and everything afterwards is considered additional data and
appended to the new action string.
This commit is contained in:
patrick96 2020-05-12 23:41:52 +02:00 committed by Patrick Ziegler
parent a2b312cc84
commit 002112df64

View File

@ -497,29 +497,40 @@ void controller::process_inputdata() {
}; };
#undef A_MAP #undef A_MAP
auto it = legacy_actions.find(cmd); // Check if any key in the map is a prefix for the `cmd`
for (const auto& entry : legacy_actions) {
const auto& key = entry.first;
if (cmd.compare(0, key.length(), key) == 0) {
string type = entry.second.first;
auto data = cmd.substr(key.length());
string action = entry.second.second + data;
if (it != legacy_actions.end()) { // Search for the first module that matches the type for this legacy action
auto action = it->second.second; for (auto&& mod : m_modules) {
if (mod->type() == type) {
for (auto&& handler : m_inputhandlers) { auto handler_ptr = std::dynamic_pointer_cast<input_handler>(mod);
auto module_ptr = std::dynamic_pointer_cast<module_interface>(handler); auto handler_name = handler_ptr->input_handler_name();
// TODO make this message more descriptive and maybe link to some documentation
if (module_ptr && module_ptr->type() == it->second.first) { // TODO use route to string methods to print action name that should be used.
// TODO make this message more descriptive and maybe link to some documentation m_log.warn("The action '%s' is deprecated, use '#%s#%s' instead!", cmd, handler_name, action);
m_log.warn("The action '%s' is deprecated, use '#%s#%s' instead!", cmd, handler->input_handler_name(), action); m_log.info("Forwarding legacy action '%s' to module '%s' as '%s'", cmd, handler_name, action);
m_log.info("Forwarding legacy action '%s' to module '%s' as '%s'", cmd, handler->input_handler_name(), action); if (!handler_ptr->input(std::forward<string>(action))) {
if (!handler->input(string{action})) { m_log.err("Failed to forward deprecated action to %s module", type);
m_log.err("Failed to forward deprecated action to %s module. THIS IS A BUG!", it->second.first); /*
* Forward to shell if the module cannot accept the action to not break existing behavior.
* goto is used to break out of multiple loops at once.
*/
goto forward_shell;
}
// Only deliver to the first matching module.
return;
} }
// Only deliver to the first matching module.
return;
} }
} }
// Fall through to running the action as a command to not break existing behavior.
} }
forward_shell:
try { try {
// Run input as command if it's not an input for a module // Run input as command if it's not an input for a module
m_log.info("Forwarding command to shell... (input: %s)", cmd); m_log.info("Forwarding command to shell... (input: %s)", cmd);