* 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 {
|
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
|
||||||
|
|
|
@ -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) {
|
|
||||||
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) {
|
bool Group::handleMouseEnter(GdkEventCrossing* const& e) {
|
||||||
widget.add_events(Gdk::EventMask::ENTER_NOTIFY_MASK | Gdk::EventMask::LEAVE_NOTIFY_MASK);
|
box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||||
widget.signal_enter_notify_event().connect(sigc::mem_fun(*this, &Group::handleMouseHover));
|
revealer.set_reveal_child(true);
|
||||||
widget.signal_leave_notify_event().connect(sigc::mem_fun(*this, &Group::handleMouseHover));
|
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 {
|
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
|
widget.get_style_context()->add_class(add_class_to_drawer_children);
|
||||||
addHoverHandlerTo(widget);
|
|
||||||
if (!is_first_widget) {
|
|
||||||
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