feat(#3182): style tray icon on hover (#3203)

This commit is contained in:
Lars-Ragnar A. Haugen 2024-05-06 10:47:25 +02:00 committed by GitHub
parent c4e0c569aa
commit 8e8ce0c6bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -76,6 +76,8 @@ class Item : public sigc::trackable {
void makeMenu();
bool handleClick(GdkEventButton* const& /*ev*/);
bool handleScroll(GdkEventScroll* const&);
bool handleMouseEnter(GdkEventCrossing* const&);
bool handleMouseLeave(GdkEventCrossing* const&);
// smooth scrolling threshold
gdouble scroll_threshold_ = 0;

View File

@ -8,6 +8,7 @@
#include <fstream>
#include <map>
#include "gdk/gdk.h"
#include "util/format.hpp"
#include "util/gtk_icon.hpp"
@ -57,6 +58,8 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
event_box.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
event_box.signal_button_press_event().connect(sigc::mem_fun(*this, &Item::handleClick));
event_box.signal_scroll_event().connect(sigc::mem_fun(*this, &Item::handleScroll));
event_box.signal_enter_notify_event().connect(sigc::mem_fun(*this, &Item::handleMouseEnter));
event_box.signal_leave_notify_event().connect(sigc::mem_fun(*this, &Item::handleMouseLeave));
// initial visibility
event_box.show_all();
event_box.set_visible(show_passive_);
@ -69,6 +72,16 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
cancellable_, interface);
}
bool Item::handleMouseEnter(GdkEventCrossing* const& e) {
event_box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
return false;
}
bool Item::handleMouseLeave(GdkEventCrossing* const& e) {
event_box.unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
return false;
}
void Item::onConfigure(GdkEventConfigure* ev) { this->updateImage(); }
void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) {