Skip to content

Commit d766dbd

Browse files
igordsmJeremy WoottenjeremypwMarukesu
authored
Focus current tab (#638)
* Focus terminal tab when notification is clicked. * add meson.build * Update src/Application.vala Co-authored-by: Gustavo Marques <[email protected]> * Rewrite for TerminalView; Use hack to raise window --------- Co-authored-by: Jeremy Wootten <[email protected]> Co-authored-by: Jeremy Wootten <[email protected]> Co-authored-by: Gustavo Marques <[email protected]>
1 parent 8b6367f commit d766dbd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Application.vala

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ public class Terminal.Application : Gtk.Application {
3131
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
3232
Intl.textdomain (Config.GETTEXT_PACKAGE);
3333

34+
var act = new SimpleAction ("process-finished", VariantType.STRING);
35+
add_action (act);
36+
act.activate.connect ((v) => {
37+
MainWindow window_to_present = (MainWindow)active_window;
38+
size_t len;
39+
var tid = v.get_string (out len);
40+
foreach (var window in (List<MainWindow>) get_windows ()) {
41+
var terminal = window.get_terminal (tid);
42+
if (terminal != null) {
43+
window.set_active_terminal_tab (terminal.tab);
44+
window_to_present = window;
45+
break;
46+
}
47+
}
48+
49+
// This is a hack to avoid using Gdk-Xii dependency. Using present_with_time ()
50+
// with the current event time does not work either on X11 or Wayland perhaps
51+
// because the triggering event did not occur on the Terminal window?
52+
// Using set_keep_above () at least works on X11 but not on Wayland
53+
//TODO It may well be possible to use present () on Gtk4 so this needs revisiting
54+
window_to_present.set_keep_above (true);
55+
window_to_present.present ();
56+
window_to_present.grab_focus ();
57+
Idle.add (() => {
58+
window_to_present.set_keep_above (false);
59+
return Source.REMOVE;
60+
});
61+
});
62+
3463
add_main_option ("version", 'v', 0, OptionArg.NONE, _("Show version"), null);
3564
// -n flag forces a new window
3665
add_main_option ("new-window", 'n', 0, OptionArg.NONE, _("Open a new terminal window"), null);
@@ -171,7 +200,8 @@ public class Terminal.Application : Gtk.Application {
171200
var notification = new Notification (process_string);
172201
notification.set_body (process);
173202
notification.set_icon (process_icon);
174-
send_notification (null, notification);
203+
notification.set_default_action_and_target_value ("app.process-finished", new Variant.string (id));
204+
send_notification ("process-finished-%s".printf (id), notification);
175205
}
176206
});
177207

src/MainWindow.vala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,10 @@ namespace Terminal {
11171117
return null;
11181118
}
11191119

1120+
public void set_active_terminal_tab (Hdy.TabPage tab) {
1121+
notebook.tab_view.selected_page = tab;
1122+
}
1123+
11201124
/** Compare every tab label with every other and resolve ambiguities **/
11211125
private void check_for_tabs_with_same_name () requires (current_terminal != null) {
11221126
int i = 0;

0 commit comments

Comments
 (0)