ghostty icon indicating copy to clipboard operation
ghostty copied to clipboard

core: add a UUID to every core surface

Open jcollie opened this issue 4 months ago • 9 comments

  • Adds a 128bit UUID to every core surface.
  • Expose that UUID as an environment variable.
  • Add a function to the core app to search for surfaces by UUID.

jcollie avatar Aug 10 '25 14:08 jcollie

I went ahead and implemented our own UUID type.

jcollie avatar Aug 13 '25 04:08 jcollie

One downside to an UUID is that you can't fit it inside a glib.Variant by itself (the type system only supports 64-bit integers at most), which means that when you want to pass the surface ID through our GTK actions, you either have to stuff it inside a string (ew, bad) or split it up into two u64s. Neither option sounds enticing, really...

pluiedev avatar Aug 13 '25 20:08 pluiedev

Plus: u128s are also ill-defined at best in C land (just search "__int128" and the horrors therein), so every time you want to refer to a surface via libghostty you have to specify two u64s (or even worse, a string). Why not just use one single u64 in this case?

pluiedev avatar Aug 13 '25 20:08 pluiedev

Yeah we may be able to get away with an incrementing u64. Surface creation can grab a lock to increment and you’d have to have an unfathomable amount of surfaces to ever overflow.

I’ve been meaning to look at that as an option.

mitchellh avatar Aug 13 '25 21:08 mitchellh

Yeah we may be able to get away with an incrementing u64. Surface creation can grab a lock to increment and you’d have to have an unfathomable amount of surfaces to ever overflow.

Incrementing a u64 would def be my least preferred option. So many network protocols have had security issues due to easily predictable identifiers that I just automatically reject that as an option. Plus the need for a mutex.

If we aren't going for "real" UUIDs then std.crypto.random.int(u64) is the best way to go IMHO.

jcollie avatar Aug 13 '25 21:08 jcollie

Yeah sorry saying incrementing was definitely wrong. I mean something closer to Snowflake.

mitchellh avatar Aug 13 '25 22:08 mitchellh

If UUIDs are overkill because of their size, Snowflake IDs are overkill because of their complexity. Ghostty's not really a distributed system so all of that work constructing that ID is kinda pointless.

jcollie avatar Aug 14 '25 00:08 jcollie

It’s roughly the same complexity as a UUID, some bits for time, some bits incremented, some bits random. Just 64 instead of 128 bits.

mitchellh avatar Aug 14 '25 00:08 mitchellh

Switched to a plain 'ol random u64.

jcollie avatar Aug 14 '25 01:08 jcollie

Going to wait on this until we need it.

mitchellh avatar Dec 15 '25 17:12 mitchellh