From 1e530dc3486f9d69d8a39d00c8cb61e85f714528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 15 Apr 2022 17:19:34 -0700 Subject: [PATCH 1/2] Remove IndicatorMenuBar --- po/POTFILES | 1 - src/Widgets/IndicatorEntry.vala | 24 +-------- src/Widgets/IndicatorMenuBar.vala | 82 ------------------------------- src/Widgets/Panel.vala | 51 +++++++++++++++++-- src/meson.build | 1 - 5 files changed, 49 insertions(+), 110 deletions(-) delete mode 100644 src/Widgets/IndicatorMenuBar.vala diff --git a/po/POTFILES b/po/POTFILES index 999af397..0099366e 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -10,6 +10,5 @@ src/Services/BackgroundManager.vala src/Services/IndicatorSorter.vala src/Services/PopoverManager.vala src/Widgets/IndicatorEntry.vala -src/Widgets/IndicatorMenuBar.vala src/Widgets/IndicatorPopover.vala src/Widgets/Panel.vala diff --git a/src/Widgets/IndicatorEntry.vala b/src/Widgets/IndicatorEntry.vala index 0ef8ea96..457d5382 100644 --- a/src/Widgets/IndicatorEntry.vala +++ b/src/Widgets/IndicatorEntry.vala @@ -21,7 +21,6 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { public Indicator base_indicator { get; construct; } public Services.PopoverManager popover_manager { get; construct; } - public IndicatorMenuBar? menu_bar; public Gtk.Widget display_widget { get; private set; } private Gtk.Widget _indicator_widget = null; @@ -72,23 +71,7 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { }); base_indicator.notify["visible"].connect (() => { - if (menu_bar != null) { - /* order will be changed so close all open popovers */ - popover_manager.close (); - - if (base_indicator.visible) { - popover_manager.register_indicator (this); - menu_bar.apply_new_order (); - set_reveal (base_indicator.visible); - } else { - set_reveal (base_indicator.visible); - popover_manager.unregister_indicator (this); - // reorder indicators when indicator is invisible - display_widget.unmap.connect (indicator_unmapped); - } - } else { - set_reveal (base_indicator.visible); - } + set_reveal (base_indicator.visible); }); add_events (Gdk.EventMask.SCROLL_MASK); @@ -124,11 +107,6 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { set_reveal (base_indicator.visible); } - private void indicator_unmapped () { - base_indicator.get_display_widget ().unmap.disconnect (indicator_unmapped); - menu_bar.apply_new_order (); - } - public void set_transition_type (Gtk.RevealerTransitionType transition_type) { revealer.set_transition_type (transition_type); } diff --git a/src/Widgets/IndicatorMenuBar.vala b/src/Widgets/IndicatorMenuBar.vala deleted file mode 100644 index 266ef369..00000000 --- a/src/Widgets/IndicatorMenuBar.vala +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2011-2015 Wingpanel Developers (http://launchpad.net/wingpanel) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - */ - -public class Wingpanel.Widgets.IndicatorMenuBar : Gtk.MenuBar { - private Gee.List sorted_items; - private Services.IndicatorSorter sorter = new Services.IndicatorSorter (); - private uint apply_new_order_idle_id = 0; - - public IndicatorMenuBar () { - sorted_items = new Gee.ArrayList (); - } - - public void insert_sorted (IndicatorEntry item) { - foreach (var indicator in sorted_items) { - if (item.base_indicator.code_name == indicator.base_indicator.code_name) { - return; /* item already added */ - } - } - - item.menu_bar = this; - - sorted_items.add (item); - sorted_items.sort (sorter.compare_func); - - apply_new_order (); - } - - public override void remove (Gtk.Widget widget) { - var indicator_widget = widget as IndicatorEntry; - - if (indicator_widget != null) { - sorted_items.remove (indicator_widget); - } - - base.remove (widget); - } - - public void apply_new_order () { - if (apply_new_order_idle_id > 0) { - GLib.Source.remove (apply_new_order_idle_id); - apply_new_order_idle_id = 0; - } - apply_new_order_idle_id = GLib.Idle.add_full (GLib.Priority.LOW, () => { - clear (); - append_all_items (); - apply_new_order_idle_id = 0; - return false; - }); - } - - private void clear () { - var children = this.get_children (); - - foreach (var child in children) { - base.remove (child); - } - } - - private void append_all_items () { - foreach (var widget in sorted_items) { - if (widget.base_indicator.visible) { - this.append (widget); - } - } - } -} diff --git a/src/Widgets/Panel.vala b/src/Widgets/Panel.vala index 96dd1197..53b6eaa7 100644 --- a/src/Widgets/Panel.vala +++ b/src/Widgets/Panel.vala @@ -20,10 +20,14 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { public Services.PopoverManager popover_manager { get; construct; } - private IndicatorMenuBar right_menubar; + private Gtk.MenuBar right_menubar; private Gtk.MenuBar left_menubar; private Gtk.MenuBar center_menubar; + private Gee.List sorted_items; + private Services.IndicatorSorter sorter = new Services.IndicatorSorter (); + private uint apply_new_order_idle_id = 0; + private unowned Gtk.StyleContext style_context; private Gtk.CssProvider? style_provider = null; @@ -44,6 +48,8 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { vexpand = true; valign = Gtk.Align.START; + sorted_items = new Gee.ArrayList (); + left_menubar = new Gtk.MenuBar () { can_focus = true, halign = Gtk.Align.START @@ -55,7 +61,7 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { }; center_menubar.get_style_context ().add_provider (resource_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - right_menubar = new IndicatorMenuBar () { + right_menubar = new Gtk.MenuBar () { can_focus = true, halign = Gtk.Align.END }; @@ -83,6 +89,14 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { style_context.add_provider (resource_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); Services.BackgroundManager.get_default ().background_state_changed.connect (update_background); + + right_menubar.remove.connect ((widget) => { + var indicator_widget = widget as IndicatorEntry; + + if (indicator_widget != null) { + sorted_items.remove (indicator_widget); + } + }); } public override bool button_press_event (Gdk.EventButton event) { @@ -257,13 +271,44 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { break; default: indicator_entry.set_transition_type (Gtk.RevealerTransitionType.SLIDE_LEFT); - right_menubar.insert_sorted (indicator_entry); + insert_sorted (indicator_entry); break; } indicator_entry.show_all (); } + private void insert_sorted (IndicatorEntry item) { + foreach (var indicator in sorted_items) { + if (item.base_indicator.code_name == indicator.base_indicator.code_name) { + return; /* item already added */ + } + } + + sorted_items.add (item); + sorted_items.sort (sorter.compare_func); + + if (apply_new_order_idle_id > 0) { + GLib.Source.remove (apply_new_order_idle_id); + apply_new_order_idle_id = 0; + } + + apply_new_order_idle_id = GLib.Idle.add_full (GLib.Priority.LOW, () => { + foreach (unowned var child in right_menubar.get_children ()) { + right_menubar.remove (child); + } + + foreach (var widget in sorted_items) { + if (widget.base_indicator.visible) { + right_menubar.append (widget); + } + } + + apply_new_order_idle_id = 0; + return false; + }); + } + private void remove_indicator (Indicator indicator) { remove_indicator_from_container (left_menubar, indicator); remove_indicator_from_container (center_menubar, indicator); diff --git a/src/meson.build b/src/meson.build index 7a743804..246c153e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,7 +7,6 @@ wingpanel_files = files( 'Services/IndicatorSorter.vala', 'Services/PopoverManager.vala', 'Widgets/IndicatorEntry.vala', - 'Widgets/IndicatorMenuBar.vala', 'Widgets/IndicatorPopover.vala', 'Widgets/Panel.vala', 'Widgets/StyleClass.vala', From e1e937752ccfdc2d6225180390846cc5fb16e7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 15 Apr 2022 17:36:10 -0700 Subject: [PATCH 2/2] fix sort order stuff --- src/Widgets/IndicatorEntry.vala | 22 +++++++++++++++++++++- src/Widgets/Panel.vala | 7 +++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Widgets/IndicatorEntry.vala b/src/Widgets/IndicatorEntry.vala index 457d5382..d15cbb46 100644 --- a/src/Widgets/IndicatorEntry.vala +++ b/src/Widgets/IndicatorEntry.vala @@ -21,6 +21,7 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { public Indicator base_indicator { get; construct; } public Services.PopoverManager popover_manager { get; construct; } + public Gtk.MenuBar? menu_bar; public Gtk.Widget display_widget { get; private set; } private Gtk.Widget _indicator_widget = null; @@ -71,7 +72,22 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { }); base_indicator.notify["visible"].connect (() => { - set_reveal (base_indicator.visible); + if (menu_bar != null) { + /* order will be changed so close all open popovers */ + popover_manager.close (); + + if (base_indicator.visible) { + popover_manager.register_indicator (this); + set_reveal (base_indicator.visible); + } else { + set_reveal (base_indicator.visible); + popover_manager.unregister_indicator (this); + // reorder indicators when indicator is invisible + display_widget.unmap.connect (indicator_unmapped); + } + } else { + set_reveal (base_indicator.visible); + } }); add_events (Gdk.EventMask.SCROLL_MASK); @@ -107,6 +123,10 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { set_reveal (base_indicator.visible); } + private void indicator_unmapped () { + base_indicator.get_display_widget ().unmap.disconnect (indicator_unmapped); + } + public void set_transition_type (Gtk.RevealerTransitionType transition_type) { revealer.set_transition_type (transition_type); } diff --git a/src/Widgets/Panel.vala b/src/Widgets/Panel.vala index 53b6eaa7..561b9e3c 100644 --- a/src/Widgets/Panel.vala +++ b/src/Widgets/Panel.vala @@ -285,9 +285,15 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { } } + item.menu_bar = right_menubar; + sorted_items.add (item); sorted_items.sort (sorter.compare_func); + apply_new_order (); + } + + private void apply_new_order () { if (apply_new_order_idle_id > 0) { GLib.Source.remove (apply_new_order_idle_id); apply_new_order_idle_id = 0; @@ -313,6 +319,7 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { remove_indicator_from_container (left_menubar, indicator); remove_indicator_from_container (center_menubar, indicator); remove_indicator_from_container (right_menubar, indicator); + apply_new_order (); } private void remove_indicator_from_container (Gtk.Container container, Indicator indicator) {