diff options
author | Juhani Krekelä | 2021-10-23 00:33:17 +0300 |
---|---|---|
committer | Wolfgang Müller | 2021-11-27 14:05:19 +0100 |
commit | 71388f94c694a36b0ac360b34f09d7c16a51f803 (patch) | |
tree | c3522f312133b1b6bff844982064ab464d415b34 /terminal.vala | |
parent | 743db7dd1c0ced6d4aeb4d4719e4985e8f83890b (diff) | |
download | weltschmerz-71388f94c694a36b0ac360b34f09d7c16a51f803.tar.gz |
Add procfs fallback for figuring out the cwd
Opening a terminal or file manager window requires weltschmerz to know
the current working directory. At the moment weltschmerz relies on the
application being run in the terminal to generate OSC 7 codes that
specify the path. However, OSC 7 is not yet widely supported by default,
and the VTE terminal emulation layer, which manages the OSC 7 path state
for weltschmerz, will overwrite local paths with ones that point to a
remote computer if an OSC 7 enabled application is run under ssh.
This change adds a fallback that uses the symlink to current working
directory located at /proc/<child pid>/cwd. On Linux this method should
always work and was how these features were implemented before adoption
of OSC 7. The procfs method is used as a fallback instead of the primary
method since it can only see the working directory changes of the direct
child process.
Diffstat (limited to '')
-rw-r--r-- | terminal.vala | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/terminal.vala b/terminal.vala index 47c33bc..1005996 100644 --- a/terminal.vala +++ b/terminal.vala @@ -40,6 +40,8 @@ class Terminal : Gtk.Overlay { Gtk.MenuItem[] open_with_items = {}; + Pid child_pid; + bool has_search; bool overlay_scrolling_env_override; string url_match; @@ -83,7 +85,7 @@ class Terminal : Gtk.Overlay { argv = { Utils.get_shell() }; } - vte.spawn_sync(DEFAULT, null, argv, null, SEARCH_PATH, null, null, null); + vte.spawn_sync(DEFAULT, null, argv, null, SEARCH_PATH, null, out child_pid, null); } catch (Error e) { error(e.message); } @@ -368,7 +370,7 @@ class Terminal : Gtk.Overlay { adjust_font_scale(vte.get_font_scale() / FONT_SCALE_FACTOR); } - string? get_local_directory_path() { + string? get_osc7_path() { var uri = vte.get_current_directory_uri(); if (uri == null) return null; @@ -392,6 +394,13 @@ class Terminal : Gtk.Overlay { return path; } + string? get_cwd() { + string? osc7_path = get_osc7_path(); + if (osc7_path != null) + return osc7_path; + return Posix.realpath("/proc/%i/cwd".printf(child_pid)); + } + void spawn_process(string? cwd, string[] argv) { Pid child; @@ -407,7 +416,7 @@ class Terminal : Gtk.Overlay { [GtkCallback] void open_terminal() { - var cwd = get_local_directory_path(); + var cwd = get_cwd(); if (cwd == null) return; spawn_process(cwd, {PROGRAM_NAME}); @@ -415,7 +424,7 @@ class Terminal : Gtk.Overlay { [GtkCallback] void open_directory() { - var cwd = get_local_directory_path(); + var cwd = get_cwd(); if (cwd == null) return; @@ -449,8 +458,8 @@ class Terminal : Gtk.Overlay { } else { copy_item_text.set_sensitive(vte.get_has_selection()); copy_item_html.set_sensitive(vte.get_has_selection()); - open_terminal_item.set_sensitive(get_local_directory_path() != null); - open_directory_item.set_sensitive(get_local_directory_path() != null); + open_terminal_item.set_sensitive(get_cwd() != null); + open_directory_item.set_sensitive(get_cwd() != null); standard_context_menu.popup_at_pointer(event); } return true; |