feat(apprt-gtk): port the GTK4/libadwaita app runtime

Ports ZIG/src/apprt/gtk into ghostty-apprt-gtk: every GObject class
(application, window, tab, split tree, surface + scrolled window,
child-exited banner, search/key-state/resize overlays, command palette,
global shortcuts, all dialogs, config wrapper) as glib subclasses with
the same GType names, properties, signals and template children; GDK
key translation; X11 and Wayland window-protocol helpers (blur, CSD,
quick terminal via gtk4-layer-shell); single-instance D-Bus IPC;
gsettings; cgroup scope creation.

build.rs compiles Ghostty's blueprints with blueprint-compiler and
bundles UI, CSS and icons into a gresource, as Ghostty's build does.

The core is not ported yet, so the crate defines the boundary it needs
in src/core.rs (CoreApp, CoreSurface, RtApp, RtSurface, Waker); the
spec is in docs/rewrite/notes/ghostty-apprt-gtk.md. ghostty-core will
implement these traits (the crate no longer depends on core to avoid a
cycle). examples/demo.rs runs the app with a dummy core that clears the
GLArea; it launches on Wayland without GTK criticals.

Stubs/open items: toggle_visibility, float_window, secure_input and
close_all_windows return false; inspector is a no-op; X11/Wayland
protocol code is untested against real compositors; gtk4-rs doesn't
expose the GLArea framebuffer id, so the renderer must query it.

Also registers ghostty-apprt and ghostty-cli in workspace.dependencies.

Test Plan:
- cargo test -p ghostty-apprt-gtk (36 tests)
- DEMO_QUIT_AFTER_MS=3000 cargo run -p ghostty-apprt-gtk --example demo
This commit is contained in:
ddidderr committed 2026-10-11 22:57:15 +02:00
1 parent 72434a1255
commit 88cc13871c
80 files changed
+17271 -4

No files matched your search

@@ -0,0 +1,152 @@
//! Port of apprt/gtk/class/close_confirmation_dialog.zig
//! (`GhosttyCloseConfirmationDialog`). Property `target`; signals
//! `close-request` and `cancel`.
use adw::prelude::*;
use adw::subclass::prelude::*;
use ghostty_os::i18n::tr;
use gtk::glib;
use gtk::glib::subclass::Signal;
use std::cell::Cell;
use std::sync::OnceLock;
use super::dialog::{Dialog, DialogImpl};
/// The target of a close dialog (`GhosttyCloseConfirmationDialogTarget`).
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, glib::Enum)]
#[enum_type(name = "GhosttyCloseConfirmationDialogTarget")]
#[repr(i32)]
pub enum Target {
#[default]
App,
Tab,
Window,
Surface,
}
impl Target {
pub fn title(self) -> String {
match self {
Target::App => tr("Quit Ghostty?"),
Target::Tab => tr("Close Tab?"),
Target::Window => tr("Close Window?"),
Target::Surface => tr("Close Split?"),
}
}
pub fn body(self) -> String {
match self {
Target::App => tr("All terminal sessions will be terminated."),
Target::Tab => tr("All terminal sessions in this tab will be terminated."),
Target::Window => tr("All terminal sessions in this window will be terminated."),
Target::Surface => {
tr("The currently running process in this split will be terminated.")
}
}
}
}
mod imp {
use super::{
AdwAlertDialogImpl, AdwDialogImpl, Cell, Dialog, DialogImpl, ObjectImpl, ObjectSubclass,
OnceLock, Signal, Target, WidgetImpl,
};
use gtk::glib;
use gtk::glib::prelude::*;
use gtk::subclass::prelude::*;
#[derive(Default, glib::Properties, gtk::CompositeTemplate)]
#[properties(wrapper_type = super::CloseConfirmationDialog)]
#[template(resource = "/com/mitchellh/ghostty/ui/1.2/close-confirmation-dialog.ui")]
pub struct CloseConfirmationDialog {
#[property(get, set, builder(Target::App))]
pub target: Cell<Target>,
}
#[glib::object_subclass]
impl ObjectSubclass for CloseConfirmationDialog {
const NAME: &'static str = "GhosttyCloseConfirmationDialog";
type Type = super::CloseConfirmationDialog;
type ParentType = Dialog;
fn class_init(klass: &mut Self::Class) {
Dialog::ensure_type();
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
#[glib::derived_properties]
impl ObjectImpl for CloseConfirmationDialog {
fn signals() -> &'static [Signal] {
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
SIGNALS.get_or_init(|| {
vec![
Signal::builder("close-request").build(),
Signal::builder("cancel").build(),
]
})
}
fn dispose(&self) {
self.dispose_template();
}
}
impl WidgetImpl for CloseConfirmationDialog {}
impl AdwDialogImpl for CloseConfirmationDialog {}
impl AdwAlertDialogImpl for CloseConfirmationDialog {
fn response(&self, response: &str) {
let name = if response == "close" {
"close-request"
} else {
"cancel"
};
self.obj().emit_by_name::<()>(name, &[]);
}
}
impl DialogImpl for CloseConfirmationDialog {}
}
glib::wrapper! {
pub struct CloseConfirmationDialog(ObjectSubclass<imp::CloseConfirmationDialog>)
@extends Dialog, adw::AlertDialog, adw::Dialog, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::ShortcutManager;
}
impl CloseConfirmationDialog {
pub fn new(target: Target) -> Self {
crate::register_resources();
glib::Object::builder().property("target", target).build()
}
/// Sets the heading/body from the target and presents over `parent`.
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
let target = self.target();
self.set_heading(Some(&target.title()));
self.set_body(&target.body());
self.upcast_ref::<Dialog>().present(parent);
}
pub fn close(&self) {
self.upcast_ref::<Dialog>().close();
}
pub fn connect_close_request<F: Fn(&Self) + 'static>(&self, f: F) -> glib::SignalHandlerId {
self.connect_closure(
"close-request",
false,
glib::closure_local!(move |obj: &Self| f(obj)),
)
}
pub fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> glib::SignalHandlerId {
self.connect_closure(
"cancel",
false,
glib::closure_local!(move |obj: &Self| f(obj)),
)
}
}