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
This commit is contained in:
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

@ -11,15 +11,13 @@ namespace waybar {
class Group : public AModule { class Group : public AModule {
public: public:
Group(const std::string&, const std::string&, const Json::Value&, bool); Group(const std::string &, const std::string &, const Json::Value &, bool);
virtual ~Group() = default; virtual ~Group() = default;
auto update() -> void override; auto update() -> void override;
operator Gtk::Widget&() override; operator Gtk::Widget &() override;
virtual Gtk::Box& getBox(); virtual Gtk::Box &getBox();
void addWidget(Gtk::Widget& widget); void addWidget(Gtk::Widget &widget);
bool handleMouseHover(GdkEventCrossing* const& e);
protected: protected:
Gtk::Box box; Gtk::Box box;
@ -28,8 +26,8 @@ class Group : public AModule {
bool is_first_widget = true; bool is_first_widget = true;
bool is_drawer = false; bool is_drawer = false;
std::string add_class_to_drawer_children; std::string add_class_to_drawer_children;
bool handleMouseEnter(GdkEventCrossing *const &ev) override;
void addHoverHandlerTo(Gtk::Widget& widget); bool handleMouseLeave(GdkEventCrossing *const &ev) override;
}; };
} // namespace waybar } // namespace waybar

View File

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