From 10eb0bc744165ae91dfce9fd731fe170410b34ec Mon Sep 17 00:00:00 2001 From: Can Celik Date: Mon, 3 Aug 2026 02:05:27 +0300 Subject: fix: propagate host color scheme to pane apps (#2214) refs #714 --- src/ghostty/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/ghostty') diff --git a/src/ghostty/mod.rs b/src/ghostty/mod.rs index c4541948..685c0735 100644 --- a/src/ghostty/mod.rs +++ b/src/ghostty/mod.rs @@ -119,6 +119,21 @@ impl FocusEvent { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ColorScheme { + Light, + Dark, +} + +impl ColorScheme { + fn as_raw(self) -> ffi::GhosttyColorScheme { + match self { + Self::Light => ffi::GhosttyColorScheme_GHOSTTY_COLOR_SCHEME_LIGHT, + Self::Dark => ffi::GhosttyColorScheme_GHOSTTY_COLOR_SCHEME_DARK, + } + } +} + pub const MOD_SHIFT: u16 = ffi::GHOSTTY_MODS_SHIFT as u16; pub const MOD_CTRL: u16 = ffi::GHOSTTY_MODS_CTRL as u16; pub const MOD_ALT: u16 = ffi::GHOSTTY_MODS_ALT as u16; @@ -163,6 +178,7 @@ pub const MODE_MOUSE_SGR_PIXELS: u16 = 1016; pub const MODE_BRACKETED_PASTE: u16 = 2004; pub const MODE_SYNCHRONIZED_OUTPUT: u16 = 2026; pub const MODE_GRAPHEME_CLUSTER: u16 = 2027; +pub const MODE_COLOR_SCHEME_REPORT: u16 = 2031; // These are documented in vendor/libghostty-vt/include/ghostty/vt/terminal.h, // but the generated bindings do not currently expose named constants for them. const TERMINAL_DATA_COLOR_FOREGROUND: ffi::GhosttyTerminalData = 18; @@ -457,6 +473,25 @@ struct TerminalCallbackState { pwd_changes: Vec>, clipboard_writes: Vec>, size_report: ffi::GhosttySizeReportSize, + color_scheme: Option, +} + +unsafe extern "C" fn color_scheme_trampoline( + _terminal: ffi::GhosttyTerminal, + userdata: *mut c_void, + out_scheme: *mut ffi::GhosttyColorScheme, +) -> bool { + if userdata.is_null() || out_scheme.is_null() { + return false; + } + let state = unsafe { &*userdata.cast::() }; + let Some(color_scheme) = state.color_scheme else { + return false; + }; + unsafe { + out_scheme.write(color_scheme.as_raw()); + } + true } unsafe extern "C" fn size_trampoline( @@ -791,6 +826,12 @@ impl Terminal { (clipboard_write_trampoline as *const ()).cast(), ) .into_result()?; + ffi::ghostty_terminal_set( + terminal.raw, + ffi::GhosttyTerminalOption_GHOSTTY_TERMINAL_OPT_COLOR_SCHEME, + (color_scheme_trampoline as *const ()).cast(), + ) + .into_result()?; ffi::ghostty_terminal_set( terminal.raw, ffi::GhosttyTerminalOption_GHOSTTY_TERMINAL_OPT_GLYPH_PROTOCOL, @@ -913,6 +954,10 @@ impl Terminal { Ok(()) } + pub fn set_color_scheme(&mut self, color_scheme: Option) -> Option { + mem::replace(&mut self.callback_state.color_scheme, color_scheme) + } + pub fn take_pwd_changes(&mut self) -> Vec> { mem::take(&mut self.callback_state.pwd_changes) } -- cgit v1.2.3