From bd300d99bb8886bf5f5b98504c923f30303dc247 Mon Sep 17 00:00:00 2001 From: Leonhard <106322251+leolost2605@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:27:44 +0100 Subject: [PATCH] Add window spread for an app (#1833) --- src/DBus.vala | 25 ++++++++++-------------- src/DesktopIntegration.vala | 34 +++++++++++++++++++++++++++------ src/Widgets/WindowOverview.vala | 9 ++++++++- src/WindowManager.vala | 3 ++- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/DBus.vala b/src/DBus.vala index e474c1dc0..51eb6d24f 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -19,10 +19,10 @@ namespace Gala { [DBus (name="org.pantheon.gala")] public class DBus { private static DBus? instance; - private static WindowManager wm; + private static WindowManagerGala wm; [DBus (visible = false)] - public static void init (WindowManager _wm) { + public static void init (WindowManagerGala _wm) { wm = _wm; Bus.own_name (BusType.SESSION, "org.pantheon.gala", BusNameOwnerFlags.NONE, @@ -65,19 +65,14 @@ namespace Gala { () => {}, () => critical ("Could not acquire name") ); - unowned WindowManagerGala? gala_wm = wm as WindowManagerGala; - if (gala_wm != null) { - var screensaver_manager = gala_wm.screensaver; - - Bus.own_name (BusType.SESSION, "org.gnome.ScreenSaver", BusNameOwnerFlags.REPLACE, - (connection) => { - try { - connection.register_object ("/org/gnome/ScreenSaver", screensaver_manager); - } catch (Error e) { warning (e.message); } - }, - () => {}, - () => critical ("Could not acquire ScreenSaver bus") ); - } + Bus.own_name (BusType.SESSION, "org.gnome.ScreenSaver", BusNameOwnerFlags.REPLACE, + (connection) => { + try { + connection.register_object ("/org/gnome/ScreenSaver", wm.screensaver); + } catch (Error e) { warning (e.message); } + }, + () => {}, + () => critical ("Could not acquire ScreenSaver bus") ); } private DBus () { diff --git a/src/DesktopIntegration.vala b/src/DesktopIntegration.vala index 2b701b902..a0422494a 100644 --- a/src/DesktopIntegration.vala +++ b/src/DesktopIntegration.vala @@ -16,17 +16,14 @@ public class Gala.DesktopIntegration : GLib.Object { GLib.HashTable properties; } - private unowned WindowManager wm; + private unowned WindowManagerGala wm; public uint version { get; default = 1; } public signal void running_applications_changed (); public signal void windows_changed (); - public DesktopIntegration (WindowManager wm) { + public DesktopIntegration (WindowManagerGala wm) { this.wm = wm; - unowned WindowManagerGala? gala_wm = wm as WindowManagerGala; - if (gala_wm != null) { - gala_wm.window_tracker.windows_changed.connect (() => windows_changed ()); - } + wm.window_tracker.windows_changed.connect (() => windows_changed ()); } public RunningApplication[] get_running_applications () throws GLib.DBusError, GLib.IOError { @@ -102,4 +99,29 @@ public class Gala.DesktopIntegration : GLib.Object { return (owned) returned_windows; } + + public void show_windows_for (string app_id) throws IOError, DBusError { + if (wm.window_overview == null) { + throw new IOError.FAILED ("Window overview not provided by window manager"); + } + + App app; + if ((app = AppSystem.get_default ().lookup_app (app_id)) == null) { + throw new IOError.NOT_FOUND ("App not found"); + } + + uint64[] window_ids = {}; + foreach (var window in app.get_windows ()) { + window_ids += window.get_id (); + } + + var hints = new HashTable (str_hash, str_equal); + hints["windows"] = window_ids; + + if (wm.window_overview.is_opened ()) { + wm.window_overview.close (); + } + + wm.window_overview.open (hints); + } } diff --git a/src/Widgets/WindowOverview.vala b/src/Widgets/WindowOverview.vala index 627b14544..b2e122024 100644 --- a/src/Widgets/WindowOverview.vala +++ b/src/Widgets/WindowOverview.vala @@ -75,6 +75,11 @@ public class Gala.WindowOverview : Clutter.Actor, ActivatableComponent { workspaces.append (workspace); } + uint64[]? window_ids = null; + if (hints != null && "windows" in hints) { + window_ids = (uint64[]) hints["windows"]; + } + var windows = new List (); foreach (var workspace in workspaces) { foreach (unowned var window in workspace.list_windows ()) { @@ -85,7 +90,9 @@ public class Gala.WindowOverview : Clutter.Actor, ActivatableComponent { if (window.window_type != Meta.WindowType.NORMAL && window.window_type != Meta.WindowType.DIALOG || - window.is_attached_dialog ()) { + window.is_attached_dialog () || + (window_ids != null && !(window.get_id () in window_ids)) + ) { unowned var actor = (Meta.WindowActor) window.get_compositor_private (); actor.hide (); diff --git a/src/WindowManager.vala b/src/WindowManager.vala index b44536497..657061e5b 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -72,7 +72,8 @@ namespace Gala { private Meta.PluginInfo info; private WindowSwitcher? window_switcher = null; - private ActivatableComponent? window_overview = null; + + public ActivatableComponent? window_overview { get; private set; } public ScreenSaverManager? screensaver { get; private set; }