Skip to content

Commit

Permalink
GTK4 prep: Replace MenuBar/Item
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jul 10, 2024
1 parent 544081a commit 65ef6ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 44 deletions.
22 changes: 12 additions & 10 deletions src/Widgets/IndicatorMenuBar.vala → src/Widgets/IndicatorBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndicatorEntry> sorted_items;
private Services.IndicatorSorter sorter = new Services.IndicatorSorter ();

construct {
sorted_items = new Gee.ArrayList<IndicatorEntry> ();

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);
Expand All @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/Widgets/IndicatorEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 16 additions & 28 deletions src/Widgets/Panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down

0 comments on commit 65ef6ef

Please sign in to comment.