From 7b87a3c16e83b6e0ea33b915533e968a3a0dfa53 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 19 Sep 2026 11:28:13 +0300 Subject: [PATCH] Simplify PopoverManager.current_indicator --- src/Services/PopoverManager.vala | 17 ++++++----------- src/Widgets/IndicatorEntry.vala | 2 +- src/Widgets/Panel.vala | 9 ++++++++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Services/PopoverManager.vala b/src/Services/PopoverManager.vala index 78bfe843..ea74b347 100644 --- a/src/Services/PopoverManager.vala +++ b/src/Services/PopoverManager.vala @@ -34,17 +34,15 @@ public class Wingpanel.Services.PopoverManager : Object { } if (_current_indicator == null && value != null) { // First open - indicator_open = true; _current_indicator = value; + indicator_open = true; } else if (value == null && _current_indicator != null) { // Close requested - indicator_open = false; - _current_indicator.base_indicator.closed (); - _current_indicator.set_state_flags (NORMAL, true); - _current_indicator = null; - } else if (_current_indicator.base_indicator.code_name == value.base_indicator.code_name) { // Close due to toggle _current_indicator.set_state_flags (NORMAL, true); + _current_indicator.display_widget.has_tooltip = true; _current_indicator.base_indicator.closed (); _current_indicator = null; + popover.popdown (); + indicator_open = false; } else { // Switch _current_indicator.set_state_flags (NORMAL, true); _current_indicator.display_widget.has_tooltip = true; @@ -55,14 +53,12 @@ public class Wingpanel.Services.PopoverManager : Object { if (_current_indicator != null) { popover.child = _current_indicator.indicator_widget; - _current_indicator.display_widget.has_tooltip = false; popover.set_parent (_current_indicator); popover.popup (); + _current_indicator.set_state_flags (CHECKED, true); + _current_indicator.display_widget.has_tooltip = false; _current_indicator.base_indicator.opened (); - } else { - ((Widgets.IndicatorEntry)popover.parent).display_widget.has_tooltip = true; - popover.popdown (); } } } @@ -75,7 +71,6 @@ public class Wingpanel.Services.PopoverManager : Object { popover.add_css_class ("indicator"); popover.closed.connect (() => { - _current_indicator.set_state_flags (NORMAL, true); current_indicator = null; popover.unparent (); }); diff --git a/src/Widgets/IndicatorEntry.vala b/src/Widgets/IndicatorEntry.vala index e25c71ff..60e39de4 100644 --- a/src/Widgets/IndicatorEntry.vala +++ b/src/Widgets/IndicatorEntry.vala @@ -96,7 +96,7 @@ public class Wingpanel.Widgets.IndicatorEntry : Granite.Bin { add_controller (gesture_controller); gesture_controller.pressed.connect ((_gesture_controller, n_press, x, y) => { - popover_manager.current_indicator = this; + popover_manager.current_indicator = popover_manager.current_indicator == this ? null : this; _gesture_controller.set_state (CLAIMED); }); diff --git a/src/Widgets/Panel.vala b/src/Widgets/Panel.vala index 6999e9c3..6092f37d 100644 --- a/src/Widgets/Panel.vala +++ b/src/Widgets/Panel.vala @@ -237,12 +237,19 @@ public class Wingpanel.Widgets.Panel : Granite.Bin { } public void toggle_indicator (string name) { + IndicatorEntry? indicator_entry_to_toggle = null; for (var i = 0; i < visible_indicator_entries.get_n_items (); i++) { var indicator_entry = (IndicatorEntry) visible_indicator_entries.get_item (i); if (indicator_entry.base_indicator.code_name == name) { - popover_manager.current_indicator = indicator_entry; + indicator_entry_to_toggle = indicator_entry; break; } } + + popover_manager.current_indicator = ( + popover_manager.current_indicator == indicator_entry_to_toggle ? + null : + indicator_entry_to_toggle + ); } }