dwm: Add build_cmd helper and rename events
build_cmd simplifies building a command string and helps avoid typo errors when adding new commands since most commands follow the same format. Rename EVENT_LCLICK and EVENT_RCLICK and to EVENT_TAG_LCLICK and EVENT_TAG_RCLICK for clarity and to allow specifying multiple click commands in the future without confusion. Also remove std:: from vector since it is not needed.
This commit is contained in:
parent
f91fc2c7ab
commit
ecc881b9b3
@ -85,13 +85,13 @@ namespace modules {
|
|||||||
/**
|
/**
|
||||||
* Event name is same as the IPC command name to view the tag clicked on
|
* Event name is same as the IPC command name to view the tag clicked on
|
||||||
*/
|
*/
|
||||||
static constexpr const char* EVENT_LCLICK{"view"};
|
static constexpr const char* EVENT_TAG_LCLICK{"view"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event name is same as IPC command name to toggle the view of the tag
|
* Event name is same as IPC command name to toggle the view of the tag
|
||||||
* clicked on
|
* clicked on
|
||||||
*/
|
*/
|
||||||
static constexpr const char* EVENT_RCLICK{"toggleview"};
|
static constexpr const char* EVENT_TAG_RCLICK{"toggleview"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by has_event on layout changes. This updates the layout label
|
* Called by has_event on layout changes. This updates the layout label
|
||||||
@ -175,6 +175,14 @@ namespace modules {
|
|||||||
*/
|
*/
|
||||||
auto check_send_cmd(string cmd, const string& ev_name) -> bool;
|
auto check_send_cmd(string cmd, const string& ev_name) -> bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to build cmd string
|
||||||
|
*
|
||||||
|
* @param ev The event name (should be same as dwm command name)
|
||||||
|
* @param arg The argument to the dwm command
|
||||||
|
*/
|
||||||
|
auto static build_cmd(const char* ev, const string& arg) -> string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to connect to any disconnected dwm sockets. Catch errors.
|
* Attempt to connect to any disconnected dwm sockets. Catch errors.
|
||||||
*/
|
*/
|
||||||
@ -223,7 +231,7 @@ namespace modules {
|
|||||||
/**
|
/**
|
||||||
* Vector of monitors returned by m_ipc->get_monitors
|
* Vector of monitors returned by m_ipc->get_monitors
|
||||||
*/
|
*/
|
||||||
shared_ptr<std::vector<dwmipc::Monitor>> m_monitors;
|
shared_ptr<vector<dwmipc::Monitor>> m_monitors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps state_t enum values to their corresponding labels
|
* Maps state_t enum values to their corresponding labels
|
||||||
|
@ -132,6 +132,10 @@ namespace modules {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto dwm_module::build_cmd(const char* ev, const string& arg) -> string {
|
||||||
|
return EVENT_PREFIX + string(ev) + "-" + arg;
|
||||||
|
}
|
||||||
|
|
||||||
auto dwm_module::build(builder* builder, const string& tag) const -> bool {
|
auto dwm_module::build(builder* builder, const string& tag) const -> bool {
|
||||||
if (tag == TAG_LABEL_LAYOUT) {
|
if (tag == TAG_LABEL_LAYOUT) {
|
||||||
builder->node(m_layout_label);
|
builder->node(m_layout_label);
|
||||||
@ -148,8 +152,8 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_click) {
|
if (m_click) {
|
||||||
builder->cmd(mousebtn::LEFT, EVENT_PREFIX + string{EVENT_LCLICK} + "-" + to_string(tag.bit_mask));
|
builder->cmd(mousebtn::LEFT, build_cmd(EVENT_TAG_LCLICK, to_string(tag.bit_mask)));
|
||||||
builder->cmd(mousebtn::RIGHT, EVENT_PREFIX + string{EVENT_RCLICK} + "-" + to_string(tag.bit_mask));
|
builder->cmd(mousebtn::RIGHT, build_cmd(EVENT_TAG_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();
|
||||||
@ -192,7 +196,7 @@ namespace modules {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return check_send_cmd(cmd, EVENT_LCLICK) || check_send_cmd(cmd, EVENT_RCLICK);
|
return check_send_cmd(cmd, EVENT_TAG_LCLICK) || check_send_cmd(cmd, EVENT_TAG_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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user