* 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 workflowmaster
parent
fc6d708fb6
commit
e7779b5458
|
@ -19,8 +19,6 @@ class Group : public AModule {
|
||||||
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;
|
||||||
Gtk::Box revealer_box;
|
Gtk::Box revealer_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
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Group::handleMouseHover(GdkEventCrossing* const& e) {
|
event_box_.add(box);
|
||||||
switch (e->type) {
|
}
|
||||||
case GDK_ENTER_NOTIFY:
|
|
||||||
|
bool Group::handleMouseEnter(GdkEventCrossing* const& e) {
|
||||||
|
box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||||
revealer.set_reveal_child(true);
|
revealer.set_reveal_child(true);
|
||||||
break;
|
return false;
|
||||||
case GDK_LEAVE_NOTIFY:
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Group::handleMouseLeave(GdkEventCrossing* const& e) {
|
||||||
|
box.unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||||
revealer.set_reveal_child(false);
|
revealer.set_reveal_child(false);
|
||||||
break;
|
return false;
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue