diff --git a/src/App.vala b/src/App.vala index 27cb4da2..2fd5c816 100644 --- a/src/App.vala +++ b/src/App.vala @@ -9,6 +9,8 @@ public class Dock.App : Object { private const string PINNED_ACTION = "pinned"; private const string SWITCHEROO_ACTION = "switcheroo"; private const string APP_ACTION = "action.%s"; + private const string CLOSE_WINDOWS_LABEL = "Close All Windows"; + private const string CLOSE_WINDOWS_ACTION = "close-instances"; public signal void launched () { if (!running && app_info.get_boolean ("StartupNotify")) { @@ -120,6 +122,27 @@ public class Dock.App : Object { pinned_action.set_state (pinned); LauncherManager.get_default ().sync_pinned (); }); + + var close_item = new GLib.MenuItem (_(CLOSE_WINDOWS_LABEL), ACTION_PREFIX + CLOSE_WINDOWS_ACTION); + close_item.set_attribute ("hidden-when", "s", "action-disabled"); + menu_model.append_item (close_item); + + var close_action = new SimpleAction (CLOSE_WINDOWS_ACTION, null); + close_action.activate.connect (() => { + var desktop_integration = LauncherManager.get_default ().desktop_integration; + foreach (var win in windows) { + desktop_integration.close_window.begin (win.uid); + } + }); + action_group.add_action (close_action); + + notify["running"].connect (() => { + if (running) { + close_action.set_enabled (true); + } else { + close_action.set_enabled (false); + } + }); } public void launch (AppLaunchContext context, string? action = null, bool? use_preferred_gpu = true) { diff --git a/src/DesktopIntegration.vala b/src/DesktopIntegration.vala index f39465c1..939ee489 100644 --- a/src/DesktopIntegration.vala +++ b/src/DesktopIntegration.vala @@ -25,4 +25,5 @@ public interface Dock.DesktopIntegration : GLib.Object { public abstract async Window[] get_windows () throws GLib.DBusError, GLib.IOError; public abstract async void show_windows_for (string app_id) throws GLib.DBusError, GLib.IOError; public abstract async void focus_window (uint64 uid) throws GLib.DBusError, GLib.IOError; + public abstract async void close_window (uint64 uid) throws GLib.DBusError, GLib.IOError; }