From c5cfbcd2a1ce4aefa46001b094518ed1d157ef18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 4 Dec 2024 08:25:37 -0800 Subject: [PATCH] Application: withdraw stale notifications (#813) --- src/Application.vala | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Application.vala b/src/Application.vala index 99d07a21cf..82d504fedb 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -202,12 +202,38 @@ public class Terminal.Application : Gtk.Application { notification.set_icon (process_icon); notification.set_default_action_and_target_value ("app.process-finished", new Variant.string (id)); send_notification ("process-finished-%s".printf (id), notification); + + ulong tab_change_handler = 0; + ulong focus_in_handler = 0; + + tab_change_handler = terminal.main_window.notify["current-terminal"].connect (() => { + withdraw_notification_for_terminal (terminal, id, tab_change_handler, focus_in_handler); + }); + + focus_in_handler = terminal.main_window.focus_in_event.connect (() => { + withdraw_notification_for_terminal (terminal, id, tab_change_handler, focus_in_handler); + + return Gdk.EVENT_PROPAGATE; + }); + } }); return true; } + private void withdraw_notification_for_terminal (TerminalWidget terminal, string id, ulong tab_change_handler, ulong focus_in_handler) { + if (terminal.main_window.current_terminal != terminal) { + return; + } + + terminal.tab.icon = null; + withdraw_notification ("process-finished-%s".printf (id)); + + terminal.main_window.disconnect (tab_change_handler); + terminal.main_window.disconnect (focus_in_handler); + } + protected override void startup () { base.startup (); Hdy.init ();