feat(#3174): hover for whole group (#3201)

* feat(#3174): hover for whole group

* fix: target eventbox for class also

* fix: actually no reason to add handler, just override AModule

* fix: actually remove existing handler as well

drawer functionality still works from my testing. anything else to think
abotu?

* revert: keep id and class on original box

* refactor: clang-format group.hpp

* dev: try stop workflow
master
Lars-Ragnar A. Haugen 2024-05-06 10:51:03 +02:00 committed by GitHub
parent fc6d708fb6
commit e7779b5458
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 36 deletions

View File

@ -19,8 +19,6 @@ class Group : public AModule {
virtual Gtk::Box &getBox();
void addWidget(Gtk::Widget &widget);
bool handleMouseHover(GdkEventCrossing* const& e);
protected:
Gtk::Box box;
Gtk::Box revealer_box;
@ -28,8 +26,8 @@ class Group : public AModule {
bool is_first_widget = true;
bool is_drawer = false;
std::string add_class_to_drawer_children;
void addHoverHandlerTo(Gtk::Widget& widget);
bool handleMouseEnter(GdkEventCrossing *const &ev) override;
bool handleMouseLeave(GdkEventCrossing *const &ev) override;
};
} // namespace waybar

View File

@ -4,7 +4,7 @@
#include <util/command.hpp>
#include "gdkmm/device.h"
#include "gtkmm/enums.h"
#include "gtkmm/widget.h"
namespace waybar {
@ -78,30 +78,23 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
} else {
box.pack_start(revealer);
}
addHoverHandlerTo(revealer);
}
}
bool Group::handleMouseHover(GdkEventCrossing* const& e) {
switch (e->type) {
case GDK_ENTER_NOTIFY:
event_box_.add(box);
}
bool Group::handleMouseEnter(GdkEventCrossing* const& e) {
box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
revealer.set_reveal_child(true);
break;
case GDK_LEAVE_NOTIFY:
return false;
}
bool Group::handleMouseLeave(GdkEventCrossing* const& e) {
box.unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
revealer.set_reveal_child(false);
break;
default:
break;
}
return true;
}
void Group::addHoverHandlerTo(Gtk::Widget& widget) {
widget.add_events(Gdk::EventMask::ENTER_NOTIFY_MASK | Gdk::EventMask::LEAVE_NOTIFY_MASK);
widget.signal_enter_notify_event().connect(sigc::mem_fun(*this, &Group::handleMouseHover));
widget.signal_leave_notify_event().connect(sigc::mem_fun(*this, &Group::handleMouseHover));
return false;
}
auto Group::update() -> void {
@ -113,17 +106,13 @@ Gtk::Box& Group::getBox() { return is_drawer ? (is_first_widget ? box : revealer
void Group::addWidget(Gtk::Widget& widget) {
getBox().pack_start(widget, false, false);
if (is_drawer) {
// Necessary because of GTK's hitbox detection
addHoverHandlerTo(widget);
if (!is_first_widget) {
if (is_drawer && !is_first_widget) {
widget.get_style_context()->add_class(add_class_to_drawer_children);
}
}
is_first_widget = false;
}
Group::operator Gtk::Widget&() { return box; }
Group::operator Gtk::Widget&() { return event_box_; }
} // namespace waybar