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; } diff --git a/src/Launcher.vala b/src/Launcher.vala index c2798948..68919f92 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -259,6 +259,8 @@ public class Dock.Launcher : Gtk.Box { app.notify["running"].connect (update_running_revealer); update_running_revealer (); + app.notify["running"].connect(close_all_instances); + var drop_target_file = new Gtk.DropTarget (typeof (File), COPY); add_controller (drop_target_file); @@ -336,6 +338,31 @@ public class Dock.Launcher : Gtk.Box { } } + private void close_all_instances(){ + if (app.running) { + if (app.action_group.lookup_action("close-instances") != null) { + return; + } + + var close_item = new GLib.MenuItem(_("Close All Windows"), "app-actions.close-instances"); + app.menu_model.append_item(close_item); + + var close_action = new SimpleAction("close-instances", null); + close_action.activate.connect(() => { + var desktop_integration = LauncherManager.get_default().desktop_integration; + + foreach (var win in app.windows) { + desktop_integration.close_window.begin(win.uid, null); + } + + app.windows.clear(); + }); + + close_action.set_enabled(true); + app.action_group.add_action(close_action); + } + } + private void animate_launch () { if (bounce_up.state == PLAYING || bounce_down.state == PLAYING) { return;