From 64f084a2d8abc679f6e968251984134f1657d8b9 Mon Sep 17 00:00:00 2001 From: marc24force Date: Sat, 12 Oct 2024 11:20:05 +0200 Subject: [PATCH 1/2] Add signal to hide/show group --- include/group.hpp | 1 + src/group.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/group.hpp b/include/group.hpp index 5ce331a8d..33c5b4f97 100644 --- a/include/group.hpp +++ b/include/group.hpp @@ -30,6 +30,7 @@ class Group : public AModule { bool handleMouseEnter(GdkEventCrossing *const &ev) override; bool handleMouseLeave(GdkEventCrossing *const &ev) override; bool handleToggle(GdkEventButton *const &ev) override; + void refresh(int sig) override; void show_group(); void hide_group(); }; diff --git a/src/group.cpp b/src/group.cpp index 50841efd6..4a509cec2 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -120,6 +120,18 @@ bool Group::handleToggle(GdkEventButton* const& e) { return true; } +void Group::refresh(int sig) { + if (click_to_reveal) { + if (sig == SIGRTMIN + config_["signal"].asInt()) { + if ((box.get_state_flags() & Gtk::StateFlags::STATE_FLAG_PRELIGHT) != 0U) { + hide_group(); + } else { + show_group(); + } + } + } +} + auto Group::update() -> void { // noop } From 6d69aa39b3eff0b63a8495a8b60825accd194ee3 Mon Sep 17 00:00:00 2001 From: marc24force Date: Sun, 3 Nov 2024 22:31:55 +0100 Subject: [PATCH 2/2] Signal to open non-click group and close after delay --- include/group.hpp | 7 +++++++ src/group.cpp | 28 ++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/group.hpp b/include/group.hpp index 33c5b4f97..12b0a1d13 100644 --- a/include/group.hpp +++ b/include/group.hpp @@ -7,6 +7,8 @@ #include "AModule.hpp" #include "gtkmm/revealer.h" +#include "util/sleeper_thread.hpp" + namespace waybar { class Group : public AModule { @@ -33,6 +35,11 @@ class Group : public AModule { void refresh(int sig) override; void show_group(); void hide_group(); + util::SleeperThread thread_; + bool reset_ = false; + bool free_ = true; + std::chrono::seconds interval_; + }; } // namespace waybar diff --git a/src/group.cpp b/src/group.cpp index 4a509cec2..6533e211a 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -79,6 +79,20 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value& } else { box.pack_start(revealer); } + + if(!click_to_reveal) { + interval_ = (config_["interval"] == "once" || !config_["interval"].isUInt()) + ? std::chrono::seconds::max() + : std::chrono::seconds(config_["interval"].asUInt()); + thread_ = [this] { + if(free_ && reset_) { + show_group(); + reset_=false; + } + thread_.sleep_for(interval_); + if(free_ && !reset_) hide_group(); + }; + } } event_box_.add(box); @@ -96,6 +110,7 @@ void Group::hide_group() { bool Group::handleMouseEnter(GdkEventCrossing* const& e) { if (!click_to_reveal) { + free_ = false; show_group(); } return false; @@ -103,6 +118,7 @@ bool Group::handleMouseEnter(GdkEventCrossing* const& e) { bool Group::handleMouseLeave(GdkEventCrossing* const& e) { if (!click_to_reveal && e->detail != GDK_NOTIFY_INFERIOR) { + free_ = true; hide_group(); } return false; @@ -121,12 +137,12 @@ bool Group::handleToggle(GdkEventButton* const& e) { } void Group::refresh(int sig) { - if (click_to_reveal) { - if (sig == SIGRTMIN + config_["signal"].asInt()) { - if ((box.get_state_flags() & Gtk::StateFlags::STATE_FLAG_PRELIGHT) != 0U) { - hide_group(); - } else { - show_group(); + if (sig == SIGRTMIN + config_["signal"].asInt()) { + GdkEventButton ev = { .button = 1 }; //Generate fake button click + if (!handleToggle(&ev)) { //It's not click to reveal + if (free_) { //And the group is not governed by mouse + reset_=true; + thread_.wake_up(); } } }