From 6a44d3196d8b8b57513086ddff7a0ac4f2361c17 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:16:46 -0700 Subject: [PATCH 01/15] input: yeet usingnamespace --- src/input.zig | 15 +++++++++++++-- src/input/mouse.zig | 10 +++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/input.zig b/src/input.zig index b3a1fe4b7..204adcfbe 100644 --- a/src/input.zig +++ b/src/input.zig @@ -1,15 +1,26 @@ const std = @import("std"); const builtin = @import("builtin"); -pub usingnamespace @import("input/mouse.zig"); -pub usingnamespace @import("input/key.zig"); +const mouse = @import("input/mouse.zig"); +const key = @import("input/key.zig"); + pub const function_keys = @import("input/function_keys.zig"); pub const keycodes = @import("input/keycodes.zig"); pub const kitty = @import("input/kitty.zig"); + +pub const ctrlOrSuper = key.ctrlOrSuper; +pub const Action = key.Action; pub const Binding = @import("input/Binding.zig"); pub const Link = @import("input/Link.zig"); +pub const Key = key.Key; pub const KeyEncoder = @import("input/KeyEncoder.zig"); +pub const KeyEvent = key.KeyEvent; pub const InspectorMode = Binding.Action.InspectorMode; +pub const Mods = key.Mods; +pub const MouseButton = mouse.Button; +pub const MouseButtonState = mouse.ButtonState; +pub const MousePressureStage = mouse.PressureStage; +pub const ScrollMods = mouse.ScrollMods; pub const SplitFocusDirection = Binding.Action.SplitFocusDirection; pub const SplitResizeDirection = Binding.Action.SplitResizeDirection; diff --git a/src/input/mouse.zig b/src/input/mouse.zig index 7fb3cfe89..10eae6b48 100644 --- a/src/input/mouse.zig +++ b/src/input/mouse.zig @@ -5,7 +5,7 @@ const std = @import("std"); /// This is backed by a c_int so we can use this as-is for our embedding API. /// /// IMPORTANT: Any changes here update include/ghostty.h -pub const MouseButtonState = enum(c_int) { +pub const ButtonState = enum(c_int) { release, press, }; @@ -20,7 +20,7 @@ pub const MouseButtonState = enum(c_int) { /// This is backed by a c_int so we can use this as-is for our embedding API. /// /// IMPORTANT: Any changes here update include/ghostty.h -pub const MouseButton = enum(c_int) { +pub const Button = enum(c_int) { const Self = @This(); /// The maximum value in this enum. This can be used to create a densely @@ -53,7 +53,7 @@ pub const MouseButton = enum(c_int) { /// This is used to handle "inertial scrolling" (i.e. flicking). /// /// https://developer.apple.com/documentation/appkit/nseventphase -pub const MouseMomentum = enum(u3) { +pub const Momentum = enum(u3) { none = 0, began = 1, stationary = 2, @@ -66,7 +66,7 @@ pub const MouseMomentum = enum(u3) { /// The pressure stage of a pressure-sensitive input device. /// /// This currently only supports the stages that macOS supports. -pub const MousePressureStage = enum(u2) { +pub const PressureStage = enum(u2) { /// The input device is unpressed. none = 0, @@ -88,7 +88,7 @@ pub const ScrollMods = packed struct(u8) { /// The momentum phase (if available, supported) of the scroll event. /// This is used to handle "inertial scrolling" (i.e. flicking). - momentum: MouseMomentum = .none, + momentum: Momentum = .none, _padding: u4 = 0, From dbeb4c1a4ac31b938649ced87582989e431bcbeb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:19:46 -0700 Subject: [PATCH 02/15] apprt: yeet usingnamespace --- src/apprt.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/apprt.zig b/src/apprt.zig index 26622297c..767fc57e6 100644 --- a/src/apprt.zig +++ b/src/apprt.zig @@ -12,7 +12,8 @@ const std = @import("std"); const builtin = @import("builtin"); const build_config = @import("build_config.zig"); -pub usingnamespace @import("apprt/structs.zig"); +const structs = @import("apprt/structs.zig"); + pub const glfw = @import("apprt/glfw.zig"); pub const gtk = @import("apprt/gtk.zig"); pub const none = @import("apprt/none.zig"); @@ -20,6 +21,18 @@ pub const browser = @import("apprt/browser.zig"); pub const embedded = @import("apprt/embedded.zig"); pub const surface = @import("apprt/surface.zig"); +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 DesktopNotification = structs.DesktopNotification; +pub const IMEPos = structs.IMEPos; +pub const Selection = structs.Selection; +pub const SplitDirection = structs.SplitDirection; +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 From d8f43b34ba6ecf7b878f6be7bc4f96c771b3c1fc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:32:43 -0700 Subject: [PATCH 03/15] terminal: yeet usingnamespace --- src/terminal/kitty.zig | 6 ++- src/terminal/kitty/graphics.zig | 15 +++++-- src/terminal/kitty/graphics_command.zig | 28 ++++++------- src/terminal/kitty/key.zig | 52 ++++++++++++------------- src/terminal/main.zig | 5 ++- 5 files changed, 59 insertions(+), 47 deletions(-) diff --git a/src/terminal/kitty.zig b/src/terminal/kitty.zig index 497dd4aba..6492aca6f 100644 --- a/src/terminal/kitty.zig +++ b/src/terminal/kitty.zig @@ -1,7 +1,11 @@ //! Types and functions related to Kitty protocols. +const key = @import("kitty/key.zig"); pub const graphics = @import("kitty/graphics.zig"); -pub usingnamespace @import("kitty/key.zig"); + +pub const KeyFlags = key.Flags; +pub const KeyFlagStack = key.FlagStack; +pub const KeySetMode = key.SetMode; test { @import("std").testing.refAllDecls(@This()); diff --git a/src/terminal/kitty/graphics.zig b/src/terminal/kitty/graphics.zig index 0beb4901e..c710f81a1 100644 --- a/src/terminal/kitty/graphics.zig +++ b/src/terminal/kitty/graphics.zig @@ -17,12 +17,19 @@ //! though and I think we can go back through and fix this up. const render = @import("graphics_render.zig"); -pub usingnamespace @import("graphics_command.zig"); -pub usingnamespace @import("graphics_exec.zig"); -pub usingnamespace @import("graphics_image.zig"); -pub usingnamespace @import("graphics_storage.zig"); +const command = @import("graphics_command.zig"); +const exec = @import("graphics_exec.zig"); +const image = @import("graphics_image.zig"); +const storage = @import("graphics_storage.zig"); pub const unicode = @import("graphics_unicode.zig"); +pub const Command = command.Command; +pub const CommandParser = command.Parser; +pub const Image = image.Image; +pub const ImageStorage = storage.ImageStorage; pub const RenderPlacement = render.Placement; +pub const Response = command.Response; + +pub const execute = exec.execute; test { @import("std").testing.refAllDecls(@This()); diff --git a/src/terminal/kitty/graphics_command.zig b/src/terminal/kitty/graphics_command.zig index 9bcdc3f02..649d83f34 100644 --- a/src/terminal/kitty/graphics_command.zig +++ b/src/terminal/kitty/graphics_command.zig @@ -15,7 +15,7 @@ const log = std.log.scoped(.kitty_gfx); const KV = std.AutoHashMapUnmanaged(u8, u32); /// Command parser parses the Kitty graphics protocol escape sequence. -pub const CommandParser = struct { +pub const Parser = struct { /// The memory used by the parser is stored in an arena because it is /// all freed at the end of the command. arena: ArenaAllocator, @@ -54,7 +54,7 @@ pub const CommandParser = struct { /// Initialize the parser. The allocator given will be used for both /// temporary data and long-lived values such as the final image blob. - pub fn init(alloc: Allocator) CommandParser { + pub fn init(alloc: Allocator) Parser { var arena = ArenaAllocator.init(alloc); errdefer arena.deinit(); return .{ @@ -63,7 +63,7 @@ pub const CommandParser = struct { }; } - pub fn deinit(self: *CommandParser) void { + pub fn deinit(self: *Parser) void { // We don't free the hash map because its in the arena self.arena.deinit(); self.data.deinit(); @@ -74,7 +74,7 @@ pub const CommandParser = struct { /// The first byte to start parsing should be the byte immediately following /// the "G" in the APC sequence, i.e. "\x1b_G123" the first byte should /// be "1". - pub fn feed(self: *CommandParser, c: u8) !void { + pub fn feed(self: *Parser, c: u8) !void { switch (self.state) { .control_key => switch (c) { // '=' means the key is complete and we're moving to the value. @@ -119,7 +119,7 @@ pub const CommandParser = struct { /// /// The allocator given will be used for the long-lived data /// of the final command. - pub fn complete(self: *CommandParser) !Command { + pub fn complete(self: *Parser) !Command { switch (self.state) { // We can't ever end in the control key state and be valid. // This means the command looked something like "a=1,b" @@ -175,7 +175,7 @@ pub const CommandParser = struct { /// Decodes the payload data from base64 and returns it as a slice. /// This function will destroy the contents of self.data, it should /// only be used once we are done collecting payload bytes. - fn decodeData(self: *CommandParser) ![]const u8 { + fn decodeData(self: *Parser) ![]const u8 { if (self.data.items.len == 0) { return ""; } @@ -202,7 +202,7 @@ pub const CommandParser = struct { return try self.data.toOwnedSlice(); } - fn accumulateValue(self: *CommandParser, c: u8, overflow_state: State) !void { + fn accumulateValue(self: *Parser, c: u8, overflow_state: State) !void { const idx = self.kv_temp_len; self.kv_temp_len += 1; if (self.kv_temp_len > self.kv_temp.len) { @@ -213,7 +213,7 @@ pub const CommandParser = struct { self.kv_temp[idx] = c; } - fn finishValue(self: *CommandParser, next_state: State) !void { + fn finishValue(self: *Parser, next_state: State) !void { const alloc = self.arena.allocator(); // We can move states right away, we don't use it. @@ -896,7 +896,7 @@ pub const CompositionMode = enum { test "transmission command" { const testing = std.testing; const alloc = testing.allocator; - var p = CommandParser.init(alloc); + var p = Parser.init(alloc); defer p.deinit(); const input = "f=24,s=10,v=20"; @@ -914,7 +914,7 @@ test "transmission command" { test "query command" { const testing = std.testing; const alloc = testing.allocator; - var p = CommandParser.init(alloc); + var p = Parser.init(alloc); defer p.deinit(); const input = "i=31,s=1,v=1,a=q,t=d,f=24;QUFBQQ"; @@ -934,7 +934,7 @@ test "query command" { test "display command" { const testing = std.testing; const alloc = testing.allocator; - var p = CommandParser.init(alloc); + var p = Parser.init(alloc); defer p.deinit(); const input = "a=p,U=1,i=31,c=80,r=120"; @@ -952,7 +952,7 @@ test "display command" { test "delete command" { const testing = std.testing; const alloc = testing.allocator; - var p = CommandParser.init(alloc); + var p = Parser.init(alloc); defer p.deinit(); const input = "a=d,d=p,x=3,y=4"; @@ -972,7 +972,7 @@ test "delete command" { test "ignore unknown keys (long)" { const testing = std.testing; const alloc = testing.allocator; - var p = CommandParser.init(alloc); + var p = Parser.init(alloc); defer p.deinit(); const input = "f=24,s=10,v=20,hello=world"; @@ -990,7 +990,7 @@ test "ignore unknown keys (long)" { test "ignore very long values" { const testing = std.testing; const alloc = testing.allocator; - var p = CommandParser.init(alloc); + var p = Parser.init(alloc); defer p.deinit(); const input = "f=24,s=10,v=2000000000000000000000000000000000000000"; diff --git a/src/terminal/kitty/key.zig b/src/terminal/kitty/key.zig index 938bf65b5..a3e154543 100644 --- a/src/terminal/kitty/key.zig +++ b/src/terminal/kitty/key.zig @@ -5,23 +5,23 @@ const std = @import("std"); /// Stack for the key flags. This implements the push/pop behavior /// of the CSI > u and CSI < u sequences. We implement the stack as /// fixed size to avoid heap allocation. -pub const KeyFlagStack = struct { +pub const FlagStack = struct { const len = 8; - flags: [len]KeyFlags = .{.{}} ** len, + flags: [len]Flags = .{.{}} ** len, idx: u3 = 0, /// Return the current stack value - pub fn current(self: KeyFlagStack) KeyFlags { + pub fn current(self: FlagStack) Flags { return self.flags[self.idx]; } /// Perform the "set" operation as described in the spec for /// the CSI = u sequence. pub fn set( - self: *KeyFlagStack, - mode: KeySetMode, - v: KeyFlags, + self: *FlagStack, + mode: SetMode, + v: Flags, ) void { switch (mode) { .set => self.flags[self.idx] = v, @@ -36,7 +36,7 @@ pub const KeyFlagStack = struct { /// Push a new set of flags onto the stack. If the stack is full /// then the oldest entry is evicted. - pub fn push(self: *KeyFlagStack, flags: KeyFlags) void { + pub fn push(self: *FlagStack, flags: Flags) void { // Overflow and wrap around if we're full, which evicts // the oldest entry. self.idx +%= 1; @@ -45,7 +45,7 @@ pub const KeyFlagStack = struct { /// Pop `n` entries from the stack. This will just wrap around /// if `n` is greater than the amount in the stack. - pub fn pop(self: *KeyFlagStack, n: usize) void { + pub fn pop(self: *FlagStack, n: usize) void { // If n is more than our length then we just reset the stack. // This also avoids a DoS vector where a malicious client // could send a huge number of pop commands to waste cpu. @@ -64,7 +64,7 @@ pub const KeyFlagStack = struct { // Make sure we the overflow works as expected test { const testing = std.testing; - var stack: KeyFlagStack = .{}; + var stack: FlagStack = .{}; stack.idx = stack.flags.len - 1; stack.idx +%= 1; try testing.expect(stack.idx == 0); @@ -76,14 +76,14 @@ pub const KeyFlagStack = struct { }; /// The possible flags for the Kitty keyboard protocol. -pub const KeyFlags = packed struct(u5) { +pub const Flags = packed struct(u5) { disambiguate: bool = false, report_events: bool = false, report_alternates: bool = false, report_all: bool = false, report_associated: bool = false, - pub fn int(self: KeyFlags) u5 { + pub fn int(self: Flags) u5 { return @bitCast(self); } @@ -93,50 +93,50 @@ pub const KeyFlags = packed struct(u5) { try testing.expectEqual( @as(u5, 0b1), - (KeyFlags{ .disambiguate = true }).int(), + (Flags{ .disambiguate = true }).int(), ); try testing.expectEqual( @as(u5, 0b10), - (KeyFlags{ .report_events = true }).int(), + (Flags{ .report_events = true }).int(), ); } }; /// The possible modes for setting the key flags. -pub const KeySetMode = enum { set, @"or", not }; +pub const SetMode = enum { set, @"or", not }; -test "KeyFlagStack: push pop" { +test "FlagStack: push pop" { const testing = std.testing; - var stack: KeyFlagStack = .{}; + var stack: FlagStack = .{}; stack.push(.{ .disambiguate = true }); try testing.expectEqual( - KeyFlags{ .disambiguate = true }, + Flags{ .disambiguate = true }, stack.current(), ); stack.pop(1); - try testing.expectEqual(KeyFlags{}, stack.current()); + try testing.expectEqual(Flags{}, stack.current()); } -test "KeyFlagStack: pop big number" { +test "FlagStack: pop big number" { const testing = std.testing; - var stack: KeyFlagStack = .{}; + var stack: FlagStack = .{}; stack.pop(100); - try testing.expectEqual(KeyFlags{}, stack.current()); + try testing.expectEqual(Flags{}, stack.current()); } -test "KeyFlagStack: set" { +test "FlagStack: set" { const testing = std.testing; - var stack: KeyFlagStack = .{}; + var stack: FlagStack = .{}; stack.set(.set, .{ .disambiguate = true }); try testing.expectEqual( - KeyFlags{ .disambiguate = true }, + Flags{ .disambiguate = true }, stack.current(), ); stack.set(.@"or", .{ .report_events = true }); try testing.expectEqual( - KeyFlags{ + Flags{ .disambiguate = true, .report_events = true, }, @@ -145,7 +145,7 @@ test "KeyFlagStack: set" { stack.set(.not, .{ .report_events = true }); try testing.expectEqual( - KeyFlags{ .disambiguate = true }, + Flags{ .disambiguate = true }, stack.current(), ); } diff --git a/src/terminal/main.zig b/src/terminal/main.zig index cdf80a54b..d295ea1ba 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -1,8 +1,7 @@ const builtin = @import("builtin"); -pub usingnamespace @import("sanitize.zig"); - const charsets = @import("charsets.zig"); +const sanitize = @import("sanitize.zig"); const stream = @import("stream.zig"); const ansi = @import("ansi.zig"); const csi = @import("csi.zig"); @@ -57,6 +56,8 @@ pub const EraseLine = csi.EraseLine; pub const TabClear = csi.TabClear; pub const Attribute = sgr.Attribute; +pub const isSafePaste = sanitize.isSafePaste; + test { @import("std").testing.refAllDecls(@This()); From 3404f8e53a4ed2331496c6892c1a79796259ea0a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:36:10 -0700 Subject: [PATCH 04/15] termio: yeet usingns --- src/stb/main.zig | 7 ++++++- src/termio.zig | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/stb/main.zig b/src/stb/main.zig index b047104af..599e95d5f 100644 --- a/src/stb/main.zig +++ b/src/stb/main.zig @@ -1,4 +1,9 @@ -pub usingnamespace @cImport({ +const c = @cImport({ @cInclude("stb_image.h"); @cInclude("stb_image_resize.h"); }); + +// We'll just add the exports of the functions or types we actually use +// here, no need to export everything from the C lib if we don't use it. +pub const stbi_load_from_memory = c.stbi_load_from_memory; +pub const stbi_image_free = c.stbi_image_free; diff --git a/src/termio.zig b/src/termio.zig index b4943cca9..c69785b25 100644 --- a/src/termio.zig +++ b/src/termio.zig @@ -19,7 +19,7 @@ const stream_handler = @import("termio/stream_handler.zig"); -pub usingnamespace @import("termio/message.zig"); +const message = @import("termio/message.zig"); pub const backend = @import("termio/backend.zig"); pub const mailbox = @import("termio/mailbox.zig"); pub const Exec = @import("termio/Exec.zig"); @@ -29,6 +29,8 @@ pub const Thread = @import("termio/Thread.zig"); pub const Backend = backend.Backend; pub const DerivedConfig = Termio.DerivedConfig; pub const Mailbox = mailbox.Mailbox; +pub const Message = message.Message; +pub const MessageData = message.MessageData; pub const StreamHandler = stream_handler.StreamHandler; test { From 9f52a963f5dd78e0f79e13c7d17faf68e610d752 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:37:31 -0700 Subject: [PATCH 05/15] pty: remove usingns --- src/pty.zig | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/pty.zig b/src/pty.zig index c5c207b54..0bb1aff67 100644 --- a/src/pty.zig +++ b/src/pty.zig @@ -63,17 +63,15 @@ const PosixPty = struct { const TIOCSWINSZ = if (builtin.os.tag == .macos) 2148037735 else c.TIOCSWINSZ; const TIOCGWINSZ = if (builtin.os.tag == .macos) 1074295912 else c.TIOCGWINSZ; extern "c" fn setsid() std.c.pid_t; - const c = struct { - usingnamespace switch (builtin.os.tag) { - .macos => @cImport({ - @cInclude("sys/ioctl.h"); // ioctl and constants - @cInclude("util.h"); // openpty() - }), - else => @cImport({ - @cInclude("sys/ioctl.h"); // ioctl and constants - @cInclude("pty.h"); - }), - }; + const c = switch (builtin.os.tag) { + .macos => @cImport({ + @cInclude("sys/ioctl.h"); // ioctl and constants + @cInclude("util.h"); // openpty() + }), + else => @cImport({ + @cInclude("sys/ioctl.h"); // ioctl and constants + @cInclude("pty.h"); + }), }; /// The file descriptors for the master and slave side of the pty. From b660380b0115b9531fdc9069631a1759308aaa0d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:43:32 -0700 Subject: [PATCH 06/15] renderer: yeet usingns --- src/renderer.zig | 13 ++++++++--- src/renderer/cursor.zig | 52 ++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/renderer.zig b/src/renderer.zig index 72bba4c18..5cf316c70 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -12,9 +12,9 @@ const builtin = @import("builtin"); const build_config = @import("build_config.zig"); const WasmTarget = @import("os/wasm/target.zig").Target; -pub usingnamespace @import("renderer/cursor.zig"); -pub usingnamespace @import("renderer/message.zig"); -pub usingnamespace @import("renderer/size.zig"); +const cursor = @import("renderer/cursor.zig"); +const message = @import("renderer/message.zig"); +const size = @import("renderer/size.zig"); pub const shadertoy = @import("renderer/shadertoy.zig"); pub const Metal = @import("renderer/Metal.zig"); pub const OpenGL = @import("renderer/OpenGL.zig"); @@ -22,6 +22,13 @@ pub const WebGL = @import("renderer/WebGL.zig"); pub const Options = @import("renderer/Options.zig"); pub const Thread = @import("renderer/Thread.zig"); pub const State = @import("renderer/State.zig"); +pub const CursorStyle = cursor.Style; +pub const Message = message.Message; +pub const CellSize = size.CellSize; +pub const ScreenSize = size.ScreenSize; +pub const GridSize = size.GridSize; +pub const Padding = size.Padding; +pub const cursorStyle = cursor.style; /// Possible implementations, used for build options. pub const Impl = enum { diff --git a/src/renderer/cursor.zig b/src/renderer/cursor.zig index 18af9228e..468c25465 100644 --- a/src/renderer/cursor.zig +++ b/src/renderer/cursor.zig @@ -5,15 +5,15 @@ const State = @import("State.zig"); /// Available cursor styles for drawing that renderers must support. /// This is a superset of terminal cursor styles since the renderer supports /// some additional cursor states such as the hollow block. -pub const CursorStyle = enum { +pub const Style = enum { block, block_hollow, bar, underline, /// Create a cursor style from the terminal style request. - pub fn fromTerminal(style: terminal.CursorStyle) ?CursorStyle { - return switch (style) { + pub fn fromTerminal(term: terminal.CursorStyle) ?Style { + return switch (term) { .bar => .bar, .block => .block, .underline => .underline, @@ -23,11 +23,11 @@ pub const CursorStyle = enum { /// Returns the cursor style to use for the current render state or null /// if a cursor should not be rendered at all. -pub fn cursorStyle( +pub fn style( state: *State, focused: bool, blink_visible: bool, -) ?CursorStyle { +) ?Style { // Note the order of conditionals below is important. It represents // a priority system of how we determine what state overrides cursor // visibility and style. @@ -57,7 +57,7 @@ pub fn cursorStyle( } // Otherwise, we use whatever style the terminal wants. - return CursorStyle.fromTerminal(state.terminal.screen.cursor.cursor_style); + return Style.fromTerminal(state.terminal.screen.cursor.cursor_style); } test "cursor: default uses configured style" { @@ -75,10 +75,10 @@ test "cursor: default uses configured style" { .preedit = null, }; - try testing.expect(cursorStyle(&state, true, true) == .bar); - try testing.expect(cursorStyle(&state, false, true) == .block_hollow); - try testing.expect(cursorStyle(&state, false, false) == .block_hollow); - try testing.expect(cursorStyle(&state, true, false) == null); + try testing.expect(style(&state, true, true) == .bar); + try testing.expect(style(&state, false, true) == .block_hollow); + try testing.expect(style(&state, false, false) == .block_hollow); + try testing.expect(style(&state, true, false) == null); } test "cursor: blinking disabled" { @@ -96,10 +96,10 @@ test "cursor: blinking disabled" { .preedit = null, }; - try testing.expect(cursorStyle(&state, true, true) == .bar); - try testing.expect(cursorStyle(&state, true, false) == .bar); - try testing.expect(cursorStyle(&state, false, true) == .block_hollow); - try testing.expect(cursorStyle(&state, false, false) == .block_hollow); + try testing.expect(style(&state, true, true) == .bar); + try testing.expect(style(&state, true, false) == .bar); + try testing.expect(style(&state, false, true) == .block_hollow); + try testing.expect(style(&state, false, false) == .block_hollow); } test "cursor: explicitly not visible" { @@ -118,10 +118,10 @@ test "cursor: explicitly not visible" { .preedit = null, }; - try testing.expect(cursorStyle(&state, true, true) == null); - try testing.expect(cursorStyle(&state, true, false) == null); - try testing.expect(cursorStyle(&state, false, true) == null); - try testing.expect(cursorStyle(&state, false, false) == null); + try testing.expect(style(&state, true, true) == null); + try testing.expect(style(&state, true, false) == null); + try testing.expect(style(&state, false, true) == null); + try testing.expect(style(&state, false, false) == null); } test "cursor: always block with preedit" { @@ -137,18 +137,18 @@ test "cursor: always block with preedit" { }; // In any bool state - try testing.expect(cursorStyle(&state, false, false) == .block); - try testing.expect(cursorStyle(&state, true, false) == .block); - try testing.expect(cursorStyle(&state, true, true) == .block); - try testing.expect(cursorStyle(&state, false, true) == .block); + try testing.expect(style(&state, false, false) == .block); + try testing.expect(style(&state, true, false) == .block); + try testing.expect(style(&state, true, true) == .block); + try testing.expect(style(&state, false, true) == .block); // If we're scrolled though, then we don't show the cursor. for (0..100) |_| try term.index(); try term.scrollViewport(.{ .top = {} }); // In any bool state - try testing.expect(cursorStyle(&state, false, false) == null); - try testing.expect(cursorStyle(&state, true, false) == null); - try testing.expect(cursorStyle(&state, true, true) == null); - try testing.expect(cursorStyle(&state, false, true) == null); + try testing.expect(style(&state, false, false) == null); + try testing.expect(style(&state, true, false) == null); + try testing.expect(style(&state, true, true) == null); + try testing.expect(style(&state, false, true) == null); } From 14e3f43db2d0e8003da0b63a5d757f14632a3c46 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:47:15 -0700 Subject: [PATCH 07/15] font: yeet usingns --- src/font/Atlas.zig | 3 --- src/font/main.zig | 4 +++- src/font/shape.zig | 4 +++- src/font/sprite.zig | 6 +++++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/font/Atlas.zig b/src/font/Atlas.zig index 0c4b816f6..6cb546af3 100644 --- a/src/font/Atlas.zig +++ b/src/font/Atlas.zig @@ -300,9 +300,6 @@ pub fn clear(self: *Atlas) void { /// The wasm-compatible API. This lacks documentation unless the API differs /// from the standard Zig API. To learn what a function does, just look one /// level deeper to what Zig function is called and read the documentation there. -/// -/// To export this from Zig, use `usingnamespace Wasm` in some top-level -/// space and it will be exported. pub const Wasm = struct { // If you're copying this file (Atlas.zig) out to a separate project, // just replace this with the allocator you want to use. diff --git a/src/font/main.zig b/src/font/main.zig index cbcb696d2..3bbc091fc 100644 --- a/src/font/main.zig +++ b/src/font/main.zig @@ -2,6 +2,8 @@ const std = @import("std"); const builtin = @import("builtin"); const build_config = @import("../build_config.zig"); +const library = @import("library.zig"); + pub const Atlas = @import("Atlas.zig"); pub const discovery = @import("discovery.zig"); pub const face = @import("face.zig"); @@ -23,7 +25,7 @@ pub const Sprite = sprite.Sprite; pub const SpriteFace = sprite.Face; pub const Descriptor = discovery.Descriptor; pub const Discover = discovery.Discover; -pub usingnamespace @import("library.zig"); +pub const Library = library.Library; /// If we're targeting wasm then we export some wasm APIs. pub usingnamespace if (builtin.target.isWasm()) struct { diff --git a/src/font/shape.zig b/src/font/shape.zig index e633c15c9..0423d0ed1 100644 --- a/src/font/shape.zig +++ b/src/font/shape.zig @@ -1,11 +1,13 @@ const builtin = @import("builtin"); const options = @import("main.zig").options; +const run = @import("shaper/run.zig"); pub const noop = @import("shaper/noop.zig"); pub const harfbuzz = @import("shaper/harfbuzz.zig"); pub const coretext = @import("shaper/coretext.zig"); pub const web_canvas = @import("shaper/web_canvas.zig"); -pub usingnamespace @import("shaper/run.zig"); pub const Cache = @import("shaper/Cache.zig"); +pub const TextRun = run.TextRun; +pub const RunIterator = run.RunIterator; /// Shaper implementation for our compile options. pub const Shaper = switch (options.backend) { diff --git a/src/font/sprite.zig b/src/font/sprite.zig index 5f679631d..00462c205 100644 --- a/src/font/sprite.zig +++ b/src/font/sprite.zig @@ -1,7 +1,11 @@ const std = @import("std"); -pub usingnamespace @import("sprite/canvas.zig"); +const canvas = @import("sprite/canvas.zig"); pub const Face = @import("sprite/Face.zig"); +pub const Box = canvas.Box; +pub const Canvas = canvas.Canvas; +pub const Color = canvas.Color; + /// Sprites are represented as special codepoints outside of the Unicode /// codepoint range. Unicode maxes out at U+10FFFF (21 bits), and we use the /// high 11 bits to hide our special characters. From 29de3e80f1617b58bd9a00b61a783230fbeced1c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:49:37 -0700 Subject: [PATCH 08/15] config: yeet usingns --- src/config.zig | 7 +++++-- src/simd/main.zig | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/config.zig b/src/config.zig index 34b209c09..3be645cc3 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1,12 +1,15 @@ const builtin = @import("builtin"); -pub usingnamespace @import("config/key.zig"); -pub usingnamespace @import("config/formatter.zig"); +const formatter = @import("config/formatter.zig"); pub const Config = @import("config/Config.zig"); pub const string = @import("config/string.zig"); pub const edit = @import("config/edit.zig"); pub const url = @import("config/url.zig"); +pub const FileFormatter = formatter.FileFormatter; +pub const entryFormatter = formatter.entryFormatter; +pub const formatEntry = formatter.formatEntry; + // Field types pub const ClipboardAccess = Config.ClipboardAccess; pub const CopyOnSelect = Config.CopyOnSelect; diff --git a/src/simd/main.zig b/src/simd/main.zig index d3ada5708..bfcd68c0a 100644 --- a/src/simd/main.zig +++ b/src/simd/main.zig @@ -1,9 +1,10 @@ const std = @import("std"); -pub usingnamespace @import("codepoint_width.zig"); +const codepoint_width = @import("codepoint_width.zig"); pub const base64 = @import("base64.zig"); pub const index_of = @import("index_of.zig"); pub const vt = @import("vt.zig"); +pub const codepointWidth = codepoint_width.codepointWidth; test { @import("std").testing.refAllDecls(@This()); From d0ca949c098741759d9a99014a17ae53991ada49 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 10:57:19 -0700 Subject: [PATCH 09/15] os: start yeeting --- src/os/wasm/log.zig | 6 +++--- src/os/windows.zig | 28 +++++++++++++++++++++++++++- src/stb/main.zig | 1 + 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/os/wasm/log.zig b/src/os/wasm/log.zig index d1163e6e3..d81571229 100644 --- a/src/os/wasm/log.zig +++ b/src/os/wasm/log.zig @@ -4,9 +4,9 @@ const wasm = @import("../wasm.zig"); const wasm_target = @import("target.zig"); // Use the correct implementation -pub usingnamespace if (wasm_target.target) |target| switch (target) { - .browser => Browser, -} else struct {}; +pub const log = if (wasm_target.target) |target| switch (target) { + .browser => Browser.log, +} else @compileError("wasm target required"); /// Browser implementation calls an extern "log" function. pub const Browser = struct { diff --git a/src/os/windows.zig b/src/os/windows.zig index 063122738..5140cd2a4 100644 --- a/src/os/windows.zig +++ b/src/os/windows.zig @@ -1,7 +1,33 @@ const std = @import("std"); const windows = std.os.windows; -pub usingnamespace std.os.windows; +// Export any constants or functions we need from the Windows API so +// we can just import one file. +pub const kernel32 = windows.kernel32; +pub const unexpectedError = windows.unexpectedError; +pub const OpenFile = windows.OpenFile; +pub const SetHandleInformation = windows.SetHandleInformation; +pub const DWORD = windows.DWORD; +pub const FILE_ATTRIBUTE_NORMAL = windows.FILE_ATTRIBUTE_NORMAL; +pub const FILE_FLAG_OVERLAPPED = windows.FILE_FLAG_OVERLAPPED; +pub const FILE_SHARE_READ = windows.FILE_SHARE_READ; +pub const GENERIC_READ = windows.GENERIC_READ; +pub const HANDLE = windows.HANDLE; +pub const HANDLE_FLAG_INHERIT = windows.HANDLE_FLAG_INHERIT; +pub const INFINITE = windows.INFINITE; +pub const INVALID_HANDLE_VALUE = windows.INVALID_HANDLE_VALUE; +pub const OPEN_EXISTING = windows.OPEN_EXISTING; +pub const PIPE_ACCESS_OUTBOUND = windows.PIPE_ACCESS_OUTBOUND; +pub const PIPE_TYPE_BYTE = windows.PIPE_TYPE_BYTE; +pub const PROCESS_INFORMATION = windows.PROCESS_INFORMATION; +pub const S_OK = windows.S_OK; +pub const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; +pub const STARTUPINFOW = windows.STARTUPINFOW; +pub const STARTF_USESTDHANDLES = windows.STARTF_USESTDHANDLES; +pub const SYNCHRONIZE = windows.SYNCHRONIZE; +pub const WAIT_FAILED = windows.WAIT_FAILED; +pub const FALSE = windows.FALSE; +pub const TRUE = windows.TRUE; pub const exp = struct { pub const HPCON = windows.LPVOID; diff --git a/src/stb/main.zig b/src/stb/main.zig index 599e95d5f..adc594aff 100644 --- a/src/stb/main.zig +++ b/src/stb/main.zig @@ -7,3 +7,4 @@ const c = @cImport({ // here, no need to export everything from the C lib if we don't use it. pub const stbi_load_from_memory = c.stbi_load_from_memory; pub const stbi_image_free = c.stbi_image_free; +pub const stbir_resize_uint8 = c.stbir_resize_uint8; From 677f0376a097f46bc659dbe8eb8bab2c330624d0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 14:29:08 -0700 Subject: [PATCH 10/15] os: yeet usingns --- src/os/main.zig | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/os/main.zig b/src/os/main.zig index 04d53d752..42bb0cdeb 100644 --- a/src/os/main.zig +++ b/src/os/main.zig @@ -2,20 +2,42 @@ //! system. These aren't restricted to syscalls or low-level operations, but //! also OS-specific features and conventions. -pub usingnamespace @import("env.zig"); -pub usingnamespace @import("desktop.zig"); -pub usingnamespace @import("file.zig"); -pub usingnamespace @import("flatpak.zig"); -pub usingnamespace @import("homedir.zig"); -pub usingnamespace @import("locale.zig"); -pub usingnamespace @import("macos_version.zig"); -pub usingnamespace @import("mouse.zig"); -pub usingnamespace @import("open.zig"); -pub usingnamespace @import("pipe.zig"); -pub usingnamespace @import("resourcesdir.zig"); -pub const CFReleaseThread = @import("cf_release_thread.zig"); -pub const TempDir = @import("TempDir.zig"); +const desktop = @import("desktop.zig"); +const env = @import("env.zig"); +const file = @import("file.zig"); +const flatpak = @import("flatpak.zig"); +const homedir = @import("homedir.zig"); +const locale = @import("locale.zig"); +const macos_version = @import("macos_version.zig"); +const mouse = @import("mouse.zig"); +const openpkg = @import("open.zig"); +const pipepkg = @import("pipe.zig"); +const resourcesdir = @import("resourcesdir.zig"); + +// Namespaces pub const cgroup = @import("cgroup.zig"); pub const passwd = @import("passwd.zig"); pub const xdg = @import("xdg.zig"); pub const windows = @import("windows.zig"); + +// Functions and types +pub const CFReleaseThread = @import("cf_release_thread.zig"); +pub const TempDir = @import("TempDir.zig"); +pub const PATH_SEP = env.PATH_SEP; +pub const appendEnv = env.appendEnv; +pub const appendEnvAlways = env.appendEnvAlways; +pub const getenv = env.getenv; +pub const setenv = env.setenv; +pub const unsetenv = env.unsetenv; +pub const launchedFromDesktop = desktop.launchedFromDesktop; +pub const fixMaxFiles = file.fixMaxFiles; +pub const allocTmpDir = file.allocTmpDir; +pub const freeTmpDir = file.freeTmpDir; +pub const isFlatpak = flatpak.isFlatpak; +pub const home = homedir.home; +pub const ensureLocale = locale.ensureLocale; +pub const macosVersionAtLeast = macos_version.macosVersionAtLeast; +pub const clickInterval = mouse.clickInterval; +pub const open = openpkg.open; +pub const pipe = pipepkg.pipe; +pub const resourcesDir = resourcesdir.resourcesDir; From ba29bf759b4ec8ff1761915e466de52d82168cc5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 14:35:10 -0700 Subject: [PATCH 11/15] lots more yeeting --- src/apprt/embedded.zig | 222 +++++++++++++++++++++-------------------- src/font/main.zig | 16 +-- src/main_c.zig | 8 +- src/main_wasm.zig | 12 ++- 4 files changed, 137 insertions(+), 121 deletions(-) diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 9b7fcccb7..dc91871de 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -1427,6 +1427,14 @@ pub const CAPI = struct { cell_height_px: u32, }; + // Reference the conditional exports based on target platform + // so they're included in the C API. + comptime { + if (builtin.target.isDarwin()) { + _ = Darwin; + } + } + /// Create a new app. export fn ghostty_app_new( opts: *const apprt.runtime.App.Options, @@ -1830,8 +1838,112 @@ pub const CAPI = struct { ptr.freeInspector(); } - // Inspector Metal APIs are only available on Apple systems - usingnamespace if (builtin.target.isDarwin()) struct { + export fn ghostty_inspector_set_size(ptr: *Inspector, w: u32, h: u32) void { + ptr.updateSize(w, h); + } + + export fn ghostty_inspector_set_content_scale(ptr: *Inspector, x: f64, y: f64) void { + ptr.updateContentScale(x, y); + } + + export fn ghostty_inspector_mouse_button( + ptr: *Inspector, + action: input.MouseButtonState, + button: input.MouseButton, + mods: c_int, + ) void { + ptr.mouseButtonCallback( + action, + button, + @bitCast(@as( + input.Mods.Backing, + @truncate(@as(c_uint, @bitCast(mods))), + )), + ); + } + + export fn ghostty_inspector_mouse_pos(ptr: *Inspector, x: f64, y: f64) void { + ptr.cursorPosCallback(x, y); + } + + export fn ghostty_inspector_mouse_scroll( + ptr: *Inspector, + x: f64, + y: f64, + scroll_mods: c_int, + ) void { + ptr.scrollCallback( + x, + y, + @bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(scroll_mods))))), + ); + } + + export fn ghostty_inspector_key( + ptr: *Inspector, + action: input.Action, + key: input.Key, + c_mods: c_int, + ) void { + ptr.keyCallback( + action, + key, + @bitCast(@as( + input.Mods.Backing, + @truncate(@as(c_uint, @bitCast(c_mods))), + )), + ) catch |err| { + log.err("error processing key event err={}", .{err}); + return; + }; + } + + export fn ghostty_inspector_text( + ptr: *Inspector, + str: [*:0]const u8, + ) void { + ptr.textCallback(std.mem.sliceTo(str, 0)); + } + + export fn ghostty_inspector_set_focus(ptr: *Inspector, focused: bool) void { + ptr.focusCallback(focused); + } + + /// Sets the window background blur on macOS to the desired value. + /// I do this in Zig as an extern function because I don't know how to + /// call these functions in Swift. + /// + /// This uses an undocumented, non-public API because this is what + /// every terminal appears to use, including Terminal.app. + export fn ghostty_set_window_background_blur( + app: *App, + window: *anyopaque, + ) void { + // This is only supported on macOS + if (comptime builtin.target.os.tag != .macos) return; + + const config = app.config; + + // Do nothing if we don't have background transparency enabled + if (config.@"background-opacity" >= 1.0) return; + + // Do nothing if our blur value is zero + if (config.@"background-blur-radius" == 0) return; + + const nswindow = objc.Object.fromId(window); + _ = CGSSetWindowBackgroundBlurRadius( + CGSDefaultConnectionForThread(), + nswindow.msgSend(usize, objc.sel("windowNumber"), .{}), + @intCast(config.@"background-blur-radius"), + ); + } + + /// See ghostty_set_window_background_blur + extern "c" fn CGSSetWindowBackgroundBlurRadius(*anyopaque, usize, c_int) i32; + extern "c" fn CGSDefaultConnectionForThread() *anyopaque; + + // Darwin-only C APIs. + const Darwin = struct { export fn ghostty_surface_set_display_id(ptr: *Surface, display_id: u32) void { const surface = &ptr.core_surface; _ = surface.renderer_thread.mailbox.push( @@ -1984,109 +2096,5 @@ pub const CAPI = struct { ptr.backend = null; } } - } else struct {}; - - export fn ghostty_inspector_set_size(ptr: *Inspector, w: u32, h: u32) void { - ptr.updateSize(w, h); - } - - export fn ghostty_inspector_set_content_scale(ptr: *Inspector, x: f64, y: f64) void { - ptr.updateContentScale(x, y); - } - - export fn ghostty_inspector_mouse_button( - ptr: *Inspector, - action: input.MouseButtonState, - button: input.MouseButton, - mods: c_int, - ) void { - ptr.mouseButtonCallback( - action, - button, - @bitCast(@as( - input.Mods.Backing, - @truncate(@as(c_uint, @bitCast(mods))), - )), - ); - } - - export fn ghostty_inspector_mouse_pos(ptr: *Inspector, x: f64, y: f64) void { - ptr.cursorPosCallback(x, y); - } - - export fn ghostty_inspector_mouse_scroll( - ptr: *Inspector, - x: f64, - y: f64, - scroll_mods: c_int, - ) void { - ptr.scrollCallback( - x, - y, - @bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(scroll_mods))))), - ); - } - - export fn ghostty_inspector_key( - ptr: *Inspector, - action: input.Action, - key: input.Key, - c_mods: c_int, - ) void { - ptr.keyCallback( - action, - key, - @bitCast(@as( - input.Mods.Backing, - @truncate(@as(c_uint, @bitCast(c_mods))), - )), - ) catch |err| { - log.err("error processing key event err={}", .{err}); - return; - }; - } - - export fn ghostty_inspector_text( - ptr: *Inspector, - str: [*:0]const u8, - ) void { - ptr.textCallback(std.mem.sliceTo(str, 0)); - } - - export fn ghostty_inspector_set_focus(ptr: *Inspector, focused: bool) void { - ptr.focusCallback(focused); - } - - /// Sets the window background blur on macOS to the desired value. - /// I do this in Zig as an extern function because I don't know how to - /// call these functions in Swift. - /// - /// This uses an undocumented, non-public API because this is what - /// every terminal appears to use, including Terminal.app. - export fn ghostty_set_window_background_blur( - app: *App, - window: *anyopaque, - ) void { - // This is only supported on macOS - if (comptime builtin.target.os.tag != .macos) return; - - const config = app.config; - - // Do nothing if we don't have background transparency enabled - if (config.@"background-opacity" >= 1.0) return; - - // Do nothing if our blur value is zero - if (config.@"background-blur-radius" == 0) return; - - const nswindow = objc.Object.fromId(window); - _ = CGSSetWindowBackgroundBlurRadius( - CGSDefaultConnectionForThread(), - nswindow.msgSend(usize, objc.sel("windowNumber"), .{}), - @intCast(config.@"background-blur-radius"), - ); - } - - /// See ghostty_set_window_background_blur - extern "c" fn CGSSetWindowBackgroundBlurRadius(*anyopaque, usize, c_int) i32; - extern "c" fn CGSDefaultConnectionForThread() *anyopaque; + }; }; diff --git a/src/font/main.zig b/src/font/main.zig index 3bbc091fc..4c0d206b3 100644 --- a/src/font/main.zig +++ b/src/font/main.zig @@ -27,13 +27,15 @@ pub const Descriptor = discovery.Descriptor; pub const Discover = discovery.Discover; pub const Library = library.Library; -/// If we're targeting wasm then we export some wasm APIs. -pub usingnamespace if (builtin.target.isWasm()) struct { - pub usingnamespace Atlas.Wasm; - pub usingnamespace DeferredFace.Wasm; - pub usingnamespace face.web_canvas.Wasm; - pub usingnamespace shape.web_canvas.Wasm; -} else struct {}; +// If we're targeting wasm then we export some wasm APIs. +comptime { + if (builtin.target.isWasm()) { + _ = Atlas.Wasm; + _ = DeferredFace.Wasm; + _ = face.web_canvas.Wasm; + _ = shape.web_canvas.Wasm; + } +} /// Build options pub const options: struct { diff --git a/src/main_c.zig b/src/main_c.zig index 007273172..4cbca4899 100644 --- a/src/main_c.zig +++ b/src/main_c.zig @@ -23,8 +23,12 @@ comptime { /// Global options so we can log. This is identical to main. pub const std_options = main.std_options; -pub usingnamespace @import("config.zig").CAPI; -pub usingnamespace apprt.runtime.CAPI; +comptime { + // These structs need to be referenced so the `export` functions + // are truly exported by the C API lib. + _ = @import("config.zig").CAPI; + _ = apprt.runtime.CAPI; +} /// ghostty_info_s const Info = extern struct { diff --git a/src/main_wasm.zig b/src/main_wasm.zig index b275b4626..bffe5e4b7 100644 --- a/src/main_wasm.zig +++ b/src/main_wasm.zig @@ -3,11 +3,13 @@ const std = @import("std"); const builtin = @import("builtin"); -pub usingnamespace @import("os/wasm.zig"); -pub usingnamespace @import("font/main.zig"); -pub usingnamespace @import("terminal/main.zig"); -pub usingnamespace @import("config.zig").Wasm; -pub usingnamespace @import("App.zig").Wasm; +comptime { + _ = @import("os/wasm.zig"); + _ = @import("font/main.zig"); + _ = @import("terminal/main.zig"); + _ = @import("config.zig").Wasm; + _ = @import("App.zig").Wasm; +} pub const std_options = struct { // Set our log level. We try to get as much logging as possible but in From b65a804bb28c899cca0173a07a9b9e7fb7d5f9d4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 14:42:32 -0700 Subject: [PATCH 12/15] almost yeeted it all! --- src/Surface.zig | 4 +- src/cli/list_themes.zig | 2 +- src/config/CAPI.zig | 2 +- src/config/Config.zig | 2 +- src/main.zig | 11 +++- src/main_ghostty.zig | 137 +--------------------------------------- 6 files changed, 15 insertions(+), 143 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index fc3144ade..4b5b3f98c 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -20,9 +20,9 @@ const builtin = @import("builtin"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; const ArenaAllocator = std.heap.ArenaAllocator; +const global_state = &@import("global.zig").state; const oni = @import("oniguruma"); const unicode = @import("unicode/main.zig"); -const main = @import("main.zig"); const renderer = @import("renderer.zig"); const termio = @import("termio.zig"); const objc = @import("objc"); @@ -448,7 +448,7 @@ pub fn init( .shell_integration = config.@"shell-integration", .shell_integration_features = config.@"shell-integration-features", .working_directory = config.@"working-directory", - .resources_dir = main.state.resources_dir, + .resources_dir = global_state.resources_dir, .term = config.term, // Get the cgroup if we're on linux and have the decl. I'd love diff --git a/src/cli/list_themes.zig b/src/cli/list_themes.zig index 82c461893..beceab112 100644 --- a/src/cli/list_themes.zig +++ b/src/cli/list_themes.zig @@ -5,7 +5,7 @@ const Action = @import("action.zig").Action; const Arena = std.heap.ArenaAllocator; const Allocator = std.mem.Allocator; const Config = @import("../config/Config.zig"); -const global_state = &@import("../main.zig").state; +const global_state = &@import("../global.zig").state; pub const Options = struct { pub fn deinit(self: Options) void { diff --git a/src/config/CAPI.zig b/src/config/CAPI.zig index ef50c4e2b..1949d6e91 100644 --- a/src/config/CAPI.zig +++ b/src/config/CAPI.zig @@ -1,7 +1,7 @@ const std = @import("std"); const cli = @import("../cli.zig"); const inputpkg = @import("../input.zig"); -const global = &@import("../main.zig").state; +const global = &@import("../global.zig").state; const Config = @import("Config.zig"); const c_get = @import("c_get.zig"); diff --git a/src/config/Config.zig b/src/config/Config.zig index ace9c5e4a..a5d1c1e68 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -15,7 +15,7 @@ const builtin = @import("builtin"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; const ArenaAllocator = std.heap.ArenaAllocator; -const global_state = &@import("../main.zig").state; +const global_state = &@import("../global.zig").state; const fontpkg = @import("../font/main.zig"); const inputpkg = @import("../input.zig"); const terminal = @import("../terminal/main.zig"); diff --git a/src/main.zig b/src/main.zig index 3a5357471..a1f8d4a44 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,7 +1,7 @@ const build_config = @import("build_config.zig"); -// See build_config.ExeEntrypoint for why we do this. -pub usingnamespace switch (build_config.exe_entrypoint) { +/// See build_config.ExeEntrypoint for why we do this. +const entrypoint = switch (build_config.exe_entrypoint) { .ghostty => @import("main_ghostty.zig"), .helpgen => @import("helpgen.zig"), .mdgen_ghostty_1 => @import("build/mdgen/main_ghostty_1.zig"), @@ -12,3 +12,10 @@ pub usingnamespace switch (build_config.exe_entrypoint) { .bench_grapheme_break => @import("bench/grapheme-break.zig"), .bench_page_init => @import("bench/page-init.zig"), }; + +/// The main entrypoint for the program. +pub const main = entrypoint.main; + +test { + _ = entrypoint; +} diff --git a/src/main_ghostty.zig b/src/main_ghostty.zig index 6354214d0..559b399fe 100644 --- a/src/main_ghostty.zig +++ b/src/main_ghostty.zig @@ -21,12 +21,7 @@ const apprt = @import("apprt.zig"); const App = @import("App.zig"); const Ghostty = @import("main_c.zig").Ghostty; - -/// Global process state. This is initialized in main() for exe artifacts -/// and by ghostty_init() for lib artifacts. This should ONLY be used by -/// the C API. The Zig API should NOT use any global state and should -/// rely on allocators being passed in as parameters. -pub var state: GlobalState = undefined; +const state = &@import("global.zig").state; /// The return type for main() depends on the build artifact. The lib build /// also calls "main" in order to run the CLI actions, but it calls it as @@ -172,136 +167,6 @@ pub const std_options: std.Options = .{ .logFn = logFn, }; -/// This represents the global process state. There should only -/// be one of these at any given moment. This is extracted into a dedicated -/// struct because it is reused by main and the static C lib. -pub const GlobalState = struct { - const GPA = std.heap.GeneralPurposeAllocator(.{}); - - gpa: ?GPA, - alloc: std.mem.Allocator, - action: ?cli.Action, - logging: Logging, - - /// The app resources directory, equivalent to zig-out/share when we build - /// from source. This is null if we can't detect it. - resources_dir: ?[]const u8, - - /// Where logging should go - pub const Logging = union(enum) { - disabled: void, - stderr: void, - }; - - /// Initialize the global state. - pub fn init(self: *GlobalState) !void { - // Initialize ourself to nothing so we don't have any extra state. - // IMPORTANT: this MUST be initialized before any log output because - // the log function uses the global state. - self.* = .{ - .gpa = null, - .alloc = undefined, - .action = null, - .logging = .{ .stderr = {} }, - .resources_dir = null, - }; - errdefer self.deinit(); - - self.gpa = gpa: { - // Use the libc allocator if it is available because it is WAY - // faster than GPA. We only do this in release modes so that we - // can get easy memory leak detection in debug modes. - if (builtin.link_libc) { - if (switch (builtin.mode) { - .ReleaseSafe, .ReleaseFast => true, - - // We also use it if we can detect we're running under - // Valgrind since Valgrind only instruments the C allocator - else => std.valgrind.runningOnValgrind() > 0, - }) break :gpa null; - } - - break :gpa GPA{}; - }; - - self.alloc = if (self.gpa) |*value| - value.allocator() - else if (builtin.link_libc) - std.heap.c_allocator - else - unreachable; - - // We first try to parse any action that we may be executing. - self.action = try cli.Action.detectCLI(self.alloc); - - // If we have an action executing, we disable logging by default - // since we write to stderr we don't want logs messing up our - // output. - if (self.action != null) self.logging = .{ .disabled = {} }; - - // For lib mode we always disable stderr logging by default. - if (comptime build_config.app_runtime == .none) { - self.logging = .{ .disabled = {} }; - } - - // I don't love the env var name but I don't have it in my heart - // to parse CLI args 3 times (once for actions, once for config, - // maybe once for logging) so for now this is an easy way to do - // this. Env vars are useful for logging too because they are - // easy to set. - if ((try internal_os.getenv(self.alloc, "GHOSTTY_LOG"))) |v| { - defer v.deinit(self.alloc); - if (v.value.len > 0) { - self.logging = .{ .stderr = {} }; - } - } - - // Output some debug information right away - std.log.info("ghostty version={s}", .{build_config.version_string}); - std.log.info("ghostty build optimize={s}", .{build_config.mode_string}); - std.log.info("runtime={}", .{build_config.app_runtime}); - std.log.info("font_backend={}", .{build_config.font_backend}); - if (comptime build_config.font_backend.hasHarfbuzz()) { - std.log.info("dependency harfbuzz={s}", .{harfbuzz.versionString()}); - } - if (comptime build_config.font_backend.hasFontconfig()) { - std.log.info("dependency fontconfig={d}", .{fontconfig.version()}); - } - std.log.info("renderer={}", .{renderer.Renderer}); - std.log.info("libxev backend={}", .{xev.backend}); - - // First things first, we fix our file descriptors - internal_os.fixMaxFiles(); - - // We need to make sure the process locale is set properly. Locale - // affects a lot of behaviors in a shell. - try internal_os.ensureLocale(self.alloc); - - // Initialize glslang for shader compilation - try glslang.init(); - - // Initialize oniguruma for regex - try oni.init(&.{oni.Encoding.utf8}); - - // Find our resources directory once for the app so every launch - // hereafter can use this cached value. - self.resources_dir = try internal_os.resourcesDir(self.alloc); - errdefer if (self.resources_dir) |dir| self.alloc.free(dir); - } - - /// Cleans up the global state. This doesn't _need_ to be called but - /// doing so in dev modes will check for memory leaks. - pub fn deinit(self: *GlobalState) void { - if (self.resources_dir) |dir| self.alloc.free(dir); - - if (self.gpa) |*value| { - // We want to ensure that we deinit the GPA because this is - // the point at which it will output if there were safety violations. - _ = value.deinit(); - } - } -}; - test { _ = @import("circ_buf.zig"); _ = @import("pty.zig"); From c3e37b7e15b0d7feb6b09d06ab53746795850d98 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 14:43:00 -0700 Subject: [PATCH 13/15] move global state to dedicated file --- src/global.zig | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/global.zig diff --git a/src/global.zig b/src/global.zig new file mode 100644 index 000000000..0ee4914a3 --- /dev/null +++ b/src/global.zig @@ -0,0 +1,147 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const build_config = @import("build_config.zig"); +const cli = @import("cli.zig"); +const internal_os = @import("os/main.zig"); +const fontconfig = @import("fontconfig"); +const glslang = @import("glslang"); +const harfbuzz = @import("harfbuzz"); +const oni = @import("oniguruma"); +const renderer = @import("renderer.zig"); +const xev = @import("xev"); + +/// Global process state. This is initialized in main() for exe artifacts +/// and by ghostty_init() for lib artifacts. This should ONLY be used by +/// the C API. The Zig API should NOT use any global state and should +/// rely on allocators being passed in as parameters. +pub var state: GlobalState = undefined; + +/// This represents the global process state. There should only +/// be one of these at any given moment. This is extracted into a dedicated +/// struct because it is reused by main and the static C lib. +pub const GlobalState = struct { + const GPA = std.heap.GeneralPurposeAllocator(.{}); + + gpa: ?GPA, + alloc: std.mem.Allocator, + action: ?cli.Action, + logging: Logging, + + /// The app resources directory, equivalent to zig-out/share when we build + /// from source. This is null if we can't detect it. + resources_dir: ?[]const u8, + + /// Where logging should go + pub const Logging = union(enum) { + disabled: void, + stderr: void, + }; + + /// Initialize the global state. + pub fn init(self: *GlobalState) !void { + // Initialize ourself to nothing so we don't have any extra state. + // IMPORTANT: this MUST be initialized before any log output because + // the log function uses the global state. + self.* = .{ + .gpa = null, + .alloc = undefined, + .action = null, + .logging = .{ .stderr = {} }, + .resources_dir = null, + }; + errdefer self.deinit(); + + self.gpa = gpa: { + // Use the libc allocator if it is available because it is WAY + // faster than GPA. We only do this in release modes so that we + // can get easy memory leak detection in debug modes. + if (builtin.link_libc) { + if (switch (builtin.mode) { + .ReleaseSafe, .ReleaseFast => true, + + // We also use it if we can detect we're running under + // Valgrind since Valgrind only instruments the C allocator + else => std.valgrind.runningOnValgrind() > 0, + }) break :gpa null; + } + + break :gpa GPA{}; + }; + + self.alloc = if (self.gpa) |*value| + value.allocator() + else if (builtin.link_libc) + std.heap.c_allocator + else + unreachable; + + // We first try to parse any action that we may be executing. + self.action = try cli.Action.detectCLI(self.alloc); + + // If we have an action executing, we disable logging by default + // since we write to stderr we don't want logs messing up our + // output. + if (self.action != null) self.logging = .{ .disabled = {} }; + + // For lib mode we always disable stderr logging by default. + if (comptime build_config.app_runtime == .none) { + self.logging = .{ .disabled = {} }; + } + + // I don't love the env var name but I don't have it in my heart + // to parse CLI args 3 times (once for actions, once for config, + // maybe once for logging) so for now this is an easy way to do + // this. Env vars are useful for logging too because they are + // easy to set. + if ((try internal_os.getenv(self.alloc, "GHOSTTY_LOG"))) |v| { + defer v.deinit(self.alloc); + if (v.value.len > 0) { + self.logging = .{ .stderr = {} }; + } + } + + // Output some debug information right away + std.log.info("ghostty version={s}", .{build_config.version_string}); + std.log.info("ghostty build optimize={s}", .{build_config.mode_string}); + std.log.info("runtime={}", .{build_config.app_runtime}); + std.log.info("font_backend={}", .{build_config.font_backend}); + if (comptime build_config.font_backend.hasHarfbuzz()) { + std.log.info("dependency harfbuzz={s}", .{harfbuzz.versionString()}); + } + if (comptime build_config.font_backend.hasFontconfig()) { + std.log.info("dependency fontconfig={d}", .{fontconfig.version()}); + } + std.log.info("renderer={}", .{renderer.Renderer}); + std.log.info("libxev backend={}", .{xev.backend}); + + // First things first, we fix our file descriptors + internal_os.fixMaxFiles(); + + // We need to make sure the process locale is set properly. Locale + // affects a lot of behaviors in a shell. + try internal_os.ensureLocale(self.alloc); + + // Initialize glslang for shader compilation + try glslang.init(); + + // Initialize oniguruma for regex + try oni.init(&.{oni.Encoding.utf8}); + + // Find our resources directory once for the app so every launch + // hereafter can use this cached value. + self.resources_dir = try internal_os.resourcesDir(self.alloc); + errdefer if (self.resources_dir) |dir| self.alloc.free(dir); + } + + /// Cleans up the global state. This doesn't _need_ to be called but + /// doing so in dev modes will check for memory leaks. + pub fn deinit(self: *GlobalState) void { + if (self.resources_dir) |dir| self.alloc.free(dir); + + if (self.gpa) |*value| { + // We want to ensure that we deinit the GPA because this is + // the point at which it will output if there were safety violations. + _ = value.deinit(); + } + } +}; From 9409e3072fcb0e22a8a4bc8378bb7238099a7bc2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 14:57:43 -0700 Subject: [PATCH 14/15] apprt/gtk: remove usingnamespace --- build.zig | 3 +++ src/apprt/gtk/App.zig | 2 +- src/apprt/gtk/ClipboardConfirmationWindow.zig | 2 +- src/apprt/gtk/ConfigErrorsWindow.zig | 2 +- src/apprt/gtk/ImguiWidget.zig | 2 +- src/apprt/gtk/ResizeOverlay.zig | 2 +- src/apprt/gtk/Split.zig | 2 +- src/apprt/gtk/Surface.zig | 2 +- src/apprt/gtk/Tab.zig | 2 +- src/apprt/gtk/View.zig | 2 +- src/apprt/gtk/Window.zig | 2 +- src/apprt/gtk/c.zig | 22 +++++++++---------- src/apprt/gtk/cgroup.zig | 2 +- src/apprt/gtk/ghostty_gtk_compat.h | 14 ++++++++++++ src/apprt/gtk/inspector.zig | 2 +- src/apprt/gtk/key.zig | 2 +- src/apprt/gtk/x11.zig | 2 +- 17 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 src/apprt/gtk/ghostty_gtk_compat.h diff --git a/build.zig b/build.zig index 0165de802..bc829d59e 100644 --- a/build.zig +++ b/build.zig @@ -1042,6 +1042,9 @@ fn addDeps( step.linkLibC(); step.addIncludePath(b.path("src/stb")); step.addCSourceFiles(.{ .files = &.{"src/stb/stb.c"} }); + if (step.rootModuleTarget().os.tag == .linux) { + step.addIncludePath(b.path("src/apprt/gtk")); + } // C++ files step.linkLibCpp(); diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index eb7ce82c4..8c4e41111 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -28,7 +28,7 @@ const Surface = @import("Surface.zig"); const Window = @import("Window.zig"); const ConfigErrorsWindow = @import("ConfigErrorsWindow.zig"); const ClipboardConfirmationWindow = @import("ClipboardConfirmationWindow.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const inspector = @import("inspector.zig"); const key = @import("key.zig"); const x11 = @import("x11.zig"); diff --git a/src/apprt/gtk/ClipboardConfirmationWindow.zig b/src/apprt/gtk/ClipboardConfirmationWindow.zig index e4ad080e3..bcefb9d8a 100644 --- a/src/apprt/gtk/ClipboardConfirmationWindow.zig +++ b/src/apprt/gtk/ClipboardConfirmationWindow.zig @@ -8,7 +8,7 @@ const apprt = @import("../../apprt.zig"); const CoreSurface = @import("../../Surface.zig"); const App = @import("App.zig"); const View = @import("View.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const log = std.log.scoped(.gtk); diff --git a/src/apprt/gtk/ConfigErrorsWindow.zig b/src/apprt/gtk/ConfigErrorsWindow.zig index 563a3e51b..44fa83363 100644 --- a/src/apprt/gtk/ConfigErrorsWindow.zig +++ b/src/apprt/gtk/ConfigErrorsWindow.zig @@ -8,7 +8,7 @@ const Config = configpkg.Config; const App = @import("App.zig"); const View = @import("View.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const log = std.log.scoped(.gtk); diff --git a/src/apprt/gtk/ImguiWidget.zig b/src/apprt/gtk/ImguiWidget.zig index 7280a2f13..de6bf606d 100644 --- a/src/apprt/gtk/ImguiWidget.zig +++ b/src/apprt/gtk/ImguiWidget.zig @@ -4,7 +4,7 @@ const std = @import("std"); const assert = std.debug.assert; const cimgui = @import("cimgui"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const key = @import("key.zig"); const gl = @import("opengl"); const input = @import("../../input.zig"); diff --git a/src/apprt/gtk/ResizeOverlay.zig b/src/apprt/gtk/ResizeOverlay.zig index 518d4f609..73252ee62 100644 --- a/src/apprt/gtk/ResizeOverlay.zig +++ b/src/apprt/gtk/ResizeOverlay.zig @@ -1,7 +1,7 @@ const ResizeOverlay = @This(); const std = @import("std"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const configpkg = @import("../../config.zig"); const Surface = @import("Surface.zig"); diff --git a/src/apprt/gtk/Split.zig b/src/apprt/gtk/Split.zig index 622db61fe..105646c7c 100644 --- a/src/apprt/gtk/Split.zig +++ b/src/apprt/gtk/Split.zig @@ -12,7 +12,7 @@ const CoreSurface = @import("../../Surface.zig"); const Surface = @import("Surface.zig"); const Tab = @import("Tab.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const log = std.log.scoped(.gtk); diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 01d2a1d6e..7ae690ce5 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -21,7 +21,7 @@ const ClipboardConfirmationWindow = @import("ClipboardConfirmationWindow.zig"); const ResizeOverlay = @import("ResizeOverlay.zig"); const inspector = @import("inspector.zig"); const gtk_key = @import("key.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const x11 = @import("x11.zig"); const log = std.log.scoped(.gtk_surface); diff --git a/src/apprt/gtk/Tab.zig b/src/apprt/gtk/Tab.zig index 32b0c7888..42a18711b 100644 --- a/src/apprt/gtk/Tab.zig +++ b/src/apprt/gtk/Tab.zig @@ -12,7 +12,7 @@ const CoreSurface = @import("../../Surface.zig"); const Surface = @import("Surface.zig"); const Window = @import("Window.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const log = std.log.scoped(.gtk); diff --git a/src/apprt/gtk/View.zig b/src/apprt/gtk/View.zig index 2287b4737..ecab1c95e 100644 --- a/src/apprt/gtk/View.zig +++ b/src/apprt/gtk/View.zig @@ -5,7 +5,7 @@ const View = @This(); const std = @import("std"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const log = std.log.scoped(.gtk); diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index c388e0092..1615b986f 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -19,7 +19,7 @@ const App = @import("App.zig"); const Color = configpkg.Config.Color; const Surface = @import("Surface.zig"); const Tab = @import("Tab.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const log = std.log.scoped(.gtk); diff --git a/src/apprt/gtk/c.zig b/src/apprt/gtk/c.zig index 5ac8d0fe8..e8788afee 100644 --- a/src/apprt/gtk/c.zig +++ b/src/apprt/gtk/c.zig @@ -1,21 +1,19 @@ -const c = @cImport({ +/// Imported C API directly from header files +pub const c = @cImport({ @cInclude("gtk/gtk.h"); - if (@import("build_options").libadwaita) @cInclude("libadwaita-1/adwaita.h"); + if (@import("build_options").libadwaita) { + @cInclude("libadwaita-1/adwaita.h"); + } - // Add in X11-specific GDK backend which we use for specific things (e.g. - // X11 window class). + // Add in X11-specific GDK backend which we use for specific things + // (e.g. X11 window class). @cInclude("gdk/x11/gdkx.h"); // Xkb for X11 state handling @cInclude("X11/XKBlib.h"); // generated header files @cInclude("ghostty_resources.h"); + + // compatibility + @cInclude("ghostty_gtk_compat.h"); }); - -pub usingnamespace c; - -/// Compatibility with gobject < 2.74 -pub usingnamespace if (@hasDecl(c, "G_CONNECT_DEFAULT")) struct {} else struct { - pub const G_CONNECT_DEFAULT = 0; - pub const G_APPLICATION_DEFAULT_FLAGS = c.G_APPLICATION_FLAGS_NONE; -}; diff --git a/src/apprt/gtk/cgroup.zig b/src/apprt/gtk/cgroup.zig index 7eb72b9c6..039db8a04 100644 --- a/src/apprt/gtk/cgroup.zig +++ b/src/apprt/gtk/cgroup.zig @@ -3,7 +3,7 @@ const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; -const c = @import("c.zig"); +const c = @import("c.zig").c; const App = @import("App.zig"); const internal_os = @import("../../os/main.zig"); diff --git a/src/apprt/gtk/ghostty_gtk_compat.h b/src/apprt/gtk/ghostty_gtk_compat.h new file mode 100644 index 000000000..c0dc819c2 --- /dev/null +++ b/src/apprt/gtk/ghostty_gtk_compat.h @@ -0,0 +1,14 @@ +// This file is used to provide compatibility if necessary with +// older versions of GTK and GLib. + +#include + +// Compatibility with gobject < 2.74 +#ifndef G_CONNECT_DEFAULT +#define G_CONNECT_DEFAULT 0 +#endif + +// Compatibility with gobject < 2.74 +#ifndef G_APPLICATION_DEFAULT_FLAGS +#define G_APPLICATION_DEFAULT_FLAGS G_APPLICATION_FLAGS_NONE +#endif diff --git a/src/apprt/gtk/inspector.zig b/src/apprt/gtk/inspector.zig index ae7856df7..f5bdf8a24 100644 --- a/src/apprt/gtk/inspector.zig +++ b/src/apprt/gtk/inspector.zig @@ -6,7 +6,7 @@ const App = @import("App.zig"); const Surface = @import("Surface.zig"); const TerminalWindow = @import("Window.zig"); const ImguiWidget = @import("ImguiWidget.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const CoreInspector = @import("../../inspector/main.zig").Inspector; const log = std.log.scoped(.inspector); diff --git a/src/apprt/gtk/key.zig b/src/apprt/gtk/key.zig index 405c73665..887e10d7a 100644 --- a/src/apprt/gtk/key.zig +++ b/src/apprt/gtk/key.zig @@ -1,6 +1,6 @@ const std = @import("std"); const input = @import("../../input.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; /// Returns a GTK accelerator string from a trigger. pub fn accelFromTrigger(buf: []u8, trigger: input.Binding.Trigger) !?[:0]const u8 { diff --git a/src/apprt/gtk/x11.zig b/src/apprt/gtk/x11.zig index 56ae1b36d..0b116c59f 100644 --- a/src/apprt/gtk/x11.zig +++ b/src/apprt/gtk/x11.zig @@ -1,6 +1,6 @@ /// Utility functions for X11 handling. const std = @import("std"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const input = @import("../../input.zig"); const log = std.log.scoped(.gtk_x11); From a9107e7eb639e5b6aa066bcc29a2e575e8f1ba1b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Aug 2024 15:00:07 -0700 Subject: [PATCH 15/15] apprt/embedded: fix usingnamespace usage --- src/apprt/embedded.zig | 2 +- src/main_c.zig | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index dc91871de..efeb2cf6f 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -1386,7 +1386,7 @@ pub const Inspector = struct { // C API pub const CAPI = struct { - const global = &@import("../main.zig").state; + const global = &@import("../global.zig").state; /// This is the same as Surface.KeyEvent but this is the raw C API version. const KeyEvent = extern struct { diff --git a/src/main_c.zig b/src/main_c.zig index 4cbca4899..8a66837d3 100644 --- a/src/main_c.zig +++ b/src/main_c.zig @@ -12,7 +12,8 @@ const assert = std.debug.assert; const posix = std.posix; const builtin = @import("builtin"); const build_config = @import("build_config.zig"); -const main = @import("main.zig"); +const main = @import("main_ghostty.zig"); +const state = &@import("global.zig").state; const apprt = @import("apprt.zig"); // Some comptime assertions that our C API depends on. @@ -55,7 +56,7 @@ export fn ghostty_init() c_int { var argv: [0][*:0]u8 = .{}; std.os.argv = &argv; - main.state.init() catch |err| { + state.init() catch |err| { std.log.err("failed to initialize ghostty error={}", .{err}); return 1; };