Files
ghostty/src/apprt/surface.zig
Jeffrey C. Ollie ce5e55d4aa Implement the XTWINOPS (CSI t) control sequences that "make sense".
These sequences were implemented:

CSI 14 t - report the text area size in pixels
CSI 16 t - report the cell size in pixels
CSI 18 t - report the text area size in cells
CSI 21 t - report the window title

These sequences were not implemented because they manuipulate the window
state in ways that we do not want.

CSI 1 t
CSI 2 t
CSI 3 ; x ; y t
CSI 4 ; height ; width ; t
CSI 5 t
CSI 6 t
CSI 7 t
CSI 8 ; height ; width ; t
CSI 9 ; 0 t
CSI 9 ; 1 t
CSI 9 ; 2 t
CSI 9 ; 3 t
CSI 10 ; 0 t
CSI 10 ; 1 t
CSI 10 ; 2 t
CSI 24 t

These sequences were not implemented because they do not make sense in
a Wayland context:

CSI 11 t
CSI 13 t
CSI 14 ; 2 t

These sequences were not implemented because they provide information
about the screen that is unnecessary.

CSI 15 t
CSI 19 t

These sequences were not implemeted because Ghostty does not maintain an
icon title for windows.

CSI 20 t
CSI 22 ; 0 t
CSI 22 ; 1 t
CSI 23 ; 0 t
CSI 23 ; 1 t

These sequences were not implemented because of the additional
complexity of maintaining a stack of window titles.

CSI 22 ; 2 t
CSI 23 ; 2 t
2024-08-07 00:12:20 -05:00

114 lines
3.4 KiB
Zig

const apprt = @import("../apprt.zig");
const App = @import("../App.zig");
const Surface = @import("../Surface.zig");
const renderer = @import("../renderer.zig");
const termio = @import("../termio.zig");
const terminal = @import("../terminal/main.zig");
const Config = @import("../config.zig").Config;
/// The message types that can be sent to a single surface.
pub const Message = union(enum) {
/// Represents a write request. Magic number comes from the max size
/// we want this union to be.
pub const WriteReq = termio.MessageData(u8, 255);
/// Set the title of the surface.
/// TODO: we should change this to a "WriteReq" style structure in
/// the termio message so that we can more efficiently send strings
/// of any length
set_title: [256]u8,
/// Report the window title back to the terminal
report_title: ReportTitleStyle,
/// Set the mouse shape.
set_mouse_shape: terminal.MouseShape,
/// Read the clipboard and write to the pty.
clipboard_read: apprt.Clipboard,
/// Write the clipboard contents.
clipboard_write: struct {
clipboard_type: apprt.Clipboard,
req: WriteReq,
},
/// Change the configuration to the given configuration. The pointer is
/// not valid after receiving this message so any config must be used
/// and derived immediately.
change_config: *const Config,
/// Close the surface. This will only close the current surface that
/// receives this, not the full application.
close: void,
/// The child process running in the surface has exited. This may trigger
/// a surface close, it may not.
child_exited: void,
/// Show a desktop notification.
desktop_notification: struct {
/// Desktop notification title.
title: [63:0]u8,
/// Desktop notification body.
body: [255:0]u8,
},
/// Health status change for the renderer.
renderer_health: renderer.Health,
/// Report the color scheme
report_color_scheme: void,
pub const ReportTitleStyle = enum {
csi_21_t,
};
};
/// A surface mailbox.
pub const Mailbox = struct {
surface: *Surface,
app: App.Mailbox,
/// Send a message to the surface.
pub fn push(
self: Mailbox,
msg: Message,
timeout: App.Mailbox.Queue.Timeout,
) App.Mailbox.Queue.Size {
// Surface message sending is actually implemented on the app
// thread, so we have to rewrap the message with our surface
// pointer and send it to the app thread.
return self.app.push(.{
.surface_message = .{
.surface = self.surface,
.message = msg,
},
}, timeout);
}
};
/// Returns a new config for a surface for the given app that should be
/// used for any new surfaces. The resulting config should be deinitialized
/// after the surface is initialized.
pub fn newConfig(app: *const App, config: *const Config) !Config {
// Create a shallow clone
var copy = config.shallowClone(app.alloc);
// Our allocator is our config's arena
const alloc = copy._arena.?.allocator();
// Get our previously focused surface for some inherited values.
const prev = app.focusedSurface();
if (prev) |p| {
if (config.@"window-inherit-working-directory") {
if (try p.pwd(alloc)) |pwd| {
copy.@"working-directory" = pwd;
}
}
}
return copy;
}