From 1965f50c17276d6e1bc463b0b62d44d56ad96a42 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 29 Aug 2026 23:22:59 +0300 Subject: [PATCH] Rework size request and layouting --- data/styles/Application.css | 2 - src/DBus/ShellKeyGrabber.vala | 2 +- src/PanelWindow.vala | 101 ++++++++++++++++++++++++---------- src/Widgets/Panel.vala | 2 - 4 files changed, 72 insertions(+), 35 deletions(-) diff --git a/data/styles/Application.css b/data/styles/Application.css index ff0e50f2..b0e407f2 100644 --- a/data/styles/Application.css +++ b/data/styles/Application.css @@ -4,8 +4,6 @@ panel { } panel > box { - /* Keep in sync with Panel.vala height request */ - min-height: 30px; /*Don't transition shadow etc to avoid visual issues with struts*/ transition: background 200ms cubic-bezier(0.4, 0, 0.2, 1); } diff --git a/src/DBus/ShellKeyGrabber.vala b/src/DBus/ShellKeyGrabber.vala index 25cd297a..96af7011 100644 --- a/src/DBus/ShellKeyGrabber.vala +++ b/src/DBus/ShellKeyGrabber.vala @@ -47,7 +47,7 @@ public struct Accelerator { [DBus (name = "org.gnome.Shell")] public interface Wingpanel.ShellKeyGrabber : GLib.Object { - public abstract signal void accelerator_activated (uint action, GLib.HashTable parameters_dict); + public signal void accelerator_activated (uint action, GLib.HashTable parameters_dict); public abstract uint grab_accelerator (string accelerator, ActionMode mode_flags, Meta.KeyBindingFlags grab_flags) throws GLib.DBusError, GLib.IOError; public abstract uint[] grab_accelerators (Accelerator[] accelerators) throws GLib.DBusError, GLib.IOError; diff --git a/src/PanelWindow.vala b/src/PanelWindow.vala index eab20a65..57ac1c41 100644 --- a/src/PanelWindow.vala +++ b/src/PanelWindow.vala @@ -18,13 +18,21 @@ */ public class Wingpanel.PanelWindow : Gtk.Window { + private class BottomMargin : Gtk.Widget { + public const int SIZE = 64; + + construct { + height_request = SIZE; + } + } + public Services.PopoverManager popover_manager; private Widgets.Panel panel; - private int panel_height; private Pantheon.Desktop.Shell? desktop_shell; private Pantheon.Desktop.Panel? desktop_panel; + private bool initialized_background_manager = false; private Gtk.CssProvider? style_provider = null; @@ -32,8 +40,7 @@ public class Wingpanel.PanelWindow : Gtk.Window { Object ( application: application, decorated: false, - resizable: false, - vexpand: false + resizable: false ); popover_manager = new Services.PopoverManager (); @@ -41,6 +48,13 @@ public class Wingpanel.PanelWindow : Gtk.Window { panel = new Widgets.Panel (popover_manager); panel.realize.connect (on_realize); + var box = new Gtk.Box (VERTICAL, 0); + box.append (panel); + box.append (new BottomMargin ()); + + child = box; + remove_css_class (Granite.STYLE_CLASS_BACKGROUND); + var cycle_action = new SimpleAction ("cycle", null); cycle_action.activate.connect (() => panel.cycle (true)); @@ -52,9 +66,6 @@ public class Wingpanel.PanelWindow : Gtk.Window { application.set_accels_for_action ("app.cycle", {"Tab"}); application.set_accels_for_action ("app.cycle-back", {"Tab"}); - child = panel; - remove_css_class (Granite.STYLE_CLASS_BACKGROUND); - popover_manager.notify["indicator-open"].connect (() => { if (!popover_manager.indicator_open) { Services.BackgroundManager.get_default ().restore_window (); @@ -63,8 +74,6 @@ public class Wingpanel.PanelWindow : Gtk.Window { Services.BackgroundManager.get_default ().remember_window (); } }); - - notify["scale-factor"].connect (update_panel_dimensions); } construct { @@ -72,34 +81,38 @@ public class Wingpanel.PanelWindow : Gtk.Window { } private void on_realize () { - ((Gdk.Toplevel) get_surface ()).compute_size.connect (on_compute_size); + unowned var surface = (Gdk.Toplevel) get_surface (); + surface.compute_size.connect (on_compute_size); + surface.layout.connect (on_layout); - update_panel_dimensions (); - Services.BackgroundManager.initialize (panel_height); + surface.enter_monitor.connect (on_enter_monitor); init_wl (); } - private void on_compute_size (Gdk.ToplevelSize top_level_size) { - /* We do our own size calculation to make sure the box shadow in the translucent style isn't cut off */ - top_level_size.set_size (width_request, panel.get_height () + 5); - top_level_size.set_shadow_width (0, 0, 0, 5); + private static void on_compute_size (Gdk.ToplevelSize top_level_size) { + top_level_size.set_shadow_width (0, 0, 0, BottomMargin.SIZE); } - private void update_panel_dimensions () { - panel_height = panel.get_height (); - - // We just use our monitor because Gala makes sure we are always on the primary one - var monitor_dimensions = get_display ().get_monitor_at_surface (get_surface ()).get_geometry (); + private void on_layout (Gdk.Surface surface, int width, int height) { + surface.set_input_region ( + new Cairo.Region.rectangle ({ + 0, 0, width, height - BottomMargin.SIZE + }) + ); - if (!Services.DisplayConfig.is_logical_layout ()) { - monitor_dimensions.width /= get_scale_factor (); - monitor_dimensions.height /= get_scale_factor (); - monitor_dimensions.x /= get_scale_factor (); - monitor_dimensions.y /= get_scale_factor (); + if (!initialized_background_manager) { + Services.BackgroundManager.initialize (panel.get_height ()); + initialized_background_manager = true; } + } + + private void on_enter_monitor (Gdk.Monitor new_monitor) { + new_monitor.notify["geometry"].connect (queue_resize); + new_monitor.notify["scale"].connect (queue_resize); + new_monitor.notify["scale-factor"].connect (queue_resize); - this.set_size_request (monitor_dimensions.width, -1); + queue_resize (); } public void toggle_indicator (string name) { @@ -115,8 +128,6 @@ public class Wingpanel.PanelWindow : Gtk.Window { desktop_panel = desktop_shell.get_panel (wl_surface); desktop_panel.set_anchor (TOP); desktop_panel.set_hide_mode (NEVER); - - Idle.add_once (update_panel_dimensions); // Update again since we now can be 100% sure that we are on the primary monitor } } } @@ -179,7 +190,6 @@ public class Wingpanel.PanelWindow : Gtk.Window { break; } - if (desktop_panel == null) { return; } @@ -192,8 +202,39 @@ public class Wingpanel.PanelWindow : Gtk.Window { break; case Services.BackgroundState.TRANSLUCENT_DARK: case Services.BackgroundState.TRANSLUCENT_LIGHT: - desktop_panel.add_blur (0, 0, 0, 4, 0); + desktop_panel.add_blur (0, 0, 0, 0, 0); break; } } + + public override void measure ( + Gtk.Orientation orientation, + int for_size, + out int minimum, + out int natural, + out int minimum_baseline, + out int natural_baseline + ) { + if (orientation != HORIZONTAL) { + base.measure (orientation, for_size, out minimum, out natural, out minimum_baseline, out natural_baseline); + return; + } + + minimum_baseline = natural_baseline = -1; + + var monitor_width = int.MAX; + unowned var surface = get_surface (); + if (surface != null) { + unowned var monitor = get_display ().get_monitor_at_surface (surface); + if (monitor != null) { + monitor_width = monitor.geometry.width; + } + } + + if (!Services.DisplayConfig.is_logical_layout ()) { + monitor_width /= get_scale_factor (); + } + + minimum = natural = monitor_width; + } } diff --git a/src/Widgets/Panel.vala b/src/Widgets/Panel.vala index 7629d36f..999f3cdf 100644 --- a/src/Widgets/Panel.vala +++ b/src/Widgets/Panel.vala @@ -41,10 +41,8 @@ public class Wingpanel.Widgets.Panel : Granite.Bin { } construct { - height_request = 30; hexpand = true; vexpand = true; - valign = START; left_menubar = new IndicatorBar () { halign = START