From 65ef6efb01bddb6f02347229fa175625a7daf94b Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Wed, 10 Jul 2024 21:22:11 +0200 Subject: [PATCH 1/2] GTK4 prep: Replace MenuBar/Item --- ...ndicatorMenuBar.vala => IndicatorBar.vala} | 22 +++++----- src/Widgets/IndicatorEntry.vala | 10 ++--- src/Widgets/Panel.vala | 44 +++++++------------ src/meson.build | 2 +- 4 files changed, 34 insertions(+), 44 deletions(-) rename src/Widgets/{IndicatorMenuBar.vala => IndicatorBar.vala} (78%) diff --git a/src/Widgets/IndicatorMenuBar.vala b/src/Widgets/IndicatorBar.vala similarity index 78% rename from src/Widgets/IndicatorMenuBar.vala rename to src/Widgets/IndicatorBar.vala index e0f73505..1e56c9e2 100644 --- a/src/Widgets/IndicatorMenuBar.vala +++ b/src/Widgets/IndicatorBar.vala @@ -17,16 +17,18 @@ * Boston, MA 02110-1301 USA. */ -public class Wingpanel.Widgets.IndicatorMenuBar : Gtk.MenuBar { +public class Wingpanel.Widgets.IndicatorBar : Gtk.Box { private Gee.List sorted_items; private Services.IndicatorSorter sorter = new Services.IndicatorSorter (); construct { sorted_items = new Gee.ArrayList (); + + spacing = 6; } public void insert_sorted (IndicatorEntry item) { - item.menu_bar = this; + item.indicator_bar = this; if (!(item in sorted_items)) { sorted_items.add (item); @@ -46,18 +48,18 @@ public class Wingpanel.Widgets.IndicatorMenuBar : Gtk.MenuBar { } if (item.get_parent () != this) { - this.insert (item, index); + add (item); + reorder_child (item, index); } } } - public override void remove (Gtk.Widget widget) { - var indicator_widget = widget as IndicatorEntry; - - if (indicator_widget != null) { - sorted_items.remove (indicator_widget); + public void remove_indicator (Indicator indicator) { + foreach (var entry in sorted_items) { + if (entry.base_indicator.code_name == indicator.code_name) { + sorted_items.remove (entry); + remove (entry); + } } - - base.remove (widget); } } diff --git a/src/Widgets/IndicatorEntry.vala b/src/Widgets/IndicatorEntry.vala index 9c020a4f..61efefbb 100644 --- a/src/Widgets/IndicatorEntry.vala +++ b/src/Widgets/IndicatorEntry.vala @@ -17,11 +17,11 @@ * Boston, MA 02110-1301 USA. */ -public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { +public class Wingpanel.Widgets.IndicatorEntry : Gtk.EventBox { public Indicator base_indicator { get; construct; } public Services.PopoverManager popover_manager { get; construct; } - public IndicatorMenuBar? menu_bar; + public IndicatorBar? indicator_bar; public Gtk.Widget display_widget { get; private set; } private Gtk.Widget _indicator_widget = null; @@ -69,13 +69,13 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { }); base_indicator.notify["visible"].connect (() => { - if (menu_bar != null) { + if (indicator_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.insert_sorted (this); + indicator_bar.insert_sorted (this); set_reveal (base_indicator.visible); } else { set_reveal (base_indicator.visible); @@ -124,7 +124,7 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem { private void indicator_unmapped () { base_indicator.get_display_widget ().unmap.disconnect (indicator_unmapped); - menu_bar.remove (this); + indicator_bar.remove (this); } public void set_transition_type (Gtk.RevealerTransitionType transition_type) { diff --git a/src/Widgets/Panel.vala b/src/Widgets/Panel.vala index 9c03adab..1f27e783 100644 --- a/src/Widgets/Panel.vala +++ b/src/Widgets/Panel.vala @@ -20,9 +20,9 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { public Services.PopoverManager popover_manager { get; construct; } - private IndicatorMenuBar right_menubar; - private Gtk.MenuBar left_menubar; - private Gtk.MenuBar center_menubar; + private IndicatorBar right_menubar; + private IndicatorBar left_menubar; + private IndicatorBar center_menubar; private unowned Gtk.StyleContext style_context; private Gtk.CssProvider? style_provider = null; @@ -39,20 +39,16 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { height_request = 30; hexpand = true; vexpand = true; - valign = Gtk.Align.START; + valign = START; - left_menubar = new Gtk.MenuBar () { - can_focus = true, - halign = Gtk.Align.START + left_menubar = new IndicatorBar () { + halign = START }; - center_menubar = new Gtk.MenuBar () { - can_focus = true - }; + center_menubar = new IndicatorBar (); - right_menubar = new IndicatorMenuBar () { - can_focus = true, - halign = Gtk.Align.END + right_menubar = new IndicatorBar () { + halign = END }; var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); @@ -78,6 +74,10 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { } public override bool button_press_event (Gdk.EventButton event) { + if (Utils.is_wayland ()) { + return Gdk.EVENT_PROPAGATE; + } + if (event.button != Gdk.BUTTON_PRIMARY) { return Gdk.EVENT_PROPAGATE; } @@ -257,21 +257,9 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox { } private void remove_indicator (Indicator indicator) { - remove_indicator_from_container (left_menubar, indicator); - remove_indicator_from_container (center_menubar, indicator); - remove_indicator_from_container (right_menubar, indicator); - } - - private void remove_indicator_from_container (Gtk.Container container, Indicator indicator) { - foreach (unowned Gtk.Widget child in container.get_children ()) { - unowned IndicatorEntry? entry = (child as IndicatorEntry); - - if (entry != null && entry.base_indicator == indicator) { - container.remove (child); - - return; - } - } + left_menubar.remove_indicator (indicator); + center_menubar.remove_indicator (indicator); + right_menubar.remove_indicator (indicator); } private void update_background (Services.BackgroundState state, uint animation_duration) { diff --git a/src/meson.build b/src/meson.build index d9ca1250..5454be03 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,7 +7,7 @@ wingpanel_files = files( 'Services/IndicatorSorter.vala', 'Services/PopoverManager.vala', 'Widgets/IndicatorEntry.vala', - 'Widgets/IndicatorMenuBar.vala', + 'Widgets/IndicatorBar.vala', 'Widgets/IndicatorPopover.vala', 'Widgets/Panel.vala' ) From ea15fc227615d5d2e43321f07b4eb64336fc8a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 12 Jul 2024 10:08:18 -0700 Subject: [PATCH 2/2] Fix styles --- data/styles/Application.css | 33 ++++++++++++--------------------- src/Widgets/IndicatorBar.vala | 2 -- src/Widgets/IndicatorEntry.vala | 2 +- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/data/styles/Application.css b/data/styles/Application.css index 6048d381..bfb3e4a0 100644 --- a/data/styles/Application.css +++ b/data/styles/Application.css @@ -36,27 +36,18 @@ panel.translucent.color-light > box { 0 1px 1px alpha(black, 0.1); } -panel menubar { - background: transparent; - box-shadow: none; - border: none; -} - .composited-indicator { - padding: 0 6px; -} - -.composited-indicator > revealer { color: white; font-weight: bold; + padding: 0 6px; text-shadow: 0 0 2px alpha(black, 0.3), 0 1px 2px alpha(black, 0.6); transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1); } -.composited-indicator > revealer image, -.composited-indicator > revealer spinner { +.composited-indicator image, +.composited-indicator spinner { -gtk-icon-shadow: 0 0 2px alpha(black, 0.3), 0 1px 2px alpha(black, 0.6); @@ -66,15 +57,15 @@ panel menubar { warning mix(@BANANA_300, @BANANA_500, 0.5); } -.color-light .composited-indicator > revealer { +.color-light .composited-indicator { color: alpha(black, 0.65); text-shadow: 0 0 2px alpha(white, 0.3), 0 1px 0 alpha(white, 0.25); } -.color-light .composited-indicator > revealer image, -.color-light .composited-indicator > revealer spinner { +.color-light .composited-indicator image, +.color-light .composited-indicator spinner { -gtk-icon-shadow: 0 0 2px alpha(white, 0.3), 0 1px 0 alpha(white, 0.25); @@ -84,24 +75,24 @@ panel menubar { warning mix(@BANANA_700, @BANANA_900, 0.5); } -.translucent.color-dark .composited-indicator > revealer { +.translucent.color-dark .composited-indicator { text-shadow: 0 0 2px alpha(black, 0.15), 0 1px 2px alpha(black, 0.3); } -.translucent.color-dark .composited-indicator > revealer image, -.translucent.color-dark .composited-indicator > revealer spinner { +.translucent.color-dark .composited-indicator image, +.translucent.color-dark .composited-indicator spinner { -gtk-icon-shadow: 0 0 2px alpha(black, 0.15), 0 1px 2px alpha(black, 0.3); } -.translucent.color-light .composited-indicator > revealer { +.translucent.color-light .composited-indicator { text-shadow: none; } -.translucent.color-light .composited-indicator > revealer image, -.translucent.color-light .composited-indicator > revealer spinner { +.translucent.color-light .composited-indicator image, +.translucent.color-light .composited-indicator spinner { -gtk-icon-shadow: none; } diff --git a/src/Widgets/IndicatorBar.vala b/src/Widgets/IndicatorBar.vala index 1e56c9e2..63f39955 100644 --- a/src/Widgets/IndicatorBar.vala +++ b/src/Widgets/IndicatorBar.vala @@ -23,8 +23,6 @@ public class Wingpanel.Widgets.IndicatorBar : Gtk.Box { construct { sorted_items = new Gee.ArrayList (); - - spacing = 6; } public void insert_sorted (IndicatorEntry item) { diff --git a/src/Widgets/IndicatorEntry.vala b/src/Widgets/IndicatorEntry.vala index 61efefbb..c79691e4 100644 --- a/src/Widgets/IndicatorEntry.vala +++ b/src/Widgets/IndicatorEntry.vala @@ -49,13 +49,13 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.EventBox { display_widget = base_indicator.get_display_widget (); halign = Gtk.Align.START; name = base_indicator.code_name + "/entry"; - get_style_context ().add_class ("composited-indicator"); if (display_widget == null) { return; } revealer = new Gtk.Revealer (); + revealer.get_style_context ().add_class ("composited-indicator"); revealer.add (display_widget); add (revealer);