Refactor enable click condition

This shouldn't change behaviour.
This commit is contained in:
KosmX 2023-08-16 17:11:44 +02:00
parent 0a28b50a8c
commit 718db71638
No known key found for this signature in database
GPG Key ID: 779B9349C1C96DD1
1 changed files with 8 additions and 12 deletions

View File

@ -27,20 +27,16 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
} }
// configure events' user commands // configure events' user commands
if (enable_click) { // hasUserEvent is true if any element from eventMap_ is satisfying the condition in the lambda function
bool hasUserEvent =
std::find_if(eventMap_.cbegin(), eventMap_.cend(), [&config](const auto& eventEntry) {
//True if there is any non-release type event
return eventEntry.first.second != GdkEventType::GDK_BUTTON_RELEASE && config[eventEntry.second].isString();
}) != eventMap_.cend();
if (enable_click || hasUserEvent) {
event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &AModule::handleToggle)); event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &AModule::handleToggle));
} else {
std::map<std::pair<uint, GdkEventType>, std::string>::const_iterator it{eventMap_.cbegin()};
while (it != eventMap_.cend()) {
if (config_[it->second].isString()) {
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
event_box_.signal_button_press_event().connect(
sigc::mem_fun(*this, &AModule::handleToggle));
break;
}
++it;
}
} }
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString() || enable_scroll) { if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString() || enable_scroll) {
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);