core: add 64 bit unique ID to every core surface

- Expose that ID as the environment variable GHOSTTY_SURFACE_ID to
  processes running in Ghostty surfaces.
- Add a function to the core app to search for surfaces by ID.
- ID is randomly generated, it has no other meaning other than as a
  unique identifier for the surface. The ID also cannot be zero as that
  is used to indicate a null ID in some situations.
This commit is contained in:
Jeffrey C. Ollie
2025-08-13 19:28:11 -05:00
parent f16d35489b
commit ff02ed1b34
2 changed files with 30 additions and 0 deletions

View File

@@ -524,6 +524,16 @@ fn hasSurface(self: *const App, surface: *const Surface) bool {
return false;
}
/// Search for a surface by a 64 bit unique ID.
pub fn findSurfaceByID(self: *const App, id: u64) ?*Surface {
for (self.surfaces.items) |v| {
const surface: *Surface = v.core();
if (surface.id == id) return surface;
}
return null;
}
fn hasRtSurface(self: *const App, surface: *apprt.Surface) bool {
for (self.surfaces.items) |v| {
if (v == surface) return true;