feat(macos): foundation of the macOS app ported from Swift to Rust

Phase 9, MA1: crates/ghostty-macos (AppKit via objc2; empty stub on
non-Apple targets) ports the foundation of Ghostty 1.3.1's Swift macOS
app (ghostty/macos): main, AppDelegate (+Ghostty) with lifecycle, dock
menu, open-file, notifications, shortcut sync and quit/reopen paths;
MainMenu.xib as generated menu tables built into NSMenus; the
Ghostty.App/Config/Surface wrappers driving libghostty in-process via
ghostty-lib; the generic helpers; scripts/macos-bundle.sh to assemble
Ghostty.app (dry-run on Linux). Feature areas are stubbed for MA2-MA5.
Design and type mapping: docs/rewrite/notes/macos-app-design.md
(App Intents is a Swift-only framework and cannot be ported).

Compile-checked only (no macOS here): just check-macos passes for
aarch64/x86_64-apple-darwin with -D warnings; 125 platform-independent
tests run on Linux.

Test Plan:
- just check-macos
- cargo test -p ghostty-macos
This commit is contained in:
ddidderr committed 2026-10-12 19:25:44 +02:00
1 parent feacba2d69
commit 4861015105
112 files changed
+18438 -2

No files matched your search

@@ -0,0 +1,60 @@
//! The frame math of `NSWindow.constrainToScreen()`
//! (`Helpers/Extensions/NSWindow+Extension.swift`).
use crate::helpers::geometry::Rect;
/// The frame `window_frame` constrained to `visible_frame` in size and
/// origin, or `None` if it already is (no `setFrame` needed).
#[must_use]
pub fn constrained_frame(window_frame: Rect, visible_frame: Rect) -> Option<Rect> {
let mut f = window_frame;
f.size.width = f.size.width.min(visible_frame.size.width);
f.size.height = f.size.height.min(visible_frame.size.height);
f.origin.x = visible_frame
.min_x()
.max(f.origin.x.min(visible_frame.max_x() - f.width()));
f.origin.y = visible_frame
.min_y()
.max(f.origin.y.min(visible_frame.max_y() - f.height()));
(f != window_frame).then_some(f)
}
/// `cgWindowId`: the window number if it has a window device (> 0).
#[must_use]
pub fn cg_window_id(window_number: isize) -> Option<u32> {
if window_number > 0 {
u32::try_from(window_number).ok()
} else {
None
}
}
#[cfg(test)]
mod tests {
use super::*;
const V: Rect = Rect::new(0.0, 0.0, 1000.0, 800.0);
#[test]
fn already_inside() {
assert!(constrained_frame(Rect::new(10.0, 10.0, 200.0, 200.0), V).is_none());
}
#[test]
fn shrinks_and_moves() {
let f = constrained_frame(Rect::new(-50.0, 700.0, 2000.0, 100.0), V).unwrap();
assert_eq!(f, Rect::new(0.0, 700.0, 1000.0, 100.0));
let f = constrained_frame(Rect::new(900.0, 750.0, 200.0, 200.0), V).unwrap();
assert_eq!(f, Rect::new(800.0, 600.0, 200.0, 200.0));
}
#[test]
fn window_ids() {
assert_eq!(cg_window_id(0), None);
assert_eq!(cg_window_id(-1), None);
assert_eq!(cg_window_id(42), Some(42));
}
}