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/issue 3256: Toggle drawer state #3422

Merged
merged 1 commit into from
Jul 16, 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
4 changes: 4 additions & 0 deletions include/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ class Group : public AModule {
Gtk::Revealer revealer;
bool is_first_widget = true;
bool is_drawer = false;
bool click_to_reveal = false;
std::string add_class_to_drawer_children;
bool handleMouseEnter(GdkEventCrossing *const &ev) override;
bool handleMouseLeave(GdkEventCrossing *const &ev) override;
bool handleToggle(GdkEventButton *const &ev) override;
void show_group();
void hide_group();
};

} // namespace waybar
5 changes: 5 additions & 0 deletions man/waybar.5.scd.in
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ A group may hide all but one element, showing them only on mouse hover. In order
default: "hidden" ++
Defines the CSS class to be applied to the hidden elements.

*click-to-reveal*: ++
typeof: bool ++
default: false ++
Whether left click should reveal the content rather than mouse over. Note that grouped modules may still process their own on-click events.

*transition-left-to-right*: ++
typeof: bool ++
default: true ++
Expand Down
31 changes: 28 additions & 3 deletions src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
const bool left_to_right = (drawer_config["transition-left-to-right"].isBool()
? drawer_config["transition-left-to-right"].asBool()
: true);
click_to_reveal = drawer_config["click-to-reveal"].asBool();

auto transition_type = getPreferredTransitionType(vertical);

Expand All @@ -83,18 +84,42 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
event_box_.add(box);
}

bool Group::handleMouseEnter(GdkEventCrossing* const& e) {
void Group::show_group() {
box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
revealer.set_reveal_child(true);
return false;
}

bool Group::handleMouseLeave(GdkEventCrossing* const& e) {
void Group::hide_group() {
box.unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
revealer.set_reveal_child(false);
}

bool Group::handleMouseEnter(GdkEventCrossing* const& e) {
if (!click_to_reveal) {
show_group();
}
return false;
}

bool Group::handleMouseLeave(GdkEventCrossing* const& e) {
if (!click_to_reveal) {
hide_group();
}
return false;
}

bool Group::handleToggle(GdkEventButton* const& e) {
if (!click_to_reveal || e->button != 1) {
return false;
}
if (box.get_state_flags() & Gtk::StateFlags::STATE_FLAG_PRELIGHT) {
hide_group();
} else {
show_group();
}
return true;
}

auto Group::update() -> void {
// noop
}
Expand Down
Loading