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
77 lines
2.0 KiB
Rust
77 lines
2.0 KiB
Rust
//! Typed access to `GtkSettings` (port of `apprt/gtk/gsettings.zig`).
|
|
|
|
use gtk::glib;
|
|
use gtk::prelude::*;
|
|
|
|
/// Settings keys we read (the GTK property names).
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum Key {
|
|
GtkEnablePrimaryPaste,
|
|
GtkXftDpi,
|
|
GtkFontName,
|
|
}
|
|
|
|
impl Key {
|
|
/// The GTK property name.
|
|
pub fn name(self) -> &'static str {
|
|
match self {
|
|
Key::GtkEnablePrimaryPaste => "gtk-enable-primary-paste",
|
|
Key::GtkXftDpi => "gtk-xft-dpi",
|
|
Key::GtkFontName => "gtk-font-name",
|
|
}
|
|
}
|
|
|
|
/// Whether the value type needs heap allocation (strings).
|
|
pub fn requires_allocation(self) -> bool {
|
|
matches!(self, Key::GtkFontName)
|
|
}
|
|
}
|
|
|
|
fn settings() -> Option<gtk::Settings> {
|
|
gtk::Settings::default()
|
|
}
|
|
|
|
/// Get a boolean setting (`gtk-enable-primary-paste`).
|
|
pub fn get_bool(key: Key) -> Option<bool> {
|
|
debug_assert_eq!(key, Key::GtkEnablePrimaryPaste);
|
|
let s = settings()?;
|
|
Some(s.property::<bool>(key.name()))
|
|
}
|
|
|
|
/// Get an integer setting (`gtk-xft-dpi`).
|
|
pub fn get_int(key: Key) -> Option<i32> {
|
|
debug_assert_eq!(key, Key::GtkXftDpi);
|
|
let s = settings()?;
|
|
Some(s.property::<i32>(key.name()))
|
|
}
|
|
|
|
/// Get a string setting (`gtk-font-name`). None if unset.
|
|
pub fn get_string(key: Key) -> Option<String> {
|
|
debug_assert_eq!(key, Key::GtkFontName);
|
|
let s = settings()?;
|
|
s.property::<Option<glib::GString>>(key.name())
|
|
.map(Into::into)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn key_requires_allocation() {
|
|
assert!(!Key::GtkEnablePrimaryPaste.requires_allocation());
|
|
assert!(!Key::GtkXftDpi.requires_allocation());
|
|
assert!(Key::GtkFontName.requires_allocation());
|
|
}
|
|
|
|
#[test]
|
|
fn key_names() {
|
|
assert_eq!(
|
|
Key::GtkEnablePrimaryPaste.name(),
|
|
"gtk-enable-primary-paste"
|
|
);
|
|
assert_eq!(Key::GtkXftDpi.name(), "gtk-xft-dpi");
|
|
assert_eq!(Key::GtkFontName.name(), "gtk-font-name");
|
|
}
|
|
}
|