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
This commit is contained in:
Jeffrey C. Ollie
2024-08-07 00:12:20 -05:00
parent 0ec0cc0f95
commit ce5e55d4aa
13 changed files with 244 additions and 22 deletions

View File

@@ -55,6 +55,9 @@ pub const App = struct {
/// Called to set the title of the window.
set_title: *const fn (SurfaceUD, [*]const u8) callconv(.C) void,
/// Called to get the title of the window.
get_title: ?*const fn (SurfaceUD) callconv(.C) ?[*]const u8 = null,
/// Called to set the cursor shape.
set_mouse_shape: *const fn (SurfaceUD, terminal.MouseShape) callconv(.C) void,
@@ -543,6 +546,17 @@ pub const Surface = struct {
);
}
pub fn getTitle(self: *Surface) ?[:0]const u8 {
const func = self.app.opts.get_title orelse {
log.info("runtime embedder does not support get_title", .{});
return null;
};
const result = func(self.userdata);
if (result == null) return null;
return std.mem.sliceTo(@as([*:0]const u8, @ptrCast(result.?)), 0);
}
pub fn setMouseShape(self: *Surface, shape: terminal.MouseShape) !void {
self.app.opts.set_mouse_shape(
self.userdata,

View File

@@ -360,6 +360,11 @@ pub const Surface = struct {
/// The monitor dimensions so we can toggle fullscreen on and off.
monitor_dims: MonitorDimensions,
/// Save the title text so that we can return it later when requested.
/// This is allocated from the heap so it must be freed when we deinit the
/// surface.
title_text: ?[:0]const u8 = null,
pub const Options = struct {};
/// Initialize the surface into the given self pointer. This gives a
@@ -463,6 +468,8 @@ pub const Surface = struct {
}
pub fn deinit(self: *Surface) void {
if (self.title_text) |t| self.core_surface.alloc.free(t);
// Remove ourselves from the list of known surfaces in the app.
self.app.app.deleteSurface(self);
@@ -609,7 +616,14 @@ pub const Surface = struct {
/// Set the title of the window.
pub fn setTitle(self: *Surface, slice: [:0]const u8) !void {
self.window.setTitle(slice.ptr);
if (self.title_text) |t| self.core_surface.alloc.free(t);
self.title_text = try self.core_surface.alloc.dupeZ(u8, slice);
self.window.setTitle(self.title_text.?.ptr);
}
/// Return the title of the window.
pub fn getTitle(self: *Surface) ?[:0]const u8 {
return self.title_text;
}
/// Set the shape of the cursor.

View File

@@ -935,6 +935,10 @@ pub fn setTitle(self: *Surface, slice: [:0]const u8) !void {
self.updateTitleLabels();
}
pub fn getTitle(self: *Surface) ?[:0]const u8 {
return self.title_text;
}
pub fn setMouseShape(
self: *Surface,
shape: terminal.MouseShape,

View File

@@ -18,6 +18,9 @@ pub const Message = union(enum) {
/// 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,
@@ -57,6 +60,10 @@ pub const Message = union(enum) {
/// Report the color scheme
report_color_scheme: void,
pub const ReportTitleStyle = enum {
csi_21_t,
};
};
/// A surface mailbox.