Tobias Kohlbau 2025-12-17 23:13:45 +04:00 committed by GitHub
commit 783a672e9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 21 deletions

View File

@ -1059,8 +1059,6 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
.scrollbar => |scrollbar| self.updateScrollbar(scrollbar),
.report_color_scheme => |force| self.reportColorScheme(force),
.present_surface => try self.presentSurface(),
.password_input => |v| try self.passwordInput(v),
@ -1372,16 +1370,12 @@ fn passwordInput(self: *Surface, v: bool) !void {
try self.queueRender();
}
/// Sends a DSR response for the current color scheme to the pty. If
/// force is false then we only send the response if the terminal mode
/// 2031 is enabled.
fn reportColorScheme(self: *Surface, force: bool) void {
if (!force) {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
if (!self.renderer_state.terminal.modes.get(.report_color_scheme)) {
return;
}
/// Sends a DSR response for the current color scheme to the pty.
fn reportColorScheme(self: *Surface) void {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
if (!self.renderer_state.terminal.modes.get(.report_color_scheme)) {
return;
}
const output = switch (self.config_conditional_state.theme) {
@ -4836,7 +4830,7 @@ pub fn colorSchemeCallback(self: *Surface, scheme: apprt.ColorScheme) !void {
self.notifyConfigConditionalState();
// If mode 2031 is on, then we report the change live.
self.reportColorScheme(false);
self.reportColorScheme();
}
pub fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Coordinate {

View File

@ -63,11 +63,6 @@ pub const Message = union(enum) {
/// Health status change for the renderer.
renderer_health: renderer.Health,
/// Report the color scheme. The bool parameter is whether to force or not.
/// If force is true, the color scheme should be reported even if mode
/// 2031 is not set.
report_color_scheme: bool,
/// Tell the surface to present itself to the user. This may require raising
/// a window and switching tabs.
present_surface: void,

View File

@ -165,6 +165,7 @@ pub const DerivedConfig = struct {
osc_color_report_format: configpkg.Config.OSCColorReportFormat,
clipboard_write: configpkg.ClipboardAccess,
enquiry_response: []const u8,
conditional_state: configpkg.ConditionalState,
pub fn init(
alloc_gpa: Allocator,
@ -185,6 +186,7 @@ pub const DerivedConfig = struct {
.osc_color_report_format = config.@"osc-color-report-format",
.clipboard_write = config.@"clipboard-write",
.enquiry_response = try alloc.dupe(u8, config.@"enquiry-response"),
.conditional_state = config._conditional_state,
// This has to be last so that we copy AFTER the arena allocations
// above happen (Zig assigns in order).
@ -279,6 +281,7 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
.enquiry_response = opts.config.enquiry_response,
.default_cursor_style = opts.config.cursor_style,
.default_cursor_blink = opts.config.cursor_blink,
.config_conditional_state = opts.config.conditional_state,
};
const thread_enter_state = try ThreadEnterState.create(

View File

@ -53,6 +53,9 @@ pub const StreamHandler = struct {
/// The color reporting format for OSC requests.
osc_color_report_format: configpkg.Config.OSCColorReportFormat,
/// The config conditional state.
config_conditional_state: configpkg.ConditionalState,
/// The clipboard write access configuration.
clipboard_write: configpkg.ClipboardAccess,
@ -112,6 +115,7 @@ pub const StreamHandler = struct {
self.enquiry_response = config.enquiry_response;
self.default_cursor_style = config.cursor_style;
self.default_cursor_blink = config.cursor_blink;
self.config_conditional_state = config.conditional_state;
// If our cursor is the default, then we update it immediately.
if (self.default_cursor) self.setCursorStyle(.default) catch |err| {
@ -119,7 +123,7 @@ pub const StreamHandler = struct {
};
// The config could have changed any of our colors so update mode 2031
self.surfaceMessageWriter(.{ .report_color_scheme = false });
self.reportColorScheme(false);
}
inline fn surfaceMessageWriter(
@ -866,10 +870,23 @@ pub const StreamHandler = struct {
self.messageWriter(msg);
},
.color_scheme => self.surfaceMessageWriter(.{ .report_color_scheme = true }),
.color_scheme => self.reportColorScheme(true),
}
}
/// Sends a DSR response for the current color scheme to the pty.
/// The caller is resposible for holding self.renderer_state.mutex.
pub fn reportColorScheme(self: *StreamHandler, force: bool) void {
if (!force and !self.renderer_state.terminal.modes.get(.report_color_scheme)) {
return;
}
const output = switch (self.config_conditional_state.theme) {
.light => "\x1B[?997;2n",
.dark => "\x1B[?997;1n",
};
self.messageWriter(.{ .write_stable = output });
}
pub fn setCursorStyle(
self: *StreamHandler,
style: terminal.CursorStyleReq,
@ -951,7 +968,7 @@ pub const StreamHandler = struct {
try self.setMouseShape(.text);
// Reset resets our palette so we report it for mode 2031.
self.surfaceMessageWriter(.{ .report_color_scheme = false });
self.reportColorScheme(false);
}
pub fn queryKittyKeyboard(self: *StreamHandler) !void {