From 6c1125c1feaf81957e16cca924d08b56e3eb841e Mon Sep 17 00:00:00 2001 From: "Lars-Ragnar A. Haugen" Date: Wed, 17 Apr 2024 22:23:59 +0200 Subject: [PATCH] feat(#2989): (optional) hover for all modules --- include/AModule.hpp | 2 ++ man/waybar-styles.5.scd.in | 10 ++++++++++ resources/style.css | 5 +++++ src/AModule.cpp | 17 +++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/include/AModule.hpp b/include/AModule.hpp index c15efb00..ea692ff8 100644 --- a/include/AModule.hpp +++ b/include/AModule.hpp @@ -38,6 +38,8 @@ class AModule : public IModule { Gtk::EventBox event_box_; virtual bool handleToggle(GdkEventButton *const &ev); + virtual bool handleMouseEnter(GdkEventCrossing *const &ev); + virtual bool handleMouseLeave(GdkEventCrossing *const &ev); virtual bool handleScroll(GdkEventScroll *); virtual bool handleRelease(GdkEventButton *const &ev); diff --git a/man/waybar-styles.5.scd.in b/man/waybar-styles.5.scd.in index ddc4c3c9..0af393ef 100644 --- a/man/waybar-styles.5.scd.in +++ b/man/waybar-styles.5.scd.in @@ -29,6 +29,16 @@ An example user-controlled stylesheet that just changes the color of the clock t } ``` +## Hover-effect + +You can apply special styling to any module for when the cursor hovers it. + +``` +#clock:hover { + background-color: #ffffff; +} +``` + # SEE ALSO - *waybar(5)* diff --git a/resources/style.css b/resources/style.css index b5859390..7e830285 100644 --- a/resources/style.css +++ b/resources/style.css @@ -48,6 +48,11 @@ button:hover { box-shadow: inset 0 -3px #ffffff; } +/* you can set a style on hover for any module like this */ +#pulseaudio:hover { + background-color: #a37800; +} + #workspaces button { padding: 0 5px; background-color: transparent; diff --git a/src/AModule.cpp b/src/AModule.cpp index a451c3d6..a285da77 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -27,6 +27,9 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std:: spdlog::warn("Wrong actions section configuration. See config by index: {}", it.index()); } + event_box_.signal_enter_notify_event().connect(sigc::mem_fun(*this, &AModule::handleMouseEnter)); + event_box_.signal_leave_notify_event().connect(sigc::mem_fun(*this, &AModule::handleMouseLeave)); + // configure events' user commands // hasUserEvent is true if any element from eventMap_ is satisfying the condition in the lambda bool hasUserEvent = @@ -83,6 +86,20 @@ auto AModule::doAction(const std::string& name) -> void { } } +bool AModule::handleMouseEnter(GdkEventCrossing* const& e) { + if (auto* module = event_box_.get_child(); module != nullptr) { + module->set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT); + } + return true; +} + +bool AModule::handleMouseLeave(GdkEventCrossing* const& e) { + if (auto* module = event_box_.get_child(); module != nullptr) { + module->unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT); + } + return true; +} + bool AModule::handleToggle(GdkEventButton* const& e) { return handleUserEvent(e); } bool AModule::handleRelease(GdkEventButton* const& e) { return handleUserEvent(e); }