From 44544f29b272f4731b8c4ce5dd5152db9e773296 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Jan 2024 20:45:52 -0800 Subject: [PATCH] macos: support Display P3 colorspace through configuration Fixes #1214 This introduces the `window-colorspace` configuration which allows configuring the colorspace to use for windows on macOS. The default is sRGB (same as before) but this can also be set to `display-p3`. --- .../Features/Terminal/TerminalController.swift | 10 +++++++++- macos/Sources/Ghostty/AppState.swift | 10 ++++++++++ src/config/Config.zig | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index a96e56eb8..8e4ddb270 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -162,7 +162,15 @@ class TerminalController: NSWindowController, NSWindowDelegate, // Terminals typically operate in sRGB color space and macOS defaults // to "native" which is typically P3. There is a lot more resources // covered in thie GitHub issue: https://github.com/mitchellh/ghostty/pull/376 - window.colorSpace = NSColorSpace.sRGB + // Ghostty defaults to sRGB but this can be overridden. + switch (ghostty.windowColorspace) { + case "display-p3": + window.colorSpace = .displayP3 + case "srgb": + fallthrough + default: + window.colorSpace = .sRGB + } // If we have only a single surface (no splits) and that surface requested // an initial size then we set it here now. diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index 0f4570e5c..cfd9cdb95 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -65,6 +65,16 @@ extension Ghostty { return v } + /// window-colorspace + var windowColorspace: String { + guard let config = self.config else { return "" } + var v: UnsafePointer? = nil + let key = "window-colorspace" + guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return "" } + guard let ptr = v else { return "" } + return String(cString: ptr) + } + /// window-save-state var windowSaveState: String { guard let config = self.config else { return "" } diff --git a/src/config/Config.zig b/src/config/Config.zig index 3f093865f..f88bb2b70 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -587,6 +587,15 @@ keybind: Keybinds = .{}, /// This is currently only supported on macOS and linux. @"window-theme": WindowTheme = .system, +/// The colorspace to use for the terminal window. The default is "srgb" +/// but this can also be set to "display-p3" to use the Display P3 +/// colorspace. +/// +/// Changing this value at runtime will only affect new windows. +/// +/// This setting is only supported on macOS. +@"window-colorspace": WindowColorspace = .srgb, + /// The initial window size. This size is in terminal grid cells by default. /// /// We don't currently support specifying a size in pixels but a future @@ -2835,6 +2844,12 @@ pub const WindowTheme = enum { dark, }; +/// See window-colorspace +pub const WindowColorspace = enum { + srgb, + @"display-p3", +}; + /// See gtk-single-instance pub const GtkSingleInstance = enum { desktop,