mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
Merge pull request #614 from mitchellh/macos-drag-drop-2
macos: support dropping files onto terminal to paste path
This commit is contained in:
@ -388,7 +388,7 @@ void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
|
|||||||
void ghostty_surface_set_focus(ghostty_surface_t, bool);
|
void ghostty_surface_set_focus(ghostty_surface_t, bool);
|
||||||
void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
|
void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
|
||||||
void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, uint32_t, ghostty_input_mods_e);
|
void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, uint32_t, ghostty_input_mods_e);
|
||||||
void ghostty_surface_char(ghostty_surface_t, uint32_t);
|
void ghostty_surface_text(ghostty_surface_t, const char *, uintptr_t);
|
||||||
void ghostty_surface_mouse_button(ghostty_surface_t, ghostty_input_mouse_state_e, ghostty_input_mouse_button_e, ghostty_input_mods_e);
|
void ghostty_surface_mouse_button(ghostty_surface_t, ghostty_input_mouse_state_e, ghostty_input_mouse_button_e, ghostty_input_mods_e);
|
||||||
void ghostty_surface_mouse_pos(ghostty_surface_t, double, double);
|
void ghostty_surface_mouse_pos(ghostty_surface_t, double, double);
|
||||||
void ghostty_surface_mouse_scroll(ghostty_surface_t, double, double, ghostty_input_scroll_mods_t);
|
void ghostty_surface_mouse_scroll(ghostty_surface_t, double, double, ghostty_input_scroll_mods_t);
|
||||||
|
@ -129,6 +129,21 @@ extension Ghostty {
|
|||||||
// I don't know how older macOS versions behave but Ghostty only
|
// I don't know how older macOS versions behave but Ghostty only
|
||||||
// supports back to macOS 12 so its moot.
|
// supports back to macOS 12 so its moot.
|
||||||
}
|
}
|
||||||
|
.onDrop(of: [.fileURL], isTargeted: nil) { providers in
|
||||||
|
providers.forEach { provider in
|
||||||
|
_ = provider.loadObject(ofClass: URL.self) { url, _ in
|
||||||
|
guard let url = url else { return }
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
surfaceView.insertText(
|
||||||
|
url.path,
|
||||||
|
replacementRange: NSMakeRange(0, 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.ghosttySurfaceView(surfaceView)
|
.ghosttySurfaceView(surfaceView)
|
||||||
|
|
||||||
@ -826,8 +841,9 @@ extension Ghostty {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for codepoint in chars.unicodeScalars {
|
let len = chars.utf8CString.count
|
||||||
ghostty_surface_char(surface, codepoint.value)
|
chars.withCString { ptr in
|
||||||
|
ghostty_surface_text(surface, ptr, UInt(len))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1020,6 +1020,15 @@ pub fn keyCallback(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sends text as-is to the terminal without triggering any keyboard
|
||||||
|
/// protocol. This will treat the input text as if it was pasted
|
||||||
|
/// from the clipboard so the same logic will be applied. Namely,
|
||||||
|
/// if bracketed mode is on this will do a bracketed paste. Otherwise,
|
||||||
|
/// this will filter newlines to '\r'.
|
||||||
|
pub fn textCallback(self: *Surface, text: []const u8) !void {
|
||||||
|
try self.completeClipboardPaste(text);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn focusCallback(self: *Surface, focused: bool) !void {
|
pub fn focusCallback(self: *Surface, focused: bool) !void {
|
||||||
// Notify our render thread of the new state
|
// Notify our render thread of the new state
|
||||||
_ = self.renderer_thread.mailbox.push(.{
|
_ = self.renderer_thread.mailbox.push(.{
|
||||||
|
@ -678,27 +678,8 @@ pub const Surface = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn charCallback(self: *Surface, cp_: u32) void {
|
pub fn textCallback(self: *Surface, text: []const u8) void {
|
||||||
const cp = std.math.cast(u21, cp_) orelse return;
|
_ = self.core_surface.textCallback(text) catch |err| {
|
||||||
var buf: [4]u8 = undefined;
|
|
||||||
const len = std.unicode.utf8Encode(cp, &buf) catch |err| {
|
|
||||||
log.err("error encoding codepoint={} err={}", .{ cp, err });
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// For a char callback we just construct a key event with invalid
|
|
||||||
// keys but with text. This should result in the text being sent
|
|
||||||
// as-is.
|
|
||||||
_ = self.core_surface.keyCallback(.{
|
|
||||||
.action = .press,
|
|
||||||
.key = .invalid,
|
|
||||||
.physical_key = .invalid,
|
|
||||||
.mods = .{},
|
|
||||||
.consumed_mods = .{},
|
|
||||||
.composing = false,
|
|
||||||
.utf8 = buf[0..len],
|
|
||||||
.unshifted_codepoint = 0,
|
|
||||||
}) catch |err| {
|
|
||||||
log.err("error in key callback err={}", .{err});
|
log.err("error in key callback err={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -958,11 +939,15 @@ pub const CAPI = struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send for a unicode character. This is used for IME input. This
|
/// Send raw text to the terminal. This is treated like a paste
|
||||||
/// should only be sent for characters that are not the result of
|
/// so this isn't useful for sending escape sequences. For that,
|
||||||
/// key events.
|
/// individual key input should be used.
|
||||||
export fn ghostty_surface_char(surface: *Surface, codepoint: u32) void {
|
export fn ghostty_surface_text(
|
||||||
surface.charCallback(codepoint);
|
surface: *Surface,
|
||||||
|
ptr: [*]const u8,
|
||||||
|
len: usize,
|
||||||
|
) void {
|
||||||
|
surface.textCallback(ptr[0..len]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tell the surface that it needs to schedule a render
|
/// Tell the surface that it needs to schedule a render
|
||||||
|
Reference in New Issue
Block a user