diff --git a/include/ghostty.h b/include/ghostty.h index 3229675afdf..e1e040196b8 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -1156,6 +1156,7 @@ GHOSTTY_API void ghostty_surface_complete_clipboard_request(ghostty_surface_t, GHOSTTY_API bool ghostty_surface_has_selection(ghostty_surface_t); GHOSTTY_API bool ghostty_surface_select_cursor_cell(ghostty_surface_t); GHOSTTY_API bool ghostty_surface_clear_selection(ghostty_surface_t); +GHOSTTY_API int32_t ghostty_surface_foreground_pid(ghostty_surface_t); GHOSTTY_API bool ghostty_surface_read_selection(ghostty_surface_t, ghostty_text_s*); GHOSTTY_API bool ghostty_surface_read_text(ghostty_surface_t, ghostty_selection_s, diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 1186d24f07e..de1ff9975ab 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -1619,6 +1619,14 @@ pub const CAPI = struct { }; } + /// Returns the foreground process group PID (pid_t) of the surface's + /// pty master, or -1 if unavailable (cmux-specific). + export fn ghostty_surface_foreground_pid(surface: *Surface) i32 { + const raw = surface.core_surface.getProcessInfo(.foreground_pid) orelse return -1; + if (raw > @as(u64, @intCast(std.math.maxInt(i32)))) return -1; + return @intCast(raw); + } + /// Same as ghostty_surface_read_text but reads from the user selection, /// if any. export fn ghostty_surface_read_selection(