Readded signal_timeout instead of map to fix indicator being stuck

This commit is contained in:
Erik Reider 2023-10-30 18:01:47 +01:00
parent d32da917e4
commit c4226f3745
2 changed files with 21 additions and 27 deletions

View File

@ -32,6 +32,8 @@ class PrivacyItem : public Gtk::Revealer {
enum PrivacyNodeType privacy_type;
std::list<PrivacyNodeInfo *> *nodes;
sigc::connection signal_conn;
Gtk::Box tooltip_window;
bool init = false;
@ -47,8 +49,6 @@ class PrivacyItem : public Gtk::Revealer {
Gtk::Box box_;
Gtk::Image icon_;
void on_child_revealed_changed();
void on_map_changed();
void update_tooltip();
};

View File

@ -6,7 +6,6 @@
#include <cstdio>
#include <cstring>
#include <mutex>
#include <string>
#include <thread>
@ -28,6 +27,7 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac
: Gtk::Revealer(),
privacy_type(privacy_type_),
nodes(nodes_),
signal_conn(),
tooltip_window(Gtk::ORIENTATION_VERTICAL, 0),
box_(Gtk::ORIENTATION_HORIZONTAL, 0),
icon_() {
@ -94,10 +94,6 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac
*this));
}
property_child_revealed().signal_changed().connect(
sigc::mem_fun(*this, &PrivacyItem::on_child_revealed_changed));
signal_map().connect(sigc::mem_fun(*this, &PrivacyItem::on_map_changed));
// Don't show by default
set_reveal_child(true);
set_visible(false);
@ -130,18 +126,6 @@ void PrivacyItem::update_tooltip() {
bool PrivacyItem::is_enabled() { return enabled; }
void PrivacyItem::on_child_revealed_changed() {
if (!this->get_child_revealed()) {
set_visible(false);
}
}
void PrivacyItem::on_map_changed() {
if (this->get_visible()) {
set_reveal_child(true);
}
}
void PrivacyItem::set_in_use(bool in_use) {
if (in_use) {
update_tooltip();
@ -150,20 +134,30 @@ void PrivacyItem::set_in_use(bool in_use) {
if (this->in_use == in_use && init) return;
if (init) {
// Disconnect any previous connection so that it doesn't get activated in
// the future, hiding the module when it should be visible
signal_conn.disconnect();
this->in_use = in_use;
guint duration = 0;
if (this->in_use) {
set_visible(true);
// The `on_map_changed` callback will call `set_reveal_child(true)`
// when the widget is realized so we don't need to call that here.
// This fixes a bug where the revealer wouldn't start the animation
// due to us changing the visibility at the same time.
} else {
set_reveal_child(false);
// The `on_child_revealed_changed` callback will call `set_visible(false)`
// when the animation has finished so we don't need to call that here.
// We do this so that the widget gets hidden after the revealer hide animation
// has finished.
duration = get_transition_duration();
}
signal_conn = Glib::signal_timeout().connect(sigc::track_obj(
[this] {
if (this->in_use) {
set_reveal_child(true);
} else {
set_visible(false);
}
return false;
},
*this),
duration);
} else {
set_visible(false);
set_reveal_child(false);