Skip to content

Commit

Permalink
GTK4 prep: Move from MenuBar/Item to Box (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 authored Jul 12, 2024
1 parent 34d9f51 commit 8ef9f0e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 66 deletions.
33 changes: 12 additions & 21 deletions data/styles/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
20 changes: 10 additions & 10 deletions src/Widgets/IndicatorMenuBar.vala → src/Widgets/IndicatorBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* 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 ();

Expand All @@ -26,7 +26,7 @@ public class Wingpanel.Widgets.IndicatorMenuBar : Gtk.MenuBar {
}

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 +46,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);
}
}
12 changes: 6 additions & 6 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 @@ -49,13 +49,13 @@ public class Wingpanel.Widgets.IndicatorEntry : Gtk.MenuItem {
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);
Expand All @@ -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 8ef9f0e

Please sign in to comment.