Merge pull request #3422 from RobertMueller2/issue_feat_3256
feat/issue 3256: Toggle drawer state
This commit is contained in:
commit
2d9cc623c2
|
@ -25,9 +25,13 @@ class Group : public AModule {
|
||||||
Gtk::Revealer revealer;
|
Gtk::Revealer revealer;
|
||||||
bool is_first_widget = true;
|
bool is_first_widget = true;
|
||||||
bool is_drawer = false;
|
bool is_drawer = false;
|
||||||
|
bool click_to_reveal = false;
|
||||||
std::string add_class_to_drawer_children;
|
std::string add_class_to_drawer_children;
|
||||||
bool handleMouseEnter(GdkEventCrossing *const &ev) override;
|
bool handleMouseEnter(GdkEventCrossing *const &ev) override;
|
||||||
bool handleMouseLeave(GdkEventCrossing *const &ev) override;
|
bool handleMouseLeave(GdkEventCrossing *const &ev) override;
|
||||||
|
bool handleToggle(GdkEventButton *const &ev) override;
|
||||||
|
void show_group();
|
||||||
|
void hide_group();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
|
|
@ -278,6 +278,11 @@ A group may hide all but one element, showing them only on mouse hover. In order
|
||||||
default: "hidden" ++
|
default: "hidden" ++
|
||||||
Defines the CSS class to be applied to the hidden elements.
|
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*: ++
|
*transition-left-to-right*: ++
|
||||||
typeof: bool ++
|
typeof: bool ++
|
||||||
default: true ++
|
default: true ++
|
||||||
|
|
|
@ -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()
|
const bool left_to_right = (drawer_config["transition-left-to-right"].isBool()
|
||||||
? drawer_config["transition-left-to-right"].asBool()
|
? drawer_config["transition-left-to-right"].asBool()
|
||||||
: true);
|
: true);
|
||||||
|
click_to_reveal = drawer_config["click-to-reveal"].asBool();
|
||||||
|
|
||||||
auto transition_type = getPreferredTransitionType(vertical);
|
auto transition_type = getPreferredTransitionType(vertical);
|
||||||
|
|
||||||
|
@ -83,18 +84,42 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
|
||||||
event_box_.add(box);
|
event_box_.add(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Group::handleMouseEnter(GdkEventCrossing* const& e) {
|
void Group::show_group() {
|
||||||
box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
box.set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
||||||
revealer.set_reveal_child(true);
|
revealer.set_reveal_child(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Group::handleMouseLeave(GdkEventCrossing* const& e) {
|
bool Group::handleMouseLeave(GdkEventCrossing* const& e) {
|
||||||
box.unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT);
|
if (!click_to_reveal) {
|
||||||
revealer.set_reveal_child(false);
|
hide_group();
|
||||||
|
}
|
||||||
return false;
|
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 {
|
auto Group::update() -> void {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue