From a2ab0abdbb2d98cc9f458c03213bc22cdc77d6db Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Sat, 19 Nov 2022 17:44:00 +0100 Subject: Use spawn_async instead of spawn_sync The 'spawn_sync' function has been deprecated for a very long time now, but we could never use its intended replacement as its Vala bindings were broken [1]. The underlying problem had been identified in [2] a while ago, but has only been recently fixed in [3] and is now available in Vala's 0.56 branch. Since we rely on the child PID as a fallback for opinionated users or shells that are unaware of OSC 7, we have to pass a callback function to the 'spawn_async' call so we can capture the PID which is no longer supplied by the method itself. [1] https://gitlab.gnome.org/GNOME/vte/issues/227 [2] https://gitlab.gnome.org/GNOME/vala/-/issues/721 [3] https://gitlab.gnome.org/GNOME/vala/-/commit/f058e9e828f494ebf8d60cabff7999f219048623 --- TODO | 7 ------- terminal.vala | 24 +++++++++++++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index 5f45578..de89335 100644 --- a/TODO +++ b/TODO @@ -7,13 +7,6 @@ [1] https://developer.gnome.org/gtk3/stable/GtkImageMenuItem.html#gtk-image-menu-item-new -- Upstream recommends spawn_async() instead of spawn_sync(), but the bindings - for it are erroneous. - - See: https://gitlab.gnome.org/GNOME/vala/issues/721 - https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/168 - https://gitlab.gnome.org/GNOME/vte/issues/227 - - The upstream GTK devel branch has dropped some X11-specific APIs, including the interface for urgency hints. Eventually, this feature will have to be removed from weltschmerz too. diff --git a/terminal.vala b/terminal.vala index e2c8d48..67256d4 100644 --- a/terminal.vala +++ b/terminal.vala @@ -80,16 +80,26 @@ class Terminal : Gtk.Overlay { var regex = new Vte.Regex.for_match(URL_REGEX, URL_REGEX.length, PCRE2_CASELESS | PCRE2_MULTILINE); vte.match_add_regex(regex, 0); vte.match_set_cursor_name(0, "pointer"); - - var argv = args[1:args.length]; - if (argv.length == 0) { - argv = { Utils.get_shell() }; - } - - vte.spawn_sync(DEFAULT, null, argv, null, SEARCH_PATH, null, out child_pid, null); } catch (Error e) { error(e.message); } + + var argv = args[1:args.length]; + if (argv.length == 0) { + argv = { Utils.get_shell() }; + } + + Vte.TerminalSpawnAsyncCallback callback = this.spawn_terminal_callback; + vte.spawn_async(DEFAULT, null, argv, null, SEARCH_PATH, null, -1, null, callback); + } + + void spawn_terminal_callback(Vte.Terminal terminal, Pid pid, Error? error) { + if (error != null) { + print("weltschmerz: %s\n".printf(error.message)); + Process.exit(1); + } + + this.child_pid = pid; } Gtk.PolicyType get_scrollbar_policy(bool want_scrollbar) { -- cgit v1.2.3-2-gb3c3