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:
1 parent
9c3eeeba50
commit
3266108c10
42 files changed
+9301
-179
No files matched your search
@@ -1,13 +1,31 @@
|
||||
//! `+new-window` (ZIG/src/cli/new_window.zig).
|
||||
//!
|
||||
//! DEFERRED: sending the IPC needs the GTK app (`apprt.App.performIpc`).
|
||||
//! The option parsing (including the manual `+new-window` argument gathering
|
||||
//! hook) is ported; running the action reports that it is not available.
|
||||
//! Sending the IPC needs the app runtime (`apprt.App.performIpc`); the root
|
||||
//! binary registers it with [`set_ipc_handler`] so this crate does not
|
||||
//! depend on GTK.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use ghostty_apprt::ipc;
|
||||
use ghostty_config::cli_args::{ArgError, ArgIter, CliTarget};
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
/// The runtime's IPC entrypoint (`apprt.App.performIpc`). `Ok(true)` means
|
||||
/// the action was performed; `Err` carries an error message (use
|
||||
/// [`IPC_FAILED`] when the runtime already printed a specific message).
|
||||
pub type IpcHandler = fn(&ipc::Target, &ipc::Action) -> Result<bool, String>;
|
||||
|
||||
/// Error string for `error.IPCFailed`: the runtime already reported it.
|
||||
pub const IPC_FAILED: &str = "IPCFailed";
|
||||
|
||||
static IPC_HANDLER: OnceLock<IpcHandler> = OnceLock::new();
|
||||
|
||||
/// Register the runtime IPC handler. Only the first call has an effect.
|
||||
pub fn set_ipc_handler(f: IpcHandler) {
|
||||
let _ = IPC_HANDLER.set(f);
|
||||
}
|
||||
|
||||
/// Options of `+new-window`.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Options {
|
||||
@@ -178,10 +196,42 @@ pub fn run(args: &[String]) -> Result<u8, Error> {
|
||||
.insert(0, format!("--working-directory={}", wd.to_string_lossy()));
|
||||
}
|
||||
|
||||
// TODO(integration): send the `new_window` IPC (class: `opts.class` or
|
||||
// auto-detected, arguments: `opts.arguments`) via the GTK apprt's
|
||||
// `performIpc`.
|
||||
Err(Error::NotYetAvailable("new-window"))
|
||||
let target = match opts.class {
|
||||
Some(class) => ipc::Target::Class(class),
|
||||
None => ipc::Target::Detect,
|
||||
};
|
||||
let action = ipc::Action::NewWindow(ipc::NewWindow {
|
||||
arguments: if opts.arguments.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(opts.arguments)
|
||||
},
|
||||
});
|
||||
|
||||
// Without a registered runtime this behaves like `apprt.none`, whose
|
||||
// performIpc always returns false.
|
||||
let performed = match IPC_HANDLER.get() {
|
||||
Some(handler) => match handler(&target, &action) {
|
||||
Ok(v) => v,
|
||||
Err(e) if e == IPC_FAILED => {
|
||||
// The apprt should have printed a more specific error message
|
||||
// already.
|
||||
return Ok(1);
|
||||
}
|
||||
Err(e) => {
|
||||
eprint!("Sending the IPC failed: {e}");
|
||||
return Ok(1);
|
||||
}
|
||||
},
|
||||
None => false,
|
||||
};
|
||||
if performed {
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
// If we get here, the platform is not supported.
|
||||
eprintln!("+new-window is not supported on this platform.");
|
||||
Ok(1)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -236,4 +286,18 @@ mod tests {
|
||||
let o = parse_str("--help");
|
||||
assert_eq!(vec!["--help"], o.arguments);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ipc_handler_registration_is_once() {
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn h(_: &ipc::Target, _: &ipc::Action) -> Result<bool, String> {
|
||||
Ok(true)
|
||||
}
|
||||
set_ipc_handler(h);
|
||||
let r = IPC_HANDLER.get().unwrap()(
|
||||
&ipc::Target::Detect,
|
||||
&ipc::Action::NewWindow(ipc::NewWindow { arguments: None }),
|
||||
);
|
||||
assert_eq!(r, Ok(true));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user