feat(core): port App/Surface and wire up the runnable ghostty binary

This is the integration step that turns the ported crates into a working
terminal: `cargo run` now opens a GTK window running the user's shell.

ghostty-core ports App.zig, Surface.zig (split into keyboard, mouse,
binding, clipboard and config submodules), surface_mouse.zig and
global.zig, and implements the runtime traits. perform_binding_action
handles every binding action.

Cross-crate integration:
- The core<->runtime traits (CoreApp, CoreSurface, RtApp, RtSurface,
  Waker) move from apprt-gtk into ghostty_apprt::runtime_api so the core
  stays runtime-agnostic; Scrollbar/RendererHealth stand-ins are replaced
  by the real terminal/renderer types.
- termio now uses ghostty_renderer::state::{State, SharedState}; the
  renderer calls kitty_update; image-storage-limit is applied at init
  and on config change.
- The search thread locks the terminal through a TerminalLock trait so
  it can share the render state mutex; termio's Wakeup gained a hook to
  wake the renderer thread.
- apprt-gtk: GL proc addresses are resolved through libepoxy's
  epoxy_glFoo pointer variables (plain glFoo symbols resolved to null),
  default DPI fixed to 96, libadwaita version read without GTK init so
  --version works headless.

The root binary dispatches +actions to ghostty-cli (list-fonts,
show-face and new-window are now wired) and otherwise runs the GTK app
with the real core.

Verified at runtime on Wayland and X11: shell prompt and colored output
render, child exit closes the window cleanly. Not yet verified: keyboard
and mouse input, clipboard, IME, tabs and splits (no key injection was
possible in this environment). GHOSTTY_DEBUG_SCREENSHOT=<png> dumps the
renderer's last frame for headless checks.

Test Plan:
- cargo test --workspace (2890 passed)
- cargo clippy --workspace --all-targets -- -D warnings
- GSETTINGS_BACKEND=memory GHOSTTY_RESOURCES_DIR=/usr/share/ghostty \
  cargo run
This commit is contained in:
ddidderr committed 2026-10-12 01:33:44 +02:00
1 parent e256c42e53
commit ad76ae2301
42 files changed
+9301 -179

No files matched your search

+105 -2
View File
@@ -1,3 +1,106 @@
fn main() {
println!("Hello, world!");
//! The main entrypoint for the `ghostty` application (port of
//! `main_ghostty.zig` + `build_config.zig`).
//!
//! If the command line contains a `+action` it is dispatched to
//! `ghostty-cli`; otherwise the configuration is loaded by the GTK runtime
//! and the terminal application is run with the real core.
use std::process::ExitCode;
use std::rc::Rc;
use ghostty_apprt::ipc;
use ghostty_apprt_gtk::{adw_version, gtk_version};
use ghostty_cli::build_info::{self, BuildInfo, Version};
use ghostty_core::global::{self, InitOptions};
fn main() -> ExitCode {
let args: Vec<String> = std::env::args().collect();
// We first start by initializing our global state. This sets up
// process-level state we need to run the terminal. We detect whether a
// CLI action was requested so logging can be silenced for it.
let action_requested = !matches!(ghostty_cli::ghostty::detect(&args), Ok(None));
global::init(InitOptions {
action: action_requested,
});
build_info::set(build_info());
// Execute our action if we have one.
if action_requested {
ghostty_cli::new_window::set_ipc_handler(new_window_ipc);
if let Some(code) = ghostty_cli::run_from_args(&args) {
return ExitCode::from(code);
}
}
if cfg!(debug_assertions) {
log::warn!("This is a debug build. Performance will be very poor.");
log::warn!("You should only use a debug build for developing Ghostty.");
log::warn!("Otherwise, please rebuild in a release mode.");
}
run_app()
}
/// Create the core app and the GTK runtime and run the event loop.
fn run_app() -> ExitCode {
// The waker lets core threads (renderer, IO) wake the GTK main loop.
let waker = ghostty_apprt_gtk::app::waker();
// Create our app state
let core = match ghostty_core::App::new(waker) {
Ok(core) => Rc::new(core),
Err(err) => {
log::error!("failed to create the app err={err}");
return ExitCode::FAILURE;
}
};
// Create our runtime app
let app = ghostty_apprt_gtk::app::App::new(core);
// Run the GUI event loop
let result = app.run();
app.terminate();
match result {
Ok(()) => ExitCode::SUCCESS,
Err(err) => {
log::error!("app runtime failed err={err:?}");
ExitCode::FAILURE
}
}
}
/// `+new-window`: send the IPC through the GTK runtime.
fn new_window_ipc(target: &ipc::Target, action: &ipc::Action) -> Result<bool, String> {
match ghostty_apprt_gtk::app::App::perform_ipc(target, action) {
Ok(v) => Ok(v),
Err(ipc::Error::IpcFailed) => Err(ghostty_cli::new_window::IPC_FAILED.to_owned()),
}
}
/// Build information for `+version` (Zig: `build_config.zig`).
fn build_info() -> BuildInfo {
let version = |(major, minor, micro): (u32, u32, u32)| Version {
major,
minor,
micro,
};
let gtk = gtk_version::get_runtime_version();
let adw = adw_version::get_runtime_version();
BuildInfo {
gtk_build: Some(Version {
major: 4,
minor: 14,
micro: 0,
}),
gtk_runtime: Some(version((gtk.0, gtk.1, gtk.2))),
adw_build: Some(Version {
major: 1,
minor: 5,
micro: 0,
}),
adw_runtime: Some(version((adw.0, adw.1, adw.2))),
..BuildInfo::default()
}
}