actions: Separate data from action string

Modules now no longer need to manually parse the action string and
extract data from it.
This commit is contained in:
patrick96 2020-05-24 00:36:16 +02:00 committed by Patrick Ziegler
parent 8acedeef87
commit bc1b86c584
33 changed files with 124 additions and 142 deletions

View File

@ -49,9 +49,9 @@ class builder {
void underline_close();
void control(controltag tag);
void action(mousebtn index, string action);
void action(mousebtn btn, const modules::input_handler& handler, string action);
void action(mousebtn btn, const modules::input_handler& handler, string action, string data);
void action(mousebtn index, string action, const label_t& label);
void action(mousebtn btn, const modules::input_handler& handler, string action, const label_t& label);
void action(mousebtn btn, const modules::input_handler& handler, string action, string data, const label_t& label);
void action_close();
protected:

View File

@ -36,7 +36,7 @@ namespace modules {
static constexpr auto EVENT_TOGGLE = "toggle";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static constexpr auto FORMAT_VOLUME = "format-volume";

View File

@ -32,7 +32,7 @@ namespace modules {
static constexpr const char* EVENT_DEC = "dec";
protected:
bool input(string&& cmd);
bool input(string&& cmd, string&& data);
private:
static constexpr auto TAG_LABEL = "<label>";

View File

@ -54,7 +54,7 @@ namespace modules {
static constexpr auto EVENT_PREV = "prev";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:
bool handle_status(string& data);

View File

@ -21,7 +21,7 @@ namespace modules {
static constexpr auto EVENT_TOGGLE = "toggle";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static constexpr auto TAG_LABEL = "<label>";

View File

@ -58,7 +58,7 @@ namespace modules {
static constexpr auto EVENT_PREV = "prev";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static string make_workspace_command(const string& workspace);

View File

@ -28,7 +28,7 @@ namespace modules {
static constexpr auto EVENT_CLOSE = "close";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static constexpr auto TAG_LABEL_TOGGLE = "<label-toggle>";

View File

@ -137,7 +137,7 @@ namespace modules {
void teardown();
string contents();
bool input(string&& action);
bool input(string&& action, string&& data);
string input_handler_name() const;
static constexpr auto TYPE = "";

View File

@ -104,7 +104,7 @@ namespace modules {
}
template <typename Impl>
bool module<Impl>::input(string&&) {
bool module<Impl>::input(string&&, string&&) {
// By default a module doesn't support inputs
return false;
}

View File

@ -9,11 +9,14 @@ namespace modules {
public:
virtual ~input_handler() {}
/**
* Handle action
* Handle action, possibly with data attached
*
* Any implementation is free to ignore the data, if the action does not
* require additional data.
*
* \returns true if the action is supported and false otherwise
*/
virtual bool input(string&& action) = 0;
virtual bool input(string&& action, string&& data) = 0;
/**
* The name of this input handler

View File

@ -38,7 +38,7 @@ namespace modules {
static constexpr const char* EVENT_SEEK = "seek";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static constexpr const char* FORMAT_ONLINE{"format-online"};

View File

@ -29,7 +29,7 @@ namespace modules {
static constexpr auto EVENT_TOGGLE = "toggle";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static constexpr auto FORMAT_VOLUME = "format-volume";

View File

@ -24,7 +24,7 @@ namespace modules {
static constexpr auto EVENT_TOGGLE = "toggle";
protected:
bool input(string&& action);
bool input(string&& action, string&& data);
private:

View File

@ -36,7 +36,7 @@ namespace modules {
string input_handler_name() const { \
return ""; \
} \
bool input(string&&) { \
bool input(string&&, string&&) { \
return false; \
} \
}

View File

@ -37,7 +37,7 @@ namespace modules {
protected:
void handle(const evt::randr_notify& evt);
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static constexpr const char* TAG_LABEL{"<label>"};

View File

@ -38,7 +38,7 @@ namespace modules {
void handle(const evt::xkb_state_notify& evt);
void handle(const evt::xkb_indicator_state_notify& evt);
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static constexpr const char* TAG_LABEL_LAYOUT{"<label-layout>"};

View File

@ -72,7 +72,7 @@ namespace modules {
void rebuild_desktop_states();
void set_desktop_urgent(xcb_window_t window);
bool input(string&& action);
bool input(string&& action, string&& data);
private:
static vector<string> get_desktop_names();

View File

@ -6,30 +6,7 @@
POLYBAR_NS
namespace actions_util {
/**
* Specifies how an action is routed
*
* A route consists of an input handler where the action should be delivered
* and the action itself.
*
* TODO maybe remove if redundant at the end
*/
struct route {
bool valid;
string handler_name;
string action;
explicit route();
explicit route(string handler_name, string action);
explicit route(const modules::input_handler& handler, string action);
/**
* Constructs the full action string for this route
*/
string get_action_string() const;
};
string get_action_string(const modules::input_handler& handler, string action);
string get_action_string(const modules::input_handler& handler, string action, string data);
} // namespace actions_util
POLYBAR_NS_END

View File

@ -442,8 +442,8 @@ void builder::action(mousebtn index, string action) {
/**
* Open action tag for the action of the given input_handler
*/
void builder::action(mousebtn btn, const modules::input_handler& handler, string action_name) {
action(btn, actions_util::get_action_string(handler, action_name));
void builder::action(mousebtn btn, const modules::input_handler& handler, string action_name, string data) {
action(btn, actions_util::get_action_string(handler, action_name, data));
}
/**
@ -461,8 +461,8 @@ void builder::action(mousebtn index, string action_name, const label_t& label) {
/**
* Wrap label in module action tag
*/
void builder::action(mousebtn btn, const modules::input_handler& handler, string action_name, const label_t& label) {
action(btn, actions_util::get_action_string(handler, action_name), label);
void builder::action(mousebtn btn, const modules::input_handler& handler, string action_name, string data, const label_t& label) {
action(btn, actions_util::get_action_string(handler, action_name, data), label);
}
/**

View File

@ -402,9 +402,11 @@ void controller::process_inputdata() {
m_log.trace("controller: Processing inputdata: %s", cmd);
/*
* Module inputs have the following form (w/o the quotes): "#NAME#INPUT"
* Module inputs have the following form (w/o the quotes): "#NAME#ACTION[.DATA]"
* where 'NAME' is the name of the module (for which '#' is a forbidden
* character) and 'INPUT' is the input that is sent to the module
* character) and 'ACTION' is the input that is sent to the module. 'DATA'
* is optional data that is attached to the action and is also sent to the
* module.
*/
if (cmd.front() == '#') {
// Find the second delimiter '#'
@ -417,15 +419,25 @@ void controller::process_inputdata() {
auto handler_name = cmd.substr(1, end_pos - 1);
auto action = cmd.substr(end_pos + 1);
string data;
m_log.info("Forwarding data to input handlers (name: %s, action: %s) ", handler_name, action);
// Find the '.' character that separates the data from the action name
auto data_sep_pos = action.find('.', 0);
// The action contains data
if (data_sep_pos != string::npos) {
data = action.substr(end_pos + 1);
action.erase(end_pos);
}
m_log.info("Forwarding data to input handlers (name: '%s', action: '%s', data: '%s') ", handler_name, action, data);
int num_delivered = 0;
// Forwards the action to all input handlers that match the name
for (auto&& handler : m_inputhandlers) {
if (handler->input_handler_name() == handler_name) {
if (!handler->input(std::forward<string>(action))) {
if (!handler->input(std::forward<string>(action), std::forward<string>(data))) {
m_log.err("The '%s' module does not support the '%s' action.", handler_name, action);
}
@ -513,7 +525,7 @@ void controller::process_inputdata() {
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;
string action = entry.second.second;
// Search for the first module that matches the type for this legacy action
for (auto&& mod : m_modules) {
@ -522,9 +534,13 @@ void controller::process_inputdata() {
auto handler_name = handler_ptr->input_handler_name();
// TODO make this message more descriptive and maybe link to some documentation
// TODO use route to string methods to print action name that should be used.
m_log.warn("The action '%s' is deprecated, use '#%s#%s' instead!", cmd, handler_name, action);
m_log.info("Forwarding legacy action '%s' to module '%s' as '%s'", cmd, handler_name, action);
if (!handler_ptr->input(std::forward<string>(action))) {
if (data.empty()) {
m_log.warn("The action '%s' is deprecated, use '#%s#%s' instead!", cmd, handler_name, action);
} else {
m_log.warn("The action '%s' is deprecated, use '#%s#%s.%s' instead!", cmd, handler_name, action, data);
}
m_log.info("Forwarding legacy action '%s' to module '%s' as '%s' with data '%s'", cmd, handler_name, action, data);
if (!handler_ptr->input(std::forward<string>(action), std::forward<string>(data))) {
m_log.err("Failed to forward deprecated action to %s module", type);
/*
* Forward to shell if the module cannot accept the action to not break existing behavior.

View File

@ -191,9 +191,9 @@ namespace modules {
string output{module::get_output()};
if (m_handle_events) {
m_builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE);
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC);
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC);
m_builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "");
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC, "");
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
m_builder->append(output);
@ -218,7 +218,7 @@ namespace modules {
return true;
}
bool alsa_module::input(string&& action) {
bool alsa_module::input(string&& action , string&&) {
if (!m_handle_events) {
return false;
} else if (!m_mixer[mixer::MASTER]) {

View File

@ -88,8 +88,8 @@ namespace modules {
string output{module::get_output()};
if (m_scroll) {
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC);
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC);
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC, "");
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
m_builder->append(std::move(output));
@ -113,7 +113,7 @@ namespace modules {
return true;
}
bool backlight_module::input(string&& cmd) {
bool backlight_module::input(string&& cmd, string&&) {
double value_mod{0.0};
if (cmd == EVENT_INC) {

View File

@ -396,8 +396,8 @@ namespace modules {
size_t workspace_n{0U};
if (m_scroll) {
builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV);
builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT);
builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV, "");
builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT, "");
}
for (auto&& ws : m_monitors[m_index]->workspaces) {
@ -409,7 +409,7 @@ namespace modules {
workspace_n++;
if (m_click) {
builder->action(mousebtn::LEFT, *this, sstream() << EVENT_FOCUS << m_index << "+" << workspace_n, ws.second);
builder->action(mousebtn::LEFT, *this, EVENT_FOCUS, sstream() << m_index << "+" << workspace_n, ws.second);
} else {
builder->node(ws.second);
}
@ -445,7 +445,7 @@ namespace modules {
return false;
}
bool bspwm_module::input(string&& action) {
bool bspwm_module::input(string&& action, string&& data) {
auto send_command = [this](string payload_cmd, string log_info) {
try {
auto ipc = bspwm_util::make_connection();
@ -458,18 +458,16 @@ namespace modules {
}
};
if (action.compare(0, strlen(EVENT_FOCUS), EVENT_FOCUS) == 0) {
action.erase(0, strlen(EVENT_FOCUS));
size_t separator{string_util::find_nth(action, 0, "+", 1)};
size_t monitor_n{std::strtoul(action.substr(0, separator).c_str(), nullptr, 10)};
string workspace_n{action.substr(separator + 1)};
if (action == EVENT_FOCUS) {
size_t separator{string_util::find_nth(data, 0, "+", 1)};
size_t monitor_n{std::strtoul(data.substr(0, separator).c_str(), nullptr, 10)};
string workspace_n{data.substr(separator + 1)};
if (monitor_n < m_monitors.size()) {
send_command("desktop -f " + m_monitors[monitor_n]->name + ":^" + workspace_n,
"Sending desktop focus command to ipc handler");
} else {
m_log.err("%s: Invalid monitor index in command: %s", name(), action);
m_log.err("%s: Invalid monitor index in command: %s", name(), data);
}
return true;

View File

@ -72,7 +72,7 @@ namespace modules {
bool date_module::build(builder* builder, const string& tag) const {
if (tag == TAG_LABEL) {
if (!m_dateformat_alt.empty() || !m_timeformat_alt.empty()) {
builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, m_label);
builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "", m_label);
} else {
builder->node(m_label);
}
@ -83,7 +83,7 @@ namespace modules {
return true;
}
bool date_module::input(string&& action) {
bool date_module::input(string&& action, string&&) {
if (action != EVENT_TOGGLE) {
return false;
}

View File

@ -183,8 +183,8 @@ namespace modules {
builder->node(m_modelabel);
} else if (tag == TAG_LABEL_STATE && !m_workspaces.empty()) {
if (m_scroll) {
builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV);
builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT);
builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV, "");
builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT, "");
}
bool first = true;
@ -201,7 +201,7 @@ namespace modules {
}
if (m_click) {
builder->action(mousebtn::LEFT, *this, string{EVENT_FOCUS} + ws->name, ws->label);
builder->action(mousebtn::LEFT, *this, EVENT_FOCUS, ws->name, ws->label);
} else {
builder->node(ws->label);
}
@ -218,14 +218,13 @@ namespace modules {
return true;
}
bool i3_module::input(string&& action) {
bool i3_module::input(string&& action, string&& data) {
try {
const i3_util::connection_t conn{};
if (action.compare(0, strlen(EVENT_FOCUS), EVENT_FOCUS) == 0) {
action.erase(0, strlen(EVENT_FOCUS));
if (action == EVENT_FOCUS) {
m_log.info("%s: Sending workspace focus command to ipc handler", name());
conn.send_command(make_workspace_command(action));
conn.send_command(make_workspace_command(data));
return true;
}

View File

@ -58,7 +58,7 @@ namespace modules {
m_log.trace("%s: Creating menu level item %i", name(), m_levels.back()->items.size());
auto item = factory_util::unique<menu_tree_item>();
item->label = load_label(m_conf, name(), item_param);
item->exec = m_conf.get(name(), item_param + "-exec", actions_util::get_action_string(*this, EVENT_CLOSE));
item->exec = m_conf.get(name(), item_param + "-exec", actions_util::get_action_string(*this, EVENT_CLOSE, ""));
m_levels.back()->items.emplace_back(move(item));
}
}
@ -66,9 +66,9 @@ namespace modules {
bool menu_module::build(builder* builder, const string& tag) const {
if (tag == TAG_LABEL_TOGGLE && m_level == -1) {
builder->action(mousebtn::LEFT, *this, string(EVENT_OPEN) + "0", m_labelopen);
builder->action(mousebtn::LEFT, *this, string(EVENT_OPEN), "0", m_labelopen);
} else if (tag == TAG_LABEL_TOGGLE && m_level > -1) {
builder->action(mousebtn::LEFT, *this, EVENT_CLOSE, m_labelclose);
builder->action(mousebtn::LEFT, *this, EVENT_CLOSE, "", m_labelclose);
} else if (tag == TAG_MENU && m_level > -1) {
auto spacing = m_formatter->get(get_format())->spacing;
//Insert separator after menu-toggle and before menu-items for expand-right=true
@ -96,7 +96,7 @@ namespace modules {
return true;
}
bool menu_module::input(string&& action) {
bool menu_module::input(string&& action, string&& data) {
// TODO Figure out how to close menu when command is executed (maybe exec-N action)
if (action.compare(0, 4, "menu") != 0 && m_level > -1) {
for (auto&& item : m_levels[m_level]->items) {
@ -109,8 +109,8 @@ namespace modules {
return false;
}
if (action.compare(0, strlen(EVENT_OPEN), EVENT_OPEN) == 0) {
auto level = action.substr(strlen(EVENT_OPEN));
if (action == EVENT_OPEN) {
auto level = data;
if (level.empty()) {
level = "0";

View File

@ -325,27 +325,27 @@ namespace modules {
} else if (tag == TAG_LABEL_OFFLINE) {
builder->node(m_label_offline);
} else if (tag == TAG_ICON_RANDOM) {
builder->action(mousebtn::LEFT, *this, EVENT_RANDOM, m_icons->get("random"));
builder->action(mousebtn::LEFT, *this, EVENT_RANDOM, "", m_icons->get("random"));
} else if (tag == TAG_ICON_REPEAT) {
builder->action(mousebtn::LEFT, *this, EVENT_REPEAT, m_icons->get("repeat"));
builder->action(mousebtn::LEFT, *this, EVENT_REPEAT, "", m_icons->get("repeat"));
} else if (tag == TAG_ICON_REPEAT_ONE || tag == TAG_ICON_SINGLE) {
builder->action(mousebtn::LEFT, *this, EVENT_SINGLE, m_icons->get("single"));
builder->action(mousebtn::LEFT, *this, EVENT_SINGLE, "", m_icons->get("single"));
} else if (tag == TAG_ICON_CONSUME) {
builder->action(mousebtn::LEFT, *this, EVENT_CONSUME, m_icons->get("consume"));
builder->action(mousebtn::LEFT, *this, EVENT_CONSUME, "", m_icons->get("consume"));
} else if (tag == TAG_ICON_PREV) {
builder->action(mousebtn::LEFT, *this, EVENT_PREV, m_icons->get("prev"));
builder->action(mousebtn::LEFT, *this, EVENT_PREV, "", m_icons->get("prev"));
} else if ((tag == TAG_ICON_STOP || tag == TAG_TOGGLE_STOP) && (is_playing || is_paused)) {
builder->action(mousebtn::LEFT, *this, EVENT_STOP, m_icons->get("stop"));
builder->action(mousebtn::LEFT, *this, EVENT_STOP, "", m_icons->get("stop"));
} else if ((tag == TAG_ICON_PAUSE || tag == TAG_TOGGLE) && is_playing) {
builder->action(mousebtn::LEFT, *this, EVENT_PAUSE, m_icons->get("pause"));
builder->action(mousebtn::LEFT, *this, EVENT_PAUSE, "", m_icons->get("pause"));
} else if ((tag == TAG_ICON_PLAY || tag == TAG_TOGGLE || tag == TAG_TOGGLE_STOP) && !is_playing) {
builder->action(mousebtn::LEFT, *this, EVENT_PLAY, m_icons->get("play"));
builder->action(mousebtn::LEFT, *this, EVENT_PLAY, "", m_icons->get("play"));
} else if (tag == TAG_ICON_NEXT) {
builder->action(mousebtn::LEFT, *this, EVENT_NEXT, m_icons->get("next"));
builder->action(mousebtn::LEFT, *this, EVENT_NEXT, "", m_icons->get("next"));
} else if (tag == TAG_ICON_SEEKB) {
builder->action(mousebtn::LEFT, *this, EVENT_SEEK + "-5"s, m_icons->get("seekb"));
builder->action(mousebtn::LEFT, *this, EVENT_SEEK, "-5"s, m_icons->get("seekb"));
} else if (tag == TAG_ICON_SEEKF) {
builder->action(mousebtn::LEFT, *this, EVENT_SEEK + "+5"s, m_icons->get("seekf"));
builder->action(mousebtn::LEFT, *this, EVENT_SEEK, "+5"s, m_icons->get("seekf"));
} else {
return false;
}
@ -353,7 +353,7 @@ namespace modules {
return true;
}
bool mpd_module::input(string&& action) {
bool mpd_module::input(string&& action, string&& data) {
m_log.info("%s: event: %s", name(), action);
try {
@ -384,17 +384,16 @@ namespace modules {
mpd->set_random(!status->random());
} else if (action == EVENT_CONSUME) {
mpd->set_consume(!status->consume());
} else if (action.compare(0, strlen(EVENT_SEEK), EVENT_SEEK) == 0) {
auto s = action.substr(strlen(EVENT_SEEK));
} else if (action == EVENT_SEEK) {
int percentage = 0;
if (s.empty()) {
if (data.empty()) {
return false;
} else if (s[0] == '+') {
percentage = status->get_elapsed_percentage() + std::strtol(s.substr(1).c_str(), nullptr, 10);
} else if (s[0] == '-') {
percentage = status->get_elapsed_percentage() - std::strtol(s.substr(1).c_str(), nullptr, 10);
} else if (data[0] == '+') {
percentage = status->get_elapsed_percentage() + std::strtol(data.substr(1).c_str(), nullptr, 10);
} else if (data[0] == '-') {
percentage = status->get_elapsed_percentage() - std::strtol(data.substr(1).c_str(), nullptr, 10);
} else {
percentage = std::strtol(s.c_str(), nullptr, 10);
percentage = std::strtol(data.c_str(), nullptr, 10);
}
mpd->seek(status->get_songid(), status->get_seek_position(percentage));
} else {

View File

@ -117,9 +117,9 @@ namespace modules {
m_builder->action(mousebtn::RIGHT, click_right);
}
m_builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE);
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC);
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC);
m_builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "");
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC, "");
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
m_builder->append(output);
@ -142,7 +142,7 @@ namespace modules {
return true;
}
bool pulseaudio_module::input(string&& action) {
bool pulseaudio_module::input(string&& action, string&&) {
if (!m_handle_events) {
return false;
}

View File

@ -41,7 +41,7 @@ namespace modules {
*/
bool systray_module::build(builder* builder, const string& tag) const {
if (tag == TAG_LABEL_TOGGLE) {
builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, m_label);
builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "", m_label);
} else if (tag == TAG_TRAY_CLIENTS && !m_hidden) {
builder->append(TRAY_PLACEHOLDER);
} else {
@ -53,7 +53,7 @@ namespace modules {
/**
* Handle input event
*/
bool systray_module::input(string&& action) {
bool systray_module::input(string&& action, string&& data) {
if (action.find(EVENT_TOGGLE) != 0) {
return false;
}

View File

@ -116,8 +116,8 @@ namespace modules {
string output{module::get_output()};
if (m_scroll) {
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC);
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC);
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_INC, "");
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
m_builder->append(output);
@ -147,7 +147,7 @@ namespace modules {
/**
* Process scroll events by changing backlight value
*/
bool xbacklight_module::input(string&& action) {
bool xbacklight_module::input(string&& action, string&&) {
double value_mod{0.0};
if (action == EVENT_INC) {

View File

@ -172,7 +172,7 @@ namespace modules {
string output{module::get_output()};
if (m_keyboard && m_keyboard->size() > 1) {
m_builder->action(mousebtn::LEFT, *this, EVENT_SWITCH);
m_builder->action(mousebtn::LEFT, *this, EVENT_SWITCH, "");
m_builder->append(output);
m_builder->action_close();
} else {
@ -207,7 +207,7 @@ namespace modules {
/**
* Handle input command
*/
bool xkeyboard_module::input(string&& action) {
bool xkeyboard_module::input(string&& action, string&&) {
if (action != EVENT_SWITCH) {
return false;
}

View File

@ -324,8 +324,8 @@ namespace modules {
}
if (m_scroll) {
m_builder->action(mousebtn::SCROLL_DOWN, *this, string{EVENT_PREV});
m_builder->action(mousebtn::SCROLL_UP, *this, string{EVENT_NEXT});
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV, "");
m_builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT, "");
}
m_builder->append(output);
@ -352,7 +352,7 @@ namespace modules {
for (auto&& desktop : m_viewports[m_index]->desktops) {
if (desktop->label.get()) {
if (m_click && desktop->state != desktop_state::ACTIVE) {
builder->action(mousebtn::LEFT, *this, string{EVENT_FOCUS} + to_string(desktop->index), desktop->label);
builder->action(mousebtn::LEFT, *this, EVENT_FOCUS, to_string(desktop->index), desktop->label);
} else {
builder->node(desktop->label);
}
@ -368,7 +368,7 @@ namespace modules {
/**
* Handle user input event
*/
bool xworkspaces_module::input(string&& action) {
bool xworkspaces_module::input(string&& action, string&& data) {
std::lock_guard<std::mutex> lock(m_workspace_mutex);
vector<unsigned int> indexes;
@ -383,14 +383,12 @@ namespace modules {
unsigned int new_desktop{0};
unsigned int current_desktop{ewmh_util::get_current_desktop()};
size_t len;
if ((len = strlen(EVENT_FOCUS)) && action.compare(0, len, EVENT_FOCUS) == 0) {
new_desktop = std::strtoul(action.substr(len).c_str(), nullptr, 10);
} else if ((len = strlen(EVENT_NEXT)) && action.compare(0, len, EVENT_NEXT) == 0) {
if (action == EVENT_FOCUS) {
new_desktop = std::strtoul(data.c_str(), nullptr, 10);
} else if (action == EVENT_NEXT) {
new_desktop = math_util::min<unsigned int>(indexes.back(), current_desktop + 1);
new_desktop = new_desktop == current_desktop ? indexes.front() : new_desktop;
} else if ((len = strlen(EVENT_PREV)) && action.compare(0, len, EVENT_PREV) == 0) {
} else if (action == EVENT_PREV) {
new_desktop = math_util::max<unsigned int>(indexes.front(), current_desktop - 1);
new_desktop = new_desktop == current_desktop ? indexes.back() : new_desktop;
}

View File

@ -5,21 +5,13 @@
POLYBAR_NS
namespace actions_util {
route::route() : valid(false), handler_name(""), action("") {}
route::route(string handler_name, string action) : valid(true), handler_name(handler_name), action(action) {}
route::route(const modules::input_handler& handler, string action)
: valid(true), handler_name(handler.input_handler_name()), action(action) {}
string route::get_action_string() const {
if (!this->valid) {
return "";
string get_action_string(const modules::input_handler& handler, string action, string data) {
string str = "#" + handler.input_handler_name() + "#" + action;
if (!data.empty()) {
str += "." + data;
}
return "#" + this->handler_name + "#" + this->action;
}
string get_action_string(const modules::input_handler& handler, string action) {
return route(handler, action).get_action_string();
return str;
}
} // namespace actions_util