Live data from Hacker News

We rewrote the Ghostty GTK application

mitchellh.com

41–50 of 228 posts

Re: We rewrote the Ghostty GTK application

#41
post #14

Earlier quoted context omitted.

I think one of the main points of the article was about how shockingly few memory issues they have encountered. He talks about how great of a fit zig + valgrind is.

Indeed, but I'm curious about the second class of memory correctness issue he mentions: > 2. All other memory issues revolved around C API boundaries. Is this something Rust, or any other language, has the ability to prevent any more than any other language? Or once you introduce a C API boundary is it back to tools like Valgrind?

In general: whenever you call into C, you get all the safety of C, because C code can trivially have memory corruption bugs that corrupt memory "belonging" to Rust as well, inducing undefined behavior across your whole program [0].

In addition, it's often considered permissible for C APIs to exhibit undefined behavior if their API contracts are violated. This means that a bug in Rust code that calls into a C API incorrectly can (indirectly) cause undefined behavior. For this reason, all FFI calls are marked unsafe in Rust.

The typical approach to using C libraries from Rust is to create a "safe wrapper" around the unsafe FFI calls that uses Rust's type system and lifetimes to enforce the safety invariants. Of course it's possible to mess up this wrapper and have accidental undefined behavior, but you're much less likely to do so through a safe wrapper than if you use the unsafe FFI calls directly (or use C or Zig) for a couple reasons:

- Writing the safe wrapper forces you to sit down and think about safety invariants instead of glossing over it.

- Once you're done, the compiler will check the safety invariants for you every time you use the API -- no chance of making a mistake or forgetting to read a comment.

[0]: This could be avoided/mitigated with some kind of lightweight in-process sandboxing (e.g. Intel MPK + seccomp) to prevent C libraries from accessing memory that they don't own or performing syscalls they shouldn't. There's some academic research on this (and I experimented with it myself for a masters thesis project), but it generally requires some (minimal) performance overhead and code changes at language boundaries.

Re: We rewrote the Ghostty GTK application

#42

Earlier quoted context omitted.

> That lead me to think that GTK and the GObject system is opinionated in a way that are not terribly compatible with my own opinions. This might be amusing for me to say but... I also feel this way. I disagree a lot with the Gnome ecosystem's point of view. Funny! Using GTK for Linux was a pragmatic choice. A goal of Ghostty is to be "platform-native" (defined here because there's no such thing on Linux: https://gho…

I like Linux because it gives me the freedom to make my system behave how I want. The GNOME devs seem to think that GNOME should only behave how they want. For example, last time I checked, GNOME required a third-party plugin just to move the clock from the center of the status bar to the side. I'm not at all surprised to see that this mindset extends to GTK.

Can you do that on Windows/mac?

Gnome devs not withstanding, you have access to the source to change it if you want or put up a PR?

Re: We rewrote the Ghostty GTK application

#44

> This has already led to more easily introducing GUI features like a new GTK titlebar tabs option Yes! This is huge, I previously gave up on Ghostty because the title bar wasted so much space on my laptop screen: https://bsky.app/profile/reillywood.bsky.social/post/3lebapf... I found the PR in case anyone else is curious what the new functionality looks like: https://github.com/ghostty-org/ghostty/pull/8166

If it’s not maximized, the space isn’t wasted. The title in the response image looks incredibly crowded. May be ok if several buttons could be removed from the titlebar.

Re: We rewrote the Ghostty GTK application

#45
post #6

> Whatever your feelings are about OOP and memory management, the reality is that if you choose GTK, you're forced into interfacing in some way with the GObject type system. You can't avoid it. In the past this has also been my assessment of GTK. It lead me to decide to take the other path, to never directly use GTK. I appreciate the value in having a unified user interface between applications, but I have always tho…

In my view the primary reason for GTK’s prominence on Linux rides on one thing primarily: it’s got C bindings , and thus it has decent bindings for just about every other language under the sun too. If you’re not trying for anything fancy, these bindings can even be auto-generated. The runner up Qt is much more tightly tied to C++ and Python to its detriment. You really need to meet devs where they’re at instead of i…

Actually the auto generated bindings can be attributed to the gobject system. It's a very interesting system, similar DCOM in Windows.

Too bad it's so poorly documented. It seems to me like advanced technology left over from a dead civilization, that's being handled by cave people.

Re: We rewrote the Ghostty GTK application

#46
post #23

Earlier quoted context omitted.

Rust has safe and reliable GTK bindings. They used gir to auto-generate the error-prone parts of the FFI based on schemas and introspection: https://gtk-rs.org/gir/book/ Rust's bindings fully embrace GTK's refcounting, so there's no mismatch in memory management.

Do you mean gtk-rs ( https://gtk-rs.org/ )? I have done a bit of programming with it. I respect the work behind it, but it is a monumental PITA - truly a mismatch of philosophies and design - and I would a thousand times rather deal with C/C++ correctness demons than attempt it again, unless I had hard requirements for soundness. Even then, if you use gtk-rs you are pulling in 100+ crate dependencies and who knows wh…

I remember it being bad enough for a project I was working on that the engineer working on it switched to relm: https://relm4.org

It is built on top of gtk4-rs, and fairly usable: https://github.com/hackclub/burrow/blob/main/burrow-gtk/src/...

I'm sure the gtk-rs bindings are pretty good, but I do wonder if anyone ran Valgrind on them. When it comes to C interop, Rust feels weirdly less safe just because of the complexity.

Re: We rewrote the Ghostty GTK application

#47

Earlier quoted context omitted.

I like Linux because it gives me the freedom to make my system behave how I want. The GNOME devs seem to think that GNOME should only behave how they want. For example, last time I checked, GNOME required a third-party plugin just to move the clock from the center of the status bar to the side. I'm not at all surprised to see that this mindset extends to GTK.

Can you do that on Windows/mac? Gnome devs not withstanding, you have access to the source to change it if you want or put up a PR?

Being able to make a small change is good when every thing is well defined small parts. You can change the part you want and then use everything else as per normal. If everything is so tightly integrated that you end up having to maintain a fork of a large project, it doesn't work out so well.

I don't know which is true for this particular case, but I'd hazard a guess that it is a much bigger task than it needs to be.

I have seen Gnome devs talk of removing features because people were using them the wrong way. Not that people weren't using the features at all, just not for the purpose for which they were written. Experiences like that make me think that pull requests wouldn't get you very far either.

Re: We rewrote the Ghostty GTK application

#48

Earlier quoted context omitted.

In my view the primary reason for GTK’s prominence on Linux rides on one thing primarily: it’s got C bindings , and thus it has decent bindings for just about every other language under the sun too. If you’re not trying for anything fancy, these bindings can even be auto-generated. The runner up Qt is much more tightly tied to C++ and Python to its detriment. You really need to meet devs where they’re at instead of i…

Actually the auto generated bindings can be attributed to the gobject system. It's a very interesting system, similar DCOM in Windows. Too bad it's so poorly documented. It seems to me like advanced technology left over from a dead civilization, that's being handled by cave people.

GStreamer: https://gstreamer.freedesktop.org/ is written in GObject which enabled some great tooling like gst-inspect-1.0: https://gstreamer.freedesktop.org/documentation/tools/gst-in...

Re: We rewrote the Ghostty GTK application

#50

“Ghostty is cross platform…” but not on windows :D “App XYZ is mobile ready…” but not on Android. Same vibe

Windows is becoming less and less of a platform every year

Not saying you are wrong, but this is akin to “this is the year of the Linux Desktop”.

You probably don’t have this telemetry but have you thought about how having window support helps Zig adoption?

Anecdotal, at day job, we started to use Zig build system to target Windows because that’s where the customers are.

Post reply on HN