mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00

First, this commit modifies libghostty to use a single unified action dispatch system based on a tagged union versus the one-off callback system that was previously in place. This change simplifies the code on both the core and consumer sides of the library. Importantly, as we introduce new actions, we can now maintain ABI compatibility so long as our union size does not change (something I don't promise yet). Second, this moves a lot more of the functions call on a surface into the action system. This affects all apprts and continues the previous work of introducing a more unified API for optional surface features.
91 lines
3.3 KiB
Zig
91 lines
3.3 KiB
Zig
//! "apprt" is the "application runtime" package. This abstracts the
|
|
//! application runtime and lifecycle management such as creating windows,
|
|
//! getting user input (mouse/keyboard), etc.
|
|
//!
|
|
//! This enables compile-time interfaces to be built to swap out the underlying
|
|
//! application runtime. For example: glfw, pure macOS Cocoa, GTK+, browser, etc.
|
|
//!
|
|
//! The goal is to have different implementations share as much of the core
|
|
//! logic as possible, and to only reach out to platform-specific implementation
|
|
//! code when absolutely necessary.
|
|
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const build_config = @import("build_config.zig");
|
|
|
|
const structs = @import("apprt/structs.zig");
|
|
|
|
pub const action = @import("apprt/action.zig");
|
|
pub const glfw = @import("apprt/glfw.zig");
|
|
pub const gtk = @import("apprt/gtk.zig");
|
|
pub const none = @import("apprt/none.zig");
|
|
pub const browser = @import("apprt/browser.zig");
|
|
pub const embedded = @import("apprt/embedded.zig");
|
|
pub const surface = @import("apprt/surface.zig");
|
|
|
|
pub const Action = action.Action;
|
|
pub const Target = action.Target;
|
|
|
|
pub const ContentScale = structs.ContentScale;
|
|
pub const Clipboard = structs.Clipboard;
|
|
pub const ClipboardRequest = structs.ClipboardRequest;
|
|
pub const ClipboardRequestType = structs.ClipboardRequestType;
|
|
pub const ColorScheme = structs.ColorScheme;
|
|
pub const CursorPos = structs.CursorPos;
|
|
pub const IMEPos = structs.IMEPos;
|
|
pub const Selection = structs.Selection;
|
|
pub const SurfaceSize = structs.SurfaceSize;
|
|
|
|
/// The implementation to use for the app runtime. This is comptime chosen
|
|
/// so that every build has exactly one application runtime implementation.
|
|
/// Note: it is very rare to use Runtime directly; most usage will use
|
|
/// Window or something.
|
|
pub const runtime = switch (build_config.artifact) {
|
|
.exe => switch (build_config.app_runtime) {
|
|
.none => none,
|
|
.glfw => glfw,
|
|
.gtk => gtk,
|
|
},
|
|
.lib => embedded,
|
|
.wasm_module => browser,
|
|
};
|
|
|
|
pub const App = runtime.App;
|
|
pub const Surface = runtime.Surface;
|
|
|
|
/// Runtime is the runtime to use for Ghostty. All runtimes do not provide
|
|
/// equivalent feature sets. For example, GTK offers tabbing and more features
|
|
/// that glfw does not provide. However, glfw may require many less
|
|
/// dependencies.
|
|
pub const Runtime = enum {
|
|
/// Will not produce an executable at all when `zig build` is called.
|
|
/// This is only useful if you're only interested in the lib only (macOS).
|
|
none,
|
|
|
|
/// Glfw-backed. Very simple. Glfw is statically linked. Tabbing and
|
|
/// other rich windowing features are not supported.
|
|
glfw,
|
|
|
|
/// GTK-backed. Rich windowed application. GTK is dynamically linked.
|
|
gtk,
|
|
|
|
pub fn default(target: std.Target) Runtime {
|
|
// The Linux default is GTK because it is full featured.
|
|
if (target.os.tag == .linux) return .gtk;
|
|
|
|
// Windows we currently only support glfw
|
|
if (target.os.tag == .windows) return .glfw;
|
|
|
|
// Otherwise, we do NONE so we don't create an exe. The GLFW
|
|
// build is opt-in because it is missing so many features compared
|
|
// to the other builds that are impossible due to the GLFW interface.
|
|
return .none;
|
|
}
|
|
};
|
|
|
|
test {
|
|
_ = Runtime;
|
|
_ = runtime;
|
|
_ = action;
|
|
_ = structs;
|
|
}
|