mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-30 19:11:39 +00:00
rename cursor shape to mouse shape for OSC 22
This commit is contained in:
@@ -525,9 +525,9 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
||||
try self.rt_surface.setTitle(slice);
|
||||
},
|
||||
|
||||
.set_cursor_shape => |shape| {
|
||||
log.debug("changing cursor shape: {}", .{shape});
|
||||
try self.rt_surface.setCursorShape(shape);
|
||||
.set_mouse_shape => |shape| {
|
||||
log.debug("changing mouse shape: {}", .{shape});
|
||||
try self.rt_surface.setMouseShape(shape);
|
||||
},
|
||||
|
||||
.cell_size => |size| try self.setCellSize(size),
|
||||
|
||||
@@ -50,7 +50,7 @@ pub const App = struct {
|
||||
set_title: *const fn (SurfaceUD, [*]const u8) callconv(.C) void,
|
||||
|
||||
/// Called to set the cursor shape.
|
||||
set_cursor_shape: *const fn (SurfaceUD, terminal.CursorShape) callconv(.C) void,
|
||||
set_mouse_shape: *const fn (SurfaceUD, terminal.MouseShape) callconv(.C) void,
|
||||
|
||||
/// Read the clipboard value. The return value must be preserved
|
||||
/// by the host until the next call. If there is no valid clipboard
|
||||
@@ -314,8 +314,8 @@ pub const Surface = struct {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn setCursorShape(self: *Surface, shape: terminal.CursorShape) !void {
|
||||
self.app.opts.set_cursor_shape(
|
||||
pub fn setMouseShape(self: *Surface, shape: terminal.MouseShape) !void {
|
||||
self.app.opts.set_mouse_shape(
|
||||
self.opts.userdata,
|
||||
shape,
|
||||
);
|
||||
|
||||
@@ -357,7 +357,7 @@ pub const Surface = struct {
|
||||
errdefer self.* = undefined;
|
||||
|
||||
// Initialize our cursor
|
||||
try self.setCursorShape(.text);
|
||||
try self.setMouseShape(.text);
|
||||
|
||||
// Add ourselves to the list of surfaces on the app.
|
||||
try app.app.addSurface(self);
|
||||
@@ -506,7 +506,7 @@ pub const Surface = struct {
|
||||
}
|
||||
|
||||
/// Set the shape of the cursor.
|
||||
pub fn setCursorShape(self: *Surface, shape: terminal.CursorShape) !void {
|
||||
pub fn setMouseShape(self: *Surface, shape: terminal.MouseShape) !void {
|
||||
if ((comptime builtin.target.isDarwin()) and
|
||||
!internal_os.macosVersionAtLeast(13, 0, 0))
|
||||
{
|
||||
|
||||
@@ -990,9 +990,9 @@ pub const Surface = struct {
|
||||
// ));
|
||||
}
|
||||
|
||||
pub fn setCursorShape(
|
||||
pub fn setMouseShape(
|
||||
self: *Surface,
|
||||
shape: terminal.CursorShape,
|
||||
shape: terminal.MouseShape,
|
||||
) !void {
|
||||
const name: [:0]const u8 = switch (shape) {
|
||||
.default => "default",
|
||||
|
||||
@@ -17,8 +17,8 @@ pub const Message = union(enum) {
|
||||
/// of any length
|
||||
set_title: [256]u8,
|
||||
|
||||
/// Set the cursor shape.
|
||||
set_cursor_shape: terminal.CursorShape,
|
||||
/// Set the mouse shape.
|
||||
set_mouse_shape: terminal.MouseShape,
|
||||
|
||||
/// Change the cell size.
|
||||
cell_size: renderer.CellSize,
|
||||
|
||||
@@ -15,7 +15,7 @@ pub const parse_table = @import("parse_table.zig");
|
||||
pub const Charset = charsets.Charset;
|
||||
pub const CharsetSlot = charsets.Slots;
|
||||
pub const CharsetActiveSlot = charsets.ActiveSlot;
|
||||
pub const CursorShape = @import("cursor_shape.zig").CursorShape;
|
||||
pub const MouseShape = @import("mouse_shape.zig").MouseShape;
|
||||
pub const Terminal = @import("Terminal.zig");
|
||||
pub const Parser = @import("Parser.zig");
|
||||
pub const Selection = @import("Selection.zig");
|
||||
|
||||
@@ -5,7 +5,7 @@ const std = @import("std");
|
||||
/// can have a cross platform list.
|
||||
//
|
||||
// Must be kept in sync with ghostty_cursor_shape_e
|
||||
pub const CursorShape = enum(c_int) {
|
||||
pub const MouseShape = enum(c_int) {
|
||||
default,
|
||||
context_menu,
|
||||
help,
|
||||
@@ -42,12 +42,12 @@ pub const CursorShape = enum(c_int) {
|
||||
zoom_out,
|
||||
|
||||
/// Build cursor shape from string or null if its unknown.
|
||||
pub fn fromString(v: []const u8) ?CursorShape {
|
||||
pub fn fromString(v: []const u8) ?MouseShape {
|
||||
return string_map.get(v);
|
||||
}
|
||||
};
|
||||
|
||||
const string_map = std.ComptimeStringMap(CursorShape, .{
|
||||
const string_map = std.ComptimeStringMap(MouseShape, .{
|
||||
// W3C
|
||||
.{ "default", .default },
|
||||
.{ "context-menu", .context_menu },
|
||||
@@ -111,5 +111,5 @@ const string_map = std.ComptimeStringMap(CursorShape, .{
|
||||
|
||||
test "cursor shape from string" {
|
||||
const testing = std.testing;
|
||||
try testing.expectEqual(CursorShape.default, CursorShape.fromString("default").?);
|
||||
try testing.expectEqual(MouseShape.default, MouseShape.fromString("default").?);
|
||||
}
|
||||
@@ -84,11 +84,11 @@ pub const Command = union(enum) {
|
||||
value: []const u8,
|
||||
},
|
||||
|
||||
/// OSC 22. Set the cursor shape. There doesn't seem to be a standard
|
||||
/// OSC 22. Set the mouse shape. There doesn't seem to be a standard
|
||||
/// naming scheme for cursors but it looks like terminals such as Foot
|
||||
/// are moving towards using the W3C CSS cursor names. For OSC parsing,
|
||||
/// we just parse whatever string is given.
|
||||
pointer_cursor: struct {
|
||||
mouse_shape: struct {
|
||||
value: []const u8,
|
||||
},
|
||||
};
|
||||
@@ -248,10 +248,10 @@ pub const Parser = struct {
|
||||
|
||||
.@"22" => switch (c) {
|
||||
';' => {
|
||||
self.command = .{ .pointer_cursor = undefined };
|
||||
self.command = .{ .mouse_shape = undefined };
|
||||
|
||||
self.state = .string;
|
||||
self.temp_state = .{ .str = &self.command.pointer_cursor.value };
|
||||
self.temp_state = .{ .str = &self.command.mouse_shape.value };
|
||||
self.buf_start = self.buf_idx;
|
||||
},
|
||||
else => self.state = .invalid,
|
||||
@@ -672,8 +672,8 @@ test "OSC: pointer cursor" {
|
||||
for (input) |ch| p.next(ch);
|
||||
|
||||
const cmd = p.end().?;
|
||||
try testing.expect(cmd == .pointer_cursor);
|
||||
try testing.expect(std.mem.eql(u8, "pointer", cmd.pointer_cursor.value));
|
||||
try testing.expect(cmd == .mouse_shape);
|
||||
try testing.expect(std.mem.eql(u8, "pointer", cmd.mouse_shape.value));
|
||||
}
|
||||
|
||||
test "OSC: report pwd empty" {
|
||||
|
||||
@@ -9,7 +9,7 @@ const modes = @import("modes.zig");
|
||||
const osc = @import("osc.zig");
|
||||
const sgr = @import("sgr.zig");
|
||||
const trace = @import("tracy").trace;
|
||||
const CursorShape = @import("cursor_shape.zig").CursorShape;
|
||||
const MouseShape = @import("mouse_shape.zig").MouseShape;
|
||||
|
||||
const log = std.log.scoped(.stream);
|
||||
|
||||
@@ -850,14 +850,14 @@ pub fn Stream(comptime Handler: type) type {
|
||||
} else log.warn("unimplemented OSC callback: {}", .{cmd});
|
||||
},
|
||||
|
||||
.pointer_cursor => |v| {
|
||||
if (@hasDecl(T, "setCursorShape")) {
|
||||
const shape = CursorShape.fromString(v.value) orelse {
|
||||
.mouse_shape => |v| {
|
||||
if (@hasDecl(T, "setMouseShape")) {
|
||||
const shape = MouseShape.fromString(v.value) orelse {
|
||||
log.warn("unknown cursor shape: {s}", .{v.value});
|
||||
return;
|
||||
};
|
||||
|
||||
try self.handler.setCursorShape(shape);
|
||||
try self.handler.setMouseShape(shape);
|
||||
} else log.warn("unimplemented OSC callback: {}", .{cmd});
|
||||
},
|
||||
|
||||
|
||||
@@ -1682,12 +1682,12 @@ const StreamHandler = struct {
|
||||
}, .{ .forever = {} });
|
||||
}
|
||||
|
||||
pub fn setCursorShape(
|
||||
pub fn setMouseShape(
|
||||
self: *StreamHandler,
|
||||
shape: terminal.CursorShape,
|
||||
shape: terminal.MouseShape,
|
||||
) !void {
|
||||
_ = self.ev.surface_mailbox.push(.{
|
||||
.set_cursor_shape = shape,
|
||||
.set_mouse_shape = shape,
|
||||
}, .{ .forever = {} });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user