* 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
|
@ -11,15 +11,13 @@ namespace waybar {
|
|||
|
||||
class Group : public AModule {
|
||||
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;
|
||||
auto update() -> void override;
|
||||
operator Gtk::Widget&() override;
|
||||
operator Gtk::Widget &() override;
|
||||
|
||||
virtual Gtk::Box& getBox();
|
||||
void addWidget(Gtk::Widget& widget);
|
||||
|
||||
bool handleMouseHover(GdkEventCrossing* const& e);
|
||||
virtual Gtk::Box &getBox();
|
||||
void addWidget(Gtk::Widget &widget);
|
||||
|
||||
protected:
|
||||
Gtk::Box 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
|
||||
|
|
|
@ -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:
|
||||
revealer.set_reveal_child(true);
|
||||
break;
|
||||
case GDK_LEAVE_NOTIFY:
|
||||
revealer.set_reveal_child(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
event_box_.add(box);
|
||||
}
|
||||
|
||||
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));
|
||||
bool Group::handleMouseEnter(GdkEventCrossing* const& e) {
|
||||
box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||
revealer.set_reveal_child(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Group::handleMouseLeave(GdkEventCrossing* const& e) {
|
||||
box.unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||
revealer.set_reveal_child(false);
|
||||
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) {
|
||||
widget.get_style_context()->add_class(add_class_to_drawer_children);
|
||||
}
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue