From 0b3edfa1aa64cdc0e7f59bcd5d5237314e7039d3 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 13 Sep 2026 21:07:41 +0300 Subject: [PATCH] Fix scrubbing --- src/PanelWindow.vala | 2 +- src/Services/PopoverManager.vala | 43 +++++++++++++++++--------------- src/Widgets/IndicatorEntry.vala | 2 +- src/Widgets/Panel.vala | 9 ++++++- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/PanelWindow.vala b/src/PanelWindow.vala index 88c23192..920e7eca 100644 --- a/src/PanelWindow.vala +++ b/src/PanelWindow.vala @@ -36,7 +36,7 @@ public class Wingpanel.PanelWindow : Gtk.Window { private Gtk.CssProvider? style_provider = null; construct { - popover_manager = new Services.PopoverManager (); + popover_manager = new Services.PopoverManager (this); panel = new Widgets.Panel (popover_manager); panel.realize.connect (on_realize); diff --git a/src/Services/PopoverManager.vala b/src/Services/PopoverManager.vala index 78bfe843..7a003a6d 100644 --- a/src/Services/PopoverManager.vala +++ b/src/Services/PopoverManager.vala @@ -34,50 +34,53 @@ 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; _current_indicator.base_indicator.closed (); + _current_indicator = value; - popover.unparent (); } 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 (); + + popover.child = _current_indicator.indicator_widget; + + Graphene.Point point; + _current_indicator.display_widget.compute_point (_current_indicator.root, { 0.0f, 0.0f }, out point); + popover.pointing_to = { + (int) point.x + _current_indicator.display_widget.get_width () / 2, + (int) point.y + _current_indicator.display_widget.get_height () + }; + popover.popup (); } } } - construct { + public PopoverManager (Gtk.Widget root) { popover = new Gtk.Popover () { has_arrow = false, position = BOTTOM }; + popover.set_parent (root); popover.add_css_class ("indicator"); - popover.closed.connect (() => { - _current_indicator.set_state_flags (NORMAL, true); - current_indicator = null; - popover.unparent (); - }); + popover.closed.connect (() => current_indicator = null); } } 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 + ); } }