ghostty/src/apprt.zig
Mitchell Hashimoto 68a9110d8e build: make glfw opt-in on all platforms, default to GTK on Linux
The GLFW build has grown farther and farther in feature parity with GTK
on Linux. And on macOS, the GLFW build has been unstable (crashes) for
months.

I still find the GLFW build useful for testing some core terminal work,
but it is increasingly user-hostile in case someone just downloads the
project and does a `zig build`.

I keep GLFW as up to date as I can, but the features that are missing
are due to fundamental limitations:

  - GLFW has no tabs, splits, etc. because it has no UI elements.
    I am not interested in painting UI widgets from scratch.

  - GLFW cannot support keyboard layouts robustly because it has no
    hooks to detect keyboard layouts or functions to get keymaps.

  - GLFW cannot support the Kitty keyboard protocol because the
    key/char API is too high level and it provides no low-level
    alternatives.

  - GLFW crashes on macOS under certain scenarios (this is my problem).
    I'm not interested in fixing it because the AppKit-based build
    is highly recommended.

To build or run the GLFW build you must now explicitly pass in
`-Dapp-runtime=glfw` to `zig build`.
2023-08-17 16:27:03 -07:00

69 lines
2.6 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");
pub usingnamespace @import("apprt/structs.zig");
pub const glfw = @import("apprt/glfw.zig");
pub const gtk = @import("apprt/gtk.zig");
pub const browser = @import("apprt/browser.zig");
pub const embedded = @import("apprt/embedded.zig");
pub const surface = @import("apprt/surface.zig");
/// 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 => @compileError("exe with no runtime not allowed"),
.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.zig.CrossTarget) Runtime {
// The Linux default is GTK because it is full featured.
if (target.isLinux()) return .gtk;
// 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 {
@import("std").testing.refAllDecls(@This());
}