From 7f9ea40f88b7344a4d0aea26c2445b944395f8ef Mon Sep 17 00:00:00 2001 From: moises2657 Date: Wed, 1 Jan 2025 23:55:17 +0000 Subject: [PATCH 01/12] Launcher: new context option to close all windows --- src/DesktopIntegration.vala | 1 + src/Launcher.vala | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/DesktopIntegration.vala b/src/DesktopIntegration.vala index f39465c15..939ee4895 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 c27989483..68919f92f 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; From e03b4a224a4252ed80f3ecc644d8539a90f70c29 Mon Sep 17 00:00:00 2001 From: moises2657 Date: Wed, 1 Jan 2025 18:20:38 -0600 Subject: [PATCH 02/12] Launcher: hotfix option still persist after app closes --- src/Launcher.vala | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Launcher.vala b/src/Launcher.vala index 68919f92f..dbbea000f 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -25,6 +25,8 @@ public class Dock.Launcher : Gtk.Box { public const string ACTION_PREFIX = ACTION_GROUP_PREFIX + "."; public const string PINNED_ACTION = "pinned"; public const string APP_ACTION = "action.%s"; + private const string CLOSE_WINDOWS_LABEL = "Close All Windows"; + private const string CLOSE_WINDOWS_ACTION = "close-instances"; public App app { get; construct; } @@ -340,14 +342,14 @@ public class Dock.Launcher : Gtk.Box { private void close_all_instances(){ if (app.running) { - if (app.action_group.lookup_action("close-instances") != null) { + if (app.action_group.lookup_action(CLOSE_WINDOWS_ACTION) != null) { return; } - var close_item = new GLib.MenuItem(_("Close All Windows"), "app-actions.close-instances"); + var close_item = new GLib.MenuItem(_(CLOSE_WINDOWS_LABEL), ACTION_PREFIX + CLOSE_WINDOWS_ACTION); app.menu_model.append_item(close_item); - var close_action = new SimpleAction("close-instances", null); + var close_action = new SimpleAction(CLOSE_WINDOWS_ACTION, null); close_action.activate.connect(() => { var desktop_integration = LauncherManager.get_default().desktop_integration; @@ -360,6 +362,15 @@ public class Dock.Launcher : Gtk.Box { close_action.set_enabled(true); app.action_group.add_action(close_action); + }else{ + for (int i = 0; i < app.menu_model.get_n_items(); i++) { + var attribute = app.menu_model.get_item_attribute_value(i, "label", null); + var label = attribute != null ? attribute.get_string() : null; + if (label == _(CLOSE_WINDOWS_LABEL)) { + app.menu_model.remove(i); // Remove menu + break; + } + } } } From 5b26c54eaf392d59a84a06418a7937369c90c43f Mon Sep 17 00:00:00 2001 From: moises2657 Date: Wed, 1 Jan 2025 18:43:31 -0600 Subject: [PATCH 03/12] Launcher: remove actionn group of close all windows --- src/Launcher.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Launcher.vala b/src/Launcher.vala index dbbea000f..613231804 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -262,10 +262,12 @@ public class Dock.Launcher : Gtk.Box { update_running_revealer (); app.notify["running"].connect(close_all_instances); + close_all_instances(); var drop_target_file = new Gtk.DropTarget (typeof (File), COPY); add_controller (drop_target_file); + drop_target_file.enter.connect ((x, y) => { var _launcher_manager = LauncherManager.get_default (); if (_launcher_manager.added_launcher != null) { @@ -371,6 +373,9 @@ public class Dock.Launcher : Gtk.Box { break; } } + if (app.action_group.lookup_action(CLOSE_WINDOWS_ACTION) != null) { + app.action_group.remove_action(CLOSE_WINDOWS_ACTION); + } } } From b38b0fdd631b07e16839cbb39c321eedb20c31c5 Mon Sep 17 00:00:00 2001 From: moises2657 Date: Thu, 2 Jan 2025 10:58:14 -0600 Subject: [PATCH 04/12] Update src/Launcher.vala Co-authored-by: Leonhard --- src/Launcher.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Launcher.vala b/src/Launcher.vala index 613231804..1acf1cac6 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -267,7 +267,6 @@ public class Dock.Launcher : Gtk.Box { var drop_target_file = new Gtk.DropTarget (typeof (File), COPY); add_controller (drop_target_file); - drop_target_file.enter.connect ((x, y) => { var _launcher_manager = LauncherManager.get_default (); if (_launcher_manager.added_launcher != null) { From 71fe829370522885c3afdc09adefff80cf53c784 Mon Sep 17 00:00:00 2001 From: moises2657 Date: Thu, 2 Jan 2025 10:58:21 -0600 Subject: [PATCH 05/12] Update src/Launcher.vala Co-authored-by: Leonhard --- src/Launcher.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Launcher.vala b/src/Launcher.vala index 1acf1cac6..0e379cc0c 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -355,7 +355,7 @@ public class Dock.Launcher : Gtk.Box { var desktop_integration = LauncherManager.get_default().desktop_integration; foreach (var win in app.windows) { - desktop_integration.close_window.begin(win.uid, null); + desktop_integration.close_window.begin(win.uid); } app.windows.clear(); From 31fa1d0db3c918607309b29492e5e30c8abda31c Mon Sep 17 00:00:00 2001 From: moises2657 Date: Thu, 2 Jan 2025 11:12:01 -0600 Subject: [PATCH 06/12] move functionality to app --- src/App.vala | 22 ++++++++++++++++++++++ src/Launcher.vala | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/App.vala b/src/App.vala index 27cb4da2d..c94bb7f2f 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,26 @@ 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); + } + }); + + 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/Launcher.vala b/src/Launcher.vala index 0e379cc0c..fb82d0f29 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -3,7 +3,7 @@ * SPDX-FileCopyrightText: 2022 elementary, Inc. (https://elementary.io) */ -public class Dock.Launcher : Gtk.Box { + public class Dock.Launcher : Gtk.Box { private static Settings settings; private static Settings? notify_settings; @@ -551,4 +551,4 @@ public class Dock.Launcher : Gtk.Box { private void update_running_revealer () { running_revealer.reveal_child = !moving && app.running; } -} +} \ No newline at end of file From a81734f413c29b76adf84fc11efc176fd1326bcc Mon Sep 17 00:00:00 2001 From: moises2657 Date: Thu, 2 Jan 2025 11:13:53 -0600 Subject: [PATCH 07/12] restore launcher --- src/Launcher.vala | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/src/Launcher.vala b/src/Launcher.vala index fb82d0f29..aa7f793d1 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -25,8 +25,6 @@ public const string ACTION_PREFIX = ACTION_GROUP_PREFIX + "."; public const string PINNED_ACTION = "pinned"; public const string APP_ACTION = "action.%s"; - private const string CLOSE_WINDOWS_LABEL = "Close All Windows"; - private const string CLOSE_WINDOWS_ACTION = "close-instances"; public App app { get; construct; } @@ -261,9 +259,6 @@ app.notify["running"].connect (update_running_revealer); update_running_revealer (); - app.notify["running"].connect(close_all_instances); - close_all_instances(); - var drop_target_file = new Gtk.DropTarget (typeof (File), COPY); add_controller (drop_target_file); @@ -341,43 +336,6 @@ } } - private void close_all_instances(){ - if (app.running) { - if (app.action_group.lookup_action(CLOSE_WINDOWS_ACTION) != null) { - return; - } - - var close_item = new GLib.MenuItem(_(CLOSE_WINDOWS_LABEL), ACTION_PREFIX + CLOSE_WINDOWS_ACTION); - app.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 app.windows) { - desktop_integration.close_window.begin(win.uid); - } - - app.windows.clear(); - }); - - close_action.set_enabled(true); - app.action_group.add_action(close_action); - }else{ - for (int i = 0; i < app.menu_model.get_n_items(); i++) { - var attribute = app.menu_model.get_item_attribute_value(i, "label", null); - var label = attribute != null ? attribute.get_string() : null; - if (label == _(CLOSE_WINDOWS_LABEL)) { - app.menu_model.remove(i); // Remove menu - break; - } - } - if (app.action_group.lookup_action(CLOSE_WINDOWS_ACTION) != null) { - app.action_group.remove_action(CLOSE_WINDOWS_ACTION); - } - } - } - private void animate_launch () { if (bounce_up.state == PLAYING || bounce_down.state == PLAYING) { return; From b87626e7e42b3fd841ebdb88c3bf67cd44f0a3eb Mon Sep 17 00:00:00 2001 From: moises2657 Date: Thu, 2 Jan 2025 11:15:23 -0600 Subject: [PATCH 08/12] restore launcher --- src/Launcher.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Launcher.vala b/src/Launcher.vala index aa7f793d1..ef364a8f2 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -3,7 +3,7 @@ * SPDX-FileCopyrightText: 2022 elementary, Inc. (https://elementary.io) */ - public class Dock.Launcher : Gtk.Box { +public class Dock.Launcher : Gtk.Box { private static Settings settings; private static Settings? notify_settings; From bc4d11a183b7dee108263367e298600afc82fa20 Mon Sep 17 00:00:00 2001 From: moises2657 Date: Thu, 2 Jan 2025 11:36:37 -0600 Subject: [PATCH 09/12] Update Launcher.vala --- src/Launcher.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Launcher.vala b/src/Launcher.vala index ef364a8f2..c27989483 100644 --- a/src/Launcher.vala +++ b/src/Launcher.vala @@ -509,4 +509,4 @@ public class Dock.Launcher : Gtk.Box { private void update_running_revealer () { running_revealer.reveal_child = !moving && app.running; } -} \ No newline at end of file +} From a3a16bf6a5c66c159ff1a0083b560ab560cc0863 Mon Sep 17 00:00:00 2001 From: moises2657 Date: Thu, 2 Jan 2025 11:40:27 -0600 Subject: [PATCH 10/12] lint fix --- src/App.vala | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/App.vala b/src/App.vala index c94bb7f2f..a160612e5 100644 --- a/src/App.vala +++ b/src/App.vala @@ -123,23 +123,23 @@ public class Dock.App : Object { 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_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; + 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); + desktop_integration.close_window.begin (win.uid); } }); notify["running"].connect (() => { if(running){ - close_action.set_enabled(true); + close_action.set_enabled (true); }else{ - close_action.set_enabled(false); + close_action.set_enabled (false); } }); } From 402e74170e2f7fbaac4e4e523504a164f1ac3c76 Mon Sep 17 00:00:00 2001 From: mmagos Date: Fri, 3 Jan 2025 22:41:57 +0000 Subject: [PATCH 11/12] add close action to action_group --- src/App.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App.vala b/src/App.vala index a160612e5..49b0fe294 100644 --- a/src/App.vala +++ b/src/App.vala @@ -134,6 +134,7 @@ public class Dock.App : Object { desktop_integration.close_window.begin (win.uid); } }); + action_group.add_action (close_action); notify["running"].connect (() => { if(running){ From ae9764313662cc9a4ce18143bc271e0f4cc6c542 Mon Sep 17 00:00:00 2001 From: mmagos Date: Sun, 5 Jan 2025 20:14:21 -0600 Subject: [PATCH 12/12] fix lint --- src/App.vala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/App.vala b/src/App.vala index 49b0fe294..2fd5c8169 100644 --- a/src/App.vala +++ b/src/App.vala @@ -132,14 +132,14 @@ public class Dock.App : Object { 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){ + if (running) { close_action.set_enabled (true); - }else{ + } else { close_action.set_enabled (false); } });