From cb2931cb276dd15fc078e87334a6ad3a37248118 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 14 Sep 2023 10:59:22 -0700 Subject: [PATCH] rename cursor shape to mouse shape for OSC 22 --- include/ghostty.h | 74 +++++++++---------- macos/Sources/Ghostty/AppState.swift | 4 +- macos/Sources/Ghostty/SurfaceView.swift | 36 ++++----- src/Surface.zig | 6 +- src/apprt/embedded.zig | 6 +- src/apprt/glfw.zig | 4 +- src/apprt/gtk.zig | 4 +- src/apprt/surface.zig | 4 +- src/terminal/main.zig | 2 +- .../{cursor_shape.zig => mouse_shape.zig} | 8 +- src/terminal/osc.zig | 12 +-- src/terminal/stream.zig | 10 +-- src/termio/Exec.zig | 6 +- 13 files changed, 88 insertions(+), 88 deletions(-) rename src/terminal/{cursor_shape.zig => mouse_shape.zig} (92%) diff --git a/include/ghostty.h b/include/ghostty.h index 5c5ba7d59..225265633 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -71,41 +71,41 @@ typedef enum { } ghostty_input_mouse_momentum_e; typedef enum { - GHOSTTY_CURSOR_SHAPE_DEFAULT, - GHOSTTY_CURSOR_SHAPE_CONTEXT_MENU, - GHOSTTY_CURSOR_SHAPE_HELP, - GHOSTTY_CURSOR_SHAPE_POINTER, - GHOSTTY_CURSOR_SHAPE_PROGRESS, - GHOSTTY_CURSOR_SHAPE_WAIT, - GHOSTTY_CURSOR_SHAPE_CELL, - GHOSTTY_CURSOR_SHAPE_CROSSHAIR, - GHOSTTY_CURSOR_SHAPE_TEXT, - GHOSTTY_CURSOR_SHAPE_VERTICAL_TEXT, - GHOSTTY_CURSOR_SHAPE_ALIAS, - GHOSTTY_CURSOR_SHAPE_COPY, - GHOSTTY_CURSOR_SHAPE_MOVE, - GHOSTTY_CURSOR_SHAPE_NO_DROP, - GHOSTTY_CURSOR_SHAPE_NOT_ALLOWED, - GHOSTTY_CURSOR_SHAPE_GRAB, - GHOSTTY_CURSOR_SHAPE_GRABBING, - GHOSTTY_CURSOR_SHAPE_ALL_SCROLL, - GHOSTTY_CURSOR_SHAPE_COL_RESIZE, - GHOSTTY_CURSOR_SHAPE_ROW_RESIZE, - GHOSTTY_CURSOR_SHAPE_N_RESIZE, - GHOSTTY_CURSOR_SHAPE_E_RESIZE, - GHOSTTY_CURSOR_SHAPE_S_RESIZE, - GHOSTTY_CURSOR_SHAPE_W_RESIZE, - GHOSTTY_CURSOR_SHAPE_NE_RESIZE, - GHOSTTY_CURSOR_SHAPE_NW_RESIZE, - GHOSTTY_CURSOR_SHAPE_SE_RESIZE, - GHOSTTY_CURSOR_SHAPE_SW_RESIZE, - GHOSTTY_CURSOR_SHAPE_EW_RESIZE, - GHOSTTY_CURSOR_SHAPE_NS_RESIZE, - GHOSTTY_CURSOR_SHAPE_NESW_RESIZE, - GHOSTTY_CURSOR_SHAPE_NWSE_RESIZE, - GHOSTTY_CURSOR_SHAPE_ZOOM_IN, - GHOSTTY_CURSOR_SHAPE_ZOOM_OUT, -} ghostty_cursor_shape_e; + GHOSTTY_MOUSE_SHAPE_DEFAULT, + GHOSTTY_MOUSE_SHAPE_CONTEXT_MENU, + GHOSTTY_MOUSE_SHAPE_HELP, + GHOSTTY_MOUSE_SHAPE_POINTER, + GHOSTTY_MOUSE_SHAPE_PROGRESS, + GHOSTTY_MOUSE_SHAPE_WAIT, + GHOSTTY_MOUSE_SHAPE_CELL, + GHOSTTY_MOUSE_SHAPE_CROSSHAIR, + GHOSTTY_MOUSE_SHAPE_TEXT, + GHOSTTY_MOUSE_SHAPE_VERTICAL_TEXT, + GHOSTTY_MOUSE_SHAPE_ALIAS, + GHOSTTY_MOUSE_SHAPE_COPY, + GHOSTTY_MOUSE_SHAPE_MOVE, + GHOSTTY_MOUSE_SHAPE_NO_DROP, + GHOSTTY_MOUSE_SHAPE_NOT_ALLOWED, + GHOSTTY_MOUSE_SHAPE_GRAB, + GHOSTTY_MOUSE_SHAPE_GRABBING, + GHOSTTY_MOUSE_SHAPE_ALL_SCROLL, + GHOSTTY_MOUSE_SHAPE_COL_RESIZE, + GHOSTTY_MOUSE_SHAPE_ROW_RESIZE, + GHOSTTY_MOUSE_SHAPE_N_RESIZE, + GHOSTTY_MOUSE_SHAPE_E_RESIZE, + GHOSTTY_MOUSE_SHAPE_S_RESIZE, + GHOSTTY_MOUSE_SHAPE_W_RESIZE, + GHOSTTY_MOUSE_SHAPE_NE_RESIZE, + GHOSTTY_MOUSE_SHAPE_NW_RESIZE, + GHOSTTY_MOUSE_SHAPE_SE_RESIZE, + GHOSTTY_MOUSE_SHAPE_SW_RESIZE, + GHOSTTY_MOUSE_SHAPE_EW_RESIZE, + GHOSTTY_MOUSE_SHAPE_NS_RESIZE, + GHOSTTY_MOUSE_SHAPE_NESW_RESIZE, + GHOSTTY_MOUSE_SHAPE_NWSE_RESIZE, + GHOSTTY_MOUSE_SHAPE_ZOOM_IN, + GHOSTTY_MOUSE_SHAPE_ZOOM_OUT, +} ghostty_mouse_shape_e; typedef enum { GHOSTTY_NON_NATIVE_FULLSCREEN_FALSE, @@ -301,7 +301,7 @@ typedef struct { typedef void (*ghostty_runtime_wakeup_cb)(void *); typedef const ghostty_config_t (*ghostty_runtime_reload_config_cb)(void *); typedef void (*ghostty_runtime_set_title_cb)(void *, const char *); -typedef void (*ghostty_runtime_set_cursor_shape_cb)(void *, ghostty_cursor_shape_e); +typedef void (*ghostty_runtime_set_mouse_shape_cb)(void *, ghostty_mouse_shape_e); typedef const char* (*ghostty_runtime_read_clipboard_cb)(void *, ghostty_clipboard_e); typedef void (*ghostty_runtime_write_clipboard_cb)(void *, const char *, ghostty_clipboard_e); typedef void (*ghostty_runtime_new_split_cb)(void *, ghostty_split_direction_e, ghostty_surface_config_s); @@ -319,7 +319,7 @@ typedef struct { ghostty_runtime_wakeup_cb wakeup_cb; ghostty_runtime_reload_config_cb reload_config_cb; ghostty_runtime_set_title_cb set_title_cb; - ghostty_runtime_set_cursor_shape_cb set_cursor_shape_cb; + ghostty_runtime_set_mouse_shape_cb set_mouse_shape_cb; ghostty_runtime_read_clipboard_cb read_clipboard_cb; ghostty_runtime_write_clipboard_cb write_clipboard_cb; ghostty_runtime_new_split_cb new_split_cb; diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index fb043991f..2743ef01f 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -72,7 +72,7 @@ extension Ghostty { wakeup_cb: { userdata in AppState.wakeup(userdata) }, reload_config_cb: { userdata in AppState.reloadConfig(userdata) }, set_title_cb: { userdata, title in AppState.setTitle(userdata, title: title) }, - set_cursor_shape_cb: { userdata, shape in AppState.setCursorShape(userdata, shape: shape) }, + set_mouse_shape_cb: { userdata, shape in AppState.setMouseShape(userdata, shape: shape) }, read_clipboard_cb: { userdata, loc in AppState.readClipboard(userdata, location: loc) }, write_clipboard_cb: { userdata, str, loc in AppState.writeClipboard(userdata, string: str, location: loc) }, new_split_cb: { userdata, direction, surfaceConfig in AppState.newSplit(userdata, direction: direction, config: surfaceConfig) }, @@ -334,7 +334,7 @@ extension Ghostty { } } - static func setCursorShape(_ userdata: UnsafeMutableRawPointer?, shape: ghostty_cursor_shape_e) { + static func setMouseShape(_ userdata: UnsafeMutableRawPointer?, shape: ghostty_mouse_shape_e) { let surfaceView = Unmanaged.fromOpaque(userdata!).takeUnretainedValue() surfaceView.setCursorShape(shape) } diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 48d932b06..94c4700f4 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -267,51 +267,51 @@ extension Ghostty { ghostty_surface_set_size(surface, UInt32(scaledSize.width), UInt32(scaledSize.height)) } - func setCursorShape(_ shape: ghostty_cursor_shape_e) { + func setCursorShape(_ shape: ghostty_mouse_shape_e) { switch (shape) { - case GHOSTTY_CURSOR_SHAPE_DEFAULT: + case GHOSTTY_MOUSE_SHAPE_DEFAULT: cursor = .arrow - case GHOSTTY_CURSOR_SHAPE_CONTEXT_MENU: + case GHOSTTY_MOUSE_SHAPE_CONTEXT_MENU: cursor = .contextualMenu - case GHOSTTY_CURSOR_SHAPE_TEXT: + case GHOSTTY_MOUSE_SHAPE_TEXT: cursor = .iBeam - case GHOSTTY_CURSOR_SHAPE_CROSSHAIR: + case GHOSTTY_MOUSE_SHAPE_CROSSHAIR: cursor = .crosshair - case GHOSTTY_CURSOR_SHAPE_GRAB: + case GHOSTTY_MOUSE_SHAPE_GRAB: cursor = .openHand - case GHOSTTY_CURSOR_SHAPE_GRABBING: + case GHOSTTY_MOUSE_SHAPE_GRABBING: cursor = .closedHand - case GHOSTTY_CURSOR_SHAPE_POINTER: + case GHOSTTY_MOUSE_SHAPE_POINTER: cursor = .pointingHand - case GHOSTTY_CURSOR_SHAPE_W_RESIZE: + case GHOSTTY_MOUSE_SHAPE_W_RESIZE: cursor = .resizeLeft - case GHOSTTY_CURSOR_SHAPE_E_RESIZE: + case GHOSTTY_MOUSE_SHAPE_E_RESIZE: cursor = .resizeRight - case GHOSTTY_CURSOR_SHAPE_N_RESIZE: + case GHOSTTY_MOUSE_SHAPE_N_RESIZE: cursor = .resizeUp - case GHOSTTY_CURSOR_SHAPE_S_RESIZE: + case GHOSTTY_MOUSE_SHAPE_S_RESIZE: cursor = .resizeDown - case GHOSTTY_CURSOR_SHAPE_NS_RESIZE: + case GHOSTTY_MOUSE_SHAPE_NS_RESIZE: cursor = .resizeUpDown - case GHOSTTY_CURSOR_SHAPE_EW_RESIZE: + case GHOSTTY_MOUSE_SHAPE_EW_RESIZE: cursor = .resizeLeftRight - case GHOSTTY_CURSOR_SHAPE_VERTICAL_TEXT: + case GHOSTTY_MOUSE_SHAPE_VERTICAL_TEXT: cursor = .iBeamCursorForVerticalLayout - case GHOSTTY_CURSOR_SHAPE_NOT_ALLOWED: + case GHOSTTY_MOUSE_SHAPE_NOT_ALLOWED: cursor = .operationNotAllowed default: @@ -433,11 +433,11 @@ extension Ghostty { override func mouseEntered(with event: NSEvent) { mouseEntered = true } - + override func mouseExited(with event: NSEvent) { mouseEntered = false } - + override func scrollWheel(with event: NSEvent) { guard let surface = self.surface else { return } diff --git a/src/Surface.zig b/src/Surface.zig index 3e957844b..eda00483f 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -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), diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 80d296c9b..54746ec50 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -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, ); diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index a56868924..2efab9539 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -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)) { diff --git a/src/apprt/gtk.zig b/src/apprt/gtk.zig index 813d8c9bf..2919c8fe6 100644 --- a/src/apprt/gtk.zig +++ b/src/apprt/gtk.zig @@ -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", diff --git a/src/apprt/surface.zig b/src/apprt/surface.zig index a0ba1a54d..1cf303888 100644 --- a/src/apprt/surface.zig +++ b/src/apprt/surface.zig @@ -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, diff --git a/src/terminal/main.zig b/src/terminal/main.zig index 32b7d6898..3de1835d9 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -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"); diff --git a/src/terminal/cursor_shape.zig b/src/terminal/mouse_shape.zig similarity index 92% rename from src/terminal/cursor_shape.zig rename to src/terminal/mouse_shape.zig index 99dfed461..cf8f42c4b 100644 --- a/src/terminal/cursor_shape.zig +++ b/src/terminal/mouse_shape.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").?); } diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index c4af80cf1..f61504daf 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -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" { diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index a7c4834da..c12bc4063 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -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}); }, diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 4365c3a6a..36deb1235 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -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 = {} }); }