core: add a UUID to every core surface#8200
Conversation
mitchellh
left a comment
There was a problem hiding this comment.
Just a change requested on the dependency.
Other than that, I'm fine with this as it is. I think we'll take a much harder look at surface IDs in the future when we also make libghostty aware of hierarchy (windows vs tabs vs splits) but for now this is fine.
mitchellh
left a comment
There was a problem hiding this comment.
I don't want to vendor the UUID. I just want to make our own UUID type that copy and pastes what we need. I can take this over.
|
I went ahead and implemented our own UUID type. |
|
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... |
|
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? |
|
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. |
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 |
|
Yeah sorry saying incrementing was definitely wrong. I mean something closer to Snowflake. |
|
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. |
f4984dc to
74c0051
Compare
|
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. |
|
Switched to a plain 'ol random u64. |
- Expose that ID as the environment variable GHOSTTY_SURFACE 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.
|
Going to wait on this until we need it. |
Uh oh!
There was an error while loading. Please reload this page.