Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#2989): (optional) hover for all modules #3145

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/AModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions man/waybar-styles.5.scd.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
5 changes: 5 additions & 0 deletions resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
haug1 marked this conversation as resolved.
Show resolved Hide resolved
}

#workspaces button {
padding: 0 5px;
background-color: transparent;
Expand Down
17 changes: 17 additions & 0 deletions src/AModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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); }
Expand Down
Loading