dwm: Fix input handling

The command strings were not updated since the event variable formats changed.

Also, the EVENT_PREFIX already contained a dash, so an extra character would be
erased when adding 1.

Don't move the cmd string into the check_send_cmd function since if the first
event doesn't match, the cmd string would have been modified when passed to
the function again to check if the second event matches.
This commit is contained in:
Mihir Lad 2020-07-20 00:13:10 -04:00
parent 866c88c1d3
commit 399a797b45
2 changed files with 9 additions and 9 deletions

View File

@ -63,7 +63,7 @@ namespace modules {
void update_title_label(unsigned int client_id); void update_title_label(unsigned int client_id);
auto get_state(tag_mask_t bit_mask) const -> state_t; auto get_state(tag_mask_t bit_mask) const -> state_t;
auto check_send_cmd(string&& cmd, const string& ev_name) -> bool; auto check_send_cmd(string cmd, const string& ev_name) -> bool;
auto reconnect_dwm() -> bool; auto reconnect_dwm() -> bool;
bool m_click{true}; bool m_click{true};

View File

@ -152,8 +152,8 @@ namespace modules {
} }
if (m_click) { if (m_click) {
builder->cmd(mousebtn::LEFT, string{EVENT_LCLICK} + to_string(tag.bit_mask)); builder->cmd(mousebtn::LEFT, EVENT_PREFIX + string{EVENT_LCLICK} + "-" + to_string(tag.bit_mask));
builder->cmd(mousebtn::RIGHT, string{EVENT_RCLICK} + to_string(tag.bit_mask)); builder->cmd(mousebtn::RIGHT, EVENT_PREFIX + string{EVENT_RCLICK} + "-" + to_string(tag.bit_mask));
builder->node(tag.label); builder->node(tag.label);
builder->cmd_close(); builder->cmd_close();
builder->cmd_close(); builder->cmd_close();
@ -168,16 +168,16 @@ namespace modules {
return true; return true;
} }
auto dwm_module::check_send_cmd(string&& cmd, const string& ev_name) -> bool { auto dwm_module::check_send_cmd(string cmd, const string& ev_name) -> bool {
// cmd = <EVENT_PREFIX>-<ev_name>-<arg> std::cerr << cmd << std::endl;
// +1 : Erase '-' // cmd = <EVENT_PREFIX><ev_name>-<arg>
cmd.erase(0, strlen(EVENT_PREFIX) + 1); cmd.erase(0, strlen(EVENT_PREFIX));
// cmd = <ev_name>-<arg> // cmd = <ev_name>-<arg>
if (cmd.compare(0, ev_name.size(), ev_name) == 0) { if (cmd.compare(0, ev_name.size(), ev_name) == 0) {
// Erase '<ev_name>-' // Erase '<ev_name>-'
cmd.erase(0, ev_name.size() + 1); cmd.erase(0, ev_name.size() + 1);
m_log.info("%s: Sending workspace view command to ipc handler", name()); m_log.info("%s: Sending workspace %s command to ipc handler", ev_name, name());
try { try {
m_ipc->run_command(ev_name, stoul(cmd)); m_ipc->run_command(ev_name, stoul(cmd));
@ -194,7 +194,7 @@ namespace modules {
return false; return false;
} }
return check_send_cmd(move(cmd), EVENT_LCLICK) || check_send_cmd(move(cmd), EVENT_RCLICK); return check_send_cmd(cmd, EVENT_LCLICK) || check_send_cmd(cmd, EVENT_RCLICK);
} }
auto dwm_module::get_state(tag_mask_t bit_mask) const -> state_t { auto dwm_module::get_state(tag_mask_t bit_mask) const -> state_t {