Merge branch 'master' into issue-1681
This commit is contained in:
@ -12,6 +12,20 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
|
||||
config_(std::move(config)),
|
||||
distance_scrolled_y_(0.0),
|
||||
distance_scrolled_x_(0.0) {
|
||||
// Configure module action Map
|
||||
const Json::Value actions{config_["actions"]};
|
||||
for (Json::Value::const_iterator it = actions.begin(); it != actions.end(); ++it) {
|
||||
if (it.key().isString() && it->isString())
|
||||
if (eventActionMap_.count(it.key().asString()) == 0) {
|
||||
eventActionMap_.insert({it.key().asString(), it->asString()});
|
||||
enable_click = true;
|
||||
enable_scroll = true;
|
||||
} else
|
||||
spdlog::warn("Dublicate action is ignored: {0}", it.key().asString());
|
||||
else
|
||||
spdlog::warn("Wrong actions section configuration. See config by index: {}", it.index());
|
||||
}
|
||||
|
||||
// configure events' user commands
|
||||
if (enable_click) {
|
||||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||
@ -48,19 +62,33 @@ auto AModule::update() -> void {
|
||||
pid_children_.push_back(util::command::forkExec(config_["on-update"].asString()));
|
||||
}
|
||||
}
|
||||
// Get mapping between event name and module action name
|
||||
// Then call overrided doAction in order to call appropriate module action
|
||||
auto AModule::doAction(const std::string& name) -> void {
|
||||
if (!name.empty()) {
|
||||
const std::map<std::string, std::string>::const_iterator& recA{eventActionMap_.find(name)};
|
||||
// Call overrided action if derrived class has implemented it
|
||||
if (recA != eventActionMap_.cend() && name != recA->second) this->doAction(recA->second);
|
||||
}
|
||||
}
|
||||
|
||||
bool AModule::handleToggle(GdkEventButton* const& e) {
|
||||
std::string format{};
|
||||
const std::map<std::pair<uint, GdkEventType>, std::string>::const_iterator& rec{
|
||||
eventMap_.find(std::pair(e->button, e->type))};
|
||||
std::string format{(rec != eventMap_.cend()) ? rec->second : std::string{""}};
|
||||
if (rec != eventMap_.cend()) {
|
||||
// First call module actions
|
||||
this->AModule::doAction(rec->second);
|
||||
|
||||
format = rec->second;
|
||||
}
|
||||
// Second call user scripts
|
||||
if (!format.empty()) {
|
||||
if (config_[format].isString())
|
||||
format = config_[format].asString();
|
||||
else
|
||||
format.clear();
|
||||
}
|
||||
|
||||
if (!format.empty()) {
|
||||
pid_children_.push_back(util::command::forkExec(format));
|
||||
}
|
||||
@ -69,11 +97,21 @@ bool AModule::handleToggle(GdkEventButton* const& e) {
|
||||
}
|
||||
|
||||
AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
|
||||
// only affects up/down
|
||||
bool reverse = config_["reverse-scrolling"].asBool();
|
||||
bool reverse_mouse = config_["reverse-mouse-scrolling"].asBool();
|
||||
|
||||
// ignore reverse-scrolling if event comes from a mouse wheel
|
||||
GdkDevice* device = gdk_event_get_source_device((GdkEvent*)e);
|
||||
if (device != NULL && gdk_device_get_source(device) == GDK_SOURCE_MOUSE) {
|
||||
reverse = reverse_mouse;
|
||||
}
|
||||
|
||||
switch (e->direction) {
|
||||
case GDK_SCROLL_UP:
|
||||
return SCROLL_DIR::UP;
|
||||
return reverse ? SCROLL_DIR::DOWN : SCROLL_DIR::UP;
|
||||
case GDK_SCROLL_DOWN:
|
||||
return SCROLL_DIR::DOWN;
|
||||
return reverse ? SCROLL_DIR::UP : SCROLL_DIR::DOWN;
|
||||
case GDK_SCROLL_LEFT:
|
||||
return SCROLL_DIR::LEFT;
|
||||
case GDK_SCROLL_RIGHT:
|
||||
@ -90,9 +128,9 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
|
||||
}
|
||||
|
||||
if (distance_scrolled_y_ < -threshold) {
|
||||
dir = SCROLL_DIR::UP;
|
||||
dir = reverse ? SCROLL_DIR::DOWN : SCROLL_DIR::UP;
|
||||
} else if (distance_scrolled_y_ > threshold) {
|
||||
dir = SCROLL_DIR::DOWN;
|
||||
dir = reverse ? SCROLL_DIR::UP : SCROLL_DIR::DOWN;
|
||||
} else if (distance_scrolled_x_ > threshold) {
|
||||
dir = SCROLL_DIR::RIGHT;
|
||||
} else if (distance_scrolled_x_ < -threshold) {
|
||||
@ -122,11 +160,19 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
|
||||
|
||||
bool AModule::handleScroll(GdkEventScroll* e) {
|
||||
auto dir = getScrollDir(e);
|
||||
if (dir == SCROLL_DIR::UP && config_["on-scroll-up"].isString()) {
|
||||
pid_children_.push_back(util::command::forkExec(config_["on-scroll-up"].asString()));
|
||||
} else if (dir == SCROLL_DIR::DOWN && config_["on-scroll-down"].isString()) {
|
||||
pid_children_.push_back(util::command::forkExec(config_["on-scroll-down"].asString()));
|
||||
}
|
||||
std::string eventName{};
|
||||
|
||||
if (dir == SCROLL_DIR::UP)
|
||||
eventName = "on-scroll-up";
|
||||
else if (dir == SCROLL_DIR::DOWN)
|
||||
eventName = "on-scroll-down";
|
||||
|
||||
// First call module actions
|
||||
this->AModule::doAction(eventName);
|
||||
// Second call user scripts
|
||||
if (config_[eventName].isString())
|
||||
pid_children_.push_back(util::command::forkExec(config_[eventName].asString()));
|
||||
|
||||
dp.emit();
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user