From fad150ef0bf01c5e1ac0cb0c06ed520821e2dfd9 Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sun, 29 Sep 2024 19:53:11 +0200 Subject: [PATCH 1/8] Make monitor labels a protocol method --- daemon/MonitorLabel.vala | 49 ----------------------- protocol/pantheon-desktop-shell-v1.xml | 9 +++++ protocol/pantheon-desktop-shell.vapi | 3 ++ src/DaemonManager.vala | 12 ------ src/PantheonShell.vala | 16 ++++++++ src/ShellClients/ShellClientsManager.vala | 19 +++++++++ 6 files changed, 47 insertions(+), 61 deletions(-) delete mode 100644 daemon/MonitorLabel.vala diff --git a/daemon/MonitorLabel.vala b/daemon/MonitorLabel.vala deleted file mode 100644 index c3a19f4bb..000000000 --- a/daemon/MonitorLabel.vala +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2024 elementary, Inc. (https://elementary.io) - * SPDX-License-Identifier: LGPL-3.0-or-later - */ - - public class Gala.Daemon.MonitorLabel : Gtk.Window { - private const int SPACING = 12; - private const string COLORED_STYLE_CSS = """ - .%s { - background-color: alpha(%s, 0.8); - color: %s; - } - """; - - public MonitorLabelInfo info { get; construct; } - - public MonitorLabel (MonitorLabelInfo info) { - Object (info: info); - } - - construct { - child = new Gtk.Label (info.label); - - title = "LABEL-%i".printf (info.monitor); - - decorated = false; - resizable = false; - deletable = false; - can_focus = false; - titlebar = new Gtk.Grid (); - - var provider = new Gtk.CssProvider (); - try { - provider.load_from_string (COLORED_STYLE_CSS.printf (title, info.background_color, info.text_color)); - get_style_context ().add_class (title); - get_style_context ().add_class ("monitor-label"); - - Gtk.StyleContext.add_provider_for_display ( - Gdk.Display.get_default (), - provider, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION - ); - } catch (Error e) { - warning ("Failed to load CSS: %s", e.message); - } - - present (); - } -} diff --git a/protocol/pantheon-desktop-shell-v1.xml b/protocol/pantheon-desktop-shell-v1.xml index 63d9d5982..2c8f716ba 100644 --- a/protocol/pantheon-desktop-shell-v1.xml +++ b/protocol/pantheon-desktop-shell-v1.xml @@ -119,6 +119,15 @@ + + + Request to make the surface a monitor label for the given monitor. The surface will be placed + in the top left corner of the monitor and will be kept above other surfaces. + + + + + Request keyboard focus, taking it away from any other window. diff --git a/protocol/pantheon-desktop-shell.vapi b/protocol/pantheon-desktop-shell.vapi index 4c57de974..db2160182 100644 --- a/protocol/pantheon-desktop-shell.vapi +++ b/protocol/pantheon-desktop-shell.vapi @@ -57,6 +57,7 @@ namespace Pantheon.Desktop { public Destroy destroy; public SetKeepAbove set_keep_above; public MakeCentered make_centered; + public MakeMonitorLabel make_monitor_label; public Focus focus; } @@ -79,5 +80,7 @@ namespace Pantheon.Desktop { [CCode (has_target = false, has_typedef = false)] public delegate void MakeCentered (Wl.Client client, Wl.Resource resource); [CCode (has_target = false, has_typedef = false)] + public delegate void MakeMonitorLabel (Wl.Client client, Wl.Resource resource, int monitor_index); + [CCode (has_target = false, has_typedef = false)] public delegate void Destroy (Wl.Client client, Wl.Resource resource); } diff --git a/src/DaemonManager.vala b/src/DaemonManager.vala index 551f3f470..0ee8ccf80 100644 --- a/src/DaemonManager.vala +++ b/src/DaemonManager.vala @@ -89,18 +89,6 @@ public class Gala.DaemonManager : GLib.Object { } switch (info[0]) { - case "LABEL": - if (info.length < 2) { - return; - } - - var index = int.parse (info[1]); - - var monitor_geometry = display.get_monitor_geometry (index); - window.move_frame (false, monitor_geometry.x + SPACING, monitor_geometry.y + SPACING); - window.make_above (); - break; - case "MODAL": #if HAS_MUTTER46 daemon_client.make_dock (window); diff --git a/src/PantheonShell.vala b/src/PantheonShell.vala index 1e0f173ff..f8a301c3d 100644 --- a/src/PantheonShell.vala +++ b/src/PantheonShell.vala @@ -68,6 +68,7 @@ namespace Gala { destroy_extended_behavior_surface, set_keep_above, make_centered, + make_monitor_label, focus_extended_behavior, }; @@ -359,6 +360,21 @@ namespace Gala { ShellClientsManager.get_instance ().make_centered (window); } + internal static void make_monitor_label (Wl.Client client, Wl.Resource resource, int monitor_index) { + unowned ExtendedBehaviorSurface? eb_surface = resource.get_user_data (); + if (eb_surface.wayland_surface == null) { + return; + } + + Meta.Window? window; + eb_surface.wayland_surface.get ("window", out window, null); + if (window == null) { + return; + } + + ShellClientsManager.get_instance ().make_monitor_label (window, monitor_index); + } + internal static void destroy_panel_surface (Wl.Client client, Wl.Resource resource) { resource.destroy (); } diff --git a/src/ShellClients/ShellClientsManager.vala b/src/ShellClients/ShellClientsManager.vala index ad15ca9e8..79f38017c 100644 --- a/src/ShellClients/ShellClientsManager.vala +++ b/src/ShellClients/ShellClientsManager.vala @@ -193,6 +193,25 @@ public class Gala.ShellClientsManager : Object { window.unmanaging.connect_after (() => centered_windows.remove (window)); } + public void make_monitor_label (Meta.Window window, int monitor_index) { + unowned var display = wm.get_display (); + + if (monitor_index < 0 || monitor_index > display.get_n_monitors ()) { + warning ("Invalid moitor index provided: %d", monitor_index); + return; + } + + window.make_above (); + + var monitor_geometry = display.get_monitor_geometry (monitor_index); + + ulong handler_id = 0; + handler_id = window.shown.connect (() => { + window.move_frame (false, monitor_geometry.x + 12, monitor_geometry.y + 12); + window.disconnect (handler_id); + }); + } + public bool is_positioned_window (Meta.Window window) { bool positioned = (window in centered_windows) || (window in windows); window.foreach_ancestor ((ancestor) => { From 797ea04b0b061914d8487e2e52b22c58e12a49be Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sun, 29 Sep 2024 22:36:07 +0200 Subject: [PATCH 2/8] Remove more unnecessary stuff --- daemon-gtk3/DBus.vala | 28 ---------------- daemon-gtk3/MonitorLabel.vala | 62 ----------------------------------- daemon-gtk3/meson.build | 1 - daemon/DBus.vala | 28 ---------------- daemon/meson.build | 1 - data/gala-daemon.css | 10 ------ 6 files changed, 130 deletions(-) delete mode 100644 daemon-gtk3/MonitorLabel.vala diff --git a/daemon-gtk3/DBus.vala b/daemon-gtk3/DBus.vala index 41a2e0c31..0d502e2aa 100644 --- a/daemon-gtk3/DBus.vala +++ b/daemon-gtk3/DBus.vala @@ -8,15 +8,6 @@ public interface Gala.WMDBus : GLib.Object { public abstract void perform_action (Gala.ActionType type) throws DBusError, IOError; } -public struct Gala.Daemon.MonitorLabelInfo { - public int monitor; - public string label; - public string background_color; - public string text_color; - public int x; - public int y; -} - [DBus (name = "org.pantheon.gala.daemon")] public class Gala.Daemon.DBus : GLib.Object { private const string DBUS_NAME = "org.pantheon.gala"; @@ -30,8 +21,6 @@ public class Gala.Daemon.DBus : GLib.Object { private WindowMenu? window_menu; private BackgroundMenu? background_menu; - private List monitor_labels = new List (); - construct { Bus.watch_name (BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, gala_appeared, lost_gala); } @@ -113,21 +102,4 @@ public class Gala.Daemon.DBus : GLib.Object { }); } } - - public void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError { - hide_monitor_labels (); - - monitor_labels = new List (); - foreach (var info in label_infos) { - var label = new MonitorLabel (info); - monitor_labels.append (label); - label.present (); - } - } - - public void hide_monitor_labels () throws GLib.DBusError, GLib.IOError { - foreach (var monitor_label in monitor_labels) { - monitor_label.close (); - } - } } diff --git a/daemon-gtk3/MonitorLabel.vala b/daemon-gtk3/MonitorLabel.vala deleted file mode 100644 index 0ece57239..000000000 --- a/daemon-gtk3/MonitorLabel.vala +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2024 elementary, Inc. (https://elementary.io) - * SPDX-License-Identifier: LGPL-3.0-or-later - */ - - public class Gala.Daemon.MonitorLabel : Hdy.Window { - private const int SPACING = 12; - private const string COLORED_STYLE_CSS = """ - .%s { - background-color: alpha(%s, 0.8); - color: %s; - } - """; - - public MonitorLabelInfo info { get; construct; } - - public MonitorLabel (MonitorLabelInfo info) { - Object (info: info); - } - - construct { - child = new Gtk.Label (info.label); - - title = "LABEL-%i".printf (info.monitor); - - input_shape_combine_region (null); - accept_focus = false; - decorated = false; - resizable = false; - deletable = false; - can_focus = false; - skip_taskbar_hint = true; - skip_pager_hint = true; - type_hint = Gdk.WindowTypeHint.TOOLTIP; - set_keep_above (true); - - stick (); - - var scale_factor = get_style_context ().get_scale (); - move ( - (int) (info.x / scale_factor) + SPACING, - (int) (info.y / scale_factor) + SPACING - ); - - var provider = new Gtk.CssProvider (); - try { - provider.load_from_data (COLORED_STYLE_CSS.printf (title, info.background_color, info.text_color)); - get_style_context ().add_class (title); - get_style_context ().add_class ("monitor-label"); - - Gtk.StyleContext.add_provider_for_screen ( - Gdk.Screen.get_default (), - provider, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION - ); - } catch (Error e) { - warning ("Failed to load CSS: %s", e.message); - } - - show_all (); - } -} diff --git a/daemon-gtk3/meson.build b/daemon-gtk3/meson.build index c4a53ccec..43f7c0123 100644 --- a/daemon-gtk3/meson.build +++ b/daemon-gtk3/meson.build @@ -1,7 +1,6 @@ gala_daemon_sources = files( 'Main.vala', 'DBus.vala', - 'MonitorLabel.vala', 'Window.vala', 'WindowMenu.vala', 'BackgroundMenu.vala', diff --git a/daemon/DBus.vala b/daemon/DBus.vala index 75f996f73..59b9b2566 100644 --- a/daemon/DBus.vala +++ b/daemon/DBus.vala @@ -44,15 +44,6 @@ public interface Gala.WMDBus : GLib.Object { public abstract void perform_action (Gala.ActionType type) throws DBusError, IOError; } -public struct Gala.Daemon.MonitorLabelInfo { - public int monitor; - public string label; - public string background_color; - public string text_color; - public int x; - public int y; -} - [DBus (name = "org.pantheon.gala.daemon")] public class Gala.Daemon.DBus : GLib.Object { private const string DBUS_NAME = "org.pantheon.gala"; @@ -70,8 +61,6 @@ public class Gala.Daemon.DBus : GLib.Object { private WindowMenu? window_menu; private Gtk.PopoverMenu background_menu; - private List monitor_labels = new List (); - construct { Bus.watch_name (BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, gala_appeared, lost_gala); @@ -182,23 +171,6 @@ public class Gala.Daemon.DBus : GLib.Object { }); } - public void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError { - hide_monitor_labels (); - - monitor_labels = new List (); - foreach (var info in label_infos) { - var label = new MonitorLabel (info); - monitor_labels.append (label); - label.present (); - } - } - - public void hide_monitor_labels () throws GLib.DBusError, GLib.IOError { - foreach (var monitor_label in monitor_labels) { - monitor_label.close (); - } - } - private static void action_launch (SimpleAction action, Variant? variant) { try { AppInfo.launch_default_for_uri (variant.get_string (), null); diff --git a/daemon/meson.build b/daemon/meson.build index 595d1dfa3..ff49decd8 100644 --- a/daemon/meson.build +++ b/daemon/meson.build @@ -1,7 +1,6 @@ gala_daemon_sources = files( 'Main.vala', 'DBus.vala', - 'MonitorLabel.vala', 'Window.vala', 'WindowMenu.vala', ) diff --git a/data/gala-daemon.css b/data/gala-daemon.css index 43a0f9eb1..81c528760 100644 --- a/data/gala-daemon.css +++ b/data/gala-daemon.css @@ -6,13 +6,3 @@ daemon-window { background: transparent; } - -.monitor-label { - border-radius: 9px; - font-weight: 600; -} - -.monitor-label label { - margin: 1em; - text-shadow: 0 1px 1px alpha(white, 0.1); -} From 669f94761461f14a8d6bba77a85885cc4ce1a358 Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Mon, 30 Sep 2024 14:15:27 +0200 Subject: [PATCH 3/8] Add x support --- src/ShellClients/ShellClientsManager.vala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ShellClients/ShellClientsManager.vala b/src/ShellClients/ShellClientsManager.vala index 79f38017c..54cafe47b 100644 --- a/src/ShellClients/ShellClientsManager.vala +++ b/src/ShellClients/ShellClientsManager.vala @@ -278,6 +278,15 @@ public class Gala.ShellClientsManager : Object { make_centered (window); break; + case "monitor-label": + int parsed; + if (int.try_parse (val, out parsed)) { + make_monitor_label (window, parsed); + } else { + warning ("Failed to parse %s as monitor label", val); + } + break; + default: break; } From 406baebea949871505d46c8b3a340c299459c4dd Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 12 Oct 2024 12:25:47 +0200 Subject: [PATCH 4/8] Introduce window positioner and fix monitor labels --- src/ShellClients/MonitorLabelWindow.vala | 36 ++++++++++++++++ src/ShellClients/ShellClientsManager.vala | 17 +++----- src/ShellClients/WindowPositioner.vala | 52 +++++++++++++++++++++++ src/meson.build | 2 + 4 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 src/ShellClients/MonitorLabelWindow.vala create mode 100644 src/ShellClients/WindowPositioner.vala diff --git a/src/ShellClients/MonitorLabelWindow.vala b/src/ShellClients/MonitorLabelWindow.vala new file mode 100644 index 000000000..b6d3c77eb --- /dev/null +++ b/src/ShellClients/MonitorLabelWindow.vala @@ -0,0 +1,36 @@ +/* + * Copyright 2024 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Authored by: Leonhard Kargl + */ + + public class Gala.MonitorLabelWindow : Object { + public WindowManager wm { get; construct; } + public Meta.Window window { get; construct; } + public int monitor_index { get; construct; } + + private WindowPositioner positioner; + + public MonitorLabelWindow (WindowManager wm, Meta.Window window, int monitor_index) { + Object (wm: wm, window: window, monitor_index: monitor_index); + } + + construct { + window.make_above (); + + positioner = new WindowPositioner (window, wm, (ref x, ref y) => { + var display = wm.get_display (); + + if (monitor_index >= display.get_n_monitors ()) { + critical ("Monitor index %d of monitor label window %s went out of bounds", monitor_index, window.title ?? "Unnamed"); + return; + } + + var monitor_geom = display.get_monitor_geometry (monitor_index); + + x = monitor_geom.x + 12; + y = monitor_geom.y + 12; + }); + } +} diff --git a/src/ShellClients/ShellClientsManager.vala b/src/ShellClients/ShellClientsManager.vala index 54cafe47b..74d11e1d9 100644 --- a/src/ShellClients/ShellClientsManager.vala +++ b/src/ShellClients/ShellClientsManager.vala @@ -27,6 +27,7 @@ public class Gala.ShellClientsManager : Object { private GLib.HashTable windows = new GLib.HashTable (null, null); private GLib.HashTable centered_windows = new GLib.HashTable (null, null); + private GLib.HashTable monitor_labels = new GLib.HashTable (null, null); private ShellClientsManager (WindowManager wm) { Object (wm: wm); @@ -193,27 +194,21 @@ public class Gala.ShellClientsManager : Object { window.unmanaging.connect_after (() => centered_windows.remove (window)); } - public void make_monitor_label (Meta.Window window, int monitor_index) { + public void make_monitor_label (Meta.Window window, int monitor_index) requires (!is_positioned_window (window)) { unowned var display = wm.get_display (); if (monitor_index < 0 || monitor_index > display.get_n_monitors ()) { - warning ("Invalid moitor index provided: %d", monitor_index); + warning ("Invalid monitor index provided: %d", monitor_index); return; } - window.make_above (); + monitor_labels[window] = new MonitorLabelWindow (wm, window, monitor_index); - var monitor_geometry = display.get_monitor_geometry (monitor_index); - - ulong handler_id = 0; - handler_id = window.shown.connect (() => { - window.move_frame (false, monitor_geometry.x + 12, monitor_geometry.y + 12); - window.disconnect (handler_id); - }); + window.unmanaging.connect_after ((_window) => monitor_labels.remove (_window)); } public bool is_positioned_window (Meta.Window window) { - bool positioned = (window in centered_windows) || (window in windows); + bool positioned = (window in centered_windows) || (window in windows) || (window in monitor_labels); window.foreach_ancestor ((ancestor) => { if (ancestor in centered_windows || ancestor in windows) { positioned = true; diff --git a/src/ShellClients/WindowPositioner.vala b/src/ShellClients/WindowPositioner.vala new file mode 100644 index 000000000..e834f21d5 --- /dev/null +++ b/src/ShellClients/WindowPositioner.vala @@ -0,0 +1,52 @@ +public class Gala.WindowPositioner : Object { + public delegate void PositionFunc (ref int x, ref int y); + + public Meta.Window window { get; construct; } + public WindowManager wm { get; construct; } + + private PositionFunc position_func; + + private uint idle_move_id = 0; + + public WindowPositioner (Meta.Window window, WindowManager wm, owned PositionFunc position_func) { + Object (window: window, wm: wm); + + this.position_func = position_func; + } + + construct { + window.stick (); + + window.size_changed.connect (position_window); + window.position_changed.connect (position_window); + window.shown.connect (position_window); + + var monitor_manager = wm.get_display ().get_context ().get_backend ().get_monitor_manager (); + monitor_manager.monitors_changed.connect (position_window); + monitor_manager.monitors_changed_internal.connect (position_window); + + position_window (); + + window.unmanaging.connect (() => { + if (idle_move_id != 0) { + Source.remove (idle_move_id); + } + }); + } + + private void position_window () { + if (idle_move_id != 0) { + Source.remove (idle_move_id); + } + + idle_move_id = Idle.add (() => { + int x = 0, y = 0; + position_func (ref x, ref y); + + window.move_frame (false, x, y); + + idle_move_id = 0; + return Source.REMOVE; + }); + } +} diff --git a/src/meson.build b/src/meson.build index e2e61807b..807b12056 100644 --- a/src/meson.build +++ b/src/meson.build @@ -44,10 +44,12 @@ gala_bin_sources = files( 'ShellClients/CenteredWindow.vala', 'ShellClients/HideTracker.vala', 'ShellClients/ManagedClient.vala', + 'ShellClients/MonitorLabelWindow.vala', 'ShellClients/NotificationsClient.vala', 'ShellClients/PanelClone.vala', 'ShellClients/PanelWindow.vala', 'ShellClients/ShellClientsManager.vala', + 'ShellClients/WindowPositioner.vala', 'Widgets/DwellClickTimer.vala', 'Widgets/IconGroup.vala', 'Widgets/IconGroupContainer.vala', From d034a728faa9ae9beb0cddc1b6c36f11eca20531 Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 12 Oct 2024 12:26:35 +0200 Subject: [PATCH 5/8] Add license header --- src/ShellClients/WindowPositioner.vala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ShellClients/WindowPositioner.vala b/src/ShellClients/WindowPositioner.vala index e834f21d5..d4c9c9ad9 100644 --- a/src/ShellClients/WindowPositioner.vala +++ b/src/ShellClients/WindowPositioner.vala @@ -1,3 +1,10 @@ +/* + * Copyright 2024 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Authored by: Leonhard Kargl + */ + public class Gala.WindowPositioner : Object { public delegate void PositionFunc (ref int x, ref int y); From edce4f372ab45e61f6e1bc9f305d6b75e8a1bc6a Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 12 Oct 2024 12:31:15 +0200 Subject: [PATCH 6/8] Use window positioner for centered window --- src/ShellClients/CenteredWindow.vala | 41 +++++----------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/src/ShellClients/CenteredWindow.vala b/src/ShellClients/CenteredWindow.vala index 6099c68d1..780c93ca0 100644 --- a/src/ShellClients/CenteredWindow.vala +++ b/src/ShellClients/CenteredWindow.vala @@ -9,47 +9,20 @@ public class Gala.CenteredWindow : Object { public WindowManager wm { get; construct; } public Meta.Window window { get; construct; } - private uint idle_move_id = 0; + private WindowPositioner window_positioner; public CenteredWindow (WindowManager wm, Meta.Window window) { Object (wm: wm, window: window); } construct { - window.size_changed.connect (position_window); - window.stick (); + window_positioner = new WindowPositioner (window, wm, (ref x, ref y) => { + unowned var display = wm.get_display (); + var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ()); + var window_rect = window.get_frame_rect (); - var monitor_manager = wm.get_display ().get_context ().get_backend ().get_monitor_manager (); - monitor_manager.monitors_changed.connect (() => position_window ()); - - position_window (); - - window.shown.connect (() => window.focus (wm.get_display ().get_current_time ())); - - window.unmanaging.connect (() => { - if (idle_move_id != 0) { - Source.remove (idle_move_id); - } - }); - } - - private void position_window () { - var display = wm.get_display (); - var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ()); - var window_rect = window.get_frame_rect (); - - var x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2; - var y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2; - - if (idle_move_id != 0) { - Source.remove (idle_move_id); - } - - idle_move_id = Idle.add (() => { - window.move_frame (false, x, y); - - idle_move_id = 0; - return Source.REMOVE; + x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2; + y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2; }); } } From 693519faea223ff23a9d3e148ca82117f3b67ef0 Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 12 Oct 2024 12:56:08 +0200 Subject: [PATCH 7/8] Rm centeredwindow and monitorlabelwindow --- src/ShellClients/CenteredWindow.vala | 28 ---------- src/ShellClients/MonitorLabelWindow.vala | 36 ------------- src/ShellClients/ShellClientsManager.vala | 62 ++++++++++++++--------- src/ShellClients/WindowPositioner.vala | 2 +- src/meson.build | 2 - 5 files changed, 39 insertions(+), 91 deletions(-) delete mode 100644 src/ShellClients/CenteredWindow.vala delete mode 100644 src/ShellClients/MonitorLabelWindow.vala diff --git a/src/ShellClients/CenteredWindow.vala b/src/ShellClients/CenteredWindow.vala deleted file mode 100644 index 780c93ca0..000000000 --- a/src/ShellClients/CenteredWindow.vala +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2024 elementary, Inc. (https://elementary.io) - * SPDX-License-Identifier: GPL-3.0-or-later - * - * Authored by: Leonhard Kargl - */ - -public class Gala.CenteredWindow : Object { - public WindowManager wm { get; construct; } - public Meta.Window window { get; construct; } - - private WindowPositioner window_positioner; - - public CenteredWindow (WindowManager wm, Meta.Window window) { - Object (wm: wm, window: window); - } - - construct { - window_positioner = new WindowPositioner (window, wm, (ref x, ref y) => { - unowned var display = wm.get_display (); - var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ()); - var window_rect = window.get_frame_rect (); - - x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2; - y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2; - }); - } -} diff --git a/src/ShellClients/MonitorLabelWindow.vala b/src/ShellClients/MonitorLabelWindow.vala deleted file mode 100644 index b6d3c77eb..000000000 --- a/src/ShellClients/MonitorLabelWindow.vala +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2024 elementary, Inc. (https://elementary.io) - * SPDX-License-Identifier: GPL-3.0-or-later - * - * Authored by: Leonhard Kargl - */ - - public class Gala.MonitorLabelWindow : Object { - public WindowManager wm { get; construct; } - public Meta.Window window { get; construct; } - public int monitor_index { get; construct; } - - private WindowPositioner positioner; - - public MonitorLabelWindow (WindowManager wm, Meta.Window window, int monitor_index) { - Object (wm: wm, window: window, monitor_index: monitor_index); - } - - construct { - window.make_above (); - - positioner = new WindowPositioner (window, wm, (ref x, ref y) => { - var display = wm.get_display (); - - if (monitor_index >= display.get_n_monitors ()) { - critical ("Monitor index %d of monitor label window %s went out of bounds", monitor_index, window.title ?? "Unnamed"); - return; - } - - var monitor_geom = display.get_monitor_geometry (monitor_index); - - x = monitor_geom.x + 12; - y = monitor_geom.y + 12; - }); - } -} diff --git a/src/ShellClients/ShellClientsManager.vala b/src/ShellClients/ShellClientsManager.vala index 74d11e1d9..d39491b78 100644 --- a/src/ShellClients/ShellClientsManager.vala +++ b/src/ShellClients/ShellClientsManager.vala @@ -25,9 +25,8 @@ public class Gala.ShellClientsManager : Object { private NotificationsClient notifications_client; private ManagedClient[] protocol_clients = {}; - private GLib.HashTable windows = new GLib.HashTable (null, null); - private GLib.HashTable centered_windows = new GLib.HashTable (null, null); - private GLib.HashTable monitor_labels = new GLib.HashTable (null, null); + private GLib.HashTable panel_windows = new GLib.HashTable (null, null); + private GLib.HashTable positioned_windows = new GLib.HashTable (null, null); private ShellClientsManager (WindowManager wm) { Object (wm: wm); @@ -145,18 +144,18 @@ public class Gala.ShellClientsManager : Object { } public void set_anchor (Meta.Window window, Meta.Side side) { - if (window in windows) { - windows[window].update_anchor (side); + if (window in panel_windows) { + panel_windows[window].update_anchor (side); return; } make_dock (window); // TODO: Return if requested by window that's not a trusted client? - windows[window] = new PanelWindow (wm, window, side); + panel_windows[window] = new PanelWindow (wm, window, side); // connect_after so we make sure the PanelWindow can destroy its barriers and struts - window.unmanaging.connect_after (() => windows.remove (window)); + window.unmanaging.connect_after ((_window) => panel_windows.remove (_window)); } /** @@ -167,50 +166,65 @@ public class Gala.ShellClientsManager : Object { * TODO: Maybe use for strut only? */ public void set_size (Meta.Window window, int width, int height) { - if (!(window in windows)) { + if (!(window in panel_windows)) { warning ("Set anchor for window before size."); return; } - windows[window].set_size (width, height); + panel_windows[window].set_size (width, height); } public void set_hide_mode (Meta.Window window, Pantheon.Desktop.HideMode hide_mode) { - if (!(window in windows)) { + if (!(window in panel_windows)) { warning ("Set anchor for window before hide mode."); return; } - windows[window].set_hide_mode (hide_mode); + panel_windows[window].set_hide_mode (hide_mode); } - public void make_centered (Meta.Window window) { - if (window in centered_windows) { - return; - } + public void make_centered (Meta.Window window) requires (!is_positioned_window (window)) { + positioned_windows[window] = new WindowPositioner (window, wm, (ref x, ref y) => { + unowned var display = wm.get_display (); + var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ()); + var window_rect = window.get_frame_rect (); - centered_windows[window] = new CenteredWindow (wm, window); + x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2; + y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2; + }); - window.unmanaging.connect_after (() => centered_windows.remove (window)); + window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window)); } public void make_monitor_label (Meta.Window window, int monitor_index) requires (!is_positioned_window (window)) { - unowned var display = wm.get_display (); - - if (monitor_index < 0 || monitor_index > display.get_n_monitors ()) { + if (monitor_index < 0 || monitor_index > wm.get_display ().get_n_monitors ()) { warning ("Invalid monitor index provided: %d", monitor_index); return; } - monitor_labels[window] = new MonitorLabelWindow (wm, window, monitor_index); + window.make_above (); + + positioned_windows[window] = new WindowPositioner (window, wm, (ref x, ref y) => { + unowned var display = wm.get_display (); + + if (monitor_index >= display.get_n_monitors ()) { + critical ("Monitor index %d of monitor label window %s went out of bounds", monitor_index, window.title ?? "Unnamed"); + return; + } + + var monitor_geom = display.get_monitor_geometry (monitor_index); + + x = monitor_geom.x + 12; + y = monitor_geom.y + 12; + }); - window.unmanaging.connect_after ((_window) => monitor_labels.remove (_window)); + window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window)); } public bool is_positioned_window (Meta.Window window) { - bool positioned = (window in centered_windows) || (window in windows) || (window in monitor_labels); + bool positioned = (window in positioned_windows) || (window in panel_windows); window.foreach_ancestor ((ancestor) => { - if (ancestor in centered_windows || ancestor in windows) { + if (ancestor in positioned_windows || ancestor in panel_windows) { positioned = true; } diff --git a/src/ShellClients/WindowPositioner.vala b/src/ShellClients/WindowPositioner.vala index d4c9c9ad9..3f9df883a 100644 --- a/src/ShellClients/WindowPositioner.vala +++ b/src/ShellClients/WindowPositioner.vala @@ -18,7 +18,7 @@ public class Gala.WindowPositioner : Object { public WindowPositioner (Meta.Window window, WindowManager wm, owned PositionFunc position_func) { Object (window: window, wm: wm); - this.position_func = position_func; + this.position_func = (owned) position_func; } construct { diff --git a/src/meson.build b/src/meson.build index 807b12056..7e6488fd1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -41,10 +41,8 @@ gala_bin_sources = files( 'HotCorners/Barrier.vala', 'HotCorners/HotCorner.vala', 'HotCorners/HotCornerManager.vala', - 'ShellClients/CenteredWindow.vala', 'ShellClients/HideTracker.vala', 'ShellClients/ManagedClient.vala', - 'ShellClients/MonitorLabelWindow.vala', 'ShellClients/NotificationsClient.vala', 'ShellClients/PanelClone.vala', 'ShellClients/PanelWindow.vala', From 538a0b8cbf9515797a5a408fc44a81f1b5dea3fd Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 12 Oct 2024 13:18:23 +0200 Subject: [PATCH 8/8] Fix shutdown dialogs --- src/ShellClients/ShellClientsManager.vala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ShellClients/ShellClientsManager.vala b/src/ShellClients/ShellClientsManager.vala index d39491b78..780b4cdf1 100644 --- a/src/ShellClients/ShellClientsManager.vala +++ b/src/ShellClients/ShellClientsManager.vala @@ -183,7 +183,7 @@ public class Gala.ShellClientsManager : Object { panel_windows[window].set_hide_mode (hide_mode); } - public void make_centered (Meta.Window window) requires (!is_positioned_window (window)) { + public void make_centered (Meta.Window window) requires (!is_itself_positioned (window)) { positioned_windows[window] = new WindowPositioner (window, wm, (ref x, ref y) => { unowned var display = wm.get_display (); var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ()); @@ -196,7 +196,7 @@ public class Gala.ShellClientsManager : Object { window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window)); } - public void make_monitor_label (Meta.Window window, int monitor_index) requires (!is_positioned_window (window)) { + public void make_monitor_label (Meta.Window window, int monitor_index) requires (!is_itself_positioned (window)) { if (monitor_index < 0 || monitor_index > wm.get_display ().get_n_monitors ()) { warning ("Invalid monitor index provided: %d", monitor_index); return; @@ -221,8 +221,12 @@ public class Gala.ShellClientsManager : Object { window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window)); } + private bool is_itself_positioned (Meta.Window window) { + return (window in positioned_windows) || (window in panel_windows); + } + public bool is_positioned_window (Meta.Window window) { - bool positioned = (window in positioned_windows) || (window in panel_windows); + bool positioned = is_itself_positioned (window); window.foreach_ancestor ((ancestor) => { if (ancestor in positioned_windows || ancestor in panel_windows) { positioned = true;