Merge pull request #2414 from KosmX/add_release_v2
Release button event second attemptpull/2456/head
commit
82b7e4ea01
|
@ -36,26 +36,34 @@ class AModule : public IModule {
|
||||||
|
|
||||||
virtual bool handleToggle(GdkEventButton *const &ev);
|
virtual bool handleToggle(GdkEventButton *const &ev);
|
||||||
virtual bool handleScroll(GdkEventScroll *);
|
virtual bool handleScroll(GdkEventScroll *);
|
||||||
|
virtual bool handleRelease(GdkEventButton *const &ev);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool handleUserEvent(GdkEventButton *const &ev);
|
||||||
|
|
||||||
std::vector<int> pid_;
|
std::vector<int> pid_;
|
||||||
gdouble distance_scrolled_y_;
|
gdouble distance_scrolled_y_;
|
||||||
gdouble distance_scrolled_x_;
|
gdouble distance_scrolled_x_;
|
||||||
std::map<std::string, std::string> eventActionMap_;
|
std::map<std::string, std::string> eventActionMap_;
|
||||||
static const inline std::map<std::pair<uint, GdkEventType>, std::string> eventMap_{
|
static const inline std::map<std::pair<uint, GdkEventType>, std::string> eventMap_{
|
||||||
{std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"},
|
{std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"},
|
||||||
|
{std::make_pair(1, GdkEventType::GDK_BUTTON_RELEASE), "on-click-release"},
|
||||||
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},
|
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},
|
||||||
{std::make_pair(1, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click"},
|
{std::make_pair(1, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click"},
|
||||||
{std::make_pair(2, GdkEventType::GDK_BUTTON_PRESS), "on-click-middle"},
|
{std::make_pair(2, GdkEventType::GDK_BUTTON_PRESS), "on-click-middle"},
|
||||||
|
{std::make_pair(2, GdkEventType::GDK_BUTTON_RELEASE), "on-click-middle-release"},
|
||||||
{std::make_pair(2, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-middle"},
|
{std::make_pair(2, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-middle"},
|
||||||
{std::make_pair(2, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-middle"},
|
{std::make_pair(2, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-middle"},
|
||||||
{std::make_pair(3, GdkEventType::GDK_BUTTON_PRESS), "on-click-right"},
|
{std::make_pair(3, GdkEventType::GDK_BUTTON_PRESS), "on-click-right"},
|
||||||
|
{std::make_pair(3, GdkEventType::GDK_BUTTON_RELEASE), "on-click-right-release"},
|
||||||
{std::make_pair(3, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-right"},
|
{std::make_pair(3, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-right"},
|
||||||
{std::make_pair(3, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-right"},
|
{std::make_pair(3, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-right"},
|
||||||
{std::make_pair(8, GdkEventType::GDK_BUTTON_PRESS), "on-click-backward"},
|
{std::make_pair(8, GdkEventType::GDK_BUTTON_PRESS), "on-click-backward"},
|
||||||
|
{std::make_pair(8, GdkEventType::GDK_BUTTON_RELEASE), "on-click-backward-release"},
|
||||||
{std::make_pair(8, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-backward"},
|
{std::make_pair(8, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-backward"},
|
||||||
{std::make_pair(8, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-backward"},
|
{std::make_pair(8, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-backward"},
|
||||||
{std::make_pair(9, GdkEventType::GDK_BUTTON_PRESS), "on-click-forward"},
|
{std::make_pair(9, GdkEventType::GDK_BUTTON_PRESS), "on-click-forward"},
|
||||||
|
{std::make_pair(9, GdkEventType::GDK_BUTTON_RELEASE), "on-click-forward-release"},
|
||||||
{std::make_pair(9, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-forward"},
|
{std::make_pair(9, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-forward"},
|
||||||
{std::make_pair(9, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-forward"}};
|
{std::make_pair(9, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-forward"}};
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,20 +27,28 @@ 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
|
||||||
|
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()) {
|
bool hasReleaseEvent =
|
||||||
if (config_[it->second].isString()) {
|
std::find_if(eventMap_.cbegin(), eventMap_.cend(), [&config](const auto& eventEntry) {
|
||||||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
// True if there is any non-release type event
|
||||||
event_box_.signal_button_press_event().connect(
|
return eventEntry.first.second == GdkEventType::GDK_BUTTON_RELEASE &&
|
||||||
sigc::mem_fun(*this, &AModule::handleToggle));
|
config[eventEntry.second].isString();
|
||||||
break;
|
}) != eventMap_.cend();
|
||||||
}
|
if (hasReleaseEvent) {
|
||||||
++it;
|
event_box_.add_events(Gdk::BUTTON_RELEASE_MASK);
|
||||||
}
|
event_box_.signal_button_release_event().connect(sigc::mem_fun(*this, &AModule::handleRelease));
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
@ -72,7 +80,11 @@ auto AModule::doAction(const std::string& name) -> void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AModule::handleToggle(GdkEventButton* const& e) {
|
bool AModule::handleToggle(GdkEventButton* const& e) { return handleUserEvent(e); }
|
||||||
|
|
||||||
|
bool AModule::handleRelease(GdkEventButton* const& e) { return handleUserEvent(e); }
|
||||||
|
|
||||||
|
bool AModule::handleUserEvent(GdkEventButton* const& e) {
|
||||||
std::string format{};
|
std::string format{};
|
||||||
const std::map<std::pair<uint, GdkEventType>, std::string>::const_iterator& rec{
|
const std::map<std::pair<uint, GdkEventType>, std::string>::const_iterator& rec{
|
||||||
eventMap_.find(std::pair(e->button, e->type))};
|
eventMap_.find(std::pair(e->button, e->type))};
|
||||||
|
|
Loading…
Reference in New Issue