Skip to content

Commit

Permalink
Application: withdraw stale notifications (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Dec 4, 2024
1 parent 21162a5 commit c5cfbcd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down

0 comments on commit c5cfbcd

Please sign in to comment.