Improving mouse buttons support

Adding support for middle, backward, and forward mouse buttons click events, adds config keys : "on-click-middle", "on-click-forward" and "on-click-backward"
Adding the key "format-alt-click" to choose what mouse clicks toggles the alternative format, when present. Possible values (in config): "click-right", "click-left", "click-middle", "click-forward", "click-backward". Other values have the same effect than "click-left". Previous behaviour was to toggle it whenever any click was registered and any click that was not handled by "on-click-right" or "on-click-left" occurred
This commit is contained in:
Lucas Lazare 2019-03-02 14:07:12 -05:00
parent f47492c371
commit d0f56b7bdd
2 changed files with 58 additions and 2 deletions

View File

@ -40,11 +40,19 @@ auto waybar::ALabel::update() -> void {
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) { bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
if (config_["on-click"].isString() && e->button == 1) { if (config_["on-click"].isString() && e->button == 1) {
waybar::util::command::forkExec(config_["on-click"].asString()); waybar::util::command::forkExec(config_["on-click"].asString());
} else if (config_["on-click-middle"].isString() && e->button == 2) {
waybar::util::command::forkExec(config_["on-click-middle"].asString());
} else if (config_["on-click-right"].isString() && e->button == 3) { } else if (config_["on-click-right"].isString() && e->button == 3) {
waybar::util::command::forkExec(config_["on-click-right"].asString()); waybar::util::command::forkExec(config_["on-click-right"].asString());
} else { } else if (config_["on-click-forward"].isString() && e->button == 8) {
waybar::util::command::forkExec(config_["on-click-backward"].asString());
} else if (config_["on-click-backward"].isString() && e->button == 9) {
waybar::util::command::forkExec(config_["on-click-forward"].asString());
} else if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) {
alt_ = !alt_; alt_ = !alt_;
if (alt_) { if (alt_ && config_["format-alt"].isString()) {
format_ = config_["format-alt"].asString(); format_ = config_["format-alt"].asString();
} else { } else {
format_ = default_format_; format_ = default_format_;

View File

@ -196,6 +196,54 @@ auto waybar::Bar::setupConfig() -> void
std::istreambuf_iterator<char>()); std::istreambuf_iterator<char>());
util::JsonParser parser; util::JsonParser parser;
config_ = parser.parse(str); config_ = parser.parse(str);
// Converting string to button code rn as to avoid doing it later
auto setupAltFormatKeyForModule = [this](const std::string& module_name){
if (config_.isMember(module_name)) {
Json::Value& module = config_[module_name];
if (module.isMember("format-alt")) {
if (module.isMember("format-alt-click")) {
Json::Value& click = module["format-alt-click"];
if (click.isString()) {
std::string str_click = click.asString();
if (str_click == "click-right") {
module["format-alt-click"] = 3u;
} else if (str_click == "click-middle") {
module["format-alt-click"] = 2u;
} else if (str_click == "click-backward") {
module["format-alt-click"] = 8u;
} else if (str_click == "click-forward") {
module["format-alt-click"] = 9u;
} else {
module["format-alt-click"] = 1u; // default click-left
}
} else {
module["format-alt-click"] = 1u;
}
} else {
module["format-alt-click"] = 1u;
}
}
}
};
auto setupAltFormatKeyForModuleList = [this, &setupAltFormatKeyForModule](const char* module_list_name) {
if (config_.isMember(module_list_name)) {
Json::Value& modules = config_[module_list_name];
for (const Json::Value& module_name : modules) {
if (module_name.isString()) {
setupAltFormatKeyForModule(module_name.asString());
}
}
}
};
// Convert to button code for every module that is used.
setupAltFormatKeyForModuleList("modules-left");
setupAltFormatKeyForModuleList("modules-right");
setupAltFormatKeyForModuleList("modules-center");
} }
auto waybar::Bar::setupCss() -> void auto waybar::Bar::setupCss() -> void