Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor change to indicate module clickability #3108

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/AModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
const Json::Value &config_;
Gtk::EventBox event_box_;

virtual void setCursor(Gdk::CursorType const c);

Check warning on line 40 in include/AModule.hpp

View workflow job for this annotation

GitHub Actions / build

include/AModule.hpp:40:26 [readability-avoid-const-params-in-decls]

parameter 'c' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions

virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleMouseEnter(GdkEventCrossing *const &ev);
virtual bool handleMouseLeave(GdkEventCrossing *const &ev);
Expand All @@ -46,6 +48,7 @@
private:
bool handleUserEvent(GdkEventButton *const &ev);
const bool isTooltip;
bool hasUserEvents_;
std::vector<int> pid_;
gdouble distance_scrolled_y_;
gdouble distance_scrolled_x_;
Expand Down
26 changes: 23 additions & 3 deletions src/AModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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) {
Expand All @@ -31,17 +32,20 @@
event_box_.signal_leave_notify_event().connect(sigc::mem_fun(*this, &AModule::handleMouseLeave));

// configure events' user commands
// hasUserEvent is true if any element from eventMap_ is satisfying the condition in the lambda
bool hasUserEvent =
// hasUserEvents is true if any element from eventMap_ is satisfying the condition in the lambda
bool hasUserEvents =
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) {
if (enable_click || hasUserEvents) {
hasUserEvents_ = true;
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &AModule::handleToggle));
} else {
hasUserEvents_ = false;
}

bool hasReleaseEvent =
Expand Down Expand Up @@ -86,17 +90,32 @@
}
}


void AModule::setCursor(Gdk::CursorType c) {
auto cursor = Gdk::Cursor::create(Gdk::HAND2);
auto gdk_window = event_box_.get_window();

Check warning on line 96 in src/AModule.cpp

View workflow job for this annotation

GitHub Actions / build

src/AModule.cpp:96:8 [readability-identifier-naming]

invalid case style for variable 'gdk_window'
gdk_window->set_cursor(cursor);
}

bool AModule::handleMouseEnter(GdkEventCrossing* const& e) {
if (auto* module = event_box_.get_child(); module != nullptr) {
module->set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
}

if (hasUserEvents_) {
setCursor(Gdk::HAND2);
}
return false;
}

bool AModule::handleMouseLeave(GdkEventCrossing* const& e) {
if (auto* module = event_box_.get_child(); module != nullptr) {
module->unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
}

if (hasUserEvents_) {
setCursor(Gdk::ARROW);
}
return false;
}

Expand All @@ -108,6 +127,7 @@
std::string format{};
const std::map<std::pair<uint, GdkEventType>, std::string>::const_iterator& rec{
eventMap_.find(std::pair(e->button, e->type))};

if (rec != eventMap_.cend()) {
// First call module actions
this->AModule::doAction(rec->second);
Expand Down
Loading