From 008736c3bf8f7e45bdcf435749fe9cb7d4820c33 Mon Sep 17 00:00:00 2001 From: xdBronch <51252236+xdBronch@users.noreply.github.com> Date: Wed, 1 Nov 2023 19:19:30 -0400 Subject: [PATCH 01/11] add support for file dropping to glfw runtime --- src/apprt/glfw.zig | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index bf96e1e6c..65ab3cd57 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -353,6 +353,7 @@ pub const Surface = struct { win.setScrollCallback(scrollCallback); win.setCursorPosCallback(cursorPosCallback); win.setMouseButtonCallback(mouseButtonCallback); + win.setDropCallback(dropCallback); // Build our result self.* = .{ @@ -964,4 +965,38 @@ pub const Surface = struct { return; }; } + + fn dropCallback(window: glfw.Window, paths: [][*:0]const u8) void { + const tracy = trace(@src()); + defer tracy.end(); + + const surface = window.getUserPointer(CoreSurface) orelse return; + + var list = std.ArrayList(u8).init(surface.alloc); + defer list.deinit(); + + for (paths) |path| { + const path_slice = std.mem.span(path); + const writer = list.writer(); + + list.ensureTotalCapacity(path_slice.len * 2 + 1) catch |err| { // preallocate worst case of escaping every char + space + log.err("error in drop callback err={}", .{err}); + return; + }; + + for (path_slice) |c| { + if (std.mem.indexOfScalar(u8, "\\ ()[]{}<>\"'`!#$&;|*?\t", c)) |_| { + writer.print("\\{c}", .{c}) catch unreachable; // only error is OOM, memory preallocated + } else writer.writeByte(c) catch unreachable; // same here + } + writer.writeByte(' ') catch unreachable; // separate paths + + surface.textCallback(list.items) catch |err| { + log.err("error in drop callback err={}", .{err}); + return; + }; + + list.clearRetainingCapacity(); // avoid unnecessary reallocations + } + } }; From dc527bd2cb2f42f7c39e8dd18d064e906ea4a4b6 Mon Sep 17 00:00:00 2001 From: Leo Razoumov Date: Thu, 2 Nov 2023 17:50:17 -0400 Subject: [PATCH 02/11] feat: keybind escape sequence action "esc:text" similar to "csi:text" --- .gitignore | 6 +++++- src/Surface.zig | 8 ++++---- src/config/Config.zig | 2 ++ src/input/Binding.zig | 9 +++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index cc549e044..8e7a003ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ +*~ +.*.swp +.swp +*.log .DS_Store -.vscode +.vscode/ .direnv/ .flatpak-builder/ zig-cache/ diff --git a/src/Surface.zig b/src/Surface.zig index 31a032647..9b89f6618 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2169,19 +2169,19 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool .reload_config => try self.app.reloadConfig(self.rt_app), - .csi => |data| { - // We need to send the CSI sequence as a single write request. + .csi, .esc => |data| { + // We need to send the CSI/ESC sequence as a single write request. // If you split it across two then the shell can interpret it // as two literals. var buf: [128]u8 = undefined; - const full_data = try std.fmt.bufPrint(&buf, "\x1b[{s}", .{data}); + const full_data = try std.fmt.bufPrint(&buf, "\x1b{s}{s}", .{if(action==.csi)"["else"", data}); _ = self.io_thread.mailbox.push(try termio.Message.writeReq( self.alloc, full_data, ), .{ .forever = {} }); try self.io_thread.wakeup.notify(); - // CSI triggers a scroll. + // CSI/ESC triggers a scroll. { self.renderer_state.mutex.lock(); defer self.renderer_state.mutex.unlock(); diff --git a/src/config/Config.zig b/src/config/Config.zig index dc47fd5bd..0f416f503 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -321,6 +321,8 @@ command: ?[]const u8 = null, /// is removed, and the key will be sent through to the child command /// if it is printable. /// - "csi:text" - Send a CSI sequence. i.e. "csi:A" sends "cursor up". +/// - "esc:text" - Send an Escape sequence. i.e. "esc:d" deletes to the +/// end of the word to the right. /// /// Some notes for the action: /// diff --git a/src/input/Binding.zig b/src/input/Binding.zig index c326b21b0..9198e2f53 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -117,6 +117,9 @@ pub const Action = union(enum) { /// without the CSI header ("ESC ]" or "\x1b]"). csi: []const u8, + /// Send an ESC sequence. + esc: []const u8, + /// Send data to the pty depending on whether cursor key mode is /// enabled ("application") or disabled ("normal"). cursor_key: CursorKey, @@ -665,6 +668,12 @@ test "parse: action with string" { try testing.expect(binding.action == .csi); try testing.expectEqualStrings("A", binding.action.csi); } + // parameter + { + const binding = try parse("a=esc:A"); + try testing.expect(binding.action == .esc); + try testing.expectEqualStrings("A", binding.action.esc); + } } test "parse: action with enum" { From 2d7e2c8345e0b77740f02566ad34cefdae91c983 Mon Sep 17 00:00:00 2001 From: Hanna Date: Thu, 2 Nov 2023 21:29:29 -0700 Subject: [PATCH 03/11] Integrate libadwaita for the gtk backend (#792) * When using gtk as the backend, link libadwaita * Update c.zig * Use libadwaita's theme manager for gtk * update the documentation for window-theme * build: add libadwaita to the nix devshell * forgot to properly import libadwaita * apprt/gtk: adwaita style change --------- Co-authored-by: Mitchell Hashimoto --- build.zig | 1 + nix/devshell.nix | 3 +++ src/apprt/gtk/App.zig | 13 +++++++++++++ src/apprt/gtk/c.zig | 1 + src/config/Config.zig | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index cc914dca2..7b7f0ce94 100644 --- a/build.zig +++ b/build.zig @@ -814,6 +814,7 @@ fn addDeps( .gtk => { step.linkSystemLibrary2("gtk4", dynamic_link_opts); + step.linkSystemLibrary2("adwaita-1", dynamic_link_opts); }, } } diff --git a/nix/devshell.nix b/nix/devshell.nix index 78d8de6fb..5804cceb5 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -28,6 +28,7 @@ , freetype , glib , gtk4 +, libadwaita , harfbuzz , libpng , libGL @@ -59,6 +60,7 @@ let libXi libXrandr + libadwaita gtk4 glib ]; @@ -120,6 +122,7 @@ in mkShell rec { libXrandr # Only needed for GTK builds + libadwaita gtk4 glib ]; diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 47e69eba3..f5f93c38f 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -52,6 +52,9 @@ running: bool = true, pub fn init(core_app: *CoreApp, opts: Options) !App { _ = opts; + // Initialize libadwaita + c.adw_init(); + // Load our configuration var config = try Config.load(core_app.alloc); errdefer config.deinit(); @@ -63,6 +66,16 @@ pub fn init(core_app: *CoreApp, opts: Options) !App { } } + // Set the style based on our configuration file + c.adw_style_manager_set_color_scheme( + c.adw_style_manager_get_default(), + switch (config.@"window-theme") { + .system => c.ADW_COLOR_SCHEME_PREFER_LIGHT, + .dark => c.ADW_COLOR_SCHEME_FORCE_DARK, + .light => c.ADW_COLOR_SCHEME_FORCE_LIGHT, + }, + ); + // The "none" cursor is used for hiding the cursor const cursor_none = c.gdk_cursor_new_from_name("none", null); errdefer if (cursor_none) |cursor| c.g_object_unref(cursor); diff --git a/src/apprt/gtk/c.zig b/src/apprt/gtk/c.zig index c5952d321..7eb19233f 100644 --- a/src/apprt/gtk/c.zig +++ b/src/apprt/gtk/c.zig @@ -1,5 +1,6 @@ const c = @cImport({ @cInclude("gtk/gtk.h"); + @cInclude("libadwaita-1/adwaita.h"); }); pub usingnamespace c; diff --git a/src/config/Config.zig b/src/config/Config.zig index dc47fd5bd..7f2218ef0 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -378,7 +378,7 @@ keybind: Keybinds = .{}, /// also be set to "light" or "dark" to force a specific theme regardless /// of the system settings. /// -/// This is currently only supported on macOS. +/// This is currently only supported on macOS and linux. @"window-theme": WindowTheme = .system, /// The initial window size. This size is in terminal grid cells by default. From 657111c4101264c4d69020b0d3000e4a97e4e504 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 2 Nov 2023 21:34:43 -0700 Subject: [PATCH 04/11] apprt/glfw: small line length fixes --- src/apprt/glfw.zig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 65ab3cd57..be4103f77 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -977,16 +977,17 @@ pub const Surface = struct { for (paths) |path| { const path_slice = std.mem.span(path); - const writer = list.writer(); - list.ensureTotalCapacity(path_slice.len * 2 + 1) catch |err| { // preallocate worst case of escaping every char + space + // preallocate worst case of escaping every char + space + list.ensureTotalCapacity(path_slice.len * 2 + 1) catch |err| { log.err("error in drop callback err={}", .{err}); return; }; + const writer = list.writer(); for (path_slice) |c| { if (std.mem.indexOfScalar(u8, "\\ ()[]{}<>\"'`!#$&;|*?\t", c)) |_| { - writer.print("\\{c}", .{c}) catch unreachable; // only error is OOM, memory preallocated + writer.print("\\{c}", .{c}) catch unreachable; // memory preallocated } else writer.writeByte(c) catch unreachable; // same here } writer.writeByte(' ') catch unreachable; // separate paths From 22757683834a35fb017d95f2282af72963786ff9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 2 Nov 2023 21:46:50 -0700 Subject: [PATCH 05/11] font: if a codepoint is emoji presentation, prefer that for shaping Fixes #787 --- build.zig | 5 +++++ build.zig.zon | 11 +++++++---- src/font/shaper/run.zig | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 7b7f0ce94..30c0c6d7a 100644 --- a/build.zig +++ b/build.zig @@ -669,6 +669,10 @@ fn addDeps( .@"enable-freetype" = true, .@"enable-coretext" = font_backend.hasCoretext(), }); + const ziglyph_dep = b.dependency("ziglyph", .{ + .target = step.target, + .optimize = step.optimize, + }); // Wasm we do manually since it is such a different build. if (step.target.getCpuArch() == .wasm32) { @@ -716,6 +720,7 @@ fn addDeps( step.addModule("xev", libxev_dep.module("xev")); step.addModule("pixman", pixman_dep.module("pixman")); step.addModule("utf8proc", utf8proc_dep.module("utf8proc")); + step.addModule("ziglyph", ziglyph_dep.module("ziglyph")); // Mac Stuff if (step.target.isDarwin()) { diff --git a/build.zig.zon b/build.zig.zon index bfca4e766..765e3c0ee 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,6 +4,10 @@ .paths = .{""}, .dependencies = .{ // Zig libs + .glfw = .{ + .url = "https://pkg.machengine.org/glfw/14181bd28aa65915262ac3b4549bbd2dc70bbaa5.tar.gz", + .hash = "1220c6bb317ae3948b95161b9706777dde0509e72e8b35b62b92898aef801897d904", + }, .libxev = .{ .url = "https://github.com/mitchellh/libxev/archive/5ecbc871f3bfa80fb7bf0fa853866cb93b99bc18.tar.gz", .hash = "1220416854e424601ecc9814afb461a5dc9cf95db5917d82f794594a58ffc723b82c", @@ -20,10 +24,9 @@ .url = "https://github.com/mitchellh/zig-js/archive/60ac42ab137461cdba2b38cc6c5e16376470aae6.tar.gz", .hash = "1220319b42fbc0116f3f198343256018e9f1da9483cef259201afe4ebab0ce0d8f6a", }, - - .glfw = .{ - .url = "https://pkg.machengine.org/glfw/14181bd28aa65915262ac3b4549bbd2dc70bbaa5.tar.gz", - .hash = "1220c6bb317ae3948b95161b9706777dde0509e72e8b35b62b92898aef801897d904", + .ziglyph = .{ + .url = "https://codeberg.org/dude_the_builder/ziglyph/archive/v0.11.1.tar.gz", + .hash = "1220dee955839b7f267c1bb21e0ee60888c08f408c30f0722b243cabcc8cce8b7508", }, // C libs diff --git a/src/font/shaper/run.zig b/src/font/shaper/run.zig index 94a5da3f0..9af4a9b4c 100644 --- a/src/font/shaper/run.zig +++ b/src/font/shaper/run.zig @@ -1,6 +1,7 @@ const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; +const ziglyph = @import("ziglyph"); const font = @import("../main.zig"); const shape = @import("../shape.zig"); const terminal = @import("../../terminal/main.zig"); @@ -109,12 +110,20 @@ pub const RunIterator = struct { // presentation format must be directly adjacent to the codepoint. var it = self.row.codepointIterator(j); if (it.next()) |cp| { - if (cp == 0xFE0E) break :p font.Presentation.text; - if (cp == 0xFE0F) break :p font.Presentation.emoji; + if (cp == 0xFE0E) break :p .text; + if (cp == 0xFE0F) break :p .emoji; } break :p null; - } else null; + } else emoji: { + // If we're not a grapheme, our individual char could be + // an emoji so we want to check if we expect emoji presentation. + if (ziglyph.emoji.isEmojiPresentation(@intCast(cell.char))) { + break :emoji .emoji; + } + + break :emoji .text; + }; // If our cursor is on this line then we break the run around the // cursor. This means that any row with a cursor has at least From 63fe99809fbe59d4981d3cbf5bbe04b4a0ee2ed4 Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 2 Nov 2023 21:54:05 -0700 Subject: [PATCH 06/11] remove hard dependency on libadwaita --- build.zig | 10 +++++++++- src/apprt/gtk/App.zig | 21 ++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 7b7f0ce94..812e8f639 100644 --- a/build.zig +++ b/build.zig @@ -39,6 +39,7 @@ var flatpak: bool = false; var app_runtime: apprt.Runtime = .none; var renderer_impl: renderer.Impl = .opengl; var font_backend: font.Backend = .freetype; +var libadwaita: bool = false; pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); @@ -87,6 +88,12 @@ pub fn build(b: *std.Build) !void { "The app runtime to use. Not all values supported on all platforms.", ) orelse apprt.Runtime.default(target); + libadwaita = b.option( + bool, + "libadwaita", + "Enables the use of libadwaita when using the gtk rendering backend.", + ) orelse false; + renderer_impl = b.option( renderer.Impl, "renderer", @@ -203,6 +210,7 @@ pub fn build(b: *std.Build) !void { exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime); exe_options.addOption(font.Backend, "font_backend", font_backend); exe_options.addOption(renderer.Impl, "renderer", renderer_impl); + exe_options.addOption(bool, "libadwaita", libadwaita); // Exe if (exe_) |exe| { @@ -814,7 +822,7 @@ fn addDeps( .gtk => { step.linkSystemLibrary2("gtk4", dynamic_link_opts); - step.linkSystemLibrary2("adwaita-1", dynamic_link_opts); + if (libadwaita) step.linkSystemLibrary2("adwaita-1", dynamic_link_opts); }, } } diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index f5f93c38f..5e5c143b4 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -19,6 +19,7 @@ const internal_os = @import("../../os/main.zig"); const Config = configpkg.Config; const CoreApp = @import("../../App.zig"); const CoreSurface = @import("../../Surface.zig"); +const build_options = @import("build_options"); const Surface = @import("Surface.zig"); const Window = @import("Window.zig"); @@ -53,7 +54,7 @@ pub fn init(core_app: *CoreApp, opts: Options) !App { _ = opts; // Initialize libadwaita - c.adw_init(); + if (build_options.libadwaita) c.adw_init(); // Load our configuration var config = try Config.load(core_app.alloc); @@ -67,14 +68,16 @@ pub fn init(core_app: *CoreApp, opts: Options) !App { } // Set the style based on our configuration file - c.adw_style_manager_set_color_scheme( - c.adw_style_manager_get_default(), - switch (config.@"window-theme") { - .system => c.ADW_COLOR_SCHEME_PREFER_LIGHT, - .dark => c.ADW_COLOR_SCHEME_FORCE_DARK, - .light => c.ADW_COLOR_SCHEME_FORCE_LIGHT, - }, - ); + if (build_options.libadwaita) { + c.adw_style_manager_set_color_scheme( + c.adw_style_manager_get_default(), + switch (config.@"window-theme") { + .system => c.ADW_COLOR_SCHEME_PREFER_LIGHT, + .dark => c.ADW_COLOR_SCHEME_FORCE_DARK, + .light => c.ADW_COLOR_SCHEME_FORCE_LIGHT, + }, + ); + } // The "none" cursor is used for hiding the cursor const cursor_none = c.gdk_cursor_new_from_name("none", null); From 5a161719cc4e0516d7d5a9bc48a58ffd590b76b9 Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 2 Nov 2023 21:58:56 -0700 Subject: [PATCH 07/11] Update gtk build test to use libadwaita --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d46748584..d57263696 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -132,7 +132,7 @@ jobs: run: nix develop -c zig build -Dapp-runtime=none test - name: Test GTK Build - run: nix develop -c zig build -Dapp-runtime=gtk + run: nix develop -c zig build -Dapp-runtime=gtk -Dlibadwaita=true - name: Test GLFW Build run: nix develop -c zig build -Dapp-runtime=glfw From 60713b46e9c24ee3b8477c294a5fa843f3834cdf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 2 Nov 2023 22:00:33 -0700 Subject: [PATCH 08/11] macos: terminal window must subclass nswindow to receive events Fixes #788 --- macos/Ghostty.xcodeproj/project.pbxproj | 4 ++++ macos/Sources/Features/Terminal/Terminal.xib | 2 +- macos/Sources/Features/Terminal/TerminalWindow.swift | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 macos/Sources/Features/Terminal/TerminalWindow.swift diff --git a/macos/Ghostty.xcodeproj/project.pbxproj b/macos/Ghostty.xcodeproj/project.pbxproj index 98fd5e58d..153b146a9 100644 --- a/macos/Ghostty.xcodeproj/project.pbxproj +++ b/macos/Ghostty.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 8503D7C72A549C66006CFF3D /* FullScreenHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8503D7C62A549C66006CFF3D /* FullScreenHandler.swift */; }; 857F63812A5E64F200CA4815 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 857F63802A5E64F200CA4815 /* MainMenu.xib */; }; + A51B78472AF4B58B00F3EDB9 /* TerminalWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51B78462AF4B58B00F3EDB9 /* TerminalWindow.swift */; }; A5278A9B2AA05B2600CD3039 /* Ghostty.Input.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5278A9A2AA05B2600CD3039 /* Ghostty.Input.swift */; }; A53426352A7DA53D00EBB7A2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53426342A7DA53D00EBB7A2 /* AppDelegate.swift */; }; A535B9DA299C569B0017E2E4 /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A535B9D9299C569B0017E2E4 /* ErrorView.swift */; }; @@ -45,6 +46,7 @@ /* Begin PBXFileReference section */ 8503D7C62A549C66006CFF3D /* FullScreenHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullScreenHandler.swift; sourceTree = ""; }; 857F63802A5E64F200CA4815 /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = ""; }; + A51B78462AF4B58B00F3EDB9 /* TerminalWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalWindow.swift; sourceTree = ""; }; A5278A9A2AA05B2600CD3039 /* Ghostty.Input.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ghostty.Input.swift; sourceTree = ""; }; A53426342A7DA53D00EBB7A2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A535B9D9299C569B0017E2E4 /* ErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorView.swift; sourceTree = ""; }; @@ -171,6 +173,7 @@ A596309F2AEF6AEB00D64628 /* TerminalManager.swift */, A596309B2AEE1C9E00D64628 /* TerminalController.swift */, A596309D2AEE1D6C00D64628 /* TerminalView.swift */, + A51B78462AF4B58B00F3EDB9 /* TerminalWindow.swift */, A535B9D9299C569B0017E2E4 /* ErrorView.swift */, ); path = Terminal; @@ -313,6 +316,7 @@ A59630A22AF0415000D64628 /* Ghostty.TerminalSplit.swift in Sources */, A5FEB3002ABB69450068369E /* main.swift in Sources */, A55B7BB829B6F53A0055DE60 /* Package.swift in Sources */, + A51B78472AF4B58B00F3EDB9 /* TerminalWindow.swift in Sources */, A55B7BB629B6F47F0055DE60 /* AppState.swift in Sources */, A5CEAFDC29B8009000646FDA /* SplitView.swift in Sources */, A5CDF1932AAF9E0800513312 /* ConfigurationErrorsController.swift in Sources */, diff --git a/macos/Sources/Features/Terminal/Terminal.xib b/macos/Sources/Features/Terminal/Terminal.xib index f0f0937db..b9e9a12b6 100644 --- a/macos/Sources/Features/Terminal/Terminal.xib +++ b/macos/Sources/Features/Terminal/Terminal.xib @@ -13,7 +13,7 @@ - + diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift new file mode 100644 index 000000000..9a74a7e2b --- /dev/null +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -0,0 +1,8 @@ +import Cocoa + +class TerminalWindow: NSWindow { + // Both of these must be true for windows without decorations to be able to + // still become key/main and receive events. + override var canBecomeKey: Bool { return true } + override var canBecomeMain: Bool { return true } +} From 915f1f5e625d526ebc62ed2516b026518d285a94 Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 2 Nov 2023 22:03:11 -0700 Subject: [PATCH 09/11] change option name and default value --- build.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 812e8f639..1daee193e 100644 --- a/build.zig +++ b/build.zig @@ -90,9 +90,9 @@ pub fn build(b: *std.Build) !void { libadwaita = b.option( bool, - "libadwaita", + "gtk-libadwaita", "Enables the use of libadwaita when using the gtk rendering backend.", - ) orelse false; + ) orelse true; renderer_impl = b.option( renderer.Impl, From 3bee252389f0113494991224c43936750c862111 Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 2 Nov 2023 22:05:28 -0700 Subject: [PATCH 10/11] Correct the option on the ci workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d57263696..abf4a1633 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -132,7 +132,7 @@ jobs: run: nix develop -c zig build -Dapp-runtime=none test - name: Test GTK Build - run: nix develop -c zig build -Dapp-runtime=gtk -Dlibadwaita=true + run: nix develop -c zig build -Dapp-runtime=gtk -Dgtk-libadwaita=true - name: Test GLFW Build run: nix develop -c zig build -Dapp-runtime=glfw From 833e1a532952649137e17e1136e6a0a5fa6f4a7e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 2 Nov 2023 22:12:52 -0700 Subject: [PATCH 11/11] macos: only modify style mask, don't overwrite Fixes #784 The issue before was we were removing the fullscreen style which was triggering a Cocoa assertion. --- .../Features/Terminal/TerminalController.swift | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 6a4ae7afb..8ad1509d5 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -28,13 +28,6 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele /// True when an alert is active so we don't overlap multiple. private var alert: NSAlert? = nil - /// The style mask to use for the new window - private var styleMask: NSWindow.StyleMask { - var mask: NSWindow.StyleMask = [.resizable, .closable, .miniaturizable] - if (ghostty.windowDecorations) { mask.insert(.titled) } - return mask - } - init(_ ghostty: Ghostty.AppState, withBaseConfig base: Ghostty.SurfaceConfiguration? = nil) { self.ghostty = ghostty super.init(window: nil) @@ -76,7 +69,9 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele override func windowDidLoad() { guard let window = window else { return } - window.styleMask = self.styleMask + + // If window decorations are disabled, remove our title + if (!ghostty.windowDecorations) { window.styleMask.remove(.titled) } // Terminals typically operate in sRGB color space and macOS defaults // to "native" which is typically P3. There is a lot more resources