termio: report color scheme synchronously
The reporting of color scheme was handled asynchronously by queuing a handler in the surface. This could lead to race conditions where the DSR is reported after subsequent VT sequences. Fixes #5922pull/9705/head
parent
08c9661683
commit
6d20132d41
|
|
@ -1023,8 +1023,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),
|
||||
|
|
@ -1336,16 +1334,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) {
|
||||
|
|
@ -4772,7 +4766,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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -162,6 +162,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,
|
||||
|
|
@ -182,6 +183,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).
|
||||
|
|
@ -276,6 +278,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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
||||
|
|
@ -100,6 +103,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| {
|
||||
|
|
@ -107,7 +111,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(
|
||||
|
|
@ -790,10 +794,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,
|
||||
|
|
@ -875,7 +892,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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue