Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/ghostty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/apprt/embedded.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant cast in overflow guard

std.math.maxInt(i32) returns a comptime_int, so Zig will coerce it to u64 automatically in the comparison — the @as(u64, @intCast(...)) wrapper is unnecessary. The simpler form is equivalent:

Suggested change
if (raw > @as(u64, @intCast(std.math.maxInt(i32)))) return -1;
if (raw > 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(
Expand Down
Loading