refactor: move signal handler adding into separate method

fix: typo in handleMouseHover method name
This commit is contained in:
Brenno Lemos 2023-10-14 18:30:27 -03:00
parent fad858782c
commit 5e44cb6ba2
2 changed files with 12 additions and 8 deletions

View File

@ -19,7 +19,7 @@ class Group : public AModule {
virtual Gtk::Box& getBox(); virtual Gtk::Box& getBox();
void addWidget(Gtk::Widget& widget); void addWidget(Gtk::Widget& widget);
bool hangleMouseHover(GdkEventCrossing* const& e); bool handleMouseHover(GdkEventCrossing* const& e);
protected: protected:
Gtk::Box box; Gtk::Box box;
@ -28,6 +28,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;
void addHoverHandlerTo(Gtk::Widget& widget);
}; };
} // namespace waybar } // namespace waybar

View File

@ -75,13 +75,11 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
revealer.add(revealer_box); revealer.add(revealer_box);
box.pack_start(revealer); box.pack_start(revealer);
revealer.add_events(Gdk::EventMask::ENTER_NOTIFY_MASK | Gdk::EventMask::LEAVE_NOTIFY_MASK); addHoverHandlerTo(revealer);
revealer.signal_enter_notify_event().connect(sigc::mem_fun(*this, &Group::hangleMouseHover));
revealer.signal_leave_notify_event().connect(sigc::mem_fun(*this, &Group::hangleMouseHover));
} }
} }
bool Group::hangleMouseHover(GdkEventCrossing* const& e) { bool Group::handleMouseHover(GdkEventCrossing* const& e) {
switch (e->type) { switch (e->type) {
case GDK_ENTER_NOTIFY: case GDK_ENTER_NOTIFY:
revealer.set_reveal_child(true); revealer.set_reveal_child(true);
@ -96,6 +94,12 @@ bool Group::hangleMouseHover(GdkEventCrossing* const& e) {
return true; 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));
}
auto Group::update() -> void { auto Group::update() -> void {
// noop // noop
} }
@ -108,9 +112,7 @@ void Group::addWidget(Gtk::Widget& widget) {
if (is_first_widget) { if (is_first_widget) {
// Necessary because of GTK's hitbox detection // Necessary because of GTK's hitbox detection
widget.add_events(Gdk::EventMask::ENTER_NOTIFY_MASK | Gdk::EventMask::LEAVE_NOTIFY_MASK); addHoverHandlerTo(widget);
widget.signal_enter_notify_event().connect(sigc::mem_fun(*this, &Group::hangleMouseHover));
widget.signal_leave_notify_event().connect(sigc::mem_fun(*this, &Group::hangleMouseHover));
} else { } else {
widget.get_style_context()->add_class(add_class_to_drawer_children); widget.get_style_context()->add_class(add_class_to_drawer_children);
} }