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 6675db1eeb
commit 69d823cbc7
80 files changed
+17271 -4

No files matched your search

+114
View File
@@ -0,0 +1,114 @@
//! D-Bus helper for IPC (port of `apprt/gtk/ipc/DBus.zig`).
use ghostty_apprt::ipc::{Error, Target};
use gtk::gio;
use gtk::glib;
use gtk::prelude::*;
/// A pending `org.gtk.Actions.Activate` call.
pub struct DBus {
dbus: gio::DBusConnection,
bus_name: String,
object_path: String,
action: String,
parameters: Vec<glib::Variant>,
}
/// Bus name and object path for a target.
pub fn bus_name_and_path(target: &Target) -> (String, String) {
match target {
// Force the usage of the class specified on the CLI to determine the
// bus name and object path.
Target::Class(class) => (
class.clone(),
format!("/{class}").replace('.', "/").replace('-', "_"),
),
Target::Detect => (
crate::APPLICATION_ID.to_owned(),
crate::OBJECT_PATH.to_owned(),
),
}
}
impl DBus {
pub fn new(target: &Target, action: &str) -> Result<Self, Error> {
let (bus_name, object_path) = bus_name_and_path(target);
if !gio::Application::id_is_valid(&bus_name) {
eprintln!("D-Bus bus name is not valid: {bus_name}");
return Err(Error::IpcFailed);
}
if !glib::Variant::is_object_path(&object_path) {
eprintln!("D-Bus object path is not valid: {object_path}");
return Err(Error::IpcFailed);
}
// Get a connection to the DBus session bus.
let dbus =
gio::bus_get_sync(gio::BusType::Session, gio::Cancellable::NONE).map_err(|e| {
eprintln!("Unable to establish connection to D-Bus session bus: {e}");
Error::IpcFailed
})?;
Ok(Self {
dbus,
bus_name,
object_path,
action: action.to_owned(),
parameters: Vec::new(),
})
}
pub fn add_parameter(&mut self, variant: &glib::Variant) {
self.parameters.push(variant.clone());
}
/// The `(sava{sv})` payload (action, parameters, platform data).
pub fn payload(&self) -> glib::Variant {
// We have no platform data.
let platform: std::collections::HashMap<String, glib::Variant> =
std::collections::HashMap::new();
(self.action.clone(), self.parameters.clone(), platform).to_variant()
}
pub fn send(&self) -> Result<(), Error> {
let payload = self.payload();
self.dbus
.call_sync(
Some(&self.bus_name),
&self.object_path,
"org.gtk.Actions",
"Activate",
Some(&payload),
None, // we don't do anything with the return value
gio::DBusCallFlags::NONE,
-1,
gio::Cancellable::NONE,
)
.map(|_| ())
.map_err(|e| {
eprintln!("D-Bus method call returned an error err={e}");
Error::IpcFailed
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn class_bus_name_and_path() {
let (n, p) = bus_name_and_path(&Target::Class("com.example.my-app".into()));
assert_eq!(n, "com.example.my-app");
assert_eq!(p, "/com/example/my_app");
}
#[test]
fn detect_bus_name_and_path() {
let (n, p) = bus_name_and_path(&Target::Detect);
assert_eq!(n, crate::APPLICATION_ID);
assert_eq!(p, crate::OBJECT_PATH);
}
}
+16
View File
@@ -0,0 +1,16 @@
//! IPC to a running instance over D-Bus (`apprt/gtk/ipc/*.zig` and
//! `App.performIpc`).
pub mod dbus;
pub mod new_window;
use ghostty_apprt::ipc::{Action, Error, Target};
/// Send the given IPC to a running Ghostty. Returns `Ok(true)` if the action
/// was performed. This is a free function: it's called from a CLI process
/// without a full-featured app (`App.performIpc`).
pub fn perform_ipc(target: &Target, action: &Action) -> Result<bool, Error> {
match action {
Action::NewWindow(v) => new_window::new_window(target, v),
}
}
@@ -0,0 +1,43 @@
//! `+new-window` IPC (port of `apprt/gtk/ipc/new_window.zig`).
//!
//! Use a D-Bus method call to open a new window on GTK. See
//! <https://wiki.gnome.org/Projects/GLib/GApplication/DBusAPI>.
//!
//! `ghostty +new-window` is equivalent to (release build):
//!
//! ```text
//! gdbus call --session --dest com.mitchellh.ghostty --object-path /com/mitchellh/ghostty --method org.gtk.Actions.Activate new-window [] []
//! ```
//!
//! `ghostty +new-window -e echo hello` is equivalent to:
//!
//! ```text
//! gdbus call --session --dest com.mitchellh.ghostty --object-path /com/mitchellh/ghostty --method org.gtk.Actions.Activate new-window-command '[<@as ["-e" "echo" "hello"]>]' []
//! ```
use ghostty_apprt::ipc::{Error, NewWindow, Target};
use gtk::prelude::*;
use super::dbus::DBus;
pub fn new_window(target: &Target, value: &NewWindow) -> Result<bool, Error> {
let mut dbus = DBus::new(
target,
if value.arguments.is_none() {
"new-window"
} else {
"new-window-command"
},
)?;
if let Some(arguments) = &value.arguments {
// If any arguments were specified on the command line, the first
// parameter is an array of strings that contain the arguments. They
// will be sent to the main Ghostty instance and interpreted as CLI
// arguments.
dbus.add_parameter(&arguments.to_variant());
}
dbus.send()?;
Ok(true)
}