Cursor change to indicate module clickability (#3108)
* Indicate clickability on mouse hover * Avoid messy overrides situation * Update AModule.cpp * Update AModule.cpp * Update AModule.cpp * Update AModule.cpp --------- Co-authored-by: Alexis Rouillard <alexisr245@gmail.com>
This commit is contained in:
parent
a597a994d2
commit
9a3044a54f
|
@ -37,6 +37,8 @@ class AModule : public IModule {
|
||||||
const Json::Value &config_;
|
const Json::Value &config_;
|
||||||
Gtk::EventBox event_box_;
|
Gtk::EventBox event_box_;
|
||||||
|
|
||||||
|
virtual void setCursor(Gdk::CursorType const c);
|
||||||
|
|
||||||
virtual bool handleToggle(GdkEventButton *const &ev);
|
virtual bool handleToggle(GdkEventButton *const &ev);
|
||||||
virtual bool handleMouseEnter(GdkEventCrossing *const &ev);
|
virtual bool handleMouseEnter(GdkEventCrossing *const &ev);
|
||||||
virtual bool handleMouseLeave(GdkEventCrossing *const &ev);
|
virtual bool handleMouseLeave(GdkEventCrossing *const &ev);
|
||||||
|
@ -46,6 +48,7 @@ class AModule : public IModule {
|
||||||
private:
|
private:
|
||||||
bool handleUserEvent(GdkEventButton *const &ev);
|
bool handleUserEvent(GdkEventButton *const &ev);
|
||||||
const bool isTooltip;
|
const bool isTooltip;
|
||||||
|
bool hasUserEvents_;
|
||||||
std::vector<int> pid_;
|
std::vector<int> pid_;
|
||||||
gdouble distance_scrolled_y_;
|
gdouble distance_scrolled_y_;
|
||||||
gdouble distance_scrolled_x_;
|
gdouble distance_scrolled_x_;
|
||||||
|
|
|
@ -15,6 +15,7 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
|
||||||
distance_scrolled_x_(0.0) {
|
distance_scrolled_x_(0.0) {
|
||||||
// Configure module action Map
|
// Configure module action Map
|
||||||
const Json::Value actions{config_["actions"]};
|
const Json::Value actions{config_["actions"]};
|
||||||
|
|
||||||
for (Json::Value::const_iterator it = actions.begin(); it != actions.end(); ++it) {
|
for (Json::Value::const_iterator it = actions.begin(); it != actions.end(); ++it) {
|
||||||
if (it.key().isString() && it->isString())
|
if (it.key().isString() && it->isString())
|
||||||
if (eventActionMap_.count(it.key().asString()) == 0) {
|
if (eventActionMap_.count(it.key().asString()) == 0) {
|
||||||
|
@ -31,17 +32,20 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
|
||||||
event_box_.signal_leave_notify_event().connect(sigc::mem_fun(*this, &AModule::handleMouseLeave));
|
event_box_.signal_leave_notify_event().connect(sigc::mem_fun(*this, &AModule::handleMouseLeave));
|
||||||
|
|
||||||
// configure events' user commands
|
// configure events' user commands
|
||||||
// hasUserEvent is true if any element from eventMap_ is satisfying the condition in the lambda
|
// hasUserEvents is true if any element from eventMap_ is satisfying the condition in the lambda
|
||||||
bool hasUserEvent =
|
bool hasUserEvents =
|
||||||
std::find_if(eventMap_.cbegin(), eventMap_.cend(), [&config](const auto& eventEntry) {
|
std::find_if(eventMap_.cbegin(), eventMap_.cend(), [&config](const auto& eventEntry) {
|
||||||
// True if there is any non-release type event
|
// True if there is any non-release type event
|
||||||
return eventEntry.first.second != GdkEventType::GDK_BUTTON_RELEASE &&
|
return eventEntry.first.second != GdkEventType::GDK_BUTTON_RELEASE &&
|
||||||
config[eventEntry.second].isString();
|
config[eventEntry.second].isString();
|
||||||
}) != eventMap_.cend();
|
}) != eventMap_.cend();
|
||||||
|
|
||||||
if (enable_click || hasUserEvent) {
|
if (enable_click || hasUserEvents) {
|
||||||
|
hasUserEvents_ = true;
|
||||||
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 {
|
||||||
|
hasUserEvents_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasReleaseEvent =
|
bool hasReleaseEvent =
|
||||||
|
@ -86,10 +90,21 @@ auto AModule::doAction(const std::string& name) -> void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AModule::setCursor(Gdk::CursorType c) {
|
||||||
|
auto cursor = Gdk::Cursor::create(Gdk::HAND2);
|
||||||
|
auto gdk_window = event_box_.get_window();
|
||||||
|
gdk_window->set_cursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
bool AModule::handleMouseEnter(GdkEventCrossing* const& e) {
|
bool AModule::handleMouseEnter(GdkEventCrossing* const& e) {
|
||||||
if (auto* module = event_box_.get_child(); module != nullptr) {
|
if (auto* module = event_box_.get_child(); module != nullptr) {
|
||||||
module->set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
module->set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasUserEvents_) {
|
||||||
|
setCursor(Gdk::HAND2);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +112,10 @@ bool AModule::handleMouseLeave(GdkEventCrossing* const& e) {
|
||||||
if (auto* module = event_box_.get_child(); module != nullptr) {
|
if (auto* module = event_box_.get_child(); module != nullptr) {
|
||||||
module->unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
module->unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasUserEvents_) {
|
||||||
|
setCursor(Gdk::ARROW);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +127,7 @@ 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))};
|
||||||
|
|
||||||
if (rec != eventMap_.cend()) {
|
if (rec != eventMap_.cend()) {
|
||||||
// First call module actions
|
// First call module actions
|
||||||
this->AModule::doAction(rec->second);
|
this->AModule::doAction(rec->second);
|
||||||
|
|
Loading…
Reference in New Issue