From 6e1d6f3afe089b2ccfb9264d4719f0f543978479 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 6 Sep 2025 07:09:05 -0700 Subject: [PATCH 1/3] config: probable cli should return false on macOS for desktop launch Fixes #8542 The comment explains why this is needed. --- src/config/Config.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/config/Config.zig b/src/config/Config.zig index 221a7cf93..3ef39d87c 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -4535,6 +4535,13 @@ fn probableCliEnvironment() bool { // its not a real supported target and GTK via WSL2 assuming // single instance is probably fine. .windows => return false, + + // On macOS, we don't want to detect `open` calls as CLI envs. + // Our desktop detection on macOS is very accurate due to how + // processes are launched on macOS, so if we detect we're launched + // from the app bundle then we're not in a CLI environment. + .macos => if (internal_os.launchedFromDesktop()) return false, + else => {}, } From 6324f2b3d8e91ac2c3fd737f4546c785d666db57 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 6 Sep 2025 07:16:50 -0700 Subject: [PATCH 2/3] macOS: ghostty launched via CLI should come to front This fixes an issue I noticed where manually launching the `ghostty` binary in the app bundle via the CLI would open the app but not create a window or bring it to the front. --- macos/Sources/App/macOS/AppDelegate.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index f8cf95de2..558658b89 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -259,8 +259,16 @@ class AppDelegate: NSObject, // Setup signal handlers setupSignals() - // If we launched via zig run then we need to force foreground. - if Ghostty.launchSource == .zig_run { + switch Ghostty.launchSource { + case .app: + // Don't have to do anything. + break + + case .zig_run, .cli: + // Part of launch services (clicking an app, using `open`, etc.) activates + // the application and brings it to the front. When using the CLI we don't + // get this behavior, so we have to do it manually. + // This never gets called until we click the dock icon. This forces it // activate immediately. applicationDidBecomeActive(.init(name: NSApplication.didBecomeActiveNotification)) From 113e89b389505ade3687c63b1de31a7647cead70 Mon Sep 17 00:00:00 2001 From: Jacob Sandlund Date: Sat, 6 Sep 2025 15:06:00 -0400 Subject: [PATCH 3/3] [benchmarks] Use std.mem.doNotOptimizeAway to avoid data collisions --- src/benchmark/CodepointWidth.zig | 20 ++++---------------- src/benchmark/GraphemeBreak.zig | 3 +-- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/benchmark/CodepointWidth.zig b/src/benchmark/CodepointWidth.zig index e9207aed5..406603ceb 100644 --- a/src/benchmark/CodepointWidth.zig +++ b/src/benchmark/CodepointWidth.zig @@ -121,11 +121,7 @@ fn stepWcwidth(ptr: *anyopaque) Benchmark.Error!void { const cp_, const consumed = d.next(c); assert(consumed); if (cp_) |cp| { - const width = wcwidth(cp); - - // Write the width to the buffer to avoid it being compiled - // away - buf[0] = @intCast(width); + std.mem.doNotOptimizeAway(wcwidth(cp)); } } } @@ -151,14 +147,10 @@ fn stepTable(ptr: *anyopaque) Benchmark.Error!void { if (cp_) |cp| { // This is the same trick we do in terminal.zig so we // keep it here. - const width = if (cp <= 0xFF) + std.mem.doNotOptimizeAway(if (cp <= 0xFF) 1 else - table.get(@intCast(cp)).width; - - // Write the width to the buffer to avoid it being compiled - // away - buf[0] = @intCast(width); + table.get(@intCast(cp)).width); } } } @@ -182,11 +174,7 @@ fn stepSimd(ptr: *anyopaque) Benchmark.Error!void { const cp_, const consumed = d.next(c); assert(consumed); if (cp_) |cp| { - const width = simd.codepointWidth(cp); - - // Write the width to the buffer to avoid it being compiled - // away - buf[0] = @intCast(width); + std.mem.doNotOptimizeAway(simd.codepointWidth(cp)); } } } diff --git a/src/benchmark/GraphemeBreak.zig b/src/benchmark/GraphemeBreak.zig index 57effebe4..86661f985 100644 --- a/src/benchmark/GraphemeBreak.zig +++ b/src/benchmark/GraphemeBreak.zig @@ -126,8 +126,7 @@ fn stepTable(ptr: *anyopaque) Benchmark.Error!void { const cp_, const consumed = d.next(c); assert(consumed); if (cp_) |cp2| { - const v = unicode.graphemeBreak(cp1, @intCast(cp2), &state); - buf[0] = @intCast(@intFromBool(v)); + std.mem.doNotOptimizeAway(unicode.graphemeBreak(cp1, @intCast(cp2), &state)); cp1 = cp2; } }